• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
5package proto_test
6
7import (
8	"testing"
9
10	"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{
17		OptionalSfixed64:       proto.Int64(5),
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),
24		OneofOptional:          (*testpb.TestAllTypes_OneofOptionalUint32)(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	if m.OneofOptional != nil {
52		t.Errorf("m.OneofOptional = %p, want nil", m.OneofOptional)
53	}
54
55	if got := m.ProtoReflect().GetUnknown(); got != nil {
56		t.Errorf("m.ProtoReflect().GetUnknown() = %d, want nil", got)
57	}
58}
59