From c462e63eea7c781e00a3ce83055967dbbd67bf96 Mon Sep 17 00:00:00 2001 From: Jan Janssen Date: Wed, 24 Nov 2021 12:11:17 +0100 Subject: test: Use TEST macro in more cases This converts to TEST macro in less trivial cases. This is mostly due to having an intro or outro before/after the actual tests. Some notable changes: - add a "test" to make sure the hashmap and ordered_hashmap tests from different compilation units are actually run in test-hashmap.c - make root arg a global var in test-install-root.c - slightly rework an EFI specific test in test-proc-cmdline.c - usage of saved_argv/saved_argc in test-process-util.c - splitting test-rlimit-util.c into several tests - moving the hwdb open check into intro in test-sd-hwdb.c - condense several "tests" into one in test-udev-util.c --- src/test/test-serialize.c | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-) (limited to 'src/test/test-serialize.c') diff --git a/src/test/test-serialize.c b/src/test/test-serialize.c index 7bd53a861d..fb04b3e7fa 100644 --- a/src/test/test-serialize.c +++ b/src/test/test-serialize.c @@ -12,7 +12,7 @@ char long_string[LONG_LINE_MAX+1]; -static void test_serialize_item(void) { +TEST(serialize_item) { _cleanup_(unlink_tempfilep) char fn[] = "/tmp/test-serialize.XXXXXX"; _cleanup_fclose_ FILE *f = NULL; @@ -37,7 +37,7 @@ static void test_serialize_item(void) { assert_se(streq(line3, "")); } -static void test_serialize_item_escaped(void) { +TEST(serialize_item_escaped) { _cleanup_(unlink_tempfilep) char fn[] = "/tmp/test-serialize.XXXXXX"; _cleanup_fclose_ FILE *f = NULL; @@ -62,7 +62,7 @@ static void test_serialize_item_escaped(void) { assert_se(streq(line3, "")); } -static void test_serialize_usec(void) { +TEST(serialize_usec) { _cleanup_(unlink_tempfilep) char fn[] = "/tmp/test-serialize.XXXXXX"; _cleanup_fclose_ FILE *f = NULL; @@ -89,7 +89,7 @@ static void test_serialize_usec(void) { assert_se(x == USEC_INFINITY-1); } -static void test_serialize_strv(void) { +TEST(serialize_strv) { _cleanup_(unlink_tempfilep) char fn[] = "/tmp/test-serialize.XXXXXX"; _cleanup_fclose_ FILE *f = NULL; @@ -133,11 +133,9 @@ static void test_serialize_strv(void) { assert_se(strv_equal(strv, strv2)); } -static void test_deserialize_environment(void) { +TEST(deserialize_environment) { _cleanup_strv_free_ char **env; - log_info("/* %s */", __func__); - assert_se(env = strv_new("A=1")); assert_se(deserialize_environment("B=2", &env) >= 0); @@ -149,7 +147,7 @@ static void test_deserialize_environment(void) { assert_se(deserialize_environment("bar\\_baz", &env) < 0); } -static void test_serialize_environment(void) { +TEST(serialize_environment) { _cleanup_strv_free_ char **env = NULL, **env2 = NULL; _cleanup_(unlink_tempfilep) char fn[] = "/tmp/test-env-util.XXXXXXX"; _cleanup_fclose_ FILE *f = NULL; @@ -191,18 +189,10 @@ static void test_serialize_environment(void) { assert_se(strv_equal(env, env2)); } -int main(int argc, char *argv[]) { - test_setup_logging(LOG_INFO); - - memset(long_string, 'x', sizeof(long_string)-1); - char_array_0(long_string); - - test_serialize_item(); - test_serialize_item_escaped(); - test_serialize_usec(); - test_serialize_strv(); - test_deserialize_environment(); - test_serialize_environment(); - - return EXIT_SUCCESS; -} +DEFINE_CUSTOM_TEST_MAIN( + LOG_INFO, + ({ + memset(long_string, 'x', sizeof(long_string)-1); + char_array_0(long_string); + }), + /* no outro */); -- cgit v1.2.1