Skip to content

Commit 1e92c73

Browse files
committed
Add tests for sources, demuxers, and decoders
Uses the aurora.js-test repo for test data, so init your submodules
1 parent baf225d commit 1e92c73

17 files changed

+776
-5
lines changed

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "tests/data"]
2+
path = tests/data
3+
url = https://github.com/audiocogs/aurora.js-test.git

tests/README.md

+27-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,38 @@
11
Tests
22
=====
33

4+
The tests for Aurora are written using the [QUnit](http://qunitjs.com/) testing framework. They
5+
run in both Node.js and the browser.
6+
7+
##Setup
8+
9+
First, you'll need the test data, so init your git submodules to download them, and update them
10+
if you've already downloaded them before.
11+
12+
git submodule init
13+
git submodule update
14+
15+
Running the tests requires running an HTTP server to host both QUnit itself (for the browser),
16+
as well as the test data files as used by both the browser and Node to test HTTP loading.
17+
18+
To start a simple static HTTP server in the tests directory, run the following command:
19+
20+
python -m SimpleHTTPServer
21+
22+
If you already have the test directory on an HTTP server, all you need to do is set the base URL of
23+
the "tests" folder to the `HTTP_BASE` variable in `config.coffee`.
24+
425
## To run in the browser:
5-
1. Start servers to host Aurora and the tests:
26+
1. Follow the setup steps above.
27+
2. Start servers to host Aurora and the tests themselves:
628

729
importer ../browser.coffee -p 3030
830
importer test.coffee -p 3031
931
1032
You may need to install `importer` using `npm install importer -g` first.
11-
2. Open `test.html` in your browser.
33+
34+
3. Open `test.html` in your browser, using the HTTP server that you set up above.
1235

1336
## To run in Node:
14-
1. Either run `importer test.coffee`
15-
2. Or `npm test` from the root directory.
37+
1. Follow the setup steps above.
38+
2. Either run `importer test.coffee` or `npm test` from the root directory.

tests/config.coffee

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# set this to the base tests directory on an HTTP server
2+
HTTP_BASE = 'http://localhost:8000/'

tests/crc32.coffee

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
class CRC32
2+
CRC32_TABLE = [
3+
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
4+
0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,
5+
0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
6+
0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5,
7+
0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
8+
0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
9+
0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f,
10+
0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d,
11+
0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
12+
0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
13+
0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457,
14+
0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
15+
0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb,
16+
0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9,
17+
0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
18+
0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad,
19+
0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683,
20+
0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
21+
0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7,
22+
0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
23+
0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
24+
0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79,
25+
0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f,
26+
0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
27+
0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
28+
0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21,
29+
0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
30+
0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45,
31+
0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db,
32+
0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
33+
0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf,
34+
0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
35+
]
36+
37+
constructor: ->
38+
@crc = ~0
39+
40+
update: (buffer) ->
41+
for byte in buffer.data
42+
@crc = CRC32_TABLE[(@crc ^ byte) & 0xff] ^ (@crc >>> 8)
43+
44+
return
45+
46+
toHex: ->
47+
return (~@crc >>> 0).toString(16)

tests/data

Submodule data added at dd6bedf

tests/decoders/lpcm.coffee

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#import "shared.coffee"
2+
3+
module 'decoders/lpcm', ->
4+
decoderTest 'i8',
5+
file: 'm4a/i8.mov'
6+
data: 'f12b56ad'
7+
8+
decoderTest 'lei16',
9+
file: 'wave/lei16.wav'
10+
data: '6b6b722b'
11+
12+
decoderTest 'bei16',
13+
file: 'aiff/bei16.aiff'
14+
data: 'ca0bae1e'
15+
16+
decoderTest 'bei24',
17+
file: 'aiff/bei24.aiff'
18+
data: '689eecfa'
19+
20+
decoderTest 'lei24',
21+
file: 'wave/lei24.wav'
22+
data: '5a265e8a'
23+
24+
decoderTest 'bef32',
25+
file: 'au/bef32.au'
26+
data: '5cc026c5'
27+
28+
decoderTest 'lef32',
29+
file: 'wave/lef32.wav'
30+
data: '9b2a9317'
31+
32+
decoderTest 'lef64',
33+
file: 'caf/lef64.caf'
34+
data: '9a3372e'
35+
36+
# TODO: bef64

tests/decoders/shared.coffee

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#import "../crc32.coffee"
2+
3+
decoderTest = (name, config) ->
4+
assert.asyncTest name, ->
5+
if AV.isNode
6+
source = new AV.FileSource "#{__dirname}/data/#{config.file}"
7+
else
8+
source = new AV.HTTPSource "#{HTTP_BASE}/data/#{config.file}"
9+
10+
source.once 'data', (chunk) ->
11+
Demuxer = AV.Demuxer.find(chunk)
12+
demuxer = new Demuxer(source, chunk)
13+
14+
demuxer.once 'format', (format) ->
15+
Decoder = AV.Decoder.find(format.formatID)
16+
decoder = new Decoder(demuxer, format)
17+
crc = new CRC32
18+
19+
decoder.on 'data', (chunk) ->
20+
crc.update new AV.Buffer(new Uint8Array(chunk.buffer))
21+
22+
decoder.on 'end', ->
23+
assert.equal crc.toHex(), config.data
24+
assert.start()
25+
26+
do read = ->
27+
continue while decoder.decode()
28+
decoder.once 'data', read
29+
30+
source.start()

tests/decoders/xlaw.coffee

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#import "shared.coffee"
2+
3+
module 'decoders/xlaw', ->
4+
decoderTest 'alaw',
5+
file: 'au/alaw.au'
6+
data: '1543ac89'
7+
8+
decoderTest 'ulaw',
9+
file: 'm4a/ulaw.mov'
10+
data: '565b7fd'

tests/demuxers/aiff.coffee

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#import "shared.coffee"
2+
3+
module 'demuxers/aiff', ->
4+
demuxerTest 'bei16',
5+
file: 'aiff/bei16.aiff'
6+
format:
7+
formatID: 'lpcm'
8+
sampleRate: 44100
9+
bitsPerChannel: 16
10+
channelsPerFrame: 2
11+
bytesPerPacket: 4
12+
framesPerPacket: 1
13+
sampleCount: 347379
14+
littleEndian: false
15+
floatingPoint: false
16+
duration: 7877
17+
data: '35da18ed'
18+
19+
demuxerTest 'lei16',
20+
file: 'aiff/lei16.aifc'
21+
format:
22+
formatID: 'lpcm'
23+
sampleRate: 44100
24+
bitsPerChannel: 16
25+
channelsPerFrame: 2
26+
bytesPerPacket: 4
27+
framesPerPacket: 1
28+
sampleCount: 347379
29+
littleEndian: true
30+
floatingPoint: false
31+
duration: 7877
32+
data: 'dba3f225'
33+
34+
demuxerTest 'bef32',
35+
file: 'aiff/bef32.aifc'
36+
format:
37+
formatID: 'lpcm'
38+
sampleRate: 44100
39+
bitsPerChannel: 32
40+
channelsPerFrame: 2
41+
bytesPerPacket: 8
42+
framesPerPacket: 1
43+
sampleCount: 347379
44+
littleEndian: false
45+
floatingPoint: true
46+
duration: 7877
47+
data: 'db37e290'
48+
49+
demuxerTest 'alaw',
50+
file: 'aiff/alaw.aifc'
51+
format:
52+
formatID: 'alaw'
53+
sampleRate: 44100
54+
bitsPerChannel: 8
55+
channelsPerFrame: 2
56+
bytesPerPacket: 2
57+
framesPerPacket: 1
58+
sampleCount: 347379
59+
littleEndian: false
60+
floatingPoint: false
61+
duration: 7877
62+
data: 'f4b20b9b'

tests/demuxers/au.coffee

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#import "shared.coffee"
2+
3+
module 'demuxers/au', ->
4+
demuxerTest 'bei16',
5+
file: 'au/bei16.au'
6+
format:
7+
formatID: 'lpcm'
8+
sampleRate: 44100
9+
bitsPerChannel: 16
10+
channelsPerFrame: 2
11+
bytesPerPacket: 4
12+
framesPerPacket: 1
13+
littleEndian: false
14+
floatingPoint: false
15+
duration: 7430
16+
data: 'd4c3bdc0'
17+
18+
demuxerTest 'bef32',
19+
file: 'au/bef32.au'
20+
format:
21+
formatID: 'lpcm'
22+
sampleRate: 44100
23+
bitsPerChannel: 32
24+
channelsPerFrame: 2
25+
bytesPerPacket: 8
26+
framesPerPacket: 1
27+
littleEndian: false
28+
floatingPoint: true
29+
duration: 7430
30+
data: '52dbaba2'
31+
32+
demuxerTest 'alaw',
33+
file: 'au/alaw.au'
34+
format:
35+
formatID: 'alaw'
36+
sampleRate: 44100
37+
bitsPerChannel: 8
38+
channelsPerFrame: 2
39+
bytesPerPacket: 2
40+
framesPerPacket: 1
41+
littleEndian: false
42+
floatingPoint: false
43+
duration: 7430
44+
data: 'e49cda0c'
45+
46+
demuxerTest 'ulaw',
47+
file: 'au/ulaw.au'
48+
format:
49+
formatID: 'ulaw'
50+
sampleRate: 44100
51+
bitsPerChannel: 8
52+
channelsPerFrame: 2
53+
bytesPerPacket: 2
54+
framesPerPacket: 1
55+
littleEndian: false
56+
floatingPoint: false
57+
duration: 7430
58+
data: '18b71b9b'

tests/demuxers/caf.coffee

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#import "shared.coffee"
2+
3+
module 'demuxers/caf', ->
4+
demuxerTest 'base',
5+
file: 'caf/aac.caf'
6+
format:
7+
formatID: 'aac '
8+
sampleRate: 44100
9+
bitsPerChannel: 0
10+
channelsPerFrame: 2
11+
bytesPerPacket: 0
12+
framesPerPacket: 1024
13+
duration: 38659
14+
data: 'd21b23ee'
15+
16+
demuxerTest 'bei16',
17+
file: 'caf/bei16.caf'
18+
format:
19+
formatID: 'lpcm'
20+
sampleRate: 44100
21+
bitsPerChannel: 16
22+
channelsPerFrame: 2
23+
bytesPerPacket: 4
24+
framesPerPacket: 1
25+
floatingPoint: false
26+
littleEndian: false
27+
duration: 38659
28+
data: '4f427df9'
29+
30+
demuxerTest 'lei32',
31+
file: 'caf/lei32.caf'
32+
format:
33+
formatID: 'lpcm'
34+
sampleRate: 44100
35+
bitsPerChannel: 32
36+
channelsPerFrame: 2
37+
bytesPerPacket: 8
38+
framesPerPacket: 1
39+
floatingPoint: false
40+
littleEndian: true
41+
duration: 38659
42+
data: '771d822a'
43+
44+
demuxerTest 'bef32',
45+
file: 'caf/bef32.caf'
46+
format:
47+
formatID: 'lpcm'
48+
sampleRate: 44100
49+
bitsPerChannel: 32
50+
channelsPerFrame: 2
51+
bytesPerPacket: 8
52+
framesPerPacket: 1
53+
floatingPoint: true
54+
littleEndian: false
55+
duration: 38659
56+
data: '7bf9d9d2'
57+
58+
demuxerTest 'lef64',
59+
file: 'caf/lef64.caf'
60+
format:
61+
formatID: 'lpcm'
62+
sampleRate: 44100
63+
bitsPerChannel: 64
64+
channelsPerFrame: 2
65+
bytesPerPacket: 16
66+
framesPerPacket: 1
67+
floatingPoint: true
68+
littleEndian: true
69+
duration: 38659
70+
data: '9a3372e'

0 commit comments

Comments
 (0)