reset_test.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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/internal/scalar"
  8. "google.golang.org/protobuf/proto"
  9. testpb "google.golang.org/protobuf/internal/testprotos/test"
  10. )
  11. func TestReset(t *testing.T) {
  12. m := &testpb.TestAllTypes{
  13. OptionalSfixed64: scalar.Int64(5),
  14. RepeatedInt32: []int32{},
  15. RepeatedFloat: []float32{1.234, 5.678},
  16. MapFixed64Fixed64: map[uint64]uint64{5: 7},
  17. MapStringString: map[string]string{},
  18. OptionalForeignMessage: &testpb.ForeignMessage{},
  19. OneofField: (*testpb.TestAllTypes_OneofUint32)(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 got := m.ProtoReflect().GetUnknown(); got != nil {
  45. t.Errorf("m.ProtoReflect().GetUnknown() = %d, want nil", got)
  46. }
  47. }