]> code.delx.au - pulseaudio/blob - src/tests/format-test.c
Merge branch 'passthrough'
[pulseaudio] / src / tests / format-test.c
1 /***
2 This file is part of PulseAudio.
3
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.
8
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.
13
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
17 USA.
18 ***/
19
20 #ifdef HAVE_CONFIG_H
21 #include <config.h>
22 #endif
23
24 #include <stdlib.h>
25
26 #include <pulsecore/macro.h>
27 #include <pulse/format.h>
28
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); }
32
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" };
37
38 /* 1. Simple fixed format int check */
39 INIT(f1); INIT(f2);
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));
45
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));
54
55 /* 3. Check int array memebership - negative */
56 REINIT(f2);
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));
61
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));
70
71 /* 5. Check int range - negative */
72 REINIT(f2);
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));
77
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));
85
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));
94
95 /* 8. Check string array memebership - negative */
96 REINIT(f2);
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));
101
102 DEINIT(f1);
103 DEINIT(f2);
104
105 return 0;
106 }