Test that we can encode empty bytes fields.
(t *testing.T)
| 834 | |
| 835 | // Test that we can encode empty bytes fields. |
| 836 | func 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. |
nothing calls this directly
no test coverage detected