summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorUwe Hermann <uwe@hermann-uwe.de>2013-10-17 01:48:08 +0200
committerUwe Hermann <uwe@hermann-uwe.de>2013-10-17 01:54:25 +0200
commit3ad11099f8d45c215d3b44e5588832b7679b887d (patch)
tree9bdf6405c94b3894d111ce149d99904bb7a45414 /tests
parent7529cdaad9e9a52c93ed4d21c2fcccaf3313592c (diff)
downloadlibsigrokdecode-3ad11099f8d45c215d3b44e5588832b7679b887d.tar.gz
libsigrokdecode-3ad11099f8d45c215d3b44e5588832b7679b887d.zip
testsuite: Add some basic tests for loading PDs.
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am3
-rw-r--r--tests/check_decoder.c95
-rw-r--r--tests/check_main.c2
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);