]> sigrok.org Git - libsigrok.git/commitdiff
transform: Add a few basic unit tests.
authorUwe Hermann <redacted>
Tue, 10 Feb 2015 21:47:36 +0000 (22:47 +0100)
committerUwe Hermann <redacted>
Wed, 11 Feb 2015 14:24:38 +0000 (15:24 +0100)
Makefile.am
tests/check_main.c
tests/check_transform_all.c [new file with mode: 0644]
tests/lib.h

index 16cd288d877b788ec59275824b865c0a28e60bb9..add31e9b6c9d56ca41a5d8677191d233c9a509e7 100644 (file)
@@ -424,6 +424,7 @@ tests_check_main_SOURCES = \
        tests/check_input_all.c \
        tests/check_input_binary.c \
        tests/check_output_all.c \
+       tests/check_transform_all.c \
        tests/check_session.c \
        tests/check_strutil.c \
        tests/check_version.c \
index db0bb6857c5c3e20c5ef20cbbdc349f703d8f7a8..4c75781a4413c2e07490ddd27f7a3b42b8201064 100644 (file)
@@ -38,6 +38,7 @@ int main(void)
        srunner_add_suite(srunner, suite_input_all());
        srunner_add_suite(srunner, suite_input_binary());
        srunner_add_suite(srunner, suite_output_all());
+       srunner_add_suite(srunner, suite_transform_all());
        srunner_add_suite(srunner, suite_session());
        srunner_add_suite(srunner, suite_strutil());
        srunner_add_suite(srunner, suite_version());
diff --git a/tests/check_transform_all.c b/tests/check_transform_all.c
new file mode 100644 (file)
index 0000000..a88f97e
--- /dev/null
@@ -0,0 +1,116 @@
+/*
+ * This file is part of the libsigrok project.
+ *
+ * Copyright (C) 2015 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 <stdlib.h>
+#include <check.h>
+#include "../include/libsigrok/libsigrok.h"
+#include "lib.h"
+
+/* Check whether at least one transform module is available. */
+START_TEST(test_transform_available)
+{
+       const struct sr_transform_module **transforms;
+
+       transforms = sr_transform_list();
+       fail_unless(transforms != NULL, "No transform modules found.");
+}
+END_TEST
+
+/* Check whether sr_transform_id_get() works. */
+START_TEST(test_transform_id)
+{
+       const struct sr_transform_module **transforms;
+       const char *id;
+
+       transforms = sr_transform_list();
+
+       id = sr_transform_id_get(transforms[0]);
+       fail_unless(id != NULL, "No ID found in transform module.");
+}
+END_TEST
+
+/* Check whether sr_transform_name_get() works. */
+START_TEST(test_transform_name)
+{
+       const struct sr_transform_module **transforms;
+       const char *name;
+
+       transforms = sr_transform_list();
+
+       name = sr_transform_name_get(transforms[0]);
+       fail_unless(name != NULL, "No name found in transform module.");
+}
+END_TEST
+
+/* Check whether sr_transform_description_get() works. */
+START_TEST(test_transform_desc)
+{
+       const struct sr_transform_module **transforms;
+       const char *desc;
+
+       transforms = sr_transform_list();
+
+       desc = sr_transform_description_get(transforms[0]);
+       fail_unless(desc != NULL, "No description found in transform module.");
+}
+END_TEST
+
+/* Check whether sr_transform_find() works. */
+START_TEST(test_transform_find)
+{
+       const struct sr_transform_module *tmod;
+       const char *id;
+
+       tmod = sr_transform_find("nop");
+       fail_unless(tmod != NULL, "Couldn't find the 'nop' transform module.");
+       id = sr_transform_id_get(tmod);
+       fail_unless(id != NULL, "No ID found in transform module.");
+       fail_unless(!strcmp(id, "nop"), "That is not the 'nop' module!");
+}
+END_TEST
+
+/* Check whether sr_transform_options_get() works. */
+START_TEST(test_transform_options)
+{
+       const struct sr_option **opt;
+
+       opt = sr_transform_options_get(sr_transform_find("nop"));
+       fail_unless(opt == NULL, "Transform module 'nop' doesn't have options.");
+}
+END_TEST
+
+Suite *suite_transform_all(void)
+{
+       Suite *s;
+       TCase *tc;
+
+       s = suite_create("transform-all");
+
+       tc = tcase_create("basic");
+       tcase_add_test(tc, test_transform_available);
+       tcase_add_test(tc, test_transform_id);
+       tcase_add_test(tc, test_transform_name);
+       tcase_add_test(tc, test_transform_desc);
+       tcase_add_test(tc, test_transform_find);
+       tcase_add_test(tc, test_transform_options);
+       suite_add_tcase(s, tc);
+
+       return s;
+}
index 09282f57bdacc7a41722ab1d56550d5f4e81055b..8ef9d54eb24b03e6fd6887917e9d293a59506441 100644 (file)
@@ -45,6 +45,7 @@ Suite *suite_driver_all(void);
 Suite *suite_input_all(void);
 Suite *suite_input_binary(void);
 Suite *suite_output_all(void);
+Suite *suite_transform_all(void);
 Suite *suite_session(void);
 Suite *suite_strutil(void);
 Suite *suite_version(void);