]>
code.delx.au - pulseaudio/blob - src/tests/format-test.c
2 This file is part of PulseAudio.
4 PulseAudio is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as published
6 by the Free Software Foundation; either version 2.1 of the License,
7 or (at your option) any later version.
9 PulseAudio is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public License
15 along with PulseAudio; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
26 #include <pulsecore/macro.h>
27 #include <pulse/format.h>
29 #define INIT(f) f = pa_format_info_new()
30 #define DEINIT(f) pa_format_info_free(f);
31 #define REINIT(f) { DEINIT(f); INIT(f); }
33 int main(int argc
, char *argv
[]) {
34 pa_format_info
*f1
= NULL
, *f2
= NULL
;
35 int rates1
[] = { 32000, 44100, 48000 };
36 const char *strings
[] = { "thing1", "thing2", "thing3" };
38 /* 1. Simple fixed format int check */
40 f1
->encoding
= PA_ENCODING_AC3_IEC61937
;
41 pa_format_info_set_prop_int(f1
, PA_PROP_FORMAT_RATE
, 32000);
42 f2
->encoding
= PA_ENCODING_AC3_IEC61937
;
43 pa_format_info_set_prop_int(f2
, PA_PROP_FORMAT_RATE
, 44100);
44 pa_assert(!pa_format_info_is_compatible(f1
, f2
));
46 /* 2. Check int array membership - positive */
47 REINIT(f1
); REINIT(f2
);
48 f1
->encoding
= PA_ENCODING_AC3_IEC61937
;
49 pa_format_info_set_prop_int_array(f1
, PA_PROP_FORMAT_RATE
, rates1
, PA_ELEMENTSOF(rates1
));
50 f2
->encoding
= PA_ENCODING_AC3_IEC61937
;
51 pa_format_info_set_prop_int(f2
, PA_PROP_FORMAT_RATE
, 44100);
52 pa_assert(pa_format_info_is_compatible(f1
, f2
));
53 pa_assert(pa_format_info_is_compatible(f2
, f1
));
55 /* 3. Check int array membership - negative */
57 f2
->encoding
= PA_ENCODING_AC3_IEC61937
;
58 pa_format_info_set_prop_int(f2
, PA_PROP_FORMAT_RATE
, 96000);
59 pa_assert(!pa_format_info_is_compatible(f1
, f2
));
60 pa_assert(!pa_format_info_is_compatible(f2
, f1
));
62 /* 4. Check int range - positive */
63 REINIT(f1
); REINIT(f2
);
64 f1
->encoding
= PA_ENCODING_AC3_IEC61937
;
65 pa_format_info_set_prop_int_range(f1
, PA_PROP_FORMAT_RATE
, 32000, 48000);
66 f2
->encoding
= PA_ENCODING_AC3_IEC61937
;
67 pa_format_info_set_prop_int(f2
, PA_PROP_FORMAT_RATE
, 44100);
68 pa_assert(pa_format_info_is_compatible(f1
, f2
));
69 pa_assert(pa_format_info_is_compatible(f2
, f1
));
71 /* 5. Check int range - negative */
73 f2
->encoding
= PA_ENCODING_AC3_IEC61937
;
74 pa_format_info_set_prop_int(f2
, PA_PROP_FORMAT_RATE
, 96000);
75 pa_assert(!pa_format_info_is_compatible(f1
, f2
));
76 pa_assert(!pa_format_info_is_compatible(f2
, f1
));
78 /* 6. Simple fixed format string check */
79 REINIT(f1
); REINIT(f2
);
80 f1
->encoding
= PA_ENCODING_AC3_IEC61937
;
81 pa_format_info_set_prop_string(f1
, "format.test_string", "thing1");
82 f2
->encoding
= PA_ENCODING_AC3_IEC61937
;
83 pa_format_info_set_prop_string(f2
, "format.test_string", "notthing1");
84 pa_assert(!pa_format_info_is_compatible(f1
, f2
));
86 /* 7. Check string array membership - positive */
87 REINIT(f1
); REINIT(f2
);
88 f1
->encoding
= PA_ENCODING_AC3_IEC61937
;
89 pa_format_info_set_prop_string_array(f1
, "format.test_string", strings
, PA_ELEMENTSOF(strings
));
90 f2
->encoding
= PA_ENCODING_AC3_IEC61937
;
91 pa_format_info_set_prop_string(f2
, "format.test_string", "thing3");
92 pa_assert(pa_format_info_is_compatible(f1
, f2
));
93 pa_assert(pa_format_info_is_compatible(f2
, f1
));
95 /* 8. Check string array membership - negative */
97 f2
->encoding
= PA_ENCODING_AC3_IEC61937
;
98 pa_format_info_set_prop_string(f2
, "format.test_string", "thing5");
99 pa_assert(!pa_format_info_is_compatible(f1
, f2
));
100 pa_assert(!pa_format_info_is_compatible(f2
, f1
));