]>
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 <pulsecore/core-util.h>
28 #include <pulse/format.h>
29 #include <pulse/xmalloc.h>
31 #define INIT(f) f = pa_format_info_new()
32 #define DEINIT(f) pa_format_info_free(f);
33 #define REINIT(f) { DEINIT(f); INIT(f); }
35 int main(int argc
, char *argv
[]) {
36 pa_format_info
*f1
= NULL
, *f2
= NULL
;
37 int rates1
[] = { 32000, 44100, 48000 }, i
, temp_int1
= -1, temp_int2
= -1, *temp_int_array
;
38 const char *strings
[] = { "thing1", "thing2", "thing3" };
39 char *temp_str
, **temp_str_array
;
41 /* 1. Simple fixed format int check */
43 f1
->encoding
= PA_ENCODING_AC3_IEC61937
;
44 pa_format_info_set_prop_int(f1
, PA_PROP_FORMAT_RATE
, 32000);
45 f2
->encoding
= PA_ENCODING_AC3_IEC61937
;
46 pa_format_info_set_prop_int(f2
, PA_PROP_FORMAT_RATE
, 44100);
47 pa_assert(!pa_format_info_is_compatible(f1
, f2
));
49 /* 2. Check int array membership - positive */
50 REINIT(f1
); REINIT(f2
);
51 f1
->encoding
= PA_ENCODING_AC3_IEC61937
;
52 pa_format_info_set_prop_int_array(f1
, PA_PROP_FORMAT_RATE
, rates1
, PA_ELEMENTSOF(rates1
));
53 f2
->encoding
= PA_ENCODING_AC3_IEC61937
;
54 pa_format_info_set_prop_int(f2
, PA_PROP_FORMAT_RATE
, 44100);
55 pa_assert(pa_format_info_is_compatible(f1
, f2
));
56 pa_assert(pa_format_info_is_compatible(f2
, f1
));
58 /* 3. Check int array membership - negative */
60 f2
->encoding
= PA_ENCODING_AC3_IEC61937
;
61 pa_format_info_set_prop_int(f2
, PA_PROP_FORMAT_RATE
, 96000);
62 pa_assert(!pa_format_info_is_compatible(f1
, f2
));
63 pa_assert(!pa_format_info_is_compatible(f2
, f1
));
65 /* 4. Check int range - positive */
66 REINIT(f1
); REINIT(f2
);
67 f1
->encoding
= PA_ENCODING_AC3_IEC61937
;
68 pa_format_info_set_prop_int_range(f1
, PA_PROP_FORMAT_RATE
, 32000, 48000);
69 f2
->encoding
= PA_ENCODING_AC3_IEC61937
;
70 pa_format_info_set_prop_int(f2
, PA_PROP_FORMAT_RATE
, 44100);
71 pa_assert(pa_format_info_is_compatible(f1
, f2
));
72 pa_assert(pa_format_info_is_compatible(f2
, f1
));
74 /* 5. Check int range - negative */
76 f2
->encoding
= PA_ENCODING_AC3_IEC61937
;
77 pa_format_info_set_prop_int(f2
, PA_PROP_FORMAT_RATE
, 96000);
78 pa_assert(!pa_format_info_is_compatible(f1
, f2
));
79 pa_assert(!pa_format_info_is_compatible(f2
, f1
));
81 /* 6. Simple fixed format string check */
82 REINIT(f1
); REINIT(f2
);
83 f1
->encoding
= PA_ENCODING_AC3_IEC61937
;
84 pa_format_info_set_prop_string(f1
, "format.test_string", "thing1");
85 f2
->encoding
= PA_ENCODING_AC3_IEC61937
;
86 pa_format_info_set_prop_string(f2
, "format.test_string", "notthing1");
87 pa_assert(!pa_format_info_is_compatible(f1
, f2
));
89 /* 7. Check string array membership - positive */
90 REINIT(f1
); REINIT(f2
);
91 f1
->encoding
= PA_ENCODING_AC3_IEC61937
;
92 pa_format_info_set_prop_string_array(f1
, "format.test_string", strings
, PA_ELEMENTSOF(strings
));
93 f2
->encoding
= PA_ENCODING_AC3_IEC61937
;
94 pa_format_info_set_prop_string(f2
, "format.test_string", "thing3");
95 pa_assert(pa_format_info_is_compatible(f1
, f2
));
96 pa_assert(pa_format_info_is_compatible(f2
, f1
));
98 /* 8. Check string array membership - negative */
100 f2
->encoding
= PA_ENCODING_AC3_IEC61937
;
101 pa_format_info_set_prop_string(f2
, "format.test_string", "thing5");
102 pa_assert(!pa_format_info_is_compatible(f1
, f2
));
103 pa_assert(!pa_format_info_is_compatible(f2
, f1
));
105 /* 9. Verify setting/getting an int */
107 pa_format_info_set_prop_int(f1
, "format.test_string", 42);
108 pa_assert(pa_format_info_get_prop_int(f1
, "format.test_string", &temp_int1
) == 0);
109 pa_assert(temp_int1
== 42);
111 /* 10. Verify setting/getting an int range */
113 pa_format_info_set_prop_int_range(f1
, "format.test_string", 0, 100);
114 pa_assert(pa_format_info_get_prop_int_range(f1
, "format.test_string", &temp_int1
, &temp_int2
) == 0);
115 pa_assert(temp_int1
== 0 && temp_int2
== 100);
117 /* 11. Verify setting/getting an int array */
119 pa_format_info_set_prop_int_array(f1
, "format.test_string", rates1
, PA_ELEMENTSOF(rates1
));
120 pa_assert(pa_format_info_get_prop_int_array(f1
, "format.test_string", &temp_int_array
, &temp_int1
) == 0);
121 pa_assert(temp_int1
== PA_ELEMENTSOF(rates1
));
122 for (i
= 0; i
< temp_int1
; i
++)
123 pa_assert(temp_int_array
[i
] == rates1
[i
]);
124 pa_xfree(temp_int_array
);
126 /* 12. Verify setting/getting a string */
128 pa_format_info_set_prop_string(f1
, "format.test_string", "foo");
129 pa_assert(pa_format_info_get_prop_string(f1
, "format.test_string", &temp_str
) == 0);
130 pa_assert(pa_streq(temp_str
, "foo"));
133 /* 13. Verify setting/getting an int array */
135 pa_format_info_set_prop_string_array(f1
, "format.test_string", strings
, PA_ELEMENTSOF(strings
));
136 pa_assert(pa_format_info_get_prop_string_array(f1
, "format.test_string", &temp_str_array
, &temp_int1
) == 0);
137 pa_assert(temp_int1
== PA_ELEMENTSOF(strings
));
138 for (i
= 0; i
< temp_int1
; i
++)
139 pa_assert(pa_streq(temp_str_array
[i
], strings
[i
]));
140 pa_format_info_free_string_array(temp_str_array
, temp_int1
);