message-size-increase #3
137
tape/skim_test.go
Normal file
137
tape/skim_test.go
Normal file
@ -0,0 +1,137 @@
|
||||
package tape
|
||||
|
||||
import "bytes"
|
||||
import "testing"
|
||||
|
||||
func TestSkimInteger(test *testing.T) {
|
||||
data := []byte {
|
||||
0x12, 0x45, 0x23, 0xF9,
|
||||
}
|
||||
mainDataLen := len(data)
|
||||
// extra junk
|
||||
data = append(data, 0x00, 0x01, 0x02, 0x03,)
|
||||
|
||||
n, err := Skim(NewDecoder(bytes.NewBuffer(data)), LI.WithCN(3))
|
||||
if err != nil {
|
||||
test.Fatal(err)
|
||||
}
|
||||
if got, correct := n, mainDataLen; got != correct {
|
||||
test.Fatalf("n not equal: %d != %d", got, correct)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSkimArray(test *testing.T) {
|
||||
data := []byte {
|
||||
2, byte(LI.WithCN(1)),
|
||||
0xBE, 0xE5, 0x77, 0x77,
|
||||
}
|
||||
mainDataLen := len(data)
|
||||
// extra junk
|
||||
data = append(data, 0x00, 0x01, 0x02, 0x03,)
|
||||
|
||||
n, err := Skim(NewDecoder(bytes.NewBuffer(data)), OTA.WithCN(0))
|
||||
if err != nil {
|
||||
test.Fatal(err)
|
||||
}
|
||||
if got, correct := n, mainDataLen; got != correct {
|
||||
test.Fatalf("n not equal: %d != %d", got, correct)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSkimNestedArray(test *testing.T) {
|
||||
data := []byte {
|
||||
2, byte(OTA.WithCN(0)),
|
||||
1, byte(LSI.WithCN(1)),
|
||||
0, 0x5,
|
||||
2, byte(LSI.WithCN(1)),
|
||||
0, 0x17,
|
||||
0xF5, 0x56,
|
||||
}
|
||||
mainDataLen := len(data)
|
||||
// extra junk
|
||||
data = append(data, 0x00, 0x01, 0x02, 0x03,)
|
||||
|
||||
n, err := Skim(NewDecoder(bytes.NewBuffer(data)), OTA.WithCN(0))
|
||||
if err != nil {
|
||||
test.Fatal(err)
|
||||
}
|
||||
if got, correct := n, mainDataLen; got != correct {
|
||||
test.Fatalf("n not equal: %d != %d", got, correct)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSkimTable(test *testing.T) {
|
||||
data := []byte {
|
||||
2,
|
||||
0xF3, 0xB9,
|
||||
byte(LSI.WithCN(3)),
|
||||
0, 0, 0, 1,
|
||||
|
||||
0x01, 0x02,
|
||||
byte(LSI.WithCN(3)),
|
||||
0, 0, 0, 2,
|
||||
}
|
||||
mainDataLen := len(data)
|
||||
// extra junk
|
||||
data = append(data, 0x00, 0x01, 0x02, 0x03, 0x00, 0x01, 0x02, 0x03, 0x00, 0x01, 0x02, 0x03)
|
||||
|
||||
n, err := Skim(NewDecoder(bytes.NewBuffer(data)), KTV.WithCN(0))
|
||||
if got, correct := n, mainDataLen; got != correct {
|
||||
test.Fatalf("n not equal: %d != %d ... (%d)", got, correct, len(data))
|
||||
}
|
||||
if err != nil {
|
||||
test.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSkimTableComplex(test *testing.T) {
|
||||
data := []byte {
|
||||
7,
|
||||
0xF3, 0xB9,
|
||||
byte(LSI.WithCN(3)),
|
||||
0, 0, 0, 1,
|
||||
|
||||
0x01, 0x02,
|
||||
byte(LSI.WithCN(3)),
|
||||
0, 0, 0, 2,
|
||||
|
||||
0, 0,
|
||||
byte(SBA.WithCN(3)),
|
||||
'h', 'i', '!',
|
||||
|
||||
0xFF, 0xFF,
|
||||
byte(OTA.WithCN(0)), 2, byte(LI.WithCN(1)),
|
||||
0xBE, 0xE5, 0x77, 0x77,
|
||||
|
||||
0x12, 0x34,
|
||||
byte(OTA.WithCN(0)), 2, byte(OTA.WithCN(0)),
|
||||
1, byte(LI.WithCN(1)),
|
||||
0, 0x5,
|
||||
2, byte(LI.WithCN(1)),
|
||||
0, 0x17,
|
||||
0xAA, 0xAA,
|
||||
|
||||
0x23, 0x45,
|
||||
byte(OTA.WithCN(0)), 2, byte(OTA.WithCN(0)),
|
||||
1, byte(LSI.WithCN(1)),
|
||||
0, 0x5,
|
||||
2, byte(LSI.WithCN(1)),
|
||||
0, 0x17,
|
||||
0xF5, 0x56,
|
||||
|
||||
0x34, 0x56,
|
||||
byte(LSI.WithCN(1)),
|
||||
0x39, 0x21,
|
||||
}
|
||||
mainDataLen := len(data)
|
||||
// extra junk
|
||||
data = append(data, 0x00, 0x01, 0x02, 0x03, 0x00, 0x01, 0x02, 0x03, 0x00, 0x01, 0x02, 0x03)
|
||||
|
||||
n, err := Skim(NewDecoder(bytes.NewBuffer(data)), KTV.WithCN(0))
|
||||
if got, correct := n, mainDataLen; got != correct {
|
||||
test.Fatalf("n not equal: %d != %d ... (%d)", got, correct, len(data))
|
||||
}
|
||||
if err != nil {
|
||||
test.Fatal(err)
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user