mirror of https://bitbucket.org/ausocean/av.git
Initial revision.
This commit is contained in:
parent
255464d85a
commit
c2d4e0b4a2
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
NAME
|
||||
amf_test.go
|
||||
|
||||
DESCRIPTION
|
||||
AMF tests
|
||||
|
||||
AUTHORS
|
||||
Saxon Nelson-Milton <saxon@ausocean.org>
|
||||
Dan Kortschak <dan@ausocean.org>
|
||||
Alan Noble <alan@ausocean.org>
|
||||
|
||||
LICENSE
|
||||
amf_test.go is Copyright (C) 2017-2019 the Australian Ocean Lab (AusOcean)
|
||||
|
||||
It is free software: you can redistribute it and/or modify them
|
||||
under the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation, either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
It is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with revid in gpl.txt. If not, see http://www.gnu.org/licenses.
|
||||
*/
|
||||
|
||||
package amf
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
// TestStrings tests string encoding and decoding.
|
||||
func TestStrings(t *testing.T) {
|
||||
var testStrings = [...]string{
|
||||
"foo",
|
||||
"bar",
|
||||
}
|
||||
|
||||
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)
|
||||
enc := EncodeString(buf, s)
|
||||
if enc == nil {
|
||||
t.Errorf("EncodeString failed")
|
||||
}
|
||||
if buf[0] != typeString {
|
||||
t.Errorf("Expected typeString, got %v", buf[0])
|
||||
}
|
||||
ds := DecodeString(buf[1:])
|
||||
if s != ds {
|
||||
t.Errorf("DecodeString 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.
|
||||
func TestNumbers(t *testing.T) {
|
||||
var testNumbers = [...]int32{
|
||||
0x0,
|
||||
0xababab,
|
||||
0xffffff,
|
||||
}
|
||||
|
||||
for _, n := range testNumbers {
|
||||
buf := make([]byte, 4) // NB: encoder requires an extra byte for some reason
|
||||
enc := EncodeInt24(buf, n)
|
||||
if enc == nil {
|
||||
t.Errorf("EncodeInt24 failed")
|
||||
}
|
||||
dn := int32(DecodeInt24(buf))
|
||||
if n != dn {
|
||||
t.Errorf("DecodeInt24 did not produce original number, got %v", dn)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue