diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2018-10-26 12:30:04 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2018-10-26 13:17:49 +0200 |
commit | 1c1d719aecdb67d2d8098befa884d45fa76cb84e (patch) | |
tree | d5440bca097668368198c505d3cbd989b1699f04 | |
parent | test-serialize: allocate long_string dynamically (diff) | |
download | systemd-1c1d719aecdb67d2d8098befa884d45fa76cb84e.tar.gz systemd-1c1d719aecdb67d2d8098befa884d45fa76cb84e.tar.bz2 systemd-1c1d719aecdb67d2d8098befa884d45fa76cb84e.zip |
Move tests for *serialize_environment into test-serialize.c
The implementation is in serialize.c.
-rw-r--r-- | src/test/test-env-util.c | 57 | ||||
-rw-r--r-- | src/test/test-serialize.c | 61 |
2 files changed, 61 insertions, 57 deletions
diff --git a/src/test/test-env-util.c b/src/test/test-env-util.c index 815fb340a..ee9734fd6 100644 --- a/src/test/test-env-util.c +++ b/src/test/test-env-util.c @@ -306,61 +306,6 @@ static void test_env_assignment_is_valid(void) { assert_se(!env_assignment_is_valid("głąb=printf \"\x1b]0;<mock-chroot>\x07<mock-chroot>\"")); } -static void test_deserialize_environment(void) { - _cleanup_strv_free_ char **env; - - assert_se(env = strv_new("A=1", NULL)); - - assert_se(deserialize_environment("B=2", &env) >= 0); - assert_se(deserialize_environment("FOO%%=a\\177b\\nc\\td e", &env) >= 0); - - assert_se(strv_equal(env, STRV_MAKE("A=1", "B=2", "FOO%%=a\177b\nc\td e"))); - - assert_se(deserialize_environment("foo\\", &env) < 0); - assert_se(deserialize_environment("bar\\_baz", &env) < 0); -} - -static void test_serialize_environment(void) { - _cleanup_strv_free_ char **env = NULL, **env2 = NULL; - _cleanup_(unlink_tempfilep) char fn[] = "/tmp/test-env-util.XXXXXXX"; - _cleanup_fclose_ FILE *f = NULL; - int r; - - assert_se(env = strv_new("A=1", - "B=2", - "C=ąęółń", - "D=D=a\\x0Ab", - "FOO%%=a\177b\nc\td e", - NULL)); - - assert_se(fmkostemp_safe(fn, "r+", &f) == 0); - assert_se(serialize_strv(f, "env", env) == 1); - assert_se(fflush_and_check(f) == 0); - - rewind(f); - - for (;;) { - _cleanup_free_ char *line = NULL; - const char *l; - - r = read_line(f, LONG_LINE_MAX, &line); - assert_se(r >= 0); - - if (r == 0) - break; - - l = strstrip(line); - - assert_se(startswith(l, "env=")); - - r = deserialize_environment(l+4, &env2); - assert_se(r >= 0); - } - assert_se(feof(f)); - - assert_se(strv_equal(env, env2)); -} - int main(int argc, char *argv[]) { test_strv_env_delete(); test_strv_env_get(); @@ -377,8 +322,6 @@ int main(int argc, char *argv[]) { test_env_name_is_valid(); test_env_value_is_valid(); test_env_assignment_is_valid(); - test_deserialize_environment(); - test_serialize_environment(); return 0; } diff --git a/src/test/test-serialize.c b/src/test/test-serialize.c index e38b48fdb..b70eb3daa 100644 --- a/src/test/test-serialize.c +++ b/src/test/test-serialize.c @@ -133,6 +133,65 @@ static void test_serialize_strv(void) { assert_se(strv_equal(strv, strv2)); } +static void test_deserialize_environment(void) { + _cleanup_strv_free_ char **env; + + log_info("/* %s */", __func__); + + assert_se(env = strv_new("A=1", NULL)); + + assert_se(deserialize_environment("B=2", &env) >= 0); + assert_se(deserialize_environment("FOO%%=a\\177b\\nc\\td e", &env) >= 0); + + assert_se(strv_equal(env, STRV_MAKE("A=1", "B=2", "FOO%%=a\177b\nc\td e"))); + + assert_se(deserialize_environment("foo\\", &env) < 0); + assert_se(deserialize_environment("bar\\_baz", &env) < 0); +} + +static void test_serialize_environment(void) { + _cleanup_strv_free_ char **env = NULL, **env2 = NULL; + _cleanup_(unlink_tempfilep) char fn[] = "/tmp/test-env-util.XXXXXXX"; + _cleanup_fclose_ FILE *f = NULL; + int r; + + assert_se(fmkostemp_safe(fn, "r+", &f) == 0); + log_info("/* %s (%s) */", __func__, fn); + + assert_se(env = strv_new("A=1", + "B=2", + "C=ąęółń", + "D=D=a\\x0Ab", + "FOO%%=a\177b\nc\td e", + NULL)); + + assert_se(serialize_strv(f, "env", env) == 1); + assert_se(fflush_and_check(f) == 0); + + rewind(f); + + for (;;) { + _cleanup_free_ char *line = NULL; + const char *l; + + r = read_line(f, LONG_LINE_MAX, &line); + assert_se(r >= 0); + + if (r == 0) + break; + + l = strstrip(line); + + assert_se(startswith(l, "env=")); + + r = deserialize_environment(l+4, &env2); + assert_se(r >= 0); + } + assert_se(feof(f)); + + assert_se(strv_equal(env, env2)); +} + int main(int argc, char *argv[]) { test_setup_logging(LOG_INFO); @@ -143,6 +202,8 @@ int main(int argc, char *argv[]) { test_serialize_item_escaped(); test_serialize_usec(); test_serialize_strv(); + test_deserialize_environment(); + test_serialize_environment(); return EXIT_SUCCESS; } |