-
Notifications
You must be signed in to change notification settings - Fork 0
/
container_test.go
87 lines (65 loc) · 2.21 KB
/
container_test.go
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package chunk
import (
"encoding/binary"
"fmt"
"strings"
"testing"
)
func TestFindHeaders(t *testing.T) {
riffFile := &Container{}
for _, h := range riffFile.Headers {
fmt.Printf("%v\n", h)
}
headers := riffFile.FindHeaders("")
if headers != nil {
t.Errorf("headers should not be returned")
}
headerID := createID("test")
header := EncodeChunkHeader(headerID, 0, binary.LittleEndian)
riffFile.Headers = append(riffFile.Headers, header)
headers = riffFile.FindHeaders(string(headerID[:]))
if headers == nil {
t.Errorf("headers should be returned")
}
assertEqual(t, len(headers), 1, "headers length")
riffFile.Headers = append(riffFile.Headers, header)
headers = riffFile.FindHeaders(string(headerID[:]))
assertEqual(t, len(headers), 2, "headers length")
}
func TestReadRiff(t *testing.T) {
fileName := "testFile"
content := make([]byte, ContainerHeaderSizeBytes-1)
reader := strings.NewReader(string(content))
riff, err := ReadRiff(fileName, reader)
assertNotNil(t, err, "err should not be nil")
assertNil(t, riff, "riff should be nil")
content = make([]byte, ContainerHeaderSizeBytes)
reader = strings.NewReader(string(content))
riff, err = ReadRiff(fileName, reader)
assertNil(t, err, "err should be nil")
assertNotNil(t, riff, "riff should not be nil")
assertEqual(t, len(riff.Headers), 0, "headers length")
if riff.Headers != nil {
t.Errorf("headers should be nil")
}
content = make([]byte, ContainerHeaderSizeBytes+HeaderSizeBytes)
reader = strings.NewReader(string(content))
riff, err = ReadRiff(fileName, reader)
assertEqual(t, len(riff.Headers), 1, "headers length")
headerID := createID("test")
var headerSize int = 12
header := EncodeChunkHeader(headerID, uint32(headerSize), binary.LittleEndian)
headerBytes := header.Bytes()
headerBytes = append(headerBytes, make([]byte, headerSize)...)
content = make([]byte, ContainerHeaderSizeBytes)
content = append(content, headerBytes...)
content = append(content, headerBytes...)
reader = strings.NewReader(string(content))
riff, err = ReadRiff(fileName, reader)
assertEqual(t, len(riff.Headers), 2, "headers length")
}
func createID(idVal string) [IDSizeBytes]byte {
var id [IDSizeBytes]byte
copy(id[:], idVal)
return id
}