From: Uwe Hermann Date: Tue, 3 Nov 2015 01:12:29 +0000 (+0100) Subject: tests/decoder.c: Add some srd_decoder_unload*() tests. X-Git-Tag: libsigrokdecode-0.4.0~41 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=1b6f39e39b9700a787db81268c4ae9cd0d3f1499;p=libsigrokdecode.git tests/decoder.c: Add some srd_decoder_unload*() tests. --- diff --git a/tests/decoder.c b/tests/decoder.c index 3a86566..2b88785 100644 --- a/tests/decoder.c +++ b/tests/decoder.c @@ -149,6 +149,114 @@ START_TEST(test_load_nonexisting_pd_dir) } END_TEST +/* + * Check whether srd_decoder_unload_all() works. + * If it returns != SRD_OK (or segfaults) this test will fail. + */ +START_TEST(test_unload_all) +{ + int ret; + + srd_init(DECODERS_TESTDIR); + ret = srd_decoder_load_all(); + fail_unless(ret == SRD_OK, "srd_decoder_load_all() failed: %d.", ret); + ret = srd_decoder_unload_all(); + fail_unless(ret == SRD_OK, "srd_decoder_unload_all() failed: %d.", ret); + srd_exit(); +} +END_TEST + +/* + * Check whether srd_decoder_unload_all() works without prior srd_init(). + * If it returns != SRD_OK (or segfaults) this test will fail. + */ +START_TEST(test_unload_all_no_init) +{ + int ret; + + ret = srd_decoder_unload_all(); + fail_unless(ret == SRD_OK, "srd_decoder_unload_all() failed: %d.", ret); +} +END_TEST + +/* + * Check whether srd_decoder_unload_all() works multiple times. + * If it returns != SRD_OK (or segfaults) this test will fail. + */ +START_TEST(test_unload_all_multiple) +{ + int ret, i; + + srd_init(DECODERS_TESTDIR); + for (i = 0; i < 10; i++) { + ret = srd_decoder_load_all(); + fail_unless(ret == SRD_OK, "srd_decoder_load_all() failed: %d.", ret); + ret = srd_decoder_unload_all(); + fail_unless(ret == SRD_OK, "srd_decoder_unload_all() failed: %d.", ret); + } + srd_exit(); +} +END_TEST + +/* + * Check whether srd_decoder_unload_all() works multiple times (no load). + * If it returns != SRD_OK (or segfaults) this test will fail. + */ +START_TEST(test_unload_all_multiple_noload) +{ + int ret, i; + + srd_init(DECODERS_TESTDIR); + for (i = 0; i < 10; i++) { + ret = srd_decoder_unload_all(); + fail_unless(ret == SRD_OK, "srd_decoder_unload_all() failed: %d.", ret); + } + srd_exit(); +} +END_TEST + +/* + * Check whether srd_decoder_unload() works. + * If it returns != SRD_OK (or segfaults) this test will fail. + */ +START_TEST(test_unload) +{ + int ret; + struct srd_decoder *dec; + + srd_init(DECODERS_TESTDIR); + ret = srd_decoder_load("uart"); + fail_unless(ret == SRD_OK, "srd_decoder_load(uart) failed: %d.", ret); + dec = srd_decoder_get_by_id("uart"); + fail_unless(dec != NULL); + ret = srd_decoder_unload(dec); + fail_unless(ret == SRD_OK, "srd_decoder_unload() failed: %d.", ret); + srd_exit(); +} +END_TEST + +/* + * Check whether srd_decoder_unload(NULL) fails. + * If it returns SRD_OK (or segfaults) this test will fail. + */ +START_TEST(test_unload_null) +{ + srd_init(DECODERS_TESTDIR); + fail_unless(srd_decoder_unload(NULL) != SRD_OK); + srd_exit(); +} +END_TEST + +/* + * Check whether srd_decoder_unload(NULL) fails without prior srd_init(). + * If it returns SRD_OK (or segfaults) this test will fail. + */ +START_TEST(test_unload_null_no_init) +{ + fail_unless(srd_decoder_unload(NULL) != SRD_OK); +} +END_TEST + /* * Check whether srd_decoder_list() returns a non-empty list. * If it returns an empty list (or segfaults) this test will fail. @@ -322,6 +430,17 @@ Suite *suite_decoder(void) tcase_add_test(tc, test_load_nonexisting_pd_dir); suite_add_tcase(s, tc); + tc = tcase_create("unload"); + tcase_add_checked_fixture(tc, srdtest_setup, srdtest_teardown); + tcase_add_test(tc, test_unload_all); + tcase_add_test(tc, test_unload_all_no_init); + tcase_add_test(tc, test_unload_all_multiple); + tcase_add_test(tc, test_unload_all_multiple_noload); + tcase_add_test(tc, test_unload); + tcase_add_test(tc, test_unload_null); + tcase_add_test(tc, test_unload_null_no_init); + suite_add_tcase(s, tc); + tc = tcase_create("list"); tcase_add_checked_fixture(tc, srdtest_setup, srdtest_teardown); tcase_add_test(tc, test_decoder_list);