sink, source: Really set the fixed latency in set_fixed_latency_within_thread(),...
[platform/upstream/pulseaudio.git] / 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 <check.h>
27
28 #include <pulsecore/macro.h>
29 #include <pulsecore/core-util.h>
30 #include <pulse/format.h>
31 #include <pulse/xmalloc.h>
32
33 #define INIT(f) f = pa_format_info_new()
34 #define DEINIT(f) pa_format_info_free(f);
35 #define REINIT(f) { DEINIT(f); INIT(f); }
36
37 START_TEST (format_test) {
38     pa_format_info *f1 = NULL, *f2 = NULL;
39     int rates1[] = { 32000, 44100, 48000 }, i, temp_int1 = -1, temp_int2 = -1, *temp_int_array;
40     const char *strings[] = { "thing1", "thing2", "thing3" };
41     char *temp_str, **temp_str_array;
42
43     /* 1. Simple fixed format int check */
44     INIT(f1); INIT(f2);
45     f1->encoding = PA_ENCODING_AC3_IEC61937;
46     pa_format_info_set_prop_int(f1, PA_PROP_FORMAT_RATE, 32000);
47     f2->encoding = PA_ENCODING_AC3_IEC61937;
48     pa_format_info_set_prop_int(f2, PA_PROP_FORMAT_RATE, 44100);
49     fail_unless(!pa_format_info_is_compatible(f1, f2));
50
51     /* 2. Check int array membership - positive */
52     REINIT(f1); REINIT(f2);
53     f1->encoding = PA_ENCODING_AC3_IEC61937;
54     pa_format_info_set_prop_int_array(f1, PA_PROP_FORMAT_RATE, rates1, PA_ELEMENTSOF(rates1));
55     f2->encoding = PA_ENCODING_AC3_IEC61937;
56     pa_format_info_set_prop_int(f2, PA_PROP_FORMAT_RATE, 44100);
57     fail_unless(pa_format_info_is_compatible(f1, f2));
58     fail_unless(pa_format_info_is_compatible(f2, f1));
59
60     /* 3. Check int array membership - negative */
61     REINIT(f2);
62     f2->encoding = PA_ENCODING_AC3_IEC61937;
63     pa_format_info_set_prop_int(f2, PA_PROP_FORMAT_RATE, 96000);
64     fail_unless(!pa_format_info_is_compatible(f1, f2));
65     fail_unless(!pa_format_info_is_compatible(f2, f1));
66
67     /* 4. Check int range - positive */
68     REINIT(f1); REINIT(f2);
69     f1->encoding = PA_ENCODING_AC3_IEC61937;
70     pa_format_info_set_prop_int_range(f1, PA_PROP_FORMAT_RATE, 32000, 48000);
71     f2->encoding = PA_ENCODING_AC3_IEC61937;
72     pa_format_info_set_prop_int(f2, PA_PROP_FORMAT_RATE, 44100);
73     fail_unless(pa_format_info_is_compatible(f1, f2));
74     fail_unless(pa_format_info_is_compatible(f2, f1));
75
76     /* 5. Check int range - negative */
77     REINIT(f2);
78     f2->encoding = PA_ENCODING_AC3_IEC61937;
79     pa_format_info_set_prop_int(f2, PA_PROP_FORMAT_RATE, 96000);
80     fail_unless(!pa_format_info_is_compatible(f1, f2));
81     fail_unless(!pa_format_info_is_compatible(f2, f1));
82
83     /* 6. Simple fixed format string check */
84     REINIT(f1); REINIT(f2);
85     f1->encoding = PA_ENCODING_AC3_IEC61937;
86     pa_format_info_set_prop_string(f1, "format.test_string", "thing1");
87     f2->encoding = PA_ENCODING_AC3_IEC61937;
88     pa_format_info_set_prop_string(f2, "format.test_string", "notthing1");
89     fail_unless(!pa_format_info_is_compatible(f1, f2));
90
91     /* 7. Check string array membership - positive */
92     REINIT(f1); REINIT(f2);
93     f1->encoding = PA_ENCODING_AC3_IEC61937;
94     pa_format_info_set_prop_string_array(f1, "format.test_string", strings, PA_ELEMENTSOF(strings));
95     f2->encoding = PA_ENCODING_AC3_IEC61937;
96     pa_format_info_set_prop_string(f2, "format.test_string", "thing3");
97     fail_unless(pa_format_info_is_compatible(f1, f2));
98     fail_unless(pa_format_info_is_compatible(f2, f1));
99
100     /* 8. Check string array membership - negative */
101     REINIT(f2);
102     f2->encoding = PA_ENCODING_AC3_IEC61937;
103     pa_format_info_set_prop_string(f2, "format.test_string", "thing5");
104     fail_unless(!pa_format_info_is_compatible(f1, f2));
105     fail_unless(!pa_format_info_is_compatible(f2, f1));
106
107     /* 9. Verify setting/getting an int */
108     REINIT(f1);
109     pa_format_info_set_prop_int(f1, "format.test_string", 42);
110     fail_unless(pa_format_info_get_prop_type(f1, "format.test_string") == PA_PROP_TYPE_INT);
111     fail_unless(pa_format_info_get_prop_int(f1, "format.test_string", &temp_int1) == 0);
112     fail_unless(temp_int1 == 42);
113
114     /* 10. Verify setting/getting an int range */
115     REINIT(f1);
116     pa_format_info_set_prop_int_range(f1, "format.test_string", 0, 100);
117     pa_assert(pa_format_info_get_prop_type(f1, "format.test_string") == PA_PROP_TYPE_INT_RANGE);
118     pa_assert(pa_format_info_get_prop_int_range(f1, "format.test_string", &temp_int1, &temp_int2) == 0);
119     pa_assert(temp_int1 == 0 && temp_int2 == 100);
120
121     /* 11. Verify setting/getting an int array */
122     REINIT(f1);
123     pa_format_info_set_prop_int_array(f1, "format.test_string", rates1, PA_ELEMENTSOF(rates1));
124     fail_unless(pa_format_info_get_prop_type(f1, "format.test_string") == PA_PROP_TYPE_INT_ARRAY);
125     fail_unless(pa_format_info_get_prop_int_array(f1, "format.test_string", &temp_int_array, &temp_int1) == 0);
126     fail_unless(temp_int1 == PA_ELEMENTSOF(rates1));
127     for (i = 0; i < temp_int1; i++)
128         fail_unless(temp_int_array[i] == rates1[i]);
129     pa_xfree(temp_int_array);
130
131     /* 12. Verify setting/getting a string */
132     REINIT(f1);
133     pa_format_info_set_prop_string(f1, "format.test_string", "foo");
134     fail_unless(pa_format_info_get_prop_type(f1, "format.test_string") == PA_PROP_TYPE_STRING);
135     fail_unless(pa_format_info_get_prop_string(f1, "format.test_string", &temp_str) == 0);
136     fail_unless(pa_streq(temp_str, "foo"));
137     pa_xfree(temp_str);
138
139     /* 13. Verify setting/getting an int array */
140     REINIT(f1);
141     pa_format_info_set_prop_string_array(f1, "format.test_string", strings, PA_ELEMENTSOF(strings));
142     fail_unless(pa_format_info_get_prop_type(f1, "format.test_string") == PA_PROP_TYPE_STRING_ARRAY);
143     fail_unless(pa_format_info_get_prop_string_array(f1, "format.test_string", &temp_str_array, &temp_int1) == 0);
144     fail_unless(temp_int1 == PA_ELEMENTSOF(strings));
145     for (i = 0; i < temp_int1; i++)
146         fail_unless(pa_streq(temp_str_array[i], strings[i]));
147     pa_format_info_free_string_array(temp_str_array, temp_int1);
148
149     DEINIT(f1);
150     DEINIT(f2);
151 }
152 END_TEST
153
154 int main(int argc, char *argv[]) {
155     int failed = 0;
156     Suite *s;
157     TCase *tc;
158     SRunner *sr;
159
160     s = suite_create("Format");
161     tc = tcase_create("format");
162     tcase_add_test(tc, format_test);
163     suite_add_tcase(s, tc);
164
165     sr = srunner_create(s);
166     srunner_run_all(sr, CK_NORMAL);
167     failed = srunner_ntests_failed(sr);
168     srunner_free(sr);
169
170     return (failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
171 }