forked from apache/cassandra-gocql-driver
-
Notifications
You must be signed in to change notification settings - Fork 57
/
marshal_3_smallint_corrupt_test.go
107 lines (91 loc) · 3.09 KB
/
marshal_3_smallint_corrupt_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package gocql_test
import (
"math/big"
"testing"
"github.com/gocql/gocql"
"github.com/gocql/gocql/internal/tests/serialization"
"github.com/gocql/gocql/internal/tests/serialization/mod"
"github.com/gocql/gocql/marshal/smallint"
)
func TestMarshalSmallintCorrupt(t *testing.T) {
type testSuite struct {
name string
marshal func(interface{}) ([]byte, error)
unmarshal func(bytes []byte, i interface{}) error
}
tType := gocql.NewNativeType(4, gocql.TypeSmallInt, "")
testSuites := [2]testSuite{
{
name: "serialization.smallint",
marshal: smallint.Marshal,
unmarshal: smallint.Unmarshal,
},
{
name: "glob",
marshal: func(i interface{}) ([]byte, error) {
return gocql.Marshal(tType, i)
},
unmarshal: func(bytes []byte, i interface{}) error {
return gocql.Unmarshal(tType, bytes, i)
},
},
}
for _, tSuite := range testSuites {
marshal := tSuite.marshal
unmarshal := tSuite.unmarshal
t.Run(tSuite.name, func(t *testing.T) {
serialization.NegativeMarshalSet{
Values: mod.Values{
int32(32768), int64(32768), int(32768),
"32768", *big.NewInt(32768),
int32(-32769), int64(-32769), int(-32769),
"-32769", *big.NewInt(-32769),
uint32(65536), uint64(65536), uint(65536),
}.AddVariants(mod.All...),
}.Run("big_vals", t, marshal)
serialization.NegativeMarshalSet{
Values: mod.Values{"1s2", "1s", "-1s", ".1", ",1", "0.1", "0,1"}.AddVariants(mod.All...),
}.Run("corrupt_vals", t, marshal)
serialization.NegativeUnmarshalSet{
Data: []byte("\x80\x00\x00"),
Values: mod.Values{
int8(0), int16(0), int32(0), int64(0), int(0),
uint8(0), uint16(0), uint32(0), uint64(0), uint(0),
"", *big.NewInt(0),
}.AddVariants(mod.All...),
}.Run("big_data", t, unmarshal)
serialization.NegativeUnmarshalSet{
Data: []byte("\x80"),
Values: mod.Values{
int8(0), int16(0), int32(0), int64(0), int(0),
uint8(0), uint16(0), uint32(0), uint64(0), uint(0),
"", *big.NewInt(0),
}.AddVariants(mod.All...),
}.Run("small_data", t, unmarshal)
serialization.NegativeUnmarshalSet{
Data: []byte("\x00\x80"),
Values: mod.Values{int8(0)}.AddVariants(mod.All...),
}.Run("small_type_int8_128", t, unmarshal)
serialization.NegativeUnmarshalSet{
Data: []byte("\x7f\xff"),
Values: mod.Values{int8(0)}.AddVariants(mod.All...),
}.Run("small_type_int8_32767", t, unmarshal)
serialization.NegativeUnmarshalSet{
Data: []byte("\xff\x7f"),
Values: mod.Values{int8(0)}.AddVariants(mod.All...),
}.Run("small_type_int8_-129", t, unmarshal)
serialization.NegativeUnmarshalSet{
Data: []byte("\x7f\xff"),
Values: mod.Values{int8(0)}.AddVariants(mod.All...),
}.Run("small_type_int8_-32768", t, unmarshal)
serialization.NegativeUnmarshalSet{
Data: []byte("\x01\x00"),
Values: mod.Values{uint8(0)}.AddVariants(mod.All...),
}.Run("small_type_uint_256", t, unmarshal)
serialization.NegativeUnmarshalSet{
Data: []byte("\xff\xff"),
Values: mod.Values{uint8(0)}.AddVariants(mod.All...),
}.Run("small_type_uint_65535", t, unmarshal)
})
}
}