Debian Codegraph @

test/ALAC.cpp

raw
1 /*
2 Audio File Library
3 Copyright (C) 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 <audiofile.h>
21 #include <gtest/gtest.h>
22
23 #include <functional>
24 #include <stdint.h>
25 #include <unistd.h>
26
27 #include "Lossless.h"
28 #include "TestUtilities.h"
29
30 template <typename SampleType>
31 static void testALAC(int fileFormat, int channelCount, int sampleWidth, int frameCount)
32 {
33 testLossless<SampleType>("ALAC", fileFormat, AF_COMPRESSION_ALAC,
34 channelCount, sampleWidth, frameCount);
35 }
36
37 TEST(ALAC, ALAC_16)
38 {
39 for (int channelCount=1; channelCount<=8; channelCount++)
40 testALAC<int16_t>(AF_FILE_CAF, channelCount, 16, 82421);
41 }
42
43 TEST(ALAC, ALAC_20)
44 {
45 for (int channelCount=1; channelCount<=8; channelCount++)
46 testALAC<int32_t>(AF_FILE_CAF, channelCount, 20, 82421);
47 }
48
49 TEST(ALAC, ALAC_24)
50 {
51 for (int channelCount=1; channelCount<=8; channelCount++)
52 testALAC<int32_t>(AF_FILE_CAF, channelCount, 24, 82421);
53 }
54
55 TEST(ALAC, ALAC_32)
56 {
57 for (int channelCount=1; channelCount<=8; channelCount++)
58 testALAC<int32_t>(AF_FILE_CAF, channelCount, 32, 82421);
59 }
60
61 static void testInvalidSampleFormat(int sampleFormat, int sampleWidth)
62 {
63 std::string testFileName;
64 ASSERT_TRUE(createTemporaryFile("ALAC", &testFileName));
65
66 AFfilesetup setup = afNewFileSetup();
67 afInitFileFormat(setup, AF_FILE_CAF);
68 afInitChannels(setup, AF_DEFAULT_TRACK, 1);
69 afInitSampleFormat(setup, AF_DEFAULT_TRACK, sampleFormat, sampleWidth);
70 afInitCompression(setup, AF_DEFAULT_TRACK, AF_COMPRESSION_ALAC);
71 AFfilehandle file = afOpenFile(testFileName.c_str(), "w", setup);
72 ASSERT_FALSE(file);
73 afFreeFileSetup(setup);
74
75 ASSERT_EQ(::unlink(testFileName.c_str()), 0);
76 }
77
78 TEST(ALAC, InvalidSampleWidths)
79 {
80 IgnoreErrors ignoreErrors;
81
82 for (int sampleWidth=1; sampleWidth<=32; sampleWidth++)
83 {
84 if (sampleWidth == 16 ||
85 sampleWidth == 20 ||
86 sampleWidth == 24 ||
87 sampleWidth == 32)
88 continue;
89
90 testInvalidSampleFormat(AF_SAMPFMT_TWOSCOMP, sampleWidth);
91 }
92 }
93
94 TEST(ALAC, InvalidSampleFormats)
95 {
96 IgnoreErrors ignoreErrors;
97
98 for (int sampleWidth=1; sampleWidth<=32; sampleWidth++)
99 testInvalidSampleFormat(AF_SAMPFMT_UNSIGNED, sampleWidth);
100
101 testInvalidSampleFormat(AF_SAMPFMT_FLOAT, 32);
102 testInvalidSampleFormat(AF_SAMPFMT_DOUBLE, 64);
103 }
104
105 TEST(ALAC, InvalidChannels)
106 {
107 IgnoreErrors ignoreErrors;
108
109 std::string testFileName;
110 ASSERT_TRUE(createTemporaryFile("ALAC", &testFileName));
111
112 AFfilesetup setup = afNewFileSetup();
113 afInitFileFormat(setup, AF_FILE_CAF);
114 afInitChannels(setup, AF_DEFAULT_TRACK, 9);
115 afInitSampleFormat(setup, AF_DEFAULT_TRACK, AF_SAMPFMT_TWOSCOMP, 16);
116 afInitCompression(setup, AF_DEFAULT_TRACK, AF_COMPRESSION_ALAC);
117 AFfilehandle file = afOpenFile(testFileName.c_str(), "w", setup);
118 ASSERT_FALSE(file);
119 afFreeFileSetup(setup);
120
121 ASSERT_EQ(::unlink(testFileName.c_str()), 0);
122 }
123
124 int main(int argc, char **argv)
125 {
126 ::testing::InitGoogleTest(&argc, argv);
127 return RUN_ALL_TESTS();
128 }