153a5a1b3Sopenharmony_ci/*** 253a5a1b3Sopenharmony_ci This file is part of PulseAudio. 353a5a1b3Sopenharmony_ci 453a5a1b3Sopenharmony_ci PulseAudio is free software; you can redistribute it and/or modify 553a5a1b3Sopenharmony_ci it under the terms of the GNU Lesser General Public License as published 653a5a1b3Sopenharmony_ci by the Free Software Foundation; either version 2.1 of the License, 753a5a1b3Sopenharmony_ci or (at your option) any later version. 853a5a1b3Sopenharmony_ci 953a5a1b3Sopenharmony_ci PulseAudio is distributed in the hope that it will be useful, but 1053a5a1b3Sopenharmony_ci WITHOUT ANY WARRANTY; without even the implied warranty of 1153a5a1b3Sopenharmony_ci MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 1253a5a1b3Sopenharmony_ci General Public License for more details. 1353a5a1b3Sopenharmony_ci 1453a5a1b3Sopenharmony_ci You should have received a copy of the GNU Lesser General Public License 1553a5a1b3Sopenharmony_ci along with PulseAudio; if not, see <http://www.gnu.org/licenses/>. 1653a5a1b3Sopenharmony_ci***/ 1753a5a1b3Sopenharmony_ci 1853a5a1b3Sopenharmony_ci#ifdef HAVE_CONFIG_H 1953a5a1b3Sopenharmony_ci#include <config.h> 2053a5a1b3Sopenharmony_ci#endif 2153a5a1b3Sopenharmony_ci 2253a5a1b3Sopenharmony_ci#include <stdlib.h> 2353a5a1b3Sopenharmony_ci 2453a5a1b3Sopenharmony_ci#include <check.h> 2553a5a1b3Sopenharmony_ci 2653a5a1b3Sopenharmony_ci#include <pulsecore/macro.h> 2753a5a1b3Sopenharmony_ci#include <pulsecore/core-util.h> 2853a5a1b3Sopenharmony_ci#include <pulse/format.h> 2953a5a1b3Sopenharmony_ci#include <pulse/xmalloc.h> 3053a5a1b3Sopenharmony_ci 3153a5a1b3Sopenharmony_ci#define INIT(f) f = pa_format_info_new() 3253a5a1b3Sopenharmony_ci#define DEINIT(f) pa_format_info_free(f); 3353a5a1b3Sopenharmony_ci#define REINIT(f) { DEINIT(f); INIT(f); } 3453a5a1b3Sopenharmony_ci 3553a5a1b3Sopenharmony_ciSTART_TEST (format_test) { 3653a5a1b3Sopenharmony_ci pa_format_info *f1 = NULL, *f2 = NULL; 3753a5a1b3Sopenharmony_ci int rates1[] = { 32000, 44100, 48000 }, i, temp_int1 = -1, PA_UNUSED temp_int2 = -1, *temp_int_array; 3853a5a1b3Sopenharmony_ci const char *strings[] = { "thing1", "thing2", "thing3" }; 3953a5a1b3Sopenharmony_ci char *temp_str, **temp_str_array; 4053a5a1b3Sopenharmony_ci 4153a5a1b3Sopenharmony_ci /* 1. Simple fixed format int check */ 4253a5a1b3Sopenharmony_ci INIT(f1); INIT(f2); 4353a5a1b3Sopenharmony_ci f1->encoding = PA_ENCODING_AC3_IEC61937; 4453a5a1b3Sopenharmony_ci pa_format_info_set_prop_int(f1, PA_PROP_FORMAT_RATE, 32000); 4553a5a1b3Sopenharmony_ci f2->encoding = PA_ENCODING_AC3_IEC61937; 4653a5a1b3Sopenharmony_ci pa_format_info_set_prop_int(f2, PA_PROP_FORMAT_RATE, 44100); 4753a5a1b3Sopenharmony_ci fail_unless(!pa_format_info_is_compatible(f1, f2)); 4853a5a1b3Sopenharmony_ci 4953a5a1b3Sopenharmony_ci /* 2. Check int array membership - positive */ 5053a5a1b3Sopenharmony_ci REINIT(f1); REINIT(f2); 5153a5a1b3Sopenharmony_ci f1->encoding = PA_ENCODING_AC3_IEC61937; 5253a5a1b3Sopenharmony_ci pa_format_info_set_prop_int_array(f1, PA_PROP_FORMAT_RATE, rates1, PA_ELEMENTSOF(rates1)); 5353a5a1b3Sopenharmony_ci f2->encoding = PA_ENCODING_AC3_IEC61937; 5453a5a1b3Sopenharmony_ci pa_format_info_set_prop_int(f2, PA_PROP_FORMAT_RATE, 44100); 5553a5a1b3Sopenharmony_ci fail_unless(pa_format_info_is_compatible(f1, f2)); 5653a5a1b3Sopenharmony_ci fail_unless(pa_format_info_is_compatible(f2, f1)); 5753a5a1b3Sopenharmony_ci 5853a5a1b3Sopenharmony_ci /* 3. Check int array membership - negative */ 5953a5a1b3Sopenharmony_ci REINIT(f2); 6053a5a1b3Sopenharmony_ci f2->encoding = PA_ENCODING_AC3_IEC61937; 6153a5a1b3Sopenharmony_ci pa_format_info_set_prop_int(f2, PA_PROP_FORMAT_RATE, 96000); 6253a5a1b3Sopenharmony_ci fail_unless(!pa_format_info_is_compatible(f1, f2)); 6353a5a1b3Sopenharmony_ci fail_unless(!pa_format_info_is_compatible(f2, f1)); 6453a5a1b3Sopenharmony_ci 6553a5a1b3Sopenharmony_ci /* 4. Check int range - positive */ 6653a5a1b3Sopenharmony_ci REINIT(f1); REINIT(f2); 6753a5a1b3Sopenharmony_ci f1->encoding = PA_ENCODING_AC3_IEC61937; 6853a5a1b3Sopenharmony_ci pa_format_info_set_prop_int_range(f1, PA_PROP_FORMAT_RATE, 32000, 48000); 6953a5a1b3Sopenharmony_ci f2->encoding = PA_ENCODING_AC3_IEC61937; 7053a5a1b3Sopenharmony_ci pa_format_info_set_prop_int(f2, PA_PROP_FORMAT_RATE, 44100); 7153a5a1b3Sopenharmony_ci fail_unless(pa_format_info_is_compatible(f1, f2)); 7253a5a1b3Sopenharmony_ci fail_unless(pa_format_info_is_compatible(f2, f1)); 7353a5a1b3Sopenharmony_ci 7453a5a1b3Sopenharmony_ci /* 5. Check int range - negative */ 7553a5a1b3Sopenharmony_ci REINIT(f2); 7653a5a1b3Sopenharmony_ci f2->encoding = PA_ENCODING_AC3_IEC61937; 7753a5a1b3Sopenharmony_ci pa_format_info_set_prop_int(f2, PA_PROP_FORMAT_RATE, 96000); 7853a5a1b3Sopenharmony_ci fail_unless(!pa_format_info_is_compatible(f1, f2)); 7953a5a1b3Sopenharmony_ci fail_unless(!pa_format_info_is_compatible(f2, f1)); 8053a5a1b3Sopenharmony_ci 8153a5a1b3Sopenharmony_ci /* 6. Simple fixed format string check */ 8253a5a1b3Sopenharmony_ci REINIT(f1); REINIT(f2); 8353a5a1b3Sopenharmony_ci f1->encoding = PA_ENCODING_AC3_IEC61937; 8453a5a1b3Sopenharmony_ci pa_format_info_set_prop_string(f1, "format.test_string", "thing1"); 8553a5a1b3Sopenharmony_ci f2->encoding = PA_ENCODING_AC3_IEC61937; 8653a5a1b3Sopenharmony_ci pa_format_info_set_prop_string(f2, "format.test_string", "notthing1"); 8753a5a1b3Sopenharmony_ci fail_unless(!pa_format_info_is_compatible(f1, f2)); 8853a5a1b3Sopenharmony_ci 8953a5a1b3Sopenharmony_ci /* 7. Check string array membership - positive */ 9053a5a1b3Sopenharmony_ci REINIT(f1); REINIT(f2); 9153a5a1b3Sopenharmony_ci f1->encoding = PA_ENCODING_AC3_IEC61937; 9253a5a1b3Sopenharmony_ci pa_format_info_set_prop_string_array(f1, "format.test_string", strings, PA_ELEMENTSOF(strings)); 9353a5a1b3Sopenharmony_ci f2->encoding = PA_ENCODING_AC3_IEC61937; 9453a5a1b3Sopenharmony_ci pa_format_info_set_prop_string(f2, "format.test_string", "thing3"); 9553a5a1b3Sopenharmony_ci fail_unless(pa_format_info_is_compatible(f1, f2)); 9653a5a1b3Sopenharmony_ci fail_unless(pa_format_info_is_compatible(f2, f1)); 9753a5a1b3Sopenharmony_ci 9853a5a1b3Sopenharmony_ci /* 8. Check string array membership - negative */ 9953a5a1b3Sopenharmony_ci REINIT(f2); 10053a5a1b3Sopenharmony_ci f2->encoding = PA_ENCODING_AC3_IEC61937; 10153a5a1b3Sopenharmony_ci pa_format_info_set_prop_string(f2, "format.test_string", "thing5"); 10253a5a1b3Sopenharmony_ci fail_unless(!pa_format_info_is_compatible(f1, f2)); 10353a5a1b3Sopenharmony_ci fail_unless(!pa_format_info_is_compatible(f2, f1)); 10453a5a1b3Sopenharmony_ci 10553a5a1b3Sopenharmony_ci /* 9. Verify setting/getting an int */ 10653a5a1b3Sopenharmony_ci REINIT(f1); 10753a5a1b3Sopenharmony_ci pa_format_info_set_prop_int(f1, "format.test_string", 42); 10853a5a1b3Sopenharmony_ci fail_unless(pa_format_info_get_prop_type(f1, "format.test_string") == PA_PROP_TYPE_INT); 10953a5a1b3Sopenharmony_ci fail_unless(pa_format_info_get_prop_int(f1, "format.test_string", &temp_int1) == 0); 11053a5a1b3Sopenharmony_ci fail_unless(temp_int1 == 42); 11153a5a1b3Sopenharmony_ci 11253a5a1b3Sopenharmony_ci /* 10. Verify setting/getting an int range */ 11353a5a1b3Sopenharmony_ci REINIT(f1); 11453a5a1b3Sopenharmony_ci pa_format_info_set_prop_int_range(f1, "format.test_string", 0, 100); 11553a5a1b3Sopenharmony_ci pa_assert(pa_format_info_get_prop_type(f1, "format.test_string") == PA_PROP_TYPE_INT_RANGE); 11653a5a1b3Sopenharmony_ci pa_assert(pa_format_info_get_prop_int_range(f1, "format.test_string", &temp_int1, &temp_int2) == 0); 11753a5a1b3Sopenharmony_ci pa_assert(temp_int1 == 0 && temp_int2 == 100); 11853a5a1b3Sopenharmony_ci 11953a5a1b3Sopenharmony_ci /* 11. Verify setting/getting an int array */ 12053a5a1b3Sopenharmony_ci REINIT(f1); 12153a5a1b3Sopenharmony_ci pa_format_info_set_prop_int_array(f1, "format.test_string", rates1, PA_ELEMENTSOF(rates1)); 12253a5a1b3Sopenharmony_ci fail_unless(pa_format_info_get_prop_type(f1, "format.test_string") == PA_PROP_TYPE_INT_ARRAY); 12353a5a1b3Sopenharmony_ci fail_unless(pa_format_info_get_prop_int_array(f1, "format.test_string", &temp_int_array, &temp_int1) == 0); 12453a5a1b3Sopenharmony_ci fail_unless(temp_int1 == PA_ELEMENTSOF(rates1)); 12553a5a1b3Sopenharmony_ci for (i = 0; i < temp_int1; i++) 12653a5a1b3Sopenharmony_ci fail_unless(temp_int_array[i] == rates1[i]); 12753a5a1b3Sopenharmony_ci pa_xfree(temp_int_array); 12853a5a1b3Sopenharmony_ci 12953a5a1b3Sopenharmony_ci /* 12. Verify setting/getting a string */ 13053a5a1b3Sopenharmony_ci REINIT(f1); 13153a5a1b3Sopenharmony_ci pa_format_info_set_prop_string(f1, "format.test_string", "foo"); 13253a5a1b3Sopenharmony_ci fail_unless(pa_format_info_get_prop_type(f1, "format.test_string") == PA_PROP_TYPE_STRING); 13353a5a1b3Sopenharmony_ci fail_unless(pa_format_info_get_prop_string(f1, "format.test_string", &temp_str) == 0); 13453a5a1b3Sopenharmony_ci fail_unless(pa_streq(temp_str, "foo")); 13553a5a1b3Sopenharmony_ci pa_xfree(temp_str); 13653a5a1b3Sopenharmony_ci 13753a5a1b3Sopenharmony_ci /* 13. Verify setting/getting an int array */ 13853a5a1b3Sopenharmony_ci REINIT(f1); 13953a5a1b3Sopenharmony_ci pa_format_info_set_prop_string_array(f1, "format.test_string", strings, PA_ELEMENTSOF(strings)); 14053a5a1b3Sopenharmony_ci fail_unless(pa_format_info_get_prop_type(f1, "format.test_string") == PA_PROP_TYPE_STRING_ARRAY); 14153a5a1b3Sopenharmony_ci fail_unless(pa_format_info_get_prop_string_array(f1, "format.test_string", &temp_str_array, &temp_int1) == 0); 14253a5a1b3Sopenharmony_ci fail_unless(temp_int1 == PA_ELEMENTSOF(strings)); 14353a5a1b3Sopenharmony_ci for (i = 0; i < temp_int1; i++) 14453a5a1b3Sopenharmony_ci fail_unless(pa_streq(temp_str_array[i], strings[i])); 14553a5a1b3Sopenharmony_ci pa_format_info_free_string_array(temp_str_array, temp_int1); 14653a5a1b3Sopenharmony_ci 14753a5a1b3Sopenharmony_ci DEINIT(f1); 14853a5a1b3Sopenharmony_ci DEINIT(f2); 14953a5a1b3Sopenharmony_ci} 15053a5a1b3Sopenharmony_ciEND_TEST 15153a5a1b3Sopenharmony_ci 15253a5a1b3Sopenharmony_ciint main(int argc, char *argv[]) { 15353a5a1b3Sopenharmony_ci int failed = 0; 15453a5a1b3Sopenharmony_ci Suite *s; 15553a5a1b3Sopenharmony_ci TCase *tc; 15653a5a1b3Sopenharmony_ci SRunner *sr; 15753a5a1b3Sopenharmony_ci 15853a5a1b3Sopenharmony_ci s = suite_create("Format"); 15953a5a1b3Sopenharmony_ci tc = tcase_create("format"); 16053a5a1b3Sopenharmony_ci tcase_add_test(tc, format_test); 16153a5a1b3Sopenharmony_ci suite_add_tcase(s, tc); 16253a5a1b3Sopenharmony_ci 16353a5a1b3Sopenharmony_ci sr = srunner_create(s); 16453a5a1b3Sopenharmony_ci srunner_run_all(sr, CK_NORMAL); 16553a5a1b3Sopenharmony_ci failed = srunner_ntests_failed(sr); 16653a5a1b3Sopenharmony_ci srunner_free(sr); 16753a5a1b3Sopenharmony_ci 16853a5a1b3Sopenharmony_ci return (failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; 16953a5a1b3Sopenharmony_ci} 170