]> sigrok.org Git - libsigrok.git/commitdiff
tests: Factor out srtest_setup() and srtest_teardown().
authorUwe Hermann <redacted>
Mon, 11 Aug 2014 11:20:50 +0000 (13:20 +0200)
committerUwe Hermann <redacted>
Mon, 11 Aug 2014 11:20:50 +0000 (13:20 +0200)
tests/check_driver_all.c
tests/check_input_binary.c
tests/check_session.c
tests/check_strutil.c
tests/lib.c
tests/lib.h

index 39b713bbb66be559f5c1975a05d80827fffd2c84..585da1eaa7d6d3c8fb6228b02e1cbb52f4c8f356 100644 (file)
 #include "../include/libsigrok/libsigrok.h"
 #include "lib.h"
 
-struct sr_context *sr_ctx;
-
-static void setup(void)
-{
-       int ret;
-
-       ret = sr_init(&sr_ctx);
-       fail_unless(ret == SR_OK, "sr_init() failed: %d.", ret);
-}
-
-static void teardown(void)
-{
-       int ret;
-
-       ret = sr_exit(sr_ctx);
-       fail_unless(ret == SR_OK, "sr_exit() failed: %d.", ret);
-}
-
 /* Check whether at least one driver is available. */
 START_TEST(test_driver_available)
 {
@@ -54,7 +36,7 @@ END_TEST
 /* Check whether initializing all drivers works. */
 START_TEST(test_driver_init_all)
 {
-       srtest_driver_init_all(sr_ctx);
+       srtest_driver_init_all(srtest_ctx);
 }
 END_TEST
 
@@ -85,7 +67,7 @@ Suite *suite_driver_all(void)
        s = suite_create("driver-all");
 
        tc = tcase_create("config");
-       tcase_add_checked_fixture(tc, setup, teardown);
+       tcase_add_checked_fixture(tc, srtest_setup, srtest_teardown);
        tcase_add_test(tc, test_driver_available);
        tcase_add_test(tc, test_driver_init_all);
        // TODO: Currently broken.
index 6f11759fd2ba600b6d66eccfe323348c7bacd901..cd2e777704f9e4062a9755dd22809fd36a1def95 100644 (file)
@@ -30,8 +30,6 @@
 #define CHECK_ALL_HIGH         1
 #define CHECK_HELLO_WORLD      2
 
-static struct sr_context *sr_ctx;
-
 static uint64_t df_packet_counter = 0, sample_counter = 0;
 static gboolean have_seen_df_end = FALSE;
 static GArray *logic_channellist = NULL;
@@ -39,22 +37,6 @@ static int check_to_perform;
 static uint64_t expected_samples;
 static uint64_t *expected_samplerate;
 
-static void setup(void)
-{
-       int ret;
-
-       ret = sr_init(&sr_ctx);
-       fail_unless(ret == SR_OK, "sr_init() failed: %d.", ret);
-}
-
-static void teardown(void)
-{
-       int ret;
-
-       ret = sr_exit(sr_ctx);
-       fail_unless(ret == SR_OK, "sr_exit() failed: %d.", ret);
-}
-
 static void check_all_low(const struct sr_datafeed_logic *logic)
 {
        uint64_t i;
@@ -325,7 +307,7 @@ Suite *suite_input_binary(void)
        s = suite_create("input-binary");
 
        tc = tcase_create("basic");
-       tcase_add_checked_fixture(tc, setup, teardown);
+       tcase_add_checked_fixture(tc, srtest_setup, srtest_teardown);
        tcase_add_test(tc, test_input_binary_all_low);
        tcase_add_test(tc, test_input_binary_all_high);
        tcase_add_loop_test(tc, test_input_binary_all_high_loop, 0, 10);
index e48e1d468af08f186a5966c9bebd9652c868e96b..1f6e06d3a9327affb289274638427492332804fe 100644 (file)
 #include "../include/libsigrok/libsigrok.h"
 #include "lib.h"
 
-static struct sr_context *sr_ctx;
-
-static void setup(void)
-{
-       int ret;
-
-       ret = sr_init(&sr_ctx);
-       fail_unless(ret == SR_OK, "sr_init() failed: %d.", ret);
-}
-
-static void teardown(void)
-{
-       int ret;
-
-       ret = sr_exit(sr_ctx);
-       fail_unless(ret == SR_OK, "sr_exit() failed: %d.", ret);
-}
-
 /*
  * Check whether sr_session_new() works.
  * If it returns != SR_OK (or segfaults) this test will fail.
@@ -144,7 +126,7 @@ Suite *suite_session(void)
        s = suite_create("session");
 
        tc = tcase_create("new_destroy");
-       tcase_add_checked_fixture(tc, setup, teardown);
+       tcase_add_checked_fixture(tc, srtest_setup, srtest_teardown);
        tcase_add_test(tc, test_session_new);
        tcase_add_test(tc, test_session_new_bogus);
        tcase_add_test(tc, test_session_new_multiple);
index 229392d0de92c3f9ed3a875941d27bdf315d0948..68e6117dfd3c946f0ff3e4cb241b3324217e8c31 100644 (file)
 #include "../include/libsigrok/libsigrok.h"
 #include "lib.h"
 
-struct sr_context *sr_ctx;
-
-static void setup(void)
-{
-       int ret;
-
-       ret = sr_init(&sr_ctx);
-       fail_unless(ret == SR_OK, "sr_init() failed: %d.", ret);
-}
-
-static void teardown(void)
-{
-       int ret;
-
-       ret = sr_exit(sr_ctx);
-       fail_unless(ret == SR_OK, "sr_exit() failed: %d.", ret);
-}
-
 static void test_samplerate(uint64_t samplerate, const char *expected)
 {
        char *s;
@@ -180,7 +162,7 @@ Suite *suite_strutil(void)
        s = suite_create("strutil");
 
        tc = tcase_create("sr_samplerate_string");
-       tcase_add_checked_fixture(tc, setup, teardown);
+       tcase_add_checked_fixture(tc, srtest_setup, srtest_teardown);
        tcase_add_test(tc, test_hz);
        tcase_add_test(tc, test_khz);
        tcase_add_test(tc, test_mhz);
index f1c3c0159a1b4cd52308ccd505be1d060899d4a5..acdca674c49f079da546b8da7f50baf8a0613552 100644 (file)
 #include "../include/libsigrok/libsigrok.h"
 #include "lib.h"
 
+struct sr_context *srtest_ctx;
+
+void srtest_setup(void)
+{
+       int ret;
+
+       ret = sr_init(&srtest_ctx);
+       fail_unless(ret == SR_OK, "sr_init() failed: %d.", ret);
+}
+
+void srtest_teardown(void)
+{
+       int ret;
+
+       ret = sr_exit(srtest_ctx);
+       fail_unless(ret == SR_OK, "sr_exit() failed: %d.", ret);
+}
+
 /* Get a libsigrok driver by name. */
 struct sr_dev_driver *srtest_driver_get(const char *drivername)
 {
index 14c973ec7c33b87a8d7cc65d429cc74d0136e429..20a360c8c4193114fecec0405a7265e67e9c3907 100644 (file)
 
 #include "../include/libsigrok/libsigrok.h"
 
+extern struct sr_context *srtest_ctx;
+
+void srtest_setup(void);
+void srtest_teardown(void);
+
 struct sr_dev_driver *srtest_driver_get(const char *drivername);
 struct sr_input_format *srtest_input_get(const char *id);