diff options
-rw-r--r-- | tests/Makefile.am | 3 | ||||
-rw-r--r-- | tests/check_decoder.c | 95 | ||||
-rw-r--r-- | tests/check_main.c | 2 |
3 files changed, 99 insertions, 1 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index 5d04c59..777aa05 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -27,7 +27,8 @@ check_PROGRAMS = ${TESTS} check_main_SOURCES = \ $(top_builddir)/libsigrokdecode.h \ check_main.c \ - check_core.c + check_core.c \ + check_decoder.c check_main_CFLAGS = @check_CFLAGS@ diff --git a/tests/check_decoder.c b/tests/check_decoder.c new file mode 100644 index 0000000..1ad370a --- /dev/null +++ b/tests/check_decoder.c @@ -0,0 +1,95 @@ +/* + * This file is part of the libsigrokdecode project. + * + * Copyright (C) 2013 Uwe Hermann <uwe@hermann-uwe.de> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "../libsigrokdecode.h" /* First, to avoid compiler warning. */ +#include <stdlib.h> +#include <check.h> + +/* + * Check whether srd_decoder_load_all() works. + * If it returns != SRD_OK (or segfaults) this test will fail. + */ +START_TEST(test_load_all) +{ + int ret; + + srd_init(NULL); + ret = srd_decoder_load_all(); + fail_unless(ret == SRD_OK, "srd_decoder_load_all() failed: %d.", ret); + srd_exit(); +} +END_TEST + +/* + * Check whether srd_decoder_load() works. + * If it returns != SRD_OK (or segfaults) this test will fail. + */ +START_TEST(test_load) +{ + int ret; + + srd_init(NULL); + ret = srd_decoder_load("uart"); + fail_unless(ret == SRD_OK, "srd_decoder_load(uart) failed: %d.", ret); + ret = srd_decoder_load("spi"); + fail_unless(ret == SRD_OK, "srd_decoder_load(spi) failed: %d.", ret); + ret = srd_decoder_load("usb_signalling"); + fail_unless(ret == SRD_OK, "srd_decoder_load(usb_signalling) failed: %d.", ret); + srd_exit(); +} +END_TEST + +/* + * Check whether srd_decoder_load() fails for non-existing or bogus PDs. + * If it returns SRD_OK (or segfaults) this test will fail. + */ +START_TEST(test_load_bogus) +{ + srd_init(NULL); + fail_unless(srd_decoder_load(NULL) != SRD_OK); + fail_unless(srd_decoder_load("") != SRD_OK); + fail_unless(srd_decoder_load(" ") != SRD_OK); + fail_unless(srd_decoder_load("nonexisting") != SRD_OK); + fail_unless(srd_decoder_load("UART") != SRD_OK); + fail_unless(srd_decoder_load("UaRt") != SRD_OK); + fail_unless(srd_decoder_load("u a r t") != SRD_OK); + fail_unless(srd_decoder_load("uart ") != SRD_OK); + fail_unless(srd_decoder_load(" uart") != SRD_OK); + fail_unless(srd_decoder_load(" uart ") != SRD_OK); + fail_unless(srd_decoder_load("uart spi") != SRD_OK); + srd_exit(); +} +END_TEST + +Suite *suite_decoder(void) +{ + Suite *s; + TCase *tc; + + s = suite_create("decoder"); + + tc = tcase_create("load"); + tcase_add_test(tc, test_load_all); + tcase_add_test(tc, test_load); + tcase_add_test(tc, test_load_bogus); + suite_add_tcase(s, tc); + + return s; +} diff --git a/tests/check_main.c b/tests/check_main.c index e115064..32ad859 100644 --- a/tests/check_main.c +++ b/tests/check_main.c @@ -23,6 +23,7 @@ #include <check.h> Suite *suite_core(void); +Suite *suite_decoder(void); int main(void) { @@ -35,6 +36,7 @@ int main(void) /* Add all testsuites to the master suite. */ srunner_add_suite(srunner, suite_core()); + srunner_add_suite(srunner, suite_decoder()); srunner_run_all(srunner, CK_VERBOSE); ret = srunner_ntests_failed(srunner); |