test Tone.Buffer

This commit is contained in:
Yotam Mann 2014-10-22 22:27:33 -04:00
parent 0bea209d68
commit 73bb0d2b76
2 changed files with 47 additions and 1 deletions

BIN
test/testAudio/hh.mp3 Normal file

Binary file not shown.

View file

@ -1,6 +1,7 @@
/* global it, describe, after */
define(["chai", "Tone/core/Tone", "Tone/core/Master", "Tone/core/Bus", "Tone/core/Note"], function(chai, Tone, Master, Note){
define(["chai", "Tone/core/Tone", "Tone/core/Master", "Tone/core/Bus",
"Tone/core/Note", "tests/Common", "Tone/core/Buffer"], function(chai, Tone, Master, Bus, Note, Test, Buffer){
var expect = chai.expect;
describe("AudioContext", function(){
@ -39,6 +40,12 @@ define(["chai", "Tone/core/Tone", "Tone/core/Master", "Tone/core/Bus", "Tone/cor
tone.dispose();
});
it("can be created and disposed", function(){
var t = new Tone();
t.dispose();
Test.wasDisposed(t);
});
it("correctly calculates samples to seconds", function(){
var sampleRate = tone.context.sampleRate;
expect(tone.samplesToSeconds(100)).to.equal(100/sampleRate);
@ -119,6 +126,10 @@ define(["chai", "Tone/core/Tone", "Tone/core/Master", "Tone/core/Bus", "Tone/cor
it ("exists", function(){
expect(Tone.Master).to.equal(Master);
});
it ("provides a toMaster method", function(){
expect(Tone.prototype.toMaster).is.a("function");
});
});
describe("Tone.Bus", function(){
@ -128,6 +139,41 @@ define(["chai", "Tone/core/Tone", "Tone/core/Master", "Tone/core/Bus", "Tone/cor
});
});
describe("Tone.Buffer", function(){
it ("can be created and disposed", function(){
var buff = new Tone.Buffer("./testAudio/kick.mp3");
buff.dispose();
Test.wasDisposed(buff);
});
it("loads a file from a string", function(done){
var buffer = new Buffer("./testAudio/kick.mp3", function(buff){
expect(buff).to.be.instanceof(AudioBuffer);
buffer.dispose();
done();
});
});
it("loads a file from an array", function(done){
var buffer = new Buffer(["./testAudio/kick.mp3", "./testAudio/hh.mp3"], function(buff){
expect(buff).to.be.instanceof(Array);
expect(buff[0]).to.be.instanceof(AudioBuffer);
expect(buff[1]).to.be.instanceof(AudioBuffer);
buffer.dispose();
done();
});
});
it("loads a file from an object", function(done){
var buffer = new Buffer({"kick" : "./testAudio/kick.mp3"}, function(buff){
expect(buff).to.be.instanceof(Object);
expect(buff.kick).to.be.instanceof(AudioBuffer);
buffer.dispose();
done();
});
});
});
describe("Tone.setContext", function(){
it ("can set a new context", function(){
var origCtx = Tone.context;