From: Uwe Hermann Date: Tue, 10 Feb 2015 21:47:36 +0000 (+0100) Subject: transform: Add a few basic unit tests. X-Git-Tag: libsigrok-0.4.0~652 X-Git-Url: http://sigrok.org/gitweb/?a=commitdiff_plain;h=8677e4e7be9aa857d273f37da2beb21d457878c4;hp=d74d30bb14b9cb240e244caff7179926c72630e6;p=libsigrok.git transform: Add a few basic unit tests. --- diff --git a/Makefile.am b/Makefile.am index 16cd288d..add31e9b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 \ diff --git a/tests/check_main.c b/tests/check_main.c index db0bb685..4c75781a 100644 --- a/tests/check_main.c +++ b/tests/check_main.c @@ -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 index 00000000..a88f97ed --- /dev/null +++ b/tests/check_transform_all.c @@ -0,0 +1,116 @@ +/* + * This file is part of the libsigrok project. + * + * Copyright (C) 2015 Uwe Hermann + * + * 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 +#include +#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; +} diff --git a/tests/lib.h b/tests/lib.h index 09282f57..8ef9d54e 100644 --- a/tests/lib.h +++ b/tests/lib.h @@ -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);