forked from rokath/tcobs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
help_test.go
121 lines (91 loc) · 4.85 KB
/
help_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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package tcobs_test
const testBufferSize = 64 * 1024
type testTable []struct {
dec []byte
enc []byte
}
var testData = testTable{
{[]byte{0x02, 0x01, 0xff, 0x01, 0x01, 0x02, 0x02, 0x01, 0xff, 0x01, 0x01, 0x01, 0x01, 0x01},
[]byte{0x02, 0x01, 0xff, 0x01, 0x01, 0x02, 0x02, 0x01, 0xff, 0x01, 0xaa, 0x18}},
// No10, R4o0
{[]byte{0x01, 0x02, 0x00, 0x00, 0xff, 0x02, 0xff, 0x01, 0x00, 0x00, 0x00, 0x02, 0x01, 0xff, 0x01, 0x01, 0x02, 0x02, 0x01, 0xff, 0x01, 0x01, 0x01, 0x01, 0x01},
[]byte{0x01, 0x02, 0x42, 0xff, 0x02, 0xff, 0x01, 0x64, 0x02, 0x01, 0xff, 0x01, 0x01, 0x02, 0x02, 0x01, 0xff, 0x01, 0xaa, 0x18}},
// Z2o2 Z3o4 No10 R4o0
{[]byte{}, []byte{}},
{[]byte{0}, []byte{0x20}},
{[]byte{0, 0xAA}, []byte{0x20, 0xAA, 0xA1}},
{[]byte{0, 0xFF}, []byte{0x20, 0xFF, 0xA1}},
{[]byte{0, 0}, []byte{0x40}},
{[]byte{0, 0, 0xAA}, []byte{0x40, 0xAA, 0xA1}},
{[]byte{0, 0, 0xFF}, []byte{0x40, 0xFF, 0xA1}},
{[]byte{0, 0, 0}, []byte{0x60}},
{[]byte{0, 0, 0, 0xAA}, []byte{0x60, 0xAA, 0xA1}},
{[]byte{0, 0, 0, 0xFF}, []byte{0x60, 0xFF, 0xA1}},
{[]byte{0, 0, 0, 0}, []byte{0x60, 0x20}},
{[]byte{0, 0, 0, 0, 0}, []byte{0x60, 0x40}},
{[]byte{0, 0, 0, 0, 0, 0xFF}, []byte{0x60, 0x40, 0xFF, 0xA1}},
{[]byte{0, 0, 0, 0, 0, 0xAA}, []byte{0x60, 0x40, 0xAA, 0xA1}},
{[]byte{0, 0, 0, 0, 0, 0, 0xFF}, []byte{0x60, 0x60, 0xFF, 0xA1}},
{[]byte{0, 0, 0, 0, 0, 0xAA, 0xFF, 0xFF, 0xAA}, []byte{0x60, 0x40, 0xAA, 0xC1, 0xAA, 0xA1}},
{[]byte{0xAA, 0xAA}, []byte{0xAA, 0xAA, 0xA2}},
{[]byte{0xAA, 0xBB}, []byte{0xAA, 0xBB, 0xA2}},
{[]byte{0xFF}, []byte{0xFF, 0xA1}},
{[]byte{0xFF, 0x00}, []byte{0xFF, 0x21}},
{[]byte{0xFF, 0xAA}, []byte{0xFF, 0xAA, 0xA2}},
{[]byte{0xFF, 0xFF}, []byte{0xC0}},
{[]byte{0xFF, 0xFF, 0x00}, []byte{0xC0, 0x20}},
{[]byte{0xFF, 0xFF, 0xAA}, []byte{0xC0, 0xAA, 0xA1}},
{[]byte{0xFF, 0xFF, 0xFF}, []byte{0xE0}},
{[]byte{0xFF, 0xFF, 0xFF, 0x00}, []byte{0xE0, 0x20}},
{[]byte{0xFF, 0xFF, 0xFF, 0xAA}, []byte{0xE0, 0xAA, 0xA1}},
{[]byte{0xFF, 0xFF, 0xFF, 0xFF}, []byte{0x80}},
{[]byte{0xFF, 0xFF, 0xFF, 0xFF, 0x00}, []byte{0x80, 0x20}},
{[]byte{0xFF, 0xFF, 0xFF, 0xFF, 0xAA}, []byte{0x80, 0xAA, 0xA1}},
{[]byte{0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, []byte{0x80, 0xFF, 0xA1}},
{[]byte{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00}, []byte{0x80, 0xFF, 0x21}},
{[]byte{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xAA}, []byte{0x80, 0xFF, 0xAA, 0xA2}},
{[]byte{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, []byte{0x80, 0xC0}},
{[]byte{0xFF, 0xFF, 0xFF, 0xFF, 0xAA, 0xFF, 0xFF}, []byte{0x80, 0xAA, 0xC1}},
{[]byte{0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF}, []byte{0x80, 0x20, 0xC0}},
{[]byte{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xAA, 0xFF, 0xFF}, []byte{0x80, 0xFF, 0xAA, 0xC2}},
{[]byte{0xAA}, []byte{0xAA, 0xA1}},
{[]byte{0xAA, 0xAA}, []byte{0xAA, 0xAA, 0xA2}},
{[]byte{0xAA, 0xAA, 0xAA}, []byte{0xAA, 0x09}}, // AA R2
{[]byte{0xAA, 0xAA, 0xAA, 0xAA}, []byte{0xAA, 0x11}}, // AA R3
{[]byte{0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, []byte{0xAA, 0x19}}, // AA R4
{[]byte{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, []byte{0xAA, 0x19, 0xAA, 0xA1}},
{[]byte{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, []byte{0xAA, 0x19, 0xAA, 0xAA, 0xA2}},
{[]byte{0xAA, 0x00}, []byte{0xAA, 0x21}},
{[]byte{0xAA, 0xAA, 0x00}, []byte{0xAA, 0xAA, 0x22}},
{[]byte{0, 2, 2, 2, 0, 1, 0, 255, 255, 255, 1, 2, 1, 0, 255, 1, 2, 0, 0, 1, 2, 1, 255, 1, 2, 2, 2, 255, 1, 2, 0, 255, 2, 2, 0},
[]byte{0x20, 0x2, 0x9, 0x20, 0x1, 0x21, 0xe0, 0x1, 0x2, 0x1, 0x23, 0xff, 0x1, 0x2, 0x43, 0x1, 0x2, 0x1, 0xff, 0x1, 0x2, 0xe, 0xff, 0x1, 0x2, 0x23, 0xff, 0x2, 0x2, 0x23}},
{[]byte{0xFF, 0x02, 0x02, 0x00}, []byte{0xFF, 0x02, 0x02, 0x23}},
{[]byte{0xFF, 0x02, 0x02, 0x00, 0xFF}, []byte{0xFF, 0x02, 0x02, 0x23, 0xFF, 0xA1}},
{[]byte{0, 2, 2, 2, 0, 1, 0, 255, 255, 255, 1, 2, 1, 0, 255, 1, 2, 0, 0, 1, 2, 1, 255, 1, 2, 2, 2, 255, 1, 2, 0, 255, 2, 2, 0, 255},
[]byte{0x20, 0x2, 0x9, 0x20, 0x1, 0x21, 0xe0, 0x1, 0x2, 0x1, 0x23, 0xff, 0x1, 0x2, 0x43, 0x1, 0x2, 0x1, 0xff, 0x1, 0x2, 0xe, 0xff, 0x1, 0x2, 0x23, 0xff, 0x2, 0x2, 0x23, 0xFF, 0xA1}},
}
// createEncodedStream concatenates all trestData enc sequences with 0-delimiters into one byte slice.
func createEncodedStream() []byte {
enc := make([]byte, 0, testBufferSize)
for _, k := range testData {
enc = append(enc, k.enc...)
enc = append(enc, 0)
}
return enc
}
// createDecodedStream concatenates all trestData dec sequences with 0-delimiters into one byte slice.
func createDecodedStream() []byte {
dec := make([]byte, 0, testBufferSize)
for _, k := range testData {
dec = append(dec, k.dec...)
}
return dec
}
// // printAsGoCode prints x for easy copy & paste into test table.
// func printAsGoCode(x []byte) {
// fmt.Print("[]byte{")
// for _, b := range x {
// fmt.Printf("0x%02x, ", b)
// }
// fmt.Println("}")
// }