]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
unit-tests: Pass test iteration to fixtures
authorTobias Brunner <tobias@strongswan.org>
Fri, 24 Apr 2020 12:45:21 +0000 (14:45 +0200)
committerTobias Brunner <tobias@strongswan.org>
Mon, 20 Jul 2020 11:50:11 +0000 (13:50 +0200)
src/libstrongswan/tests/test_runner.c
src/libstrongswan/tests/test_suite.h

index 603495c13a96adf0d782651a0515eb0646a7c605..1e7f3ce1f11ff95b446e786fe328dee140799a87 100644 (file)
@@ -215,7 +215,7 @@ static bool run_test(test_function_t *tfun, int i)
 /**
  * Invoke fixture setup/teardown
  */
-static bool call_fixture(test_case_t *tcase, bool up)
+static bool call_fixture(test_case_t *tcase, bool up, int i)
 {
        enumerator_t *enumerator;
        test_fixture_t *fixture;
@@ -230,14 +230,14 @@ static bool call_fixture(test_case_t *tcase, bool up)
                        {
                                if (fixture->setup)
                                {
-                                       fixture->setup();
+                                       fixture->setup(i);
                                }
                        }
                        else
                        {
                                if (fixture->teardown)
                                {
-                                       fixture->teardown();
+                                       fixture->teardown(i);
                                }
                        }
                }
@@ -519,18 +519,18 @@ static bool run_case(test_case_t *tcase, test_runner_init_t init, char *cfg)
                                test_setup_timeout(tcase->timeout);
                                start_timing(&start);
 
-                               if (call_fixture(tcase, TRUE))
+                               if (call_fixture(tcase, TRUE, i))
                                {
                                        if (run_test(tfun, i))
                                        {
-                                               if (call_fixture(tcase, FALSE))
+                                               if (call_fixture(tcase, FALSE, i))
                                                {
                                                        ok = TRUE;
                                                }
                                        }
                                        else
                                        {
-                                               call_fixture(tcase, FALSE);
+                                               call_fixture(tcase, FALSE, i);
                                        }
                                }
                                if (!post_test(init, ok, failures, tfun->name, i, &leaks))
index 3bc3b38ca8df742ff16b60d9791eb4fa5751aea7..a35e9ec63f1a9f886aaef88b02912ac51962e631 100644 (file)
@@ -51,7 +51,7 @@ typedef void (*test_function_cb_t)(int);
 /**
  * Fixture for a test case.
  */
-typedef void (*test_fixture_cb_t)(void);
+typedef void (*test_fixture_cb_t)(int);
 
 /**
  * A test suite; a collection of test cases with fixtures
@@ -388,9 +388,9 @@ void test_fail_if_worker_failed();
 #define suite_add_tcase test_suite_add_case
 #define START_TEST(name) static void name (int _i) {
 #define END_TEST test_fail_if_worker_failed(); }
-#define START_SETUP(name) static void name() {
+#define START_SETUP(name) static void name(int _i) {
 #define END_SETUP test_fail_if_worker_failed(); }
-#define START_TEARDOWN(name) static void name() {
+#define START_TEARDOWN(name) static void name(int _i) {
 #define END_TEARDOWN test_fail_if_worker_failed(); }
 
 #endif /** TEST_SUITE_H_ @}*/