MCPcopy
hub / github.com/golang/protobuf / TestSkippingUnrecognizedFields

Function TestSkippingUnrecognizedFields

proto/proto_test.go:889–934  ·  view source on GitHub ↗

All required fields set, defaults provided, all repeated fields given two values.

(t *testing.T)

Source from the content-addressed store, hash-verified

887
888// All required fields set, defaults provided, all repeated fields given two values.
889func TestSkippingUnrecognizedFields(t *testing.T) {
890 o := new(proto.Buffer)
891 pb := initGoTestField()
892
893 // Marshal it normally.
894 o.Marshal(pb)
895
896 // Now new a GoSkipTest record.
897 skip := &pb2.GoSkipTest{
898 SkipInt32: proto.Int32(32),
899 SkipFixed32: proto.Uint32(3232),
900 SkipFixed64: proto.Uint64(6464),
901 SkipString: proto.String("skipper"),
902 Skipgroup: &pb2.GoSkipTest_SkipGroup{
903 GroupInt32: proto.Int32(75),
904 GroupString: proto.String("wxyz"),
905 },
906 }
907
908 // Marshal it into same buffer.
909 o.Marshal(skip)
910
911 pbd := new(pb2.GoTestField)
912 o.Unmarshal(pbd)
913
914 // The __unrecognized field should be a marshaling of GoSkipTest
915 skipd := new(pb2.GoSkipTest)
916
917 o.SetBuf(pbd.XXX_unrecognized)
918 o.Unmarshal(skipd)
919
920 switch {
921 case *skipd.SkipInt32 != *skip.SkipInt32:
922 t.Error("skip int32", skipd.SkipInt32)
923 case *skipd.SkipFixed32 != *skip.SkipFixed32:
924 t.Error("skip fixed32", skipd.SkipFixed32)
925 case *skipd.SkipFixed64 != *skip.SkipFixed64:
926 t.Error("skip fixed64", skipd.SkipFixed64)
927 case *skipd.SkipString != *skip.SkipString:
928 t.Error("skip string", *skipd.SkipString)
929 case *skipd.Skipgroup.GroupInt32 != *skip.Skipgroup.GroupInt32:
930 t.Error("skip group int32", skipd.Skipgroup.GroupInt32)
931 case *skipd.Skipgroup.GroupString != *skip.Skipgroup.GroupString:
932 t.Error("skip group string", *skipd.Skipgroup.GroupString)
933 }
934}
935
936// Check that unrecognized fields of a submessage are preserved.
937func TestSubmessageUnrecognizedFields(t *testing.T) {

Callers

nothing calls this directly

Calls 9

Int32Function · 0.92
Uint32Function · 0.92
Uint64Function · 0.92
StringFunction · 0.92
initGoTestFieldFunction · 0.85
SetBufMethod · 0.80
MarshalMethod · 0.65
UnmarshalMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected