6 |
#include <string.h> |
#include <string.h> |
7 |
|
|
8 |
#include "../gig.h" |
#include "../gig.h" |
9 |
|
#include "../helper.h" |
10 |
|
|
11 |
CPPUNIT_TEST_SUITE_REGISTRATION(GigWriteTest); |
CPPUNIT_TEST_SUITE_REGISTRATION(GigWriteTest); |
12 |
|
|
22 |
int16_t sampleData3[] = { 7, 8, 9 }; |
int16_t sampleData3[] = { 7, 8, 9 }; |
23 |
int16_t sampleData4[] = { 10,11,12 }; |
int16_t sampleData4[] = { 10,11,12 }; |
24 |
|
|
25 |
|
// 1. Run) print the purpose of this test case first |
26 |
void GigWriteTest::printTestSuiteName() { |
void GigWriteTest::printTestSuiteName() { |
27 |
cout << "\b \nTesting Gigasampler write support: " << flush; |
cout << "\b \nTesting Gigasampler write support: " << flush; |
28 |
} |
} |
39 |
///////////////////////////////////////////////////////////////////////////// |
///////////////////////////////////////////////////////////////////////////// |
40 |
// The actual test cases (in order) ... |
// The actual test cases (in order) ... |
41 |
|
|
42 |
// 1.) create a new Gigasampler file from scratch |
// 2. Run) create a new Gigasampler file from scratch |
43 |
void GigWriteTest::createNewGigFile() { |
void GigWriteTest::createNewGigFile() { |
44 |
try { |
try { |
45 |
// create an empty Gigasampler file |
// create an empty Gigasampler file |
126 |
} |
} |
127 |
} |
} |
128 |
|
|
129 |
// 2.) test if the newly created Gigasampler file exists & can be opened |
// 3. Run) test if the newly created Gigasampler file exists & can be opened |
130 |
void GigWriteTest::testOpenCreatedGigFile() { |
void GigWriteTest::testOpenCreatedGigFile() { |
131 |
// try to open previously created Gigasampler file |
// try to open previously created Gigasampler file |
132 |
try { |
try { |
139 |
} |
} |
140 |
} |
} |
141 |
|
|
142 |
// 3.) test if the articulation informations of the newly created Gigasampler file were correctly written |
// 4. Run) test if the articulation informations of the newly created Gigasampler file were correctly written |
143 |
void GigWriteTest::testArticulationsOfCreatedGigFile() { |
void GigWriteTest::testArticulationsOfCreatedGigFile() { |
144 |
try { |
try { |
145 |
// open previously created Gigasampler file |
// open previously created Gigasampler file |
146 |
RIFF::File riff(TEST_GIG_FILE_NAME); |
RIFF::File riff(TEST_GIG_FILE_NAME); |
147 |
gig::File file(&riff); |
gig::File file(&riff); |
148 |
|
// check global file informations |
149 |
|
CPPUNIT_ASSERT(file.pInfo); |
150 |
|
CPPUNIT_ASSERT(file.pInfo->Name == "Foo Gigasampler File"); |
151 |
// check amount of instruments and samples |
// check amount of instruments and samples |
152 |
CPPUNIT_ASSERT(file.Instruments == 4); |
CPPUNIT_ASSERT(file.Instruments == 4); |
153 |
|
int iInstruments = 0; |
154 |
|
for (gig::Instrument* pInstrument = file.GetFirstInstrument(); pInstrument; pInstrument = file.GetNextInstrument()) iInstruments++; |
155 |
|
CPPUNIT_ASSERT(iInstruments == 4); |
156 |
int iSamples = 0; |
int iSamples = 0; |
157 |
for (gig::Sample* pSample = file.GetFirstSample(); pSample; pSample = file.GetNextSample()) iSamples++; |
for (gig::Sample* pSample = file.GetFirstSample(); pSample; pSample = file.GetNextSample()) iSamples++; |
158 |
CPPUNIT_ASSERT(iSamples == 4); |
CPPUNIT_ASSERT(iSamples == 4); |
159 |
|
// check samples' meta informations |
160 |
//TODO: check all articulations previously set in createNewGigFile() |
int iSample = 1; |
161 |
|
for (gig::Sample* pSample = file.GetFirstSample(); pSample; pSample = file.GetNextSample()) { |
162 |
|
CPPUNIT_ASSERT(pSample->pInfo); |
163 |
|
std::string sOughtToBe = "Foo Sample " + ToString(iSample); |
164 |
|
CPPUNIT_ASSERT(pSample->pInfo->Name == sOughtToBe); |
165 |
|
CPPUNIT_ASSERT(pSample->GetSize() == 3); // three sample points |
166 |
|
CPPUNIT_ASSERT(pSample->SamplesTotal == 3); // three sample points |
167 |
|
CPPUNIT_ASSERT(pSample->Channels == 1); // mono |
168 |
|
CPPUNIT_ASSERT(pSample->BitDepth == 16); // bit depth 16 bits |
169 |
|
CPPUNIT_ASSERT(pSample->FrameSize == 16 / 8 * 1); |
170 |
|
CPPUNIT_ASSERT(pSample->SamplesPerSecond == 44100); |
171 |
|
iSample++; |
172 |
|
} |
173 |
|
// check instruments' meta informations |
174 |
|
int iInstrument = 1; |
175 |
|
for (gig::Instrument* pInstrument = file.GetFirstInstrument(); pInstrument; pInstrument = file.GetNextInstrument()) { |
176 |
|
CPPUNIT_ASSERT(pInstrument->pInfo); |
177 |
|
std::string sOughtToBe = "Foo Instrument " + ToString(iInstrument); |
178 |
|
CPPUNIT_ASSERT(pInstrument->pInfo->Name == sOughtToBe); |
179 |
|
gig::Region* pRegion = pInstrument->GetFirstRegion(); |
180 |
|
CPPUNIT_ASSERT(pRegion); |
181 |
|
CPPUNIT_ASSERT(pRegion->Dimensions == 0); |
182 |
|
CPPUNIT_ASSERT(pRegion->DimensionRegions == 1); |
183 |
|
sOughtToBe = "Foo Sample " + ToString(iInstrument); |
184 |
|
CPPUNIT_ASSERT(pRegion->GetSample()->pInfo->Name == sOughtToBe); |
185 |
|
gig::DimensionRegion* pDimensionRegion = pRegion->GetDimensionRegionByValue((uint[8]){0,0,0,0,0,0,0,0}); |
186 |
|
CPPUNIT_ASSERT(pDimensionRegion); |
187 |
|
CPPUNIT_ASSERT(pDimensionRegion->pSample->pInfo->Name == sOughtToBe); |
188 |
|
iInstrument++; |
189 |
|
} |
190 |
} catch (RIFF::Exception e) { |
} catch (RIFF::Exception e) { |
191 |
std::cerr << "\nThere was an exception while checking the articulation data of the newly created Gigasampler file:\n" << std::flush; |
std::cerr << "\nThere was an exception while checking the articulation data of the newly created Gigasampler file:\n" << std::flush; |
192 |
e.PrintMessage(); |
e.PrintMessage(); |
194 |
} |
} |
195 |
} |
} |
196 |
|
|
197 |
// 4.) try to write sample data to that newly created Gigasampler file |
// 5. Run) try to write sample data to that newly created Gigasampler file |
198 |
void GigWriteTest::testWriteSamples() { |
void GigWriteTest::testWriteSamples() { |
199 |
try { |
try { |
200 |
// open previously created Gigasampler file |
// open previously created Gigasampler file (in read/write mode) |
201 |
RIFF::File riff(TEST_GIG_FILE_NAME); |
RIFF::File riff(TEST_GIG_FILE_NAME); |
202 |
|
riff.SetMode(RIFF::stream_mode_read_write); |
203 |
gig::File file(&riff); |
gig::File file(&riff); |
204 |
// until this point we just wrote the articulation data to the .gig file |
// until this point we just wrote the articulation data to the .gig file |
205 |
// and prepared the .gig file for writing our 4 example sample data, so |
// and prepared the .gig file for writing our 4 example sample data, so |
223 |
e.PrintMessage(); |
e.PrintMessage(); |
224 |
throw e; // stop further tests |
throw e; // stop further tests |
225 |
} |
} |
226 |
|
} |
227 |
|
|
228 |
|
// 6. Run) check the previously written samples' data |
229 |
|
void GigWriteTest::testSamplesData() { |
230 |
|
try { |
231 |
|
// open previously created Gigasampler file |
232 |
|
RIFF::File riff(TEST_GIG_FILE_NAME); |
233 |
|
gig::File file(&riff); |
234 |
|
// check samples' meta informations |
235 |
|
gig::Sample* pSample1 = file.GetFirstSample(); |
236 |
|
gig::Sample* pSample2 = file.GetNextSample(); |
237 |
|
gig::Sample* pSample3 = file.GetNextSample(); |
238 |
|
gig::Sample* pSample4 = file.GetNextSample(); |
239 |
|
CPPUNIT_ASSERT(pSample1); |
240 |
|
CPPUNIT_ASSERT(pSample2); |
241 |
|
CPPUNIT_ASSERT(pSample3); |
242 |
|
CPPUNIT_ASSERT(pSample4); |
243 |
|
gig::buffer_t sampleBuffer1 = pSample1->LoadSampleData(); |
244 |
|
gig::buffer_t sampleBuffer2 = pSample2->LoadSampleData(); |
245 |
|
gig::buffer_t sampleBuffer3 = pSample3->LoadSampleData(); |
246 |
|
gig::buffer_t sampleBuffer4 = pSample4->LoadSampleData(); |
247 |
|
CPPUNIT_ASSERT(sampleBuffer1.pStart); |
248 |
|
CPPUNIT_ASSERT(sampleBuffer2.pStart); |
249 |
|
CPPUNIT_ASSERT(sampleBuffer3.pStart); |
250 |
|
CPPUNIT_ASSERT(sampleBuffer4.pStart); |
251 |
|
CPPUNIT_ASSERT(sampleBuffer1.Size == pSample1->FrameSize * 3); // three sample points length |
252 |
|
CPPUNIT_ASSERT(sampleBuffer2.Size == pSample2->FrameSize * 3); // three sample points length |
253 |
|
CPPUNIT_ASSERT(sampleBuffer3.Size == pSample3->FrameSize * 3); // three sample points length |
254 |
|
CPPUNIT_ASSERT(sampleBuffer4.Size == pSample4->FrameSize * 3); // three sample points length |
255 |
|
// check samples' PCM data |
256 |
|
CPPUNIT_ASSERT(memcmp(sampleBuffer1.pStart, sampleData1, 3) == 0); |
257 |
|
CPPUNIT_ASSERT(memcmp(sampleBuffer2.pStart, sampleData2, 3) == 0); |
258 |
|
CPPUNIT_ASSERT(memcmp(sampleBuffer3.pStart, sampleData3, 3) == 0); |
259 |
|
CPPUNIT_ASSERT(memcmp(sampleBuffer4.pStart, sampleData4, 3) == 0); |
260 |
|
} catch (RIFF::Exception e) { |
261 |
|
std::cerr << "\nThere was an exception while checking the written samples' data:\n" << std::flush; |
262 |
|
e.PrintMessage(); |
263 |
|
throw e; // stop further tests |
264 |
|
} |
265 |
} |
} |