(t *testing.T, mt protoreflect.MessageType)
| 41 | } |
| 42 | |
| 43 | func testMethods(t *testing.T, mt protoreflect.MessageType) { |
| 44 | m1 := mt.New() |
| 45 | populated := testPopulateMessage(t, m1, 2) |
| 46 | b, err := proto.Marshal(m1.Interface()) |
| 47 | if err != nil { |
| 48 | t.Errorf("proto.Marshal error: %v", err) |
| 49 | } |
| 50 | if populated && len(b) == 0 { |
| 51 | t.Errorf("len(proto.Marshal) = 0, want >0") |
| 52 | } |
| 53 | m2 := mt.New() |
| 54 | if err := proto.Unmarshal(b, m2.Interface()); err != nil { |
| 55 | t.Errorf("proto.Unmarshal error: %v", err) |
| 56 | } |
| 57 | if diff := cmp.Diff(m1.Interface(), m2.Interface(), protocmp.Transform()); diff != "" { |
| 58 | t.Errorf("message mismatch:\n%v", diff) |
| 59 | } |
| 60 | proto.Reset(m2.Interface()) |
| 61 | testEmptyMessage(t, m2, true) |
| 62 | proto.Merge(m2.Interface(), m1.Interface()) |
| 63 | if diff := cmp.Diff(m1.Interface(), m2.Interface(), protocmp.Transform()); diff != "" { |
| 64 | t.Errorf("message mismatch:\n%v", diff) |
| 65 | } |
| 66 | proto.Merge(mt.New().Interface(), mt.Zero().Interface()) |
| 67 | } |
| 68 | |
| 69 | func testEmptyMessage(t *testing.T, m protoreflect.Message, wantValid bool) { |
| 70 | numFields := func(m protoreflect.Message) (n int) { |
no test coverage detected