testsuite: Add some basic tests for loading PDs.
authorUwe Hermann <uwe@hermann-uwe.de>
Wed, 16 Oct 2013 23:48:08 +0000 (01:48 +0200)
committerUwe Hermann <uwe@hermann-uwe.de>
Wed, 16 Oct 2013 23:54:25 +0000 (01:54 +0200)
tests/Makefile.am
tests/check_decoder.c [new file with mode: 0644]
tests/check_main.c

index 5d04c598724e46e12fc424b996d3061146f8d879..777aa05a88c891b966e68380926cb25c0663b681 100644 (file)
@@ -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 (file)
index 0000000..1ad370a
--- /dev/null
@@ -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;
+}
index e115064f7c340df40f76fe7d1659f9066750d322..32ad859a85879f5b32dd79f905ac61d6040cef17 100644 (file)
@@ -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);