blob: 11f1957518a6ee26ead274620cc02f00e9b9942d [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),
Joe Tsai9b22b932019-08-08 19:23:32 -070024 OneofOptional: (*testpb.TestAllTypes_OneofOptionalUint32)(nil),
Joe Tsaief75bec2019-06-20 00:03:14 -070025 }
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 Tsai9b22b932019-08-08 19:23:32 -070051 if m.OneofOptional != nil {
52 t.Errorf("m.OneofOptional = %p, want nil", m.OneofOptional)
53 }
Joe Tsaief75bec2019-06-20 00:03:14 -070054
Joe Tsaief75bec2019-06-20 00:03:14 -070055 if got := m.ProtoReflect().GetUnknown(); got != nil {
56 t.Errorf("m.ProtoReflect().GetUnknown() = %d, want nil", got)
57 }
58}