![]() |
Mixxx
|
00001 #include <gtest/gtest.h> 00002 #include <QDebug> 00003 00004 #include "trackinfoobject.h" 00005 #include "analyserwavesummary.h" 00006 00007 #define BIGBUF_SIZE (1024 * 1024) //Megabyte 00008 #define CANARY_SIZE (1024*4) 00009 #define MAGIC_FLOAT 1234.567890f 00010 #define CANARY_FLOAT 0.0f 00011 00012 namespace { 00013 00014 class AnalyserWavesummaryTest: public testing::Test { 00015 protected: 00016 virtual void SetUp() { 00017 qDebug() << "SetUp"; 00018 aw = new AnalyserWavesummary(); 00019 tio = TrackPointer(new TrackInfoObject("foo")); 00020 //Subpixels per second, from waveformrenderer.cpp:247 00021 tio->setVisualResampleRate(200); 00022 00023 bigbuf = new CSAMPLE[BIGBUF_SIZE]; 00024 for (int i = 0; i < BIGBUF_SIZE; i++) 00025 bigbuf[i] = MAGIC_FLOAT; 00026 00027 //Memory layout for canaryBigBuf looks like 00028 // [ canary | big buf | canary ] 00029 // 00030 00031 canaryBigBuf = new CSAMPLE[BIGBUF_SIZE + 2*CANARY_SIZE]; 00032 for (int i = 0; i < CANARY_SIZE; i++) 00033 canaryBigBuf[i] = CANARY_FLOAT; 00034 for (int i = CANARY_SIZE; i < CANARY_SIZE+BIGBUF_SIZE; i++) 00035 canaryBigBuf[i] = MAGIC_FLOAT; 00036 for (int i = CANARY_SIZE+BIGBUF_SIZE; i < 2*CANARY_SIZE+BIGBUF_SIZE; i++) 00037 canaryBigBuf[i] = CANARY_FLOAT; 00038 } 00039 00040 virtual void TearDown() { 00041 qDebug() << "TearDown"; 00042 qDebug() << "delete aw"; 00043 delete aw; 00044 delete [] bigbuf; 00045 delete [] canaryBigBuf; 00046 } 00047 00048 AnalyserWavesummary* aw; 00049 TrackPointer tio; 00050 CSAMPLE* bigbuf; 00051 CSAMPLE* canaryBigBuf; 00052 }; 00053 00054 //Test to make sure we don't modify the source buffer. 00055 TEST_F(AnalyserWavesummaryTest, simpleAnalyze) { 00056 aw->initialise(tio, 44100, BIGBUF_SIZE); 00057 aw->process(bigbuf, BIGBUF_SIZE); 00058 aw->finalise(tio); 00059 for (int i = 0; i < BIGBUF_SIZE; i++) { 00060 EXPECT_FLOAT_EQ(bigbuf[i], MAGIC_FLOAT); 00061 } 00062 } 00063 00064 //Basic test to make sure we don't step out of bounds. 00065 TEST_F(AnalyserWavesummaryTest, canary) { 00066 aw->initialise(tio, 44100, BIGBUF_SIZE); 00067 aw->process(&canaryBigBuf[CANARY_SIZE], BIGBUF_SIZE); 00068 aw->finalise(tio); 00069 for (int i = 0; i < CANARY_SIZE; i++) { 00070 EXPECT_FLOAT_EQ(canaryBigBuf[i], CANARY_FLOAT); 00071 } 00072 for (int i = CANARY_SIZE+BIGBUF_SIZE; i < 2*CANARY_SIZE+BIGBUF_SIZE; i++) { 00073 EXPECT_FLOAT_EQ(canaryBigBuf[i], CANARY_FLOAT); 00074 } 00075 } 00076 00077 //Test to make sure that if an incorrect totalSamples is passed to 00078 //initialise(..) and process(..) is told to process more samples than that, 00079 //that we don't step out of bounds. 00080 TEST_F(AnalyserWavesummaryTest, wrongTotalSamples) { 00081 aw->initialise(tio, 44100, BIGBUF_SIZE); 00082 //Process in a loop 00083 int wrongTotalSamples = BIGBUF_SIZE+1; //Too big by 1 sample... 00084 //Note that the correct totalSamples would just be BIGBUF_SIZE. :) 00085 int blockSize = 2*32768; 00086 for (int i = CANARY_SIZE; i < CANARY_SIZE+wrongTotalSamples; i += blockSize) { 00087 aw->process(&canaryBigBuf[i], blockSize); 00088 } 00089 aw->finalise(tio); 00090 //Ensure the source buffer is intact 00091 for (int i = CANARY_SIZE; i < BIGBUF_SIZE; i++) { 00092 EXPECT_FLOAT_EQ(canaryBigBuf[i], MAGIC_FLOAT); 00093 } 00094 //Make sure our canaries are still OK 00095 for (int i = 0; i < CANARY_SIZE; i++) { 00096 EXPECT_FLOAT_EQ(canaryBigBuf[i], CANARY_FLOAT); 00097 } 00098 for (int i = CANARY_SIZE+BIGBUF_SIZE; i < 2*CANARY_SIZE+BIGBUF_SIZE; i++) { 00099 EXPECT_FLOAT_EQ(canaryBigBuf[i], CANARY_FLOAT); 00100 } 00101 } 00102 }