message-size-increase #3
@ -29,10 +29,38 @@ func TestTable(test *testing.T) {
|
||||
test.Logf("len of longText: %d 0x%X", len(longText), len(longText))
|
||||
correct := []byte("\x00\x05\x05hello\x00\x07\x05world\x00\x00\x83\x28" + longText)
|
||||
if got := buffer[:len(correct)]; !slices.Equal(got, correct) {
|
||||
if !compareHexArray(test, correct, got) {
|
||||
test.FailNow()
|
||||
}
|
||||
if !compareHexArray(test, got, correct) { test.Fatal("failed") }
|
||||
}
|
||||
|
||||
pull := DecodeTable(buffer[:len(correct)])
|
||||
|
||||
tag, value, _, err := pull()
|
||||
if err != nil { test.Fatal(err) }
|
||||
if got, correct := tag, uint16(5); got != correct {
|
||||
test.Fatal("not equal:", got)
|
||||
}
|
||||
if !compareHexArray(test, value, []byte("hello")) { test.Fatal("failed") }
|
||||
|
||||
tag, value, _, err = pull()
|
||||
if err != nil { test.Fatal(err) }
|
||||
if got, correct := tag, uint16(7); got != correct {
|
||||
test.Fatal("not equal:", got)
|
||||
}
|
||||
if !compareHexArray(test, value, []byte("world")) { test.Fatal("failed") }
|
||||
|
||||
tag, value, _, err = pull()
|
||||
if err != nil { test.Fatal(err) }
|
||||
if got, correct := tag, uint16(0); got != correct {
|
||||
test.Fatal("not equal:", got)
|
||||
}
|
||||
if !compareHexArray(test, value, []byte(longText)) { test.Fatal("failed") }
|
||||
|
||||
tag, value, _, err = pull()
|
||||
if err != nil { test.Fatal(err) }
|
||||
if got, correct := tag, uint16(3249); got != correct {
|
||||
test.Fatal("not equal:", got)
|
||||
}
|
||||
if !compareHexArray(test, value, []byte { 0x0, 0x1, 0x2, 0x3, 0xA0, 0x5 }) { test.Fatal("failed") }
|
||||
}
|
||||
|
||||
func TestTableSmall(test *testing.T) {
|
||||
@ -48,10 +76,24 @@ func TestTableSmall(test *testing.T) {
|
||||
|
||||
correct := []byte("\x00\x02\x05hello\x0C\xB1\x06\x00\x01\x02\x03\xA0\x05")
|
||||
if got := buffer[:len(correct)]; !slices.Equal(got, correct) {
|
||||
if !compareHexArray(test, correct, got) {
|
||||
test.FailNow()
|
||||
}
|
||||
if !compareHexArray(test, got, correct) { test.Fatal("failed") }
|
||||
}
|
||||
|
||||
pull := DecodeTable(buffer[:len(correct)])
|
||||
|
||||
tag, value, _, err := pull()
|
||||
if err != nil { test.Fatal(err) }
|
||||
if got, correct := tag, uint16(2); got != correct {
|
||||
test.Fatal("not equal:", got)
|
||||
}
|
||||
if !compareHexArray(test, value, []byte("hello")) { test.Fatal("failed") }
|
||||
|
||||
tag, value, _, err = pull()
|
||||
if err != nil { test.Fatal(err) }
|
||||
if got, correct := tag, uint16(3249); got != correct {
|
||||
test.Fatal("not equal:", got)
|
||||
}
|
||||
if !compareHexArray(test, value, []byte { 0x0, 0x1, 0x2, 0x3, 0xA0, 0x5 }) { test.Fatal("failed") }
|
||||
}
|
||||
|
||||
func dumpHexArray(data []byte) (message string) {
|
||||
@ -61,7 +103,7 @@ func dumpHexArray(data []byte) (message string) {
|
||||
return message
|
||||
}
|
||||
|
||||
func compareHexArray(test *testing.T, correct, got []byte) bool {
|
||||
func compareHexArray(test *testing.T, got, correct []byte) bool {
|
||||
index := 0
|
||||
for {
|
||||
if index >= len(correct) {
|
||||
@ -71,6 +113,7 @@ func compareHexArray(test *testing.T, correct, got []byte) bool {
|
||||
test.Log("correct:", dumpHexArray(correct))
|
||||
return false
|
||||
}
|
||||
break
|
||||
}
|
||||
if index >= len(got) {
|
||||
if index < len(correct) {
|
||||
@ -79,6 +122,7 @@ func compareHexArray(test *testing.T, correct, got []byte) bool {
|
||||
test.Log("correct:", dumpHexArray(correct))
|
||||
return false
|
||||
}
|
||||
break
|
||||
}
|
||||
if correct[index] != got[index] {
|
||||
test.Log("not equal")
|
||||
|
Loading…
Reference in New Issue
Block a user