Check that an int32 field can be upgraded to an int64 field.
(t *testing.T)
| 984 | |
| 985 | // Check that an int32 field can be upgraded to an int64 field. |
| 986 | func TestNegativeInt32(t *testing.T) { |
| 987 | om := &pb2.OldMessage{ |
| 988 | Num: proto.Int32(-1), |
| 989 | } |
| 990 | b, err := proto.Marshal(om) |
| 991 | if err != nil { |
| 992 | t.Fatalf("Marshal of OldMessage: %v", err) |
| 993 | } |
| 994 | |
| 995 | // Check the size. It should be 11 bytes; |
| 996 | // 1 for the field/wire type, and 10 for the negative number. |
| 997 | if len(b) != 11 { |
| 998 | t.Errorf("%v marshaled as %q, wanted 11 bytes", om, b) |
| 999 | } |
| 1000 | |
| 1001 | // Unmarshal into a NewMessage. |
| 1002 | nm := new(pb2.NewMessage) |
| 1003 | if err := proto.Unmarshal(b, nm); err != nil { |
| 1004 | t.Fatalf("Unmarshal to NewMessage: %v", err) |
| 1005 | } |
| 1006 | want := &pb2.NewMessage{ |
| 1007 | Num: proto.Int64(-1), |
| 1008 | } |
| 1009 | if !proto.Equal(nm, want) { |
| 1010 | t.Errorf("nm = %v, want %v", nm, want) |
| 1011 | } |
| 1012 | } |
| 1013 | |
| 1014 | // Check that we can grow an array (repeated field) to have many elements. |
| 1015 | // This test doesn't depend only on our encoding; for variety, it makes sure |