blob: 9447df63812c5a210951dc113a93e9358bb5c067 [file] [log] [blame]
Joe Tsaief75bec2019-06-20 00:03:14 -07001// 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
5package proto_test
6
7import (
8 "testing"
9
10 "google.golang.org/protobuf/internal/scalar"
11 "google.golang.org/protobuf/proto"
12
13 testpb "google.golang.org/protobuf/internal/testprotos/test"
14)
15
16func TestReset(t *testing.T) {
17 m := &testpb.TestAllTypes{
18 OptionalSfixed64: scalar.Int64(5),
19 RepeatedInt32: []int32{},
20 RepeatedFloat: []float32{1.234, 5.678},
21 MapFixed64Fixed64: map[uint64]uint64{5: 7},
22 MapStringString: map[string]string{},
23 OptionalForeignMessage: &testpb.ForeignMessage{},
24 OneofField: (*testpb.TestAllTypes_OneofUint32)(nil),
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 }
51
52 if got := m.ProtoReflect().Len(); got != 0 {
53 t.Errorf("m.ProtoReflect().Len() = %d, want 0", got)
54 }
55 if got := m.ProtoReflect().GetUnknown(); got != nil {
56 t.Errorf("m.ProtoReflect().GetUnknown() = %d, want nil", got)
57 }
58}