TTErr TTBuffer::test(TTValue& returnedTestInfo) { int errorCount = 0; int testAssertionCount = 0; //int badSampleCount = 0; // *** Tim's old list (we'll get there) *** // TODO: test filling with sine wave // TODO: test scaling (applying gain) // TODO: test normalizing (with optional arg, and also without an optional arg) this->init(1,"myFirstBuffer"); this->setAttributeValue("lengthInSamples", 50); TTTestLog("\nTest checkout of first SampleMatrix..."); // TEST 1: checking out a matrix returns something TTSampleMatrixPtr myFirstCheckOut = NULL; this->checkOutMatrix(myFirstCheckOut); TTBoolean result1 = { myFirstCheckOut != NULL }; TTTestAssertion("checkOutMatrix returns a valid pointer", result1, testAssertionCount, errorCount); // TEST 2: how many channels does this matrix have? TTInt32 test2expect = 1; TTInt32 test2return = 0; myFirstCheckOut->getAttributeValue("numChannels", test2return); TTBoolean result2 = { test2expect == test2return }; TTTestAssertion("numChannels is set properly", result2, testAssertionCount, errorCount); if(!result2) { TTTestLog("Expected a value of %i, but returned value was %i", test2expect, test2return); } // TEST 3: what is the user count? TTInt32 test3expect = 1; TTInt32 test3return = 0; myFirstCheckOut->getAttributeValue("userCount", test3return); TTBoolean result3 = { test2expect == test3return }; TTTestAssertion("userCount reports proper value", result3, testAssertionCount, errorCount); if(!result3) { TTTestLog("Expected a value of %i, but returned value was %i", test3expect, test3return); } // TEST 4: what is the buffer stage? TTBoolean test4expect = true; TTBoolean test4return = false; test4return = myFirstCheckOut->isBufferPoolStage(kSM_Active); TTBoolean result4 = { test4expect == test4return }; TTTestAssertion("bufferPoolStage reports proper value", result4, testAssertionCount, errorCount); if(!result4) { TTTestLog("Expected a value of %i, but returned value was %i", test4expect, test4return); } TTTestLog("\nTest second checkout of first SampleMatrix..."); // TEST 5: checking out a matrix returns something TTSampleMatrixPtr myFirstCheckOut2 = NULL; this->checkOutMatrix(myFirstCheckOut2); TTBoolean result5 = { myFirstCheckOut == myFirstCheckOut2 }; TTTestAssertion("checkOutMatrix returns the same pointer", result5, testAssertionCount, errorCount); // TEST 6: what is the user count after 2 checkouts? TTInt32 test6expect = 2; TTInt32 test6return = 0; myFirstCheckOut->getAttributeValue("userCount", test6return); TTBoolean result6 = { test6expect == test6return }; TTTestAssertion("userCount reports proper value after second checkout", result6, testAssertionCount, errorCount); if(!result6) { TTTestLog("Expected a value of %i, but returned value was %i", test6expect, test6return); } TTTestLog("\nTest if changing lengthInSamples attribute spawns new SampleMatrix..."); // TEST 7: changing length at TTBuffer should spawn a new matrix TTSampleMatrixPtr mySecondCheckOut = NULL; this->setAttributeValue("lengthInSamples", 100); this->checkOutMatrix(mySecondCheckOut); TTBoolean result7 = { mySecondCheckOut != myFirstCheckOut }; TTTestAssertion("checkOutMatrix returns pointer to different SampleMatrix", result7, testAssertionCount, errorCount); // TEST 8: what is the user count on new checkout? TTInt32 test8expect = 1; TTInt32 test8return = 0; mySecondCheckOut->getAttributeValue("userCount", test8return); TTBoolean result8 = { test8expect == test8return }; TTTestAssertion("userCount reports proper value", result8, testAssertionCount, errorCount); if(!result8) { TTTestLog("Expected a value of %i, but returned value was %i", test8expect, test8return); } TTTestLog("\nRepeat with numChannels attribute..."); // TEST 9: changing numChannels at TTBuffer should spawn a new matrix TTSampleMatrixPtr myThirdCheckOut = NULL; this->setAttributeValue("numChannels", 2); this->checkOutMatrix(myThirdCheckOut); TTBoolean result9 = { mySecondCheckOut != myThirdCheckOut && myFirstCheckOut != myThirdCheckOut}; TTTestAssertion("checkOutMatrix returns pointer to different SampleMatrix", result9, testAssertionCount, errorCount); // TEST 10: what is the user count on new checkout? TTInt32 test10expect = 1; TTInt32 test10return = 0; myThirdCheckOut->getAttributeValue("userCount", test10return); TTBoolean result10 = { test10expect == test10return }; TTTestAssertion("userCount reports proper value", result10, testAssertionCount, errorCount); if(!result10) { TTTestLog("Expected a value of %i, but returned value was %i", test10expect, test10return); } /******/ TTTestLog("\nAt this point, 3 SampleMatrix objects are checked out via 4 pointers:"); TTTestLog("myFirstCheckOut: userCount %i, Active %i, Becoming Idle %i", myFirstCheckOut->getUserCount(), myFirstCheckOut->isBufferPoolStage(kSM_Active), myFirstCheckOut->isBufferPoolStage(kSM_BecomingIdle)); TTTestLog("myFirstCheckOut2: userCount %i, Active %i, Becoming Idle %i", myFirstCheckOut2->getUserCount(), myFirstCheckOut2->isBufferPoolStage(kSM_Active), myFirstCheckOut2->isBufferPoolStage(kSM_BecomingIdle)); TTTestLog("mySecondCheckOut: userCount %i, Active %i, Becoming Idle %i", mySecondCheckOut->getUserCount(), mySecondCheckOut->isBufferPoolStage(kSM_Active), mySecondCheckOut->isBufferPoolStage(kSM_BecomingIdle)); TTTestLog("myThirdCheckOut: userCount %i, Active %i, Becoming Idle %i", myThirdCheckOut->getUserCount(), myThirdCheckOut->isBufferPoolStage(kSM_Active), myThirdCheckOut->isBufferPoolStage(kSM_BecomingIdle)); /******/ TTTestLog("\nTesting check in process..."); // TEST 11: checking out a matrix returns NULL pointer this->checkInMatrix(myFirstCheckOut); TTBoolean result11 = { myFirstCheckOut == NULL }; TTTestAssertion("checkInMatrix(myFirstCheckOut) resets pointer to NULL", result11, testAssertionCount, errorCount); // TEST 12: second pointer to first matrix is still valid TTBoolean result12 = { myFirstCheckOut2 != NULL }; TTTestAssertion("myFirstCheckOut2 is still a valid pointer", result12, testAssertionCount, errorCount); // TEST 13: poke/peek a sample into first matrix TTSampleValue test13expect = TTRandom64(); myFirstCheckOut2->poke(10,0,test13expect); TTSampleValue test13return; myFirstCheckOut2->peek(10,0,test13return); TTBoolean result13 = TTTestFloatEquivalence(test13expect,test13return); TTTestAssertion("poke/peek sample value still works", result13, testAssertionCount, errorCount); if(!result13) { TTTestLog("Expected a value of %i, but returned value was %i", test13expect, test13return); } // TEST 14: checking out a matrix returns NULL pointer this->checkInMatrix(myFirstCheckOut2); TTBoolean result14 = { myFirstCheckOut2 == NULL }; TTTestAssertion("checkInMatrix(myFirstCheckOut2) resets pointer to NULL", result14, testAssertionCount, errorCount); // TEST 15: checking out a matrix returns NULL pointer this->checkInMatrix(mySecondCheckOut); TTBoolean result15 = { mySecondCheckOut == NULL }; TTTestAssertion("checkInMatrix(mySecondCheckOut) resets pointer to NULL", result15, testAssertionCount, errorCount); // TEST 16: checking out a matrix returns NULL pointer this->checkInMatrix(myThirdCheckOut); TTBoolean result16 = { myThirdCheckOut == NULL }; TTTestAssertion("checkInMatrix(myThirdCheckOut) resets pointer to NULL", result16, testAssertionCount, errorCount); // The following is effectively taken care of through check in... //TTObjectRelease(&myFirstCheckOut); //TTObjectRelease(&mySecondCheckOut); //TTObjectRelease(&myThirdCheckOut); // Wrap up the test results to pass back to whoever called this test return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo); }
TTErr TTSoundfileLoader::test(TTValue& returnedTestInfo) { int errorCount = 0; int testAssertionCount = 0; // assemble the full path of the target sound file TTString testSoundPath = TTFoundationBinaryPath; int pos = testSoundPath.find_last_of('/'); testSoundPath = testSoundPath.substr(0,pos+1); testSoundPath += TESTFILE; std::cout << "We will be using the following path for testing: " << testSoundPath << "\n"; try { TTTestLog("\n"); TTTestLog("Testing TTSoundfileLoader Basics..."); // TEST 0: establish our objects & pointers TTObject* testTargetMatrix = new TTObject("samplematrix"); TTObject* testNonSampleMatrix = new TTObject("delay"); TTObjectBase* objectBasePtrToSampleMatrix; TTObjectBase* ptrToNonSampleMatrix; // TEST 1: set the filepath TTBoolean result1 = { this->setFilePath(TT(testSoundPath)) == kTTErrNone }; TTTestAssertion("setFilePath operates successfully", result1, testAssertionCount, errorCount); // TEST 2: set up the samplematrix first int channelsSend = 1; // compiler complained about TTInt32 being ambiguous here int lengthSend = 22050; // compiler complained about TTInt32 being ambiguous here testTargetMatrix->set("numChannels", channelsSend); testTargetMatrix->set("lengthInSamples", lengthSend); TTInt32 channelsReturn, lengthReturn; testTargetMatrix->get("numChannels", channelsReturn); testTargetMatrix->get("lengthInSamples", lengthReturn); // now for the actual test TTBoolean result2a = { channelsSend == channelsReturn }; TTTestAssertion("numChannels attribute set successfully", result2a, testAssertionCount, errorCount); TTBoolean result2b = { lengthSend == lengthReturn }; TTTestAssertion("lengthInSamples attribute set successfully", result2b, testAssertionCount, errorCount); // // TEST 3: set the target via an objectBasePtr objectBasePtrToSampleMatrix = testTargetMatrix->instance(); // is there a better syntax for this? TTBoolean result3 = { this->setTargetMatrix(objectBasePtrToSampleMatrix) == kTTErrNone }; TTTestAssertion("setTargetMatrix via ObjectBasePtr operates successfully", result3, testAssertionCount, errorCount); // TEST 4: set the target to a non-SampleMatrix, should FAIL ptrToNonSampleMatrix = testNonSampleMatrix->instance(); TTBoolean result4 = { this->setTargetMatrix(ptrToNonSampleMatrix) == kTTErrInvalidValue }; TTTestAssertion("setTargetMatrix returns error when not a SampleMatrix", result4, testAssertionCount, errorCount); // TEST 5: copy samplevalues until samplematrix is filled TTBoolean result5 = { this->copyUntilFilled() == kTTErrNone }; TTTestAssertion("copyUntilFilled operates successfully", result5, testAssertionCount, errorCount); // releasing objects objectBasePtrToSampleMatrix = NULL; ptrToNonSampleMatrix = NULL; delete testTargetMatrix; delete testNonSampleMatrix; // TEST 6: use TTSampleMatrix's load message, then compare 5 random sample values for equivalence // create a new TTSampleMatrix TTObject newTargetMatrix("samplematrix"); // set the length and channel count newTargetMatrix.set("numChannels", TESTNUMCHANNELS); newTargetMatrix.set("lengthInSamples", TESTDURATIONINSAMPLES); // prepare necessary TTValues TTValue loadInput6 = TT(testSoundPath); // we cannot pass the naked TTString, it needs to be part of a TTValue TTValue aReturnWeDontCareAbout6; // send message TTBoolean result6a = { newTargetMatrix.send("load", loadInput6, aReturnWeDontCareAbout6) == kTTErrNone }; TTTestAssertion("TTSampleMatrix load operates successfully", result6a, testAssertionCount, errorCount); // now let's test some values! int randomIndex6, randomChannel6; TTSampleValue testValueSoundFile6; TTBoolean result6b = true; for (int i = 0; i<10; i++) { randomIndex6 = lengthReturn * TTRandom64(); randomChannel6 = i % TESTNUMCHANNELS; //std::cout << "let's look at index " << randomIndex6 << " & channel " << randomChannel6 << "\n"; TTValue peekInput6(randomIndex6); peekInput6.append(randomChannel6); TTValue peekOutput6; this->peek(randomIndex6,randomChannel6,testValueSoundFile6); newTargetMatrix.send("peek",peekInput6,peekOutput6); //std::cout << "Does " << testValueSoundFile6 << " = " << double(peekOutput6) << " ?\n"; if (result6b) // allows test to keep variable false once it is false result6b = TTTestFloatEquivalence(testValueSoundFile6, double(peekOutput6), true, 0.0000001); } TTTestAssertion("comparing values @ 10 random indexes for equivalence", result6b, testAssertionCount, errorCount); // TEST 7: now use TTBuffer's load message, and again compare 5 random sample values for equivalence // create a new TTBuffer with convenience syntax TTAudioBuffer aBufferByAnyOtherName(TESTNUMCHANNELS, TESTDURATIONINSAMPLES); // prepare necessary TTValues TTValue loadInput7 = TT(testSoundPath); // we cannot pass the naked TTString, it needs to be part of a TTValue // send message TTBoolean result7a = { aBufferByAnyOtherName.load(loadInput7) == kTTErrNone }; TTTestAssertion("TTBuffer load operates successfully", result7a, testAssertionCount, errorCount); // setup pointer to samplematrix TTSampleMatrixPtr myMatrix7; // check out samplematrix TTBoolean result7b = { aBufferByAnyOtherName.checkOutMatrix(myMatrix7) == kTTErrNone }; TTTestAssertion("TTBuffer checks out SampleMatrix successfully", result7b, testAssertionCount, errorCount); TTValue testChannel, testSample; myMatrix7->getNumChannels(testChannel); myMatrix7->getLengthInSamples(testSample); //std::cout << "Samplematrix has " << int(testChannel) << " channels & " << int(testSample) << " samples\n"; // now let's test some values! int randomIndex7, randomChannel7; double testValueSoundFile7, testValueSampleMatrix7; TTBoolean result7c = true; for (int i = 0; i<10; i++) { randomIndex7 = lengthReturn * TTRandom64(); randomChannel7 = i % TESTNUMCHANNELS; //std::cout << "let's look at index " << randomIndex7 << " & channel " << randomChannel7 << "\n"; this->peek(randomIndex7,randomChannel7,testValueSoundFile7); myMatrix7->peek(randomIndex7,randomChannel7,testValueSampleMatrix7); //std::cout << "Does " << testValueSoundFile7 << " = " << testValueSampleMatrix7 << " ?\n"; if (result7c) // allows test to keep variable false once it is false result7c = TTTestFloatEquivalence(testValueSoundFile7, testValueSampleMatrix7, true, 0.0000001); } TTTestAssertion("comparing values @ 10 random indexes for equivalence", result7c, testAssertionCount, errorCount); // check in samplematrix TTBoolean result7d = { aBufferByAnyOtherName.checkInMatrix(myMatrix7) == kTTErrNone }; TTTestAssertion("TTBuffer checks in SampleMatrix successfully", result7d, testAssertionCount, errorCount); // TEST 8: use optional load parameters to copy samples 5 to 15 from channel 0 // resize aBufferByAnyOtherName.set("numChannels", 1); aBufferByAnyOtherName.set("lengthInSamples", 10); // prepare necessary TTValues int copyChannel8 = 0; // first channel int startIndex8 = 5; // start @ sample 5 int endIndex8 = 15; // end @ sample 15 TTValue loadInput8 = TT(testSoundPath); // we cannot pass the naked TTString, it needs to be part of a TTValue loadInput8.append(copyChannel8); loadInput8.append(startIndex8); loadInput8.append(endIndex8); // send message TTBoolean result8a = { aBufferByAnyOtherName.load(loadInput8) == kTTErrNone }; TTTestAssertion("TTBuffer load operates successfully w optional parameters", result8a, testAssertionCount, errorCount); // setup pointer to samplematrix TTSampleMatrixPtr myMatrix8; // check out samplematrix TTBoolean result8b = { aBufferByAnyOtherName.checkOutMatrix(myMatrix8) == kTTErrNone }; TTTestAssertion("TTBuffer checks out SampleMatrix successfully", result8b, testAssertionCount, errorCount); // now let's test some values! double testValueSoundFile8, testValueSampleMatrix8; TTBoolean result8c = true; for (int i = 0; i<10; i++) { //std::cout << "let's look at index " << i << "\n"; this->peek(i+startIndex8,copyChannel8,testValueSoundFile8); myMatrix8->peek(i,copyChannel8,testValueSampleMatrix8); //std::cout << "Does " << testValueSoundFile8 << " = " << testValueSampleMatrix8 << " ?\n"; if (result8c) // allows test to keep variable false once it is false result8c = TTTestFloatEquivalence(testValueSoundFile8, testValueSampleMatrix8, true, 0.0000001); } TTTestAssertion("comparing all 10 copied values for equivalence", result8c, testAssertionCount, errorCount); // check in samplematrix TTBoolean result8d = { aBufferByAnyOtherName.checkInMatrix(myMatrix8) == kTTErrNone }; TTTestAssertion("TTBuffer checks in SampleMatrix successfully", result8d, testAssertionCount, errorCount); // TEST 9: load soundfile into buffer/samplematrix with different sample rate TTValue testChannel9in = 2; TTValue testSampleRate9in = 88200; TTValue testLengthSec9in = 0.25; aBufferByAnyOtherName.set("numChannels", testChannel9in); aBufferByAnyOtherName.set("sampleRate", testSampleRate9in); aBufferByAnyOtherName.set("lengthInSeconds", testLengthSec9in); TTValue loadInput9 = TT(testSoundPath); // we cannot pass the naked TTString, it needs to be part of a TTValue // send message TTBoolean result9a = { aBufferByAnyOtherName.load(loadInput9) == kTTErrNone }; TTTestAssertion("TTBuffer load operates successfully when sample rates differ", result9a, testAssertionCount, errorCount); // setup pointer to samplematrix TTSampleMatrixPtr myMatrix9; // check out samplematrix TTBoolean result9b = { aBufferByAnyOtherName.checkOutMatrix(myMatrix9) == kTTErrNone }; TTTestAssertion("TTBuffer checks out SampleMatrix successfully", result9b, testAssertionCount, errorCount); TTValue testChannel9, testSampleCount9, testSampleRate9; myMatrix9->getAttributeValue("numChannels", testChannel9); myMatrix9->getAttributeValue("lengthInSamples", testSampleCount9); myMatrix9->getAttributeValue("sampleRate", testSampleRate9); /*std::cout << "Samplematrix has " << TTInt32(testChannel9) << " channels & " << TTInt32(testSampleCount9) << " samples @ " << TTInt32(testSampleRate9) << " Hz\n";*/ // check out samplematrix TTBoolean result9c = { TTInt32(testChannel9) == TTInt32(testChannel9in) && TTInt32(testSampleRate9) == TTInt32(testSampleRate9in) && TTInt32(testSampleCount9) == (TTInt32(testSampleRate9in) * TTFloat64(testLengthSec9in)) }; TTTestAssertion("SampleMatrix has same attributes set via TTBuffer", result9c, testAssertionCount, errorCount); // let's test some values int randomIndex9, randomChannel9; TTSampleValue testSoundFileValue9, testSampleMatrixValue9; TTBoolean result9d = true; for (int i = 0; i<10; i++) { randomIndex9 = int(testSampleCount9) * TTRandom64(); randomChannel9 = i % TESTNUMCHANNELS; //std::cout << "let's look at index " << randomIndex9 << " & channel " << randomChannel9 << "\n"; this->peeki(float(randomIndex9)/2.0, randomChannel9, testSoundFileValue9); myMatrix9->peek(randomIndex9, randomChannel9, testSampleMatrixValue9); //std::cout << "Does " << testSoundFileValue9 << " = " << testSampleMatrixValue9 << " ?\n"; if (result9d) // allows test to keep variable false once it is false result9d = TTTestFloatEquivalence(testSoundFileValue9, testSampleMatrixValue9, true, 0.0000001); } TTTestAssertion("comparing values @ 10 random indexes for equivalence", result9d, testAssertionCount, errorCount); // check in samplematrix TTBoolean result9e = { aBufferByAnyOtherName.checkInMatrix(myMatrix9) == kTTErrNone }; TTTestAssertion("TTBuffer checks in SampleMatrix successfully", result9e, testAssertionCount, errorCount); // TEST 10: use resizeThenLoad message and test that TTSampleMatrix conforms to sound file loaded TTAudioBuffer bufferForTest10(1,1); // start by making the buffer really tiny TTValue loadInput10 = TT(testSoundPath); // send message TTBoolean result10a = { bufferForTest10.resizeThenLoad(loadInput10) == kTTErrNone }; TTTestAssertion("TTBuffer resizeThenLoad operates successfully", result10a, testAssertionCount, errorCount); // setup pointer to samplematrix TTSampleMatrixPtr myMatrix10; // check out samplematrix TTBoolean result10b = { bufferForTest10.checkOutMatrix(myMatrix10) == kTTErrNone }; TTTestAssertion("TTBuffer checks out SampleMatrix successfully", result10b, testAssertionCount, errorCount); // do some more tests here TTValue testChannel10, testLengthSec10, testLengthSample10; myMatrix10->getAttributeValue("numChannels", testChannel10); myMatrix10->getAttributeValue("lengthInSeconds", testLengthSec10); myMatrix10->getAttributeValue("lengthInSamples", testLengthSample10); /*std::cout << "Samplematrix has " << TTInt32(testChannel10) << " channels & " << TTInt32(testLengthSample10) << " samples and is " << TTFloat64(testLengthSec10) << " secs long\n";*/ TTBoolean result10c = { TTInt32(testChannel10) == TESTNUMCHANNELS && TTInt32(testLengthSample10) == TESTDURATIONINSAMPLES }; TTTestAssertion("TTBuffer.resizeThenLoad results in properly sized TTSampleMatrix", result10c, testAssertionCount, errorCount); // check in samplematrix TTBoolean result10e = { bufferForTest10.checkInMatrix(myMatrix10) == kTTErrNone }; TTTestAssertion("TTBuffer checks in SampleMartix successfully", result10e, testAssertionCount, errorCount); } catch (...) { TTTestAssertion("FAILED to run tests -- likely that necessary objects did not instantiate", 0, testAssertionCount, errorCount); } return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo); }
TTErr TTSampleMatrix::test(TTValue& returnedTestInfo) { int errorCount = 0; int testAssertionCount = 0; // for tests TTInt16 numChannels = 2; TTUInt32 numSamples = 50000; // TODO: xcode says this is ambiguous when signed? TTFloat32 duration = 1500; int test9Index = 10; int test10Index = 11; TTInt32 test1Return, test2Return, test7Return; TTFloat32 test3Return, test6Return; TTSampleValue test9Return, test10Return, test11Return, test12return, test13return; TTTestLog("Test resizing of the SampleMatrix..."); // TEST 1: can we set the number of channels? this->setAttributeValue("numChannels", numChannels); this->getAttributeValue("numChannels", test1Return); TTBoolean result = { numChannels == test1Return }; TTTestAssertion("numChannels is set properly", result, testAssertionCount, errorCount); if(!result) { TTTestLog("Expected a value of %i, but returned value was %i", numChannels, test1Return); } // TEST 2: can we set the number of samples? //this->setAttributeValue("lengthInSamples", numSamples); // TODO: xcode says this is ambiguous? this->setLengthInSamples(numSamples); this->getAttributeValue("lengthInSamples", test2Return); TTBoolean result2 = { numSamples == test2Return }; TTTestAssertion("lengthInSamples is set properly", result2, testAssertionCount, errorCount); if(!result2) { TTTestLog("Expected a value of %i, but returned value was %i", numSamples, test2Return); } // TEST 3: is the length in sec computed properly after setting length in samples? TTFloat32 computedDuration3 = (numSamples / this->mSampleRate); this->getAttributeValue("lengthInSeconds", test3Return); TTBoolean result3 = TTTestFloatEquivalence(computedDuration3, test3Return); TTTestAssertion("after lengthInSamples is set, lengthInSeconds is correct", result3, testAssertionCount, errorCount); if(!result3) { TTTestLog("Expected a value of %f, but returned value was %f", computedDuration3, test3Return); } // TEST 4: is the matrix of samples the expected size? (lifted from TTMatrix.test.cpp) TTUInt32 computedDataSize4 = sizeof(TTFloat64) * numChannels * numSamples; TTBoolean result4 = { computedDataSize4 == this->mDataSize }; TTTestAssertion("correct amount of data storage calculated", result4, testAssertionCount, errorCount); if(!result4) { TTTestLog("Expected a value of %i, but returned value was %i", computedDataSize4, this->mDataSize); } // TEST 5: Is the component stride right? (lifted from TTMatrix.test.cpp) TTBoolean result5 = { sizeof(TTFloat64) == this->mComponentStride }; TTTestAssertion("correct byte-stride between values calculated", result5, testAssertionCount, errorCount); if(!result5) { TTTestLog("Expected a value of %i, but returned value was %i", sizeof(TTFloat64), this->mComponentStride); } // TEST 6: can we set the length in seconds? this->setAttributeValue("lengthInSeconds", duration); this->getAttributeValue("lengthInSeconds", test6Return); TTBoolean result6 = TTTestFloatEquivalence(duration, test6Return); TTTestAssertion("lengthInSeconds is set properly", result6, testAssertionCount, errorCount); if(!result6) { TTTestLog("Expected a value of %f, but returned value was %f", duration, test6Return); } // TEST 7: is the length in samples computed properly after setting length in ms? TTUInt32 computedSamples7 = TTUInt32(duration * this->mSampleRate); this->getAttributeValue("lengthInSamples", test7Return); TTBoolean result7 = { computedSamples7 == test7Return }; TTTestAssertion("after lengthInSeconds is set, lengthInSamples is correct", result7, testAssertionCount, errorCount); if(!result7) { TTTestLog("Expected a value of %i, but returned value was %i", computedSamples7, test7Return); } // TEST 8 (REPEAT TEST 4 WITH NEW SIZE): is the matrix of samples the expected size? TTUInt32 computedDataSize8 = sizeof(TTFloat64) * numChannels * test7Return; TTBoolean result8 = { computedDataSize8 == this->mDataSize }; TTTestAssertion("correct amount of data storage calculated with new length", result8, testAssertionCount, errorCount); if(!result8) { TTTestLog("Expected a value of %i, but returned value was %i", computedDataSize8, this->mDataSize); } // TEST 9 & 10: set the value of two consecutive samples TTSampleValue pokeValue9 = TTRandom64(); TTSampleValue pokeValue10 = TTRandom64(); this->poke(test9Index, 0, pokeValue9); this->poke(test10Index, 0, pokeValue10); this->peek(test9Index, 0, test9Return); this->peek(test10Index, 0, test10Return); TTBoolean result9 = { pokeValue9 == test9Return }; TTTestAssertion("set value one of two consecutive samples", result9, testAssertionCount, errorCount); if(!result9) { TTTestLog("Expected a value of %f, but returned value was %f", pokeValue9, test9Return); } TTBoolean result10 = { pokeValue10 == test10Return }; TTTestAssertion("set value two of two consecutive samples", result10, testAssertionCount, errorCount); if(!result10) { TTTestLog("Expected a value of %f, but returned value was %f", pokeValue10, test10Return); } // TEST 10a: confirm that pulling value via "peek" message works too TTValue input(test10Index); input.append(0); TTValue output; this->sendMessage("peek", input, output); TTBoolean result10a = { TTTestFloatEquivalence(pokeValue10, TTSampleValue(output)) }; TTTestAssertion("set value two of two consecutive samples", result10a, testAssertionCount, errorCount); if(!result10a) { TTTestLog("Expected a value of %f, but returned value was %f", pokeValue10, TTSampleValue(output)); } // TEST 11: test for interpolation between two consecutive samples TTFloat64 computedInterpFraction = TTRandom64(); TTFloat64 computedInterpIndex = test9Index + computedInterpFraction; TTSampleValue computedInterpValue11 = (computedInterpFraction * pokeValue10) + ((1.0 - computedInterpFraction) * pokeValue9); this->peeki(computedInterpIndex, 0, test11Return); TTBoolean result11 = TTTestFloatEquivalence(computedInterpValue11, test11Return); TTTestAssertion("interpolate between two consecutive samples", result11, testAssertionCount, errorCount); if(!result11) { TTTestLog("Expected a value of %f, but returned value was %f", computedInterpValue11, test11Return); } // TODO: inbounds testing on hold until sorted out at TTMatrix parent class // TEST 12 & 13: test whether out of bounds indices produce errors at head TTInt32 computedIndex12 = -1; // 1 before the head TTInt32 computedIndex13 = 0; // the head TTErr test12Err = this->peek(computedIndex12, 0, test12return); TTErr test13Err = this->peek(computedIndex13, 0, test13return); TTBoolean result12 = { test12Err == kTTErrOutOfBounds }; TTBoolean result13 = { test13Err == kTTErrNone }; TTTestAssertion("peeking sample before index 0 produces an error", result12, testAssertionCount, errorCount); if(!result12) { TTTestLog("Expected a value of %i, but returned value was %i", kTTErrOutOfBounds, test12Err); } TTTestAssertion("peeking sample at index 0 produces no error", result13, testAssertionCount, errorCount); if(!result13) { TTTestLog("Expected a value of %i, but returned value was %i", kTTErrNone, test13Err); } // TEST 14 & 15: test whether out of bounds indices produce errors at tail TTInt32 computedIndex14 = test7Return; // should be latest size in samples TTInt32 computedIndex15 = test7Return - 1; // the tail is actually one less TTErr test14Err = this->poke(computedIndex14, 0, test12return); TTErr test15Err = this->poke(computedIndex15, 0, test13return); TTBoolean result14 = { test14Err == kTTErrOutOfBounds }; TTBoolean result15 = { test15Err == kTTErrNone }; TTTestAssertion("poking sample after index max produces an error", result14, testAssertionCount, errorCount); if(!result14) { TTTestLog("Expected a value of %i, but returned value was %i", kTTErrOutOfBounds, test14Err); } TTTestAssertion("poking sample at index max produces no error", result15, testAssertionCount, errorCount); if(!result15) { TTTestLog("Expected a value of %i, but returned value was %i", kTTErrNone, test15Err); } // TEST 16 & 17: incrementing & decrementing userCount TTUInt16 test16expect = 4; TTUInt16 test17expect = 2; this->incrementUserCount(); this->incrementUserCount(); this->incrementUserCount(); this->incrementUserCount(); TTUInt16 test16return = this->mUserCount; this->decrementUserCount(); this->decrementUserCount(); TTUInt16 test17return = this->mUserCount; TTBoolean result16 = { test16expect == test16return }; TTBoolean result17 = { test17expect == test17return }; TTTestAssertion("incrementing userCount produces expected results", result16, testAssertionCount, errorCount); if(!result16) { TTTestLog("Expected a value of %i, but returned value was %i", test16expect, test16return); } TTTestAssertion("decrementing userCount produces expected results", result17, testAssertionCount, errorCount); if(!result17) { TTTestLog("Expected a value of %i, but returned value was %i", test17expect, test17return); } // TEST 18 & 19: setting & testing bufferPoolStage TTBoolean test18expect = true; TTBoolean test19expect = false; this->setBufferPoolStage(kSM_Active); TTBoolean test18return = this->isBufferPoolStage(kSM_Active); TTBoolean test19return = this->isBufferPoolStage(kSM_BecomingIdle); TTBoolean result18 = { test18expect == test18return }; TTBoolean result19 = { test19expect == test19return }; TTTestAssertion("reports bufferPoolStage as active", result18, testAssertionCount, errorCount); if(!result18) { TTTestLog("Expected a value of %i, but returned value was %i", test18expect, test18return); } TTTestAssertion("reports bufferPoolStage as NOT becoming idle", result19, testAssertionCount, errorCount); if(!result19) { TTTestLog("Expected a value of %i, but returned value was %i", test19expect, test19return); } /* int badSampleCount = 0; TTAudioObjectBasePtr samplematrixObject = NULL; TTAudioSignalPtr input = NULL; TTAudioSignalPtr output = NULL; // TODO: test filling with sine wave // TODO: test scaling (applying gain) // TODO: test normalizing (with optional arg, and also without an optional arg) TTObjectBaseInstantiate("samplematrix", &samplematrixObject, kTTVal1); TTObjectBaseRelease(&input); TTObjectBaseRelease(&output); TTObjectBaseRelease(&samplematrixObject); */ // Wrap up the test results to pass back to whoever called this test return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo); }