File: Query.cpp

package info (click to toggle)
audiofile 0.3.6-5%2Bdeb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 4,980 kB
  • sloc: cpp: 36,534; sh: 11,090; ansic: 6,060; makefile: 441
file content (131 lines) | stat: -rw-r--r-- 3,866 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
	Audio File Library
	Copyright (C) 2012, Michael Pruett <michael@68k.org>

	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License along
	with this program; if not, write to the Free Software Foundation, Inc.,
	51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#include <audiofile.h>
#include <gtest/gtest.h>
#include <unistd.h>

#include "TestUtilities.h"

TEST(Query, FileFormats)
{
	IgnoreErrors ignoreErrors;

	int fileFormats[] =
	{
		AF_FILE_UNKNOWN,
		AF_FILE_RAWDATA,
		AF_FILE_AIFFC,
		AF_FILE_AIFF,
		AF_FILE_NEXTSND,
		AF_FILE_WAVE,
		AF_FILE_BICSF,
		AF_FILE_MPEG1BITSTREAM,
		AF_FILE_SOUNDDESIGNER1,
		AF_FILE_SOUNDDESIGNER2,
		AF_FILE_AVR,
		AF_FILE_IFF_8SVX,
		AF_FILE_SAMPLEVISION,
		AF_FILE_VOC,
		AF_FILE_NIST_SPHERE,
		AF_FILE_SOUNDFONT2,
		AF_FILE_CAF
	};
	int numFileFormats = sizeof (fileFormats) / sizeof (int);
	for (int i=0; i<numFileFormats; i++)
	{
		long implemented = afQueryLong(AF_QUERYTYPE_FILEFMT,
			AF_QUERY_IMPLEMENTED, fileFormats[i], 0, 0);
		const char *label =
			static_cast<const char *>(afQueryPointer(AF_QUERYTYPE_FILEFMT,
				AF_QUERY_LABEL, fileFormats[i], 0, 0));
		if (implemented)
			EXPECT_TRUE(label);
		const char *name =
			static_cast<const char *>(afQueryPointer(AF_QUERYTYPE_FILEFMT,
				AF_QUERY_NAME, fileFormats[i], 0, 0));
		if (implemented)
			EXPECT_TRUE(name);
		const char *description =
			static_cast<const char *>(afQueryPointer(AF_QUERYTYPE_FILEFMT,
				AF_QUERY_DESC, fileFormats[i], 0, 0));
		if (implemented)
			EXPECT_TRUE(description);
	}
}

TEST(Query, CompressionFormats)
{
	IgnoreErrors ignoreErrors;

	int compressionFormats[] =
	{
		AF_COMPRESSION_NONE,
		AF_COMPRESSION_G711_ULAW,
		AF_COMPRESSION_G711_ALAW,
		AF_COMPRESSION_IMA,
		AF_COMPRESSION_MS_ADPCM,
		AF_COMPRESSION_G722,
		AF_COMPRESSION_APPLE_ACE2,
		AF_COMPRESSION_APPLE_ACE8,
		AF_COMPRESSION_APPLE_MAC3,
		AF_COMPRESSION_APPLE_MAC6
	};
	int numCompressionFormats = sizeof (compressionFormats) / sizeof (int);
	for (int i=0; i<numCompressionFormats; i++)
	{
		long implemented = afQueryLong(AF_QUERYTYPE_COMPRESSION,
			AF_QUERY_IMPLEMENTED, compressionFormats[i], 0, 0);
		long nativeSampleFormat = afQueryLong(AF_QUERYTYPE_COMPRESSION,
			AF_QUERY_NATIVE_SAMPFMT, compressionFormats[i], 0, 0);
		if (implemented)
			EXPECT_TRUE(nativeSampleFormat == AF_SAMPFMT_TWOSCOMP ||
				nativeSampleFormat == AF_SAMPFMT_UNSIGNED ||
				nativeSampleFormat == AF_SAMPFMT_FLOAT ||
				nativeSampleFormat == AF_SAMPFMT_DOUBLE);
		long nativeSampleWidth = afQueryLong(AF_QUERYTYPE_COMPRESSION,
			AF_QUERY_NATIVE_SAMPWIDTH, compressionFormats[i], 0, 0);
		if (implemented)
		{
			EXPECT_GE(nativeSampleWidth, 1);
			EXPECT_LE(nativeSampleWidth, 64);
		}
		const char *label =
			static_cast<const char *>(afQueryPointer(AF_QUERYTYPE_COMPRESSION,
				AF_QUERY_LABEL, compressionFormats[i], 0, 0));
		if (implemented)
			EXPECT_TRUE(label);
		const char *name =
			static_cast<const char *>(afQueryPointer(AF_QUERYTYPE_COMPRESSION,
				AF_QUERY_NAME, compressionFormats[i], 0, 0));
		if (implemented)
			EXPECT_TRUE(name);
		const char *description =
			static_cast<const char *>(afQueryPointer(AF_QUERYTYPE_COMPRESSION,
				AF_QUERY_DESC, compressionFormats[i], 0, 0));
		if (implemented)
			EXPECT_TRUE(description);
	}
}

int main(int argc, char **argv)
{
	::testing::InitGoogleTest(&argc, argv);
	return RUN_ALL_TESTS();
}