Debian Codegraph @

test/InvalidSampleFormat.cpp

raw
1 /*
2 Copyright (C) 2012, Michael Pruett. All rights reserved.
3
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions
6 are met:
7
8 1. Redistributions of source code must retain the above copyright
9 notice, this list of conditions and the following disclaimer.
10
11 2. Redistributions in binary form must reproduce the above copyright
12 notice, this list of conditions and the following disclaimer in the
13 documentation and/or other materials provided with the distribution.
14
15 3. The name of the author may not be used to endorse or promote products
16 derived from this software without specific prior written permission.
17
18 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30 #include <audiofile.h>
31 #include <gtest/gtest.h>
32 #include <stdint.h>
33 #include <stdlib.h>
34 #include <unistd.h>
35
36 #include "TestUtilities.h"
37
38 void runTest(int fileFormat, int sampleFormat, int sampleWidth)
39 {
40 IgnoreErrors ignoreErrors;
41
42 std::string testFileName;
43 ASSERT_TRUE(createTemporaryFile("InvalidSampleFormat", &testFileName));
44
45 AFfilesetup setup = afNewFileSetup();
46 afInitFileFormat(setup, fileFormat);
47 afInitSampleFormat(setup, AF_DEFAULT_TRACK, sampleFormat, sampleWidth);
48 afInitChannels(setup, AF_DEFAULT_TRACK, 1);
49 ASSERT_TRUE(afOpenFile(testFileName.c_str(), "w", setup) == AF_NULL_FILEHANDLE);
50 afFreeFileSetup(setup);
51
52 ASSERT_EQ(::unlink(testFileName.c_str()), 0);
53 }
54
55 void testInt8(int fileFormat)
56 {
57 runTest(fileFormat, AF_SAMPFMT_TWOSCOMP, 8);
58 }
59
60 void testUInt8(int fileFormat)
61 {
62 runTest(fileFormat, AF_SAMPFMT_UNSIGNED, 8);
63 }
64
65 void testInt16(int fileFormat)
66 {
67 runTest(fileFormat, AF_SAMPFMT_TWOSCOMP, 16);
68 }
69
70 void testUInt16(int fileFormat)
71 {
72 runTest(fileFormat, AF_SAMPFMT_UNSIGNED, 16);
73 }
74
75 void testInt24(int fileFormat)
76 {
77 runTest(fileFormat, AF_SAMPFMT_TWOSCOMP, 24);
78 }
79
80 void testUInt24(int fileFormat)
81 {
82 runTest(fileFormat, AF_SAMPFMT_UNSIGNED, 24);
83 }
84
85 void testInt32(int fileFormat)
86 {
87 runTest(fileFormat, AF_SAMPFMT_TWOSCOMP, 32);
88 }
89
90 void testUInt32(int fileFormat)
91 {
92 runTest(fileFormat, AF_SAMPFMT_UNSIGNED, 32);
93 }
94
95 void testFloat32(int fileFormat)
96 {
97 runTest(fileFormat, AF_SAMPFMT_FLOAT, 32);
98 }
99
100 void testFloat64(int fileFormat)
101 {
102 runTest(fileFormat, AF_SAMPFMT_DOUBLE, 64);
103 }
104
105 TEST(AIFF, Float) { testFloat32(AF_FILE_AIFF); }
106 TEST(AIFF, Double) { testFloat64(AF_FILE_AIFF); }
107
108 TEST(IFF, Int16) { testInt16(AF_FILE_IFF_8SVX); }
109 TEST(IFF, Int24) { testInt24(AF_FILE_IFF_8SVX); }
110 TEST(IFF, Int32) { testInt32(AF_FILE_IFF_8SVX); }
111 TEST(IFF, Float) { testFloat32(AF_FILE_IFF_8SVX); }
112 TEST(IFF, Double) { testFloat64(AF_FILE_IFF_8SVX); }
113
114 TEST(AVR, Int24) { testInt24(AF_FILE_AVR); }
115 TEST(AVR, Int32) { testInt32(AF_FILE_AVR); }
116 TEST(AVR, Float) { testFloat32(AF_FILE_AVR); }
117 TEST(AVR, Double) { testFloat64(AF_FILE_AVR); }
118
119 TEST(SampleVision, Int8) { testInt8(AF_FILE_SAMPLEVISION); }
120 TEST(SampleVision, Int24) { testInt24(AF_FILE_SAMPLEVISION); }
121 TEST(SampleVision, Int32) { testInt32(AF_FILE_SAMPLEVISION); }
122 TEST(SampleVision, Float) { testFloat32(AF_FILE_SAMPLEVISION); }
123 TEST(SampleVision, Double) { testFloat64(AF_FILE_SAMPLEVISION); }
124
125 TEST(VOC, Int24) { testInt24(AF_FILE_VOC); }
126 TEST(VOC, Int32) { testInt32(AF_FILE_VOC); }
127 TEST(VOC, Float) { testFloat32(AF_FILE_VOC); }
128 TEST(VOC, Double) { testFloat64(AF_FILE_VOC); }
129
130 TEST(NIST, Int24) { testInt24(AF_FILE_NIST_SPHERE); }
131 TEST(NIST, Int32) { testInt32(AF_FILE_NIST_SPHERE); }
132 TEST(NIST, Float) { testFloat32(AF_FILE_NIST_SPHERE); }
133 TEST(NIST, Double) { testFloat64(AF_FILE_NIST_SPHERE); }
134
135 int main(int argc, char **argv)
136 {
137 ::testing::InitGoogleTest(&argc, argv);
138 return RUN_ALL_TESTS();
139 }