This repository was archived by the owner on Jun 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray_test.go
More file actions
63 lines (49 loc) · 1.33 KB
/
array_test.go
File metadata and controls
63 lines (49 loc) · 1.33 KB
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
package amf0
import (
"bytes"
"testing"
"github.com/stretchr/testify/assert"
)
var arrTestData = []byte{0x00, 0x00, 0x00, 0x01, 0x00, 0x03, 0x66,
0x6f, 0x6f, 0x02, 0x00, 0x03, 0x62, 0x61, 0x72, 0x00, 0x00, 0x09}
func TestArrayDecodes(t *testing.T) {
o := NewArray()
err := o.Decode(bytes.NewBuffer(arrTestData))
assert.Nil(t, err)
assert.Equal(t, 1, o.Len())
s, _ := o.String("foo")
assert.Equal(t, "bar", string(*s))
_, err = o.Bool("app")
assert.Equal(t, WrongTypeError, err)
_, err = o.Bool("foo")
assert.Equal(t, NotFoundError, err)
}
func TestArrayBuildsAndEncodes(t *testing.T) {
s := NewArray()
s.Add("foo", NewString("bar"))
assert.Equal(t, arrTestData, s.EncodeBytes())
}
func BenchmarkArrayDecode(b *testing.B) {
out := NewArray()
for i := 0; i < b.N; i++ {
out.Decode(bytes.NewReader(arrTestData))
}
}
func BenchmarkArrayLookup(b *testing.B) {
out := NewArray()
out.Decode(bytes.NewReader(arrTestData))
for i := 0; i < b.N; i++ {
out.String("foo")
}
}
func BenchmarkArrayBuild(b *testing.B) {
for i := 0; i < b.N; i++ {
a := NewArray()
a.Add("app", NewString("myapp"))
a.Add("type", NewString("nonprivate"))
a.Add("flashVer", NewString("FMLE/3.0 (compatible; FMSc/1.0)"))
a.Add("swfUrl", NewString("rtmp://localhost/myapp"))
a.Add("tcUrl", NewString("rtmp://localhost/myapp"))
a.EncodeBytes()
}
}