| 145 | } |
| 146 | |
| 147 | void testReads() { |
| 148 | // Now use the blockfile's method to read data and compare it to what we originally wrote |
| 149 | std::cout << "\tVerifying that we can read back correctly..." << std::flush; |
| 150 | |
| 151 | samplePtr int16buf = NewSamples(dataLen, int16Sample); |
| 152 | samplePtr int24buf = NewSamples(dataLen, int24Sample); |
| 153 | samplePtr floatbuf = NewSamples(dataLen, floatSample); |
| 154 | |
| 155 | // First try a read of the entire buffer |
| 156 | int16BlockFile->ReadData(int16buf, int16Sample, 0, dataLen); |
| 157 | int24BlockFile->ReadData(int24buf, int24Sample, 0, dataLen); |
| 158 | floatBlockFile->ReadData(floatbuf, floatSample, 0, dataLen); |
| 159 | |
| 160 | AssertBuffersEqual(int16Data, (short*)int16buf, dataLen); |
| 161 | AssertBuffersEqual(int24Data, (int*)int24buf, dataLen); |
| 162 | AssertBuffersEqual(floatData, (float*)floatbuf, dataLen); |
| 163 | |
| 164 | // Now test a read that starts at the beginning but quits |
| 165 | // before the end |
| 166 | int someOffset = 537; |
| 167 | |
| 168 | int16BlockFile->ReadData(int16buf, int16Sample, 0, someOffset); |
| 169 | int24BlockFile->ReadData(int24buf, int24Sample, 0, someOffset); |
| 170 | floatBlockFile->ReadData(floatbuf, floatSample, 0, someOffset); |
| 171 | |
| 172 | AssertBuffersEqual(int16Data, (short*)int16buf, someOffset); |
| 173 | AssertBuffersEqual(int24Data, (int*)int24buf, someOffset); |
| 174 | AssertBuffersEqual(floatData, (float*)floatbuf, someOffset); |
| 175 | |
| 176 | // Now try a read that starts in the middle and goes to the |
| 177 | // end |
| 178 | int16BlockFile->ReadData(int16buf, int16Sample, someOffset, dataLen-someOffset); |
| 179 | int24BlockFile->ReadData(int24buf, int24Sample, someOffset, dataLen-someOffset); |
| 180 | floatBlockFile->ReadData(floatbuf, floatSample, someOffset, dataLen-someOffset); |
| 181 | |
| 182 | AssertBuffersEqual(int16Data+someOffset, (short*)int16buf, dataLen-someOffset); |
| 183 | AssertBuffersEqual(int24Data+someOffset, (int*)int24buf, dataLen-someOffset); |
| 184 | AssertBuffersEqual(floatData+someOffset, (float*)floatbuf, dataLen-someOffset); |
| 185 | |
| 186 | |
| 187 | std::cout << "OK\n"; |
| 188 | } |
| 189 | }; |
| 190 | |
| 191 | int main() |