mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-03 09:01:50 -05:00
tests: modify format-test to use 'check' framework
This commit is contained in:
parent
5f2a25b252
commit
8efef1e097
2 changed files with 53 additions and 33 deletions
|
|
@ -325,9 +325,9 @@ utf8_test_LDADD = $(AM_LDADD) libpulse.la libpulsecommon-@PA_MAJORMINOR@.la
|
|||
utf8_test_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS) $(LIBCHECK_LIBS)
|
||||
|
||||
format_test_SOURCES = tests/format-test.c
|
||||
format_test_CFLAGS = $(AM_CFLAGS)
|
||||
format_test_CFLAGS = $(AM_CFLAGS) $(LIBCHECK_CFLAGS)
|
||||
format_test_LDADD = $(AM_LDADD) libpulsecore-@PA_MAJORMINOR@.la libpulse.la libpulsecommon-@PA_MAJORMINOR@.la
|
||||
format_test_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS)
|
||||
format_test_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS) $(LIBCHECK_LIBS)
|
||||
|
||||
get_binary_name_test_SOURCES = tests/get-binary-name-test.c
|
||||
get_binary_name_test_CFLAGS = $(AM_CFLAGS)
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@
|
|||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <check.h>
|
||||
|
||||
#include <pulsecore/macro.h>
|
||||
#include <pulsecore/core-util.h>
|
||||
#include <pulse/format.h>
|
||||
|
|
@ -32,7 +34,7 @@
|
|||
#define DEINIT(f) pa_format_info_free(f);
|
||||
#define REINIT(f) { DEINIT(f); INIT(f); }
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
START_TEST (format_test) {
|
||||
pa_format_info *f1 = NULL, *f2 = NULL;
|
||||
int rates1[] = { 32000, 44100, 48000 }, i, temp_int1 = -1, temp_int2 = -1, *temp_int_array;
|
||||
const char *strings[] = { "thing1", "thing2", "thing3" };
|
||||
|
|
@ -44,7 +46,7 @@ int main(int argc, char *argv[]) {
|
|||
pa_format_info_set_prop_int(f1, PA_PROP_FORMAT_RATE, 32000);
|
||||
f2->encoding = PA_ENCODING_AC3_IEC61937;
|
||||
pa_format_info_set_prop_int(f2, PA_PROP_FORMAT_RATE, 44100);
|
||||
pa_assert(!pa_format_info_is_compatible(f1, f2));
|
||||
fail_unless(!pa_format_info_is_compatible(f1, f2));
|
||||
|
||||
/* 2. Check int array membership - positive */
|
||||
REINIT(f1); REINIT(f2);
|
||||
|
|
@ -52,15 +54,15 @@ int main(int argc, char *argv[]) {
|
|||
pa_format_info_set_prop_int_array(f1, PA_PROP_FORMAT_RATE, rates1, PA_ELEMENTSOF(rates1));
|
||||
f2->encoding = PA_ENCODING_AC3_IEC61937;
|
||||
pa_format_info_set_prop_int(f2, PA_PROP_FORMAT_RATE, 44100);
|
||||
pa_assert(pa_format_info_is_compatible(f1, f2));
|
||||
pa_assert(pa_format_info_is_compatible(f2, f1));
|
||||
fail_unless(pa_format_info_is_compatible(f1, f2));
|
||||
fail_unless(pa_format_info_is_compatible(f2, f1));
|
||||
|
||||
/* 3. Check int array membership - negative */
|
||||
REINIT(f2);
|
||||
f2->encoding = PA_ENCODING_AC3_IEC61937;
|
||||
pa_format_info_set_prop_int(f2, PA_PROP_FORMAT_RATE, 96000);
|
||||
pa_assert(!pa_format_info_is_compatible(f1, f2));
|
||||
pa_assert(!pa_format_info_is_compatible(f2, f1));
|
||||
fail_unless(!pa_format_info_is_compatible(f1, f2));
|
||||
fail_unless(!pa_format_info_is_compatible(f2, f1));
|
||||
|
||||
/* 4. Check int range - positive */
|
||||
REINIT(f1); REINIT(f2);
|
||||
|
|
@ -68,15 +70,15 @@ int main(int argc, char *argv[]) {
|
|||
pa_format_info_set_prop_int_range(f1, PA_PROP_FORMAT_RATE, 32000, 48000);
|
||||
f2->encoding = PA_ENCODING_AC3_IEC61937;
|
||||
pa_format_info_set_prop_int(f2, PA_PROP_FORMAT_RATE, 44100);
|
||||
pa_assert(pa_format_info_is_compatible(f1, f2));
|
||||
pa_assert(pa_format_info_is_compatible(f2, f1));
|
||||
fail_unless(pa_format_info_is_compatible(f1, f2));
|
||||
fail_unless(pa_format_info_is_compatible(f2, f1));
|
||||
|
||||
/* 5. Check int range - negative */
|
||||
REINIT(f2);
|
||||
f2->encoding = PA_ENCODING_AC3_IEC61937;
|
||||
pa_format_info_set_prop_int(f2, PA_PROP_FORMAT_RATE, 96000);
|
||||
pa_assert(!pa_format_info_is_compatible(f1, f2));
|
||||
pa_assert(!pa_format_info_is_compatible(f2, f1));
|
||||
fail_unless(!pa_format_info_is_compatible(f1, f2));
|
||||
fail_unless(!pa_format_info_is_compatible(f2, f1));
|
||||
|
||||
/* 6. Simple fixed format string check */
|
||||
REINIT(f1); REINIT(f2);
|
||||
|
|
@ -84,7 +86,7 @@ int main(int argc, char *argv[]) {
|
|||
pa_format_info_set_prop_string(f1, "format.test_string", "thing1");
|
||||
f2->encoding = PA_ENCODING_AC3_IEC61937;
|
||||
pa_format_info_set_prop_string(f2, "format.test_string", "notthing1");
|
||||
pa_assert(!pa_format_info_is_compatible(f1, f2));
|
||||
fail_unless(!pa_format_info_is_compatible(f1, f2));
|
||||
|
||||
/* 7. Check string array membership - positive */
|
||||
REINIT(f1); REINIT(f2);
|
||||
|
|
@ -92,22 +94,22 @@ int main(int argc, char *argv[]) {
|
|||
pa_format_info_set_prop_string_array(f1, "format.test_string", strings, PA_ELEMENTSOF(strings));
|
||||
f2->encoding = PA_ENCODING_AC3_IEC61937;
|
||||
pa_format_info_set_prop_string(f2, "format.test_string", "thing3");
|
||||
pa_assert(pa_format_info_is_compatible(f1, f2));
|
||||
pa_assert(pa_format_info_is_compatible(f2, f1));
|
||||
fail_unless(pa_format_info_is_compatible(f1, f2));
|
||||
fail_unless(pa_format_info_is_compatible(f2, f1));
|
||||
|
||||
/* 8. Check string array membership - negative */
|
||||
REINIT(f2);
|
||||
f2->encoding = PA_ENCODING_AC3_IEC61937;
|
||||
pa_format_info_set_prop_string(f2, "format.test_string", "thing5");
|
||||
pa_assert(!pa_format_info_is_compatible(f1, f2));
|
||||
pa_assert(!pa_format_info_is_compatible(f2, f1));
|
||||
fail_unless(!pa_format_info_is_compatible(f1, f2));
|
||||
fail_unless(!pa_format_info_is_compatible(f2, f1));
|
||||
|
||||
/* 9. Verify setting/getting an int */
|
||||
REINIT(f1);
|
||||
pa_format_info_set_prop_int(f1, "format.test_string", 42);
|
||||
pa_assert(pa_format_info_get_prop_type(f1, "format.test_string") == PA_PROP_TYPE_INT);
|
||||
pa_assert(pa_format_info_get_prop_int(f1, "format.test_string", &temp_int1) == 0);
|
||||
pa_assert(temp_int1 == 42);
|
||||
fail_unless(pa_format_info_get_prop_type(f1, "format.test_string") == PA_PROP_TYPE_INT);
|
||||
fail_unless(pa_format_info_get_prop_int(f1, "format.test_string", &temp_int1) == 0);
|
||||
fail_unless(temp_int1 == 42);
|
||||
|
||||
/* 10. Verify setting/getting an int range */
|
||||
REINIT(f1);
|
||||
|
|
@ -119,33 +121,51 @@ int main(int argc, char *argv[]) {
|
|||
/* 11. Verify setting/getting an int array */
|
||||
REINIT(f1);
|
||||
pa_format_info_set_prop_int_array(f1, "format.test_string", rates1, PA_ELEMENTSOF(rates1));
|
||||
pa_assert(pa_format_info_get_prop_type(f1, "format.test_string") == PA_PROP_TYPE_INT_ARRAY);
|
||||
pa_assert(pa_format_info_get_prop_int_array(f1, "format.test_string", &temp_int_array, &temp_int1) == 0);
|
||||
pa_assert(temp_int1 == PA_ELEMENTSOF(rates1));
|
||||
fail_unless(pa_format_info_get_prop_type(f1, "format.test_string") == PA_PROP_TYPE_INT_ARRAY);
|
||||
fail_unless(pa_format_info_get_prop_int_array(f1, "format.test_string", &temp_int_array, &temp_int1) == 0);
|
||||
fail_unless(temp_int1 == PA_ELEMENTSOF(rates1));
|
||||
for (i = 0; i < temp_int1; i++)
|
||||
pa_assert(temp_int_array[i] == rates1[i]);
|
||||
fail_unless(temp_int_array[i] == rates1[i]);
|
||||
pa_xfree(temp_int_array);
|
||||
|
||||
/* 12. Verify setting/getting a string */
|
||||
REINIT(f1);
|
||||
pa_format_info_set_prop_string(f1, "format.test_string", "foo");
|
||||
pa_assert(pa_format_info_get_prop_type(f1, "format.test_string") == PA_PROP_TYPE_STRING);
|
||||
pa_assert(pa_format_info_get_prop_string(f1, "format.test_string", &temp_str) == 0);
|
||||
pa_assert(pa_streq(temp_str, "foo"));
|
||||
fail_unless(pa_format_info_get_prop_type(f1, "format.test_string") == PA_PROP_TYPE_STRING);
|
||||
fail_unless(pa_format_info_get_prop_string(f1, "format.test_string", &temp_str) == 0);
|
||||
fail_unless(pa_streq(temp_str, "foo"));
|
||||
pa_xfree(temp_str);
|
||||
|
||||
/* 13. Verify setting/getting an int array */
|
||||
REINIT(f1);
|
||||
pa_format_info_set_prop_string_array(f1, "format.test_string", strings, PA_ELEMENTSOF(strings));
|
||||
pa_assert(pa_format_info_get_prop_type(f1, "format.test_string") == PA_PROP_TYPE_STRING_ARRAY);
|
||||
pa_assert(pa_format_info_get_prop_string_array(f1, "format.test_string", &temp_str_array, &temp_int1) == 0);
|
||||
pa_assert(temp_int1 == PA_ELEMENTSOF(strings));
|
||||
fail_unless(pa_format_info_get_prop_type(f1, "format.test_string") == PA_PROP_TYPE_STRING_ARRAY);
|
||||
fail_unless(pa_format_info_get_prop_string_array(f1, "format.test_string", &temp_str_array, &temp_int1) == 0);
|
||||
fail_unless(temp_int1 == PA_ELEMENTSOF(strings));
|
||||
for (i = 0; i < temp_int1; i++)
|
||||
pa_assert(pa_streq(temp_str_array[i], strings[i]));
|
||||
fail_unless(pa_streq(temp_str_array[i], strings[i]));
|
||||
pa_format_info_free_string_array(temp_str_array, temp_int1);
|
||||
|
||||
DEINIT(f1);
|
||||
DEINIT(f2);
|
||||
|
||||
return 0;
|
||||
}
|
||||
END_TEST
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int failed = 0;
|
||||
Suite *s;
|
||||
TCase *tc;
|
||||
SRunner *sr;
|
||||
|
||||
s = suite_create("Format");
|
||||
tc = tcase_create("format");
|
||||
tcase_add_test(tc, format_test);
|
||||
suite_add_tcase(s, tc);
|
||||
|
||||
sr = srunner_create(s);
|
||||
srunner_run_all(sr, CK_NORMAL);
|
||||
failed = srunner_ntests_failed(sr);
|
||||
srunner_free(sr);
|
||||
|
||||
return (failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue