-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbext_test.go
188 lines (149 loc) · 6.02 KB
/
bext_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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
package chunk
import (
"encoding/binary"
"fmt"
"reflect"
"testing"
)
func TestBext(t *testing.T) {
chunk := &Bext{}
headerSize := uint32(12)
header := EncodeChunkHeader(CreateFourCC(BEXTID), headerSize, binary.LittleEndian)
chunk.Header = header
assertEqual(t, chunk.ID(), BEXTID, "id")
assertEqual(t, chunk.Size(), headerSize, "size")
description := createTestString(256)
chunk.SetDescription(description)
assertEqual(t, chunk.Description(), description, "description")
description = createTestString(12)
chunk.SetDescription(description)
assertEqual(t, chunk.Description(), description, "description")
originator := createTestString(32)
chunk.SetOriginator(originator)
assertEqual(t, chunk.Originator(), originator, "originator")
originatorReference := createTestString(32)
chunk.SetOriginatorReference(originatorReference)
assertEqual(t, chunk.OriginatorReference(), originatorReference, "originatorReference")
originationDate := createTestString(10)
chunk.SetOriginationDate(originatorReference)
assertEqual(t, chunk.OriginationDate(), originationDate, "originationDate")
originationTime := createTestString(8)
chunk.SetOriginationTime(originatorReference)
assertEqual(t, chunk.OriginationTime(), originationTime, "originationTime")
timeReference := uint64(^uint(0))
chunk.SetTimeReference(timeReference)
assertEqual(t, chunk.TimeReference(), timeReference, "timeReference")
version := uint16(1)
chunk.SetVersion(version)
assertEqual(t, chunk.Version(), version, "version")
umid := [64]uint8{}
for i := 0; i < len(umid); i++ {
umid[i] = uint8(i + 1)
}
chunk.SetUMID(umid)
assertEqual(t, chunk.UMID(), umid, "umid")
var loudnessValue uint16 = 1000
chunk.SetLoudnessValue(loudnessValue)
assertEqual(t, chunk.LoudnessValue(), loudnessValue, "loudnessValue")
var loudnessRange uint16 = 1001
chunk.SetLoudnessRange(loudnessRange)
assertEqual(t, chunk.LoudnessRange(), loudnessRange, "loudnessRange")
var maxTruePeakLevel uint16 = 1002
chunk.SetMaxTruePeakLevel(maxTruePeakLevel)
assertEqual(t, chunk.MaxTruePeakLevel(), maxTruePeakLevel, "maxTruePeakLevel")
var maxMomentaryLoudness uint16 = 1003
chunk.SetMaxMomentaryLoudness(maxMomentaryLoudness)
assertEqual(t, chunk.MaxMomentaryLoudness(), maxMomentaryLoudness, "maxMomentaryLoudness")
var maxShortTermLoudness uint16 = 1004
chunk.SetMaxShortTermLoudness(maxShortTermLoudness)
assertEqual(t, chunk.MaxShortTermLoudness(), maxShortTermLoudness, "maxShortTermLoudness")
codingHistory := createTestString(8)
chunk.SetCodingHistory(codingHistory)
assertEqual(t, chunk.CodingHistory(), codingHistory, "codingHistory")
bytes := chunk.Bytes()
bext, err := DecodeBextChunk(bytes)
assertEqual(t, err, nil, "err")
assertEqual(t, bext.CodingHistory(), codingHistory, "codingHistory")
}
func TestBextBytes(t *testing.T) {
chunk := &Bext{}
bytes := chunk.Bytes()
assertNotNil(t, bytes, "bytes")
assertEqual(t, len(bytes), 610, "bext chunk length")
chunk.SetVersion(0)
history := "coding history"
chunk.SetCodingHistory(history)
chunk.SetLoudnessRange(10)
chunk.SetLoudnessValue(11)
chunk.SetMaxTruePeakLevel(12)
chunk.SetMaxMomentaryLoudness(13)
chunk.SetMaxShortTermLoudness(14)
umid := [64]byte{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
chunk.SetUMID(umid)
bytes = chunk.Bytes()
bext, err := DecodeBextChunk(bytes)
assertNil(t, err, "err: DecodeBextChunk")
assertEqual(t, bext.Version(), uint16(0), "Version")
assertEqual(t, bext.UMID(), [64]byte{}, "UMID")
assertEqual(t, bext.LoudnessRange(), uint16(0), "LoudnessRange")
assertEqual(t, bext.LoudnessValue(), uint16(0), "LoudnessValue")
assertEqual(t, bext.MaxTruePeakLevel(), uint16(0), "MaxTruePeakLevel")
assertEqual(t, bext.MaxMomentaryLoudness(), uint16(0), "MaxMomentaryLoudness")
assertEqual(t, bext.MaxShortTermLoudness(), uint16(0), "MaxShortTermLoudness")
assertEqual(t, bext.CodingHistory(), history, "CodingHistory")
chunk.SetVersion(1)
bytes = chunk.Bytes()
bext, err = DecodeBextChunk(bytes)
assertNil(t, err, "err: DecodeBextChunk")
assertEqual(t, bext.Version(), uint16(1), "Version")
assertEqual(t, bext.UMID(), umid, "UMID")
assertEqual(t, bext.LoudnessRange(), uint16(0), "LoudnessRange")
assertEqual(t, bext.LoudnessValue(), uint16(0), "LoudnessValue")
assertEqual(t, bext.MaxTruePeakLevel(), uint16(0), "MaxTruePeakLevel")
assertEqual(t, bext.MaxMomentaryLoudness(), uint16(0), "MaxMomentaryLoudness")
assertEqual(t, bext.MaxShortTermLoudness(), uint16(0), "MaxShortTermLoudness")
assertEqual(t, bext.CodingHistory(), history, "CodingHistory")
chunk.SetVersion(2)
bytes = chunk.Bytes()
bext, err = DecodeBextChunk(bytes)
assertNil(t, err, "err: DecodeBextChunk")
assertEqual(t, bext.Version(), uint16(2), "Version")
assertEqual(t, bext.UMID(), umid, "UMID")
assertEqual(t, bext.LoudnessRange(), uint16(10), "LoudnessRange")
assertEqual(t, bext.LoudnessValue(), uint16(11), "LoudnessValue")
assertEqual(t, bext.MaxTruePeakLevel(), uint16(12), "MaxTruePeakLevel")
assertEqual(t, bext.MaxMomentaryLoudness(), uint16(13), "MaxMomentaryLoudness")
assertEqual(t, bext.MaxShortTermLoudness(), uint16(14), "MaxShortTermLoudness")
assertEqual(t, bext.CodingHistory(), history, "CodingHistory")
}
func createTestString(size int) string {
var bytes = make([]byte, size)
for i := 0; i < len(bytes); i++ {
bytes[i] = 65
}
return string(bytes)
}
func assertEqual(t *testing.T, a interface{}, b interface{}, testObject string) {
if a == b {
return
}
message := fmt.Sprintf("%s is %v, want %v", testObject, a, b)
t.Fatal(message)
}
func assertNil(t *testing.T, a interface{}, testObject string) {
if reflect.ValueOf(a).Kind() == reflect.Ptr && reflect.ValueOf(a).IsNil() {
return
}
if a == nil {
return
}
message := fmt.Sprintf("%s is not nil", testObject)
t.Fatal(message)
}
func assertNotNil(t *testing.T, a interface{}, testObject string) {
if a != nil {
return
}
message := fmt.Sprintf("%s is nil", testObject)
t.Fatal(message)
}