diff options
author | Uwe Hermann <uwe@hermann-uwe.de> | 2015-11-03 02:12:29 +0100 |
---|---|---|
committer | Uwe Hermann <uwe@hermann-uwe.de> | 2015-11-03 02:12:29 +0100 |
commit | 1b6f39e39b9700a787db81268c4ae9cd0d3f1499 (patch) | |
tree | c2c986837714989441d05e4fba98ed53695aa6fd /tests | |
parent | 76a4498f3a1eb0ce3919c3ce72fad76f99049942 (diff) | |
download | libsigrokdecode-1b6f39e39b9700a787db81268c4ae9cd0d3f1499.tar.gz libsigrokdecode-1b6f39e39b9700a787db81268c4ae9cd0d3f1499.zip |
tests/decoder.c: Add some srd_decoder_unload*() tests.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/decoder.c | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/tests/decoder.c b/tests/decoder.c index 3a86566..2b88785 100644 --- a/tests/decoder.c +++ b/tests/decoder.c @@ -150,6 +150,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); |