reset_test.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. package proto_test
  5. import (
  6. "testing"
  7. "google.golang.org/protobuf/proto"
  8. testpb "google.golang.org/protobuf/internal/testprotos/test"
  9. )
  10. func TestReset(t *testing.T) {
  11. m := &testpb.TestAllTypes{
  12. OptionalSfixed64: proto.Int64(5),
  13. RepeatedInt32: []int32{},
  14. RepeatedFloat: []float32{1.234, 5.678},
  15. MapFixed64Fixed64: map[uint64]uint64{5: 7},
  16. MapStringString: map[string]string{},
  17. OptionalForeignMessage: &testpb.ForeignMessage{},
  18. OneofField: (*testpb.TestAllTypes_OneofUint32)(nil),
  19. OneofOptional: (*testpb.TestAllTypes_OneofOptionalUint32)(nil),
  20. }
  21. m.ProtoReflect().SetUnknown([]byte{})
  22. proto.Reset(m)
  23. if m.OptionalSfixed64 != nil {
  24. t.Errorf("m.OptionalSfixed64 = %p, want nil", m.OptionalSfixed64)
  25. }
  26. if m.RepeatedInt32 != nil {
  27. t.Errorf("m.RepeatedInt32 = %p, want nil", m.RepeatedInt32)
  28. }
  29. if m.RepeatedFloat != nil {
  30. t.Errorf("m.RepeatedFloat = %p, want nil", m.RepeatedFloat)
  31. }
  32. if m.MapFixed64Fixed64 != nil {
  33. t.Errorf("m.MapFixed64Fixed64 = %p, want nil", m.MapFixed64Fixed64)
  34. }
  35. if m.MapStringString != nil {
  36. t.Errorf("m.MapStringString = %p, want nil", m.MapStringString)
  37. }
  38. if m.OptionalForeignMessage != nil {
  39. t.Errorf("m.OptionalForeignMessage = %p, want nil", m.OptionalForeignMessage)
  40. }
  41. if m.OneofField != nil {
  42. t.Errorf("m.OneofField = %p, want nil", m.OneofField)
  43. }
  44. if m.OneofOptional != nil {
  45. t.Errorf("m.OneofOptional = %p, want nil", m.OneofOptional)
  46. }
  47. if got := m.ProtoReflect().GetUnknown(); got != nil {
  48. t.Errorf("m.ProtoReflect().GetUnknown() = %d, want nil", got)
  49. }
  50. }