Debian Codegraph @

test/Query.cpp

raw
1 /*
2 Audio File Library
3 Copyright (C) 2012, 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 #include <unistd.h>
23
24 #include "TestUtilities.h"
25
26 TEST(Query, FileFormats)
27 {
28 IgnoreErrors ignoreErrors;
29
30 int fileFormats[] =
31 {
32 AF_FILE_UNKNOWN,
33 AF_FILE_RAWDATA,
34 AF_FILE_AIFFC,
35 AF_FILE_AIFF,
36 AF_FILE_NEXTSND,
37 AF_FILE_WAVE,
38 AF_FILE_BICSF,
39 AF_FILE_MPEG1BITSTREAM,
40 AF_FILE_SOUNDDESIGNER1,
41 AF_FILE_SOUNDDESIGNER2,
42 AF_FILE_AVR,
43 AF_FILE_IFF_8SVX,
44 AF_FILE_SAMPLEVISION,
45 AF_FILE_VOC,
46 AF_FILE_NIST_SPHERE,
47 AF_FILE_SOUNDFONT2,
48 AF_FILE_CAF
49 };
50 int numFileFormats = sizeof (fileFormats) / sizeof (int);
51 for (int i=0; i<numFileFormats; i++)
52 {
53 long implemented = afQueryLong(AF_QUERYTYPE_FILEFMT,
54 AF_QUERY_IMPLEMENTED, fileFormats[i], 0, 0);
55 const char *label =
56 static_cast<const char *>(afQueryPointer(AF_QUERYTYPE_FILEFMT,
57 AF_QUERY_LABEL, fileFormats[i], 0, 0));
58 if (implemented)
59 EXPECT_TRUE(label);
60 const char *name =
61 static_cast<const char *>(afQueryPointer(AF_QUERYTYPE_FILEFMT,
62 AF_QUERY_NAME, fileFormats[i], 0, 0));
63 if (implemented)
64 EXPECT_TRUE(name);
65 const char *description =
66 static_cast<const char *>(afQueryPointer(AF_QUERYTYPE_FILEFMT,
67 AF_QUERY_DESC, fileFormats[i], 0, 0));
68 if (implemented)
69 EXPECT_TRUE(description);
70 }
71 }
72
73 TEST(Query, CompressionFormats)
74 {
75 IgnoreErrors ignoreErrors;
76
77 int compressionFormats[] =
78 {
79 AF_COMPRESSION_NONE,
80 AF_COMPRESSION_G711_ULAW,
81 AF_COMPRESSION_G711_ALAW,
82 AF_COMPRESSION_IMA,
83 AF_COMPRESSION_MS_ADPCM,
84 AF_COMPRESSION_G722,
85 AF_COMPRESSION_APPLE_ACE2,
86 AF_COMPRESSION_APPLE_ACE8,
87 AF_COMPRESSION_APPLE_MAC3,
88 AF_COMPRESSION_APPLE_MAC6
89 };
90 int numCompressionFormats = sizeof (compressionFormats) / sizeof (int);
91 for (int i=0; i<numCompressionFormats; i++)
92 {
93 long implemented = afQueryLong(AF_QUERYTYPE_COMPRESSION,
94 AF_QUERY_IMPLEMENTED, compressionFormats[i], 0, 0);
95 long nativeSampleFormat = afQueryLong(AF_QUERYTYPE_COMPRESSION,
96 AF_QUERY_NATIVE_SAMPFMT, compressionFormats[i], 0, 0);
97 if (implemented)
98 EXPECT_TRUE(nativeSampleFormat == AF_SAMPFMT_TWOSCOMP ||
99 nativeSampleFormat == AF_SAMPFMT_UNSIGNED ||
100 nativeSampleFormat == AF_SAMPFMT_FLOAT ||
101 nativeSampleFormat == AF_SAMPFMT_DOUBLE);
102 long nativeSampleWidth = afQueryLong(AF_QUERYTYPE_COMPRESSION,
103 AF_QUERY_NATIVE_SAMPWIDTH, compressionFormats[i], 0, 0);
104 if (implemented)
105 {
106 EXPECT_GE(nativeSampleWidth, 1);
107 EXPECT_LE(nativeSampleWidth, 64);
108 }
109 const char *label =
110 static_cast<const char *>(afQueryPointer(AF_QUERYTYPE_COMPRESSION,
111 AF_QUERY_LABEL, compressionFormats[i], 0, 0));
112 if (implemented)
113 EXPECT_TRUE(label);
114 const char *name =
115 static_cast<const char *>(afQueryPointer(AF_QUERYTYPE_COMPRESSION,
116 AF_QUERY_NAME, compressionFormats[i], 0, 0));
117 if (implemented)
118 EXPECT_TRUE(name);
119 const char *description =
120 static_cast<const char *>(afQueryPointer(AF_QUERYTYPE_COMPRESSION,
121 AF_QUERY_DESC, compressionFormats[i], 0, 0));
122 if (implemented)
123 EXPECT_TRUE(description);
124 }
125 }
126
127 int main(int argc, char **argv)
128 {
129 ::testing::InitGoogleTest(&argc, argv);
130 return RUN_ALL_TESTS();
131 }