diff --git a/rtmp/amf/amf_test.go b/rtmp/amf/amf_test.go index 04cc1ebc..437e49c9 100644 --- a/rtmp/amf/amf_test.go +++ b/rtmp/amf/amf_test.go @@ -57,12 +57,12 @@ func TestSanity(t *testing.T) { // TestStrings tests string encoding and decoding. func TestStrings(t *testing.T) { + // Short string encoding is as follows: + // enc[0] = data type (typeString) + // end[1:3] = size + // enc[3:] = data for _, s := range testStrings { - // Short string encoding is as follows: - // enc[0] = data type (typeString) - // end[1:3] = size - // enc[3:] = data - buf := make([]byte, len(s)+5) + buf := make([]byte, len(s)+7) _, err := EncodeString(buf, s) if err != nil { t.Errorf("EncodeString failed") @@ -75,10 +75,26 @@ func TestStrings(t *testing.T) { t.Errorf("DecodeString did not produce original string, got %v", ds) } } + // Long string encoding is as follows: + // enc[0] = data type (typeString) + // end[1:5] = size + // enc[5:] = data + s := string(make([]byte, 65536)) + buf := make([]byte, len(s)+7) + _, err := EncodeString(buf, s) + if err != nil { + t.Errorf("EncodeString failed") + } + if buf[0] != typeLongString { + t.Errorf("Expected typeLongString, got %v", buf[0]) + } + ds := DecodeLongString(buf[1:]) + if s != ds { + t.Errorf("DecodeLongString did not produce original string, got %v", ds) + } } -// TestNumbers tests 24-bit encoding and encoding. -// We don't test the others as they are just wrappers for standard functions in encoding/binary. +// TestNumbers tests number encoding and encoding. func TestNumbers(t *testing.T) { for _, n := range testNumbers { buf := make([]byte, 4) // NB: encoder requires an extra byte for some reason @@ -90,6 +106,14 @@ func TestNumbers(t *testing.T) { if n != dn { t.Errorf("DecodeInt24 did not produce original Number, got %v", dn) } + _, err = EncodeInt32(buf, n) + if err != nil { + t.Errorf("EncodeInt32 failed") + } + dn = int32(DecodeInt32(buf)) + if n != dn { + t.Errorf("DecodeInt32 did not produce original Number, got %v", dn) + } } }