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

Function TestEncodeDecodeBytes1

proto/proto_test.go:836–863  ·  view source on GitHub ↗

Test that we can encode empty bytes fields.

(t *testing.T)

Source from the content-addressed store, hash-verified

834
835// Test that we can encode empty bytes fields.
836func TestEncodeDecodeBytes1(t *testing.T) {
837 pb := initGoTest(false)
838
839 // Create our bytes
840 pb.F_BytesRequired = []byte{}
841 pb.F_BytesRepeated = [][]byte{{}}
842 pb.F_BytesOptional = []byte{}
843
844 d, err := proto.Marshal(pb)
845 if err != nil {
846 t.Error(err)
847 }
848
849 pbd := new(pb2.GoTest)
850 if err := proto.Unmarshal(d, pbd); err != nil {
851 t.Error(err)
852 }
853
854 if pbd.F_BytesRequired == nil || len(pbd.F_BytesRequired) != 0 {
855 t.Error("required empty bytes field is incorrect")
856 }
857 if pbd.F_BytesRepeated == nil || len(pbd.F_BytesRepeated) == 1 && pbd.F_BytesRepeated[0] == nil {
858 t.Error("repeated empty bytes field is incorrect")
859 }
860 if pbd.F_BytesOptional == nil || len(pbd.F_BytesOptional) != 0 {
861 t.Error("optional empty bytes field is incorrect")
862 }
863}
864
865// Test that we encode nil-valued fields of a repeated bytes field correctly.
866// Since entries in a repeated field cannot be nil, nil must mean empty value.

Callers

nothing calls this directly

Calls 4

MarshalFunction · 0.92
UnmarshalFunction · 0.92
initGoTestFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected