| 1 |
/* |
| 2 |
Audio File Library |
| 3 |
Copyright (C) 2012-2013, Michael Pruett <[email protected]> |
| 4 |
|
| 5 |
This program is free software; you can redistribute it and/or modify |
| 6 |
it under the terms of the GNU General Public License as published by |
| 7 |
the Free Software Foundation; either version 2 of the License, or |
| 8 |
(at your option) any later version. |
| 9 |
|
| 10 |
This program is distributed in the hope that it will be useful, |
| 11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
GNU General Public License for more details. |
| 14 |
|
| 15 |
You should have received a copy of the GNU General Public License along |
| 16 |
with this program; if not, write to the Free Software Foundation, Inc., |
| 17 |
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 |
*/ |
| 19 |
|
| 20 |
#include "config.h" |
| 21 |
|
| 22 |
#include <audiofile.h> |
| 23 |
#include <gtest/gtest.h> |
| 24 |
#include <stdint.h> |
| 25 |
#include <stdlib.h> |
| 26 |
#include <unistd.h> |
| 27 |
|
| 28 |
#include "TestUtilities.h" |
| 29 |
|
| 30 |
static const int kNativeByteOrder = |
| 31 |
#ifdef WORDS_BIGENDIAN |
| 32 |
AF_BYTEORDER_BIGENDIAN; |
| 33 |
#else |
| 34 |
AF_BYTEORDER_LITTLEENDIAN; |
| 35 |
#endif |
| 36 |
|
| 37 |
static const int kNonNativeByteOrder = |
| 38 |
#if WORDS_BIGENDIAN |
| 39 |
AF_BYTEORDER_LITTLEENDIAN; |
| 40 |
#else |
| 41 |
AF_BYTEORDER_BIGENDIAN; |
| 42 |
#endif |
| 43 |
|
| 44 |
static void runTest(int fileFormat, int compressionFormat, int channelCount = 1, |
| 45 |
int sampleFormat = AF_SAMPFMT_TWOSCOMP, int sampleWidth = 16, |
| 46 |
int byteOrder = kNativeByteOrder) |
| 47 |
{ |
| 48 |
IgnoreErrors ignoreErrors; |
| 49 |
|
| 50 |
std::string testFileName; |
| 51 |
ASSERT_TRUE(createTemporaryFile("InvalidCompressionFormat", &testFileName)); |
| 52 |
|
| 53 |
AFfilesetup setup = afNewFileSetup(); |
| 54 |
afInitFileFormat(setup, fileFormat); |
| 55 |
afInitSampleFormat(setup, AF_DEFAULT_TRACK, sampleFormat, sampleWidth); |
| 56 |
afInitChannels(setup, AF_DEFAULT_TRACK, channelCount); |
| 57 |
afInitCompression(setup, AF_DEFAULT_TRACK, compressionFormat); |
| 58 |
afInitByteOrder(setup, AF_DEFAULT_TRACK, byteOrder); |
| 59 |
ASSERT_TRUE(afOpenFile(testFileName.c_str(), "w", setup) == AF_NULL_FILEHANDLE); |
| 60 |
afFreeFileSetup(setup); |
| 61 |
|
| 62 |
ASSERT_EQ(::unlink(testFileName.c_str()), 0); |
| 63 |
} |
| 64 |
|
| 65 |
TEST(AIFF, mulaw) { runTest(AF_FILE_AIFF, AF_COMPRESSION_G711_ULAW); } |
| 66 |
TEST(AIFF, Alaw) { runTest(AF_FILE_AIFF, AF_COMPRESSION_G711_ALAW); } |
| 67 |
TEST(AIFF, IMA) { runTest(AF_FILE_AIFF, AF_COMPRESSION_IMA); } |
| 68 |
TEST(AIFF, MSADPCM) { runTest(AF_FILE_AIFF, AF_COMPRESSION_MS_ADPCM); } |
| 69 |
|
| 70 |
TEST(AIFFC, MSADPCM) { runTest(AF_FILE_AIFFC, AF_COMPRESSION_MS_ADPCM); } |
| 71 |
|
| 72 |
TEST(NeXT, IMA) { runTest(AF_FILE_NEXTSND, AF_COMPRESSION_IMA); } |
| 73 |
TEST(NeXT, MSADPCM) { runTest(AF_FILE_NEXTSND, AF_COMPRESSION_MS_ADPCM); } |
| 74 |
|
| 75 |
TEST(IRCAM, IMA) { runTest(AF_FILE_BICSF, AF_COMPRESSION_IMA); } |
| 76 |
TEST(IRCAM, MSADPCM) { runTest(AF_FILE_BICSF, AF_COMPRESSION_MS_ADPCM); } |
| 77 |
|
| 78 |
TEST(AVR, mulaw) { runTest(AF_FILE_AVR, AF_COMPRESSION_G711_ULAW); } |
| 79 |
TEST(AVR, Alaw) { runTest(AF_FILE_AVR, AF_COMPRESSION_G711_ALAW); } |
| 80 |
TEST(AVR, IMA) { runTest(AF_FILE_AVR, AF_COMPRESSION_IMA); } |
| 81 |
TEST(AVR, MSADPCM) { runTest(AF_FILE_AVR, AF_COMPRESSION_MS_ADPCM); } |
| 82 |
|
| 83 |
TEST(IFF, mulaw) { runTest(AF_FILE_IFF_8SVX, AF_COMPRESSION_G711_ULAW); } |
| 84 |
TEST(IFF, Alaw) { runTest(AF_FILE_IFF_8SVX, AF_COMPRESSION_G711_ALAW); } |
| 85 |
TEST(IFF, IMA) { runTest(AF_FILE_IFF_8SVX, AF_COMPRESSION_IMA); } |
| 86 |
TEST(IFF, MSADPCM) { runTest(AF_FILE_IFF_8SVX, AF_COMPRESSION_MS_ADPCM); } |
| 87 |
|
| 88 |
TEST(SampleVision, mulaw) { runTest(AF_FILE_SAMPLEVISION, AF_COMPRESSION_G711_ULAW); } |
| 89 |
TEST(SampleVision, Alaw) { runTest(AF_FILE_SAMPLEVISION, AF_COMPRESSION_G711_ALAW); } |
| 90 |
TEST(SampleVision, IMA) { runTest(AF_FILE_SAMPLEVISION, AF_COMPRESSION_IMA); } |
| 91 |
TEST(SampleVision, MSADPCM) { runTest(AF_FILE_SAMPLEVISION, AF_COMPRESSION_MS_ADPCM); } |
| 92 |
|
| 93 |
TEST(VOC, IMA) { runTest(AF_FILE_VOC, AF_COMPRESSION_IMA); } |
| 94 |
TEST(VOC, MSADPCM) { runTest(AF_FILE_VOC, AF_COMPRESSION_MS_ADPCM); } |
| 95 |
|
| 96 |
TEST(NIST, IMA) { runTest(AF_FILE_NIST_SPHERE, AF_COMPRESSION_IMA); } |
| 97 |
TEST(NIST, MSADPCM) { runTest(AF_FILE_NIST_SPHERE, AF_COMPRESSION_MS_ADPCM); } |
| 98 |
|
| 99 |
TEST(CAF, MSADPCM) { runTest(AF_FILE_CAF, AF_COMPRESSION_MS_ADPCM); } |
| 100 |
|
| 101 |
/* |
| 102 |
Test that opening an audio file with an invalid number of channels |
| 103 |
results in failure. |
| 104 |
*/ |
| 105 |
|
| 106 |
TEST(AIFFC, IMA) { runTest(AF_FILE_AIFFC, AF_COMPRESSION_IMA, 3); } |
| 107 |
|
| 108 |
TEST(WAVE, IMA) { runTest(AF_FILE_WAVE, AF_COMPRESSION_IMA, 3); } |
| 109 |
TEST(WAVE, MSADPCM) { runTest(AF_FILE_WAVE, AF_COMPRESSION_MS_ADPCM, 3); } |
| 110 |
|
| 111 |
TEST(CAF, IMA) { runTest(AF_FILE_CAF, AF_COMPRESSION_IMA, 3); } |
| 112 |
|
| 113 |
/* |
| 114 |
Test that opening an audio file with an invalid sample format results |
| 115 |
in failure. |
| 116 |
*/ |
| 117 |
|
| 118 |
TEST(Mulaw, Signed) |
| 119 |
{ |
| 120 |
for (int sampleWidth=1; sampleWidth<=32; sampleWidth++) |
| 121 |
{ |
| 122 |
if (sampleWidth==16) |
| 123 |
continue; |
| 124 |
runTest(AF_FILE_AIFFC, AF_COMPRESSION_G711_ULAW, 1, AF_SAMPFMT_TWOSCOMP, sampleWidth); |
| 125 |
} |
| 126 |
} |
| 127 |
|
| 128 |
TEST(Mulaw, Unsigned) |
| 129 |
{ |
| 130 |
for (int sampleWidth=1; sampleWidth<=32; sampleWidth++) |
| 131 |
runTest(AF_FILE_AIFFC, AF_COMPRESSION_G711_ULAW, 1, AF_SAMPFMT_UNSIGNED, sampleWidth); |
| 132 |
} |
| 133 |
|
| 134 |
TEST(Mulaw, Float) |
| 135 |
{ |
| 136 |
runTest(AF_FILE_AIFFC, AF_COMPRESSION_G711_ULAW, 1, AF_SAMPFMT_FLOAT, 32); |
| 137 |
} |
| 138 |
|
| 139 |
TEST(Mulaw, Double) |
| 140 |
{ |
| 141 |
runTest(AF_FILE_AIFFC, AF_COMPRESSION_G711_ULAW, 1, AF_SAMPFMT_DOUBLE, 64); |
| 142 |
} |
| 143 |
|
| 144 |
TEST(IMA, Signed) |
| 145 |
{ |
| 146 |
for (int sampleWidth=1; sampleWidth<=32; sampleWidth++) |
| 147 |
{ |
| 148 |
if (sampleWidth==16) |
| 149 |
continue; |
| 150 |
runTest(AF_FILE_AIFFC, AF_COMPRESSION_IMA, 1, AF_SAMPFMT_TWOSCOMP, sampleWidth); |
| 151 |
runTest(AF_FILE_WAVE, AF_COMPRESSION_IMA, 1, AF_SAMPFMT_TWOSCOMP, sampleWidth); |
| 152 |
runTest(AF_FILE_CAF, AF_COMPRESSION_IMA, 1, AF_SAMPFMT_TWOSCOMP, sampleWidth); |
| 153 |
} |
| 154 |
} |
| 155 |
|
| 156 |
TEST(IMA, Unsigned) |
| 157 |
{ |
| 158 |
for (int sampleWidth=1; sampleWidth<=32; sampleWidth++) |
| 159 |
{ |
| 160 |
runTest(AF_FILE_AIFFC, AF_COMPRESSION_IMA, 1, AF_SAMPFMT_UNSIGNED, sampleWidth); |
| 161 |
runTest(AF_FILE_WAVE, AF_COMPRESSION_IMA, 1, AF_SAMPFMT_UNSIGNED, sampleWidth); |
| 162 |
runTest(AF_FILE_CAF, AF_COMPRESSION_IMA, 1, AF_SAMPFMT_UNSIGNED, sampleWidth); |
| 163 |
} |
| 164 |
} |
| 165 |
|
| 166 |
TEST(IMA, Float) |
| 167 |
{ |
| 168 |
runTest(AF_FILE_AIFFC, AF_COMPRESSION_IMA, 1, AF_SAMPFMT_FLOAT, 32); |
| 169 |
runTest(AF_FILE_WAVE, AF_COMPRESSION_IMA, 1, AF_SAMPFMT_FLOAT, 32); |
| 170 |
runTest(AF_FILE_CAF, AF_COMPRESSION_IMA, 1, AF_SAMPFMT_FLOAT, 32); |
| 171 |
} |
| 172 |
|
| 173 |
TEST(IMA, Double) |
| 174 |
{ |
| 175 |
runTest(AF_FILE_AIFFC, AF_COMPRESSION_IMA, 1, AF_SAMPFMT_DOUBLE, 64); |
| 176 |
runTest(AF_FILE_WAVE, AF_COMPRESSION_IMA, 1, AF_SAMPFMT_DOUBLE, 64); |
| 177 |
runTest(AF_FILE_CAF, AF_COMPRESSION_IMA, 1, AF_SAMPFMT_DOUBLE, 64); |
| 178 |
} |
| 179 |
|
| 180 |
TEST(MSADPCM, Signed) |
| 181 |
{ |
| 182 |
for (int sampleWidth=1; sampleWidth<=32; sampleWidth++) |
| 183 |
if (sampleWidth!=16) |
| 184 |
runTest(AF_FILE_WAVE, AF_COMPRESSION_MS_ADPCM, 1, AF_SAMPFMT_TWOSCOMP, sampleWidth); |
| 185 |
} |
| 186 |
|
| 187 |
TEST(MSADPCM, Unsigned) |
| 188 |
{ |
| 189 |
for (int sampleWidth=1; sampleWidth<=32; sampleWidth++) |
| 190 |
runTest(AF_FILE_WAVE, AF_COMPRESSION_MS_ADPCM, 1, AF_SAMPFMT_UNSIGNED, sampleWidth); |
| 191 |
} |
| 192 |
|
| 193 |
TEST(MSADPCM, Float) |
| 194 |
{ |
| 195 |
runTest(AF_FILE_WAVE, AF_COMPRESSION_MS_ADPCM, 1, AF_SAMPFMT_FLOAT, 32); |
| 196 |
} |
| 197 |
|
| 198 |
TEST(MSADPCM, Double) |
| 199 |
{ |
| 200 |
runTest(AF_FILE_WAVE, AF_COMPRESSION_MS_ADPCM, 1, AF_SAMPFMT_DOUBLE, 64); |
| 201 |
} |
| 202 |
|
| 203 |
TEST(Mulaw, InvalidByteOrder) |
| 204 |
{ |
| 205 |
runTest(AF_FILE_WAVE, AF_COMPRESSION_G711_ULAW, 1, AF_SAMPFMT_TWOSCOMP, 16, |
| 206 |
kNonNativeByteOrder); |
| 207 |
} |
| 208 |
|
| 209 |
TEST(Alaw, InvalidByteOrder) |
| 210 |
{ |
| 211 |
runTest(AF_FILE_WAVE, AF_COMPRESSION_G711_ALAW, 1, AF_SAMPFMT_TWOSCOMP, 16, |
| 212 |
kNonNativeByteOrder); |
| 213 |
} |
| 214 |
|
| 215 |
TEST(IMA, InvalidByteOrder) |
| 216 |
{ |
| 217 |
runTest(AF_FILE_WAVE, AF_COMPRESSION_IMA, 1, AF_SAMPFMT_TWOSCOMP, 16, |
| 218 |
kNonNativeByteOrder); |
| 219 |
} |
| 220 |
|
| 221 |
TEST(MSADPCM, InvalidByteOrder) |
| 222 |
{ |
| 223 |
runTest(AF_FILE_WAVE, AF_COMPRESSION_MS_ADPCM, 1, AF_SAMPFMT_TWOSCOMP, 16, |
| 224 |
kNonNativeByteOrder); |
| 225 |
} |
| 226 |
|
| 227 |
int main(int argc, char **argv) |
| 228 |
{ |
| 229 |
::testing::InitGoogleTest(&argc, argv); |
| 230 |
return RUN_ALL_TESTS(); |
| 231 |
} |