tests: modify get-binary-name-test to use 'check' framework

This commit is contained in:
Deng Zhengrong 2012-07-28 17:45:50 +08:00 committed by Arun Raghavan
parent 8efef1e097
commit a5b438f825
2 changed files with 27 additions and 7 deletions

View file

@ -330,9 +330,9 @@ format_test_LDADD = $(AM_LDADD) libpulsecore-@PA_MAJORMINOR@.la libpulse.la libp
format_test_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS) $(LIBCHECK_LIBS) format_test_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS) $(LIBCHECK_LIBS)
get_binary_name_test_SOURCES = tests/get-binary-name-test.c get_binary_name_test_SOURCES = tests/get-binary-name-test.c
get_binary_name_test_CFLAGS = $(AM_CFLAGS) get_binary_name_test_CFLAGS = $(AM_CFLAGS) $(LIBCHECK_CFLAGS)
get_binary_name_test_LDADD = $(AM_LDADD) libpulse.la libpulsecommon-@PA_MAJORMINOR@.la get_binary_name_test_LDADD = $(AM_LDADD) libpulse.la libpulsecommon-@PA_MAJORMINOR@.la
get_binary_name_test_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS) get_binary_name_test_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS) $(LIBCHECK_LIBS)
ipacl_test_SOURCES = tests/ipacl-test.c ipacl_test_SOURCES = tests/ipacl-test.c
ipacl_test_CFLAGS = $(AM_CFLAGS) ipacl_test_CFLAGS = $(AM_CFLAGS)

View file

@ -24,12 +24,14 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <check.h>
#include <pulse/util.h> #include <pulse/util.h>
#include <pulse/xmalloc.h> #include <pulse/xmalloc.h>
#include <pulsecore/log.h> #include <pulsecore/log.h>
int main(int argc, char *argv[]) { START_TEST (getbinaryname_test) {
char *exename; char *exename;
size_t allocated = 128; size_t allocated = 128;
@ -39,18 +41,36 @@ int main(int argc, char *argv[]) {
if (!pa_get_binary_name(exename, allocated)) { if (!pa_get_binary_name(exename, allocated)) {
pa_log_error("failed to read binary name"); pa_log_error("failed to read binary name");
pa_xfree(exename); pa_xfree(exename);
break; fail();
} }
if (strlen(exename) < allocated - 1) { if (strlen(exename) < allocated - 1) {
pa_log("%s", exename); pa_log("%s", exename);
pa_xfree(exename); pa_xfree(exename);
return 0; return;
} }
pa_xfree(exename); pa_xfree(exename);
allocated *= 2; allocated *= 2;
} }
}
return 1; END_TEST
int main(int argc, char *argv[]) {
int failed = 0;
Suite *s;
TCase *tc;
SRunner *sr;
s = suite_create("Binary Name");
tc = tcase_create("getbinaryname");
tcase_add_test(tc, getbinaryname_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;
} }