blob: 0f2f8cd9078ccf930c1a1dac9c2b11f696646a2c [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
Joe Tsaief75bec2019-06-20 00:03:14 -070010 "google.golang.org/protobuf/proto"
11
12 testpb "google.golang.org/protobuf/internal/testprotos/test"
13)
14
15func TestReset(t *testing.T) {
16 m := &testpb.TestAllTypes{
Damien Neila8a2cea2019-07-10 16:17:16 -070017 OptionalSfixed64: proto.Int64(5),
Joe Tsaief75bec2019-06-20 00:03:14 -070018 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),
24 }
25 m.ProtoReflect().SetUnknown([]byte{})
26
27 proto.Reset(m)
28
29 if m.OptionalSfixed64 != nil {
30 t.Errorf("m.OptionalSfixed64 = %p, want nil", m.OptionalSfixed64)
31 }
32 if m.RepeatedInt32 != nil {
33 t.Errorf("m.RepeatedInt32 = %p, want nil", m.RepeatedInt32)
34 }
35 if m.RepeatedFloat != nil {
36 t.Errorf("m.RepeatedFloat = %p, want nil", m.RepeatedFloat)
37 }
38 if m.MapFixed64Fixed64 != nil {
39 t.Errorf("m.MapFixed64Fixed64 = %p, want nil", m.MapFixed64Fixed64)
40 }
41 if m.MapStringString != nil {
42 t.Errorf("m.MapStringString = %p, want nil", m.MapStringString)
43 }
44 if m.OptionalForeignMessage != nil {
45 t.Errorf("m.OptionalForeignMessage = %p, want nil", m.OptionalForeignMessage)
46 }
47 if m.OneofField != nil {
48 t.Errorf("m.OneofField = %p, want nil", m.OneofField)
49 }
50
Joe Tsaief75bec2019-06-20 00:03:14 -070051 if got := m.ProtoReflect().GetUnknown(); got != nil {
52 t.Errorf("m.ProtoReflect().GetUnknown() = %d, want nil", got)
53 }
54}