Joe Tsai | ef75bec | 2019-06-20 00:03:14 -0700 | [diff] [blame] | 1 | // Copyright 2019 The Go Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style. |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | package proto_test |
| 6 | |
| 7 | import ( |
| 8 | "testing" |
| 9 | |
Joe Tsai | ef75bec | 2019-06-20 00:03:14 -0700 | [diff] [blame] | 10 | "google.golang.org/protobuf/proto" |
| 11 | |
| 12 | testpb "google.golang.org/protobuf/internal/testprotos/test" |
| 13 | ) |
| 14 | |
| 15 | func TestReset(t *testing.T) { |
| 16 | m := &testpb.TestAllTypes{ |
Damien Neil | a8a2cea | 2019-07-10 16:17:16 -0700 | [diff] [blame] | 17 | OptionalSfixed64: proto.Int64(5), |
Joe Tsai | ef75bec | 2019-06-20 00:03:14 -0700 | [diff] [blame] | 18 | RepeatedInt32: []int32{}, |
| 19 | RepeatedFloat: []float32{1.234, 5.678}, |
| 20 | MapFixed64Fixed64: map[uint64]uint64{5: 7}, |
| 21 | MapStringString: map[string]string{}, |
| 22 | OptionalForeignMessage: &testpb.ForeignMessage{}, |
| 23 | OneofField: (*testpb.TestAllTypes_OneofUint32)(nil), |
Joe Tsai | 9b22b93 | 2019-08-08 19:23:32 -0700 | [diff] [blame] | 24 | OneofOptional: (*testpb.TestAllTypes_OneofOptionalUint32)(nil), |
Joe Tsai | ef75bec | 2019-06-20 00:03:14 -0700 | [diff] [blame] | 25 | } |
| 26 | m.ProtoReflect().SetUnknown([]byte{}) |
| 27 | |
| 28 | proto.Reset(m) |
| 29 | |
| 30 | if m.OptionalSfixed64 != nil { |
| 31 | t.Errorf("m.OptionalSfixed64 = %p, want nil", m.OptionalSfixed64) |
| 32 | } |
| 33 | if m.RepeatedInt32 != nil { |
| 34 | t.Errorf("m.RepeatedInt32 = %p, want nil", m.RepeatedInt32) |
| 35 | } |
| 36 | if m.RepeatedFloat != nil { |
| 37 | t.Errorf("m.RepeatedFloat = %p, want nil", m.RepeatedFloat) |
| 38 | } |
| 39 | if m.MapFixed64Fixed64 != nil { |
| 40 | t.Errorf("m.MapFixed64Fixed64 = %p, want nil", m.MapFixed64Fixed64) |
| 41 | } |
| 42 | if m.MapStringString != nil { |
| 43 | t.Errorf("m.MapStringString = %p, want nil", m.MapStringString) |
| 44 | } |
| 45 | if m.OptionalForeignMessage != nil { |
| 46 | t.Errorf("m.OptionalForeignMessage = %p, want nil", m.OptionalForeignMessage) |
| 47 | } |
| 48 | if m.OneofField != nil { |
| 49 | t.Errorf("m.OneofField = %p, want nil", m.OneofField) |
| 50 | } |
Joe Tsai | 9b22b93 | 2019-08-08 19:23:32 -0700 | [diff] [blame] | 51 | if m.OneofOptional != nil { |
| 52 | t.Errorf("m.OneofOptional = %p, want nil", m.OneofOptional) |
| 53 | } |
Joe Tsai | ef75bec | 2019-06-20 00:03:14 -0700 | [diff] [blame] | 54 | |
Joe Tsai | ef75bec | 2019-06-20 00:03:14 -0700 | [diff] [blame] | 55 | if got := m.ProtoReflect().GetUnknown(); got != nil { |
| 56 | t.Errorf("m.ProtoReflect().GetUnknown() = %d, want nil", got) |
| 57 | } |
| 58 | } |