diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2013-01-29 14:39:32 -0500 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2013-01-29 19:01:41 -0500 |
commit | 3251c0d2392062b2b8354793a2037d1161f824ee (patch) | |
tree | 96e14fc98152bfa02d50e31a2a1631f04a9014b7 | |
parent | 7742f7e999d58062b9784be83553eda109fff366 (diff) |
tests: compress unit name tests and add more asserts
-rw-r--r-- | src/test/test-unit-name.c | 214 |
1 files changed, 69 insertions, 145 deletions
diff --git a/src/test/test-unit-name.c b/src/test/test-unit-name.c index 50187e1129..5207781f99 100644 --- a/src/test/test-unit-name.c +++ b/src/test/test-unit-name.c @@ -27,151 +27,75 @@ #include "util.h" int main(int argc, char* argv[]) { - char *t, *k; - - t = unit_name_replace_instance("foo@.service", "waldo"); - puts(t); - free(t); - - t = unit_name_replace_instance("foo@xyz.service", "waldo"); - puts(t); - free(t); - - t = unit_name_replace_instance("xyz", "waldo"); - puts(t); - free(t); - - t = unit_name_replace_instance("", "waldo"); - puts(t); - free(t); - - t = unit_name_replace_instance("", ""); - puts(t); - free(t); - - t = unit_name_replace_instance("foo.service", "waldo"); - puts(t); - free(t); - - t = unit_name_replace_instance(".service", "waldo"); - puts(t); - free(t); - - t = unit_name_replace_instance("foo@bar", "waldo"); - puts(t); - free(t); - - t = unit_name_replace_instance("foo@", "waldo"); - puts(t); - free(t); - - t = unit_name_replace_instance("@", "waldo"); - puts(t); - free(t); - - t = unit_name_replace_instance("@bar", "waldo"); - puts(t); - free(t); - - t = unit_name_from_path("/waldo", ".mount"); - puts(t); - k = unit_name_to_path(t); - puts(k); - free(k); - free(t); - - t = unit_name_from_path("/waldo/quuix", ".mount"); - puts(t); - k = unit_name_to_path(t); - puts(k); - free(k); - free(t); - - t = unit_name_from_path("/waldo/quuix/", ".mount"); - puts(t); - k = unit_name_to_path(t); - puts(k); - free(k); - free(t); - - t = unit_name_from_path("/", ".mount"); - puts(t); - k = unit_name_to_path(t); - puts(k); - free(k); - free(t); - - t = unit_name_from_path("///", ".mount"); - puts(t); - k = unit_name_to_path(t); - puts(k); - free(k); - free(t); - - t = unit_name_from_path_instance("waldo", "/waldo", ".mount"); - puts(t); - free(t); - - t = unit_name_from_path_instance("waldo", "/waldo////quuix////", ".mount"); - puts(t); - free(t); - - t = unit_name_from_path_instance("waldo", "/", ".mount"); - puts(t); - free(t); - - t = unit_name_from_path_instance("wa--ldo", "/--", ".mount"); - puts(t); - free(t); - - assert_se(t = unit_name_mangle("/home")); - assert_se(k = unit_name_mangle(t)); - puts(t); - assert_se(streq(t, k)); - free(t); - free(k); - - assert_se(t = unit_name_mangle("/dev/sda")); - assert_se(k = unit_name_mangle(t)); - puts(t); - assert_se(streq(t, k)); - free(t); - free(k); - - assert_se(t = unit_name_mangle("üxknürz.service")); - assert_se(k = unit_name_mangle(t)); - puts(t); - assert_se(streq(t, k)); - free(t); - free(k); - - assert_se(t = unit_name_mangle("foobar-meh...waldi.service")); - assert_se(k = unit_name_mangle(t)); - puts(t); - assert_se(streq(t, k)); - free(t); - free(k); - - assert_se(t = unit_name_mangle("_____####----.....service")); - assert_se(k = unit_name_mangle(t)); - puts(t); - assert_se(streq(t, k)); - free(t); - free(k); - - assert_se(t = unit_name_mangle("_____##@;;;,,,##----.....service")); - assert_se(k = unit_name_mangle(t)); - puts(t); - assert_se(streq(t, k)); - free(t); - free(k); - - assert_se(t = unit_name_mangle("xxx@@@@/////\\\\\\\\\\yyy.service")); - assert_se(k = unit_name_mangle(t)); - puts(t); - assert_se(streq(t, k)); - free(t); - free(k); + +#define expect(pattern, repl, expected) \ + { \ + char _cleanup_free_ *t = \ + unit_name_replace_instance(pattern, repl); \ + puts(t); \ + assert(streq(t, expected)); \ + } + + expect("foo@.service", "waldo", "foo@waldo.service"); + expect("foo@xyz.service", "waldo", "foo@waldo.service"); + expect("xyz", "waldo", "xyz"); + expect("", "waldo", ""); + expect("foo.service", "waldo", "foo.service"); + expect(".service", "waldo", ".service"); + expect("foo@", "waldo", "foo@waldo"); + expect("@bar", "waldo", "@waldo"); + + puts("-------------------------------------------------"); +#undef expect +#define expect(path, suffix, expected) \ + { \ + char _cleanup_free_ *k, *t = \ + unit_name_from_path(path, suffix); \ + puts(t); \ + k = unit_name_to_path(t); \ + puts(k); \ + assert(streq(k, expected ? expected : path)); \ + } + + expect("/waldo", ".mount", NULL); + expect("/waldo/quuix", ".mount", NULL); + expect("/waldo/quuix/", ".mount", "/waldo/quuix"); + expect("/", ".mount", NULL); + expect("///", ".mount", "/"); + + puts("-------------------------------------------------"); +#undef expect +#define expect(pattern, path, suffix, expected) \ + { \ + char _cleanup_free_ *t = \ + unit_name_from_path_instance(pattern, path, suffix); \ + puts(t); \ + assert(streq(t, expected)); \ + } + + expect("waldo", "/waldo", ".mount", "waldo@waldo.mount"); + expect("waldo", "/waldo////quuix////", ".mount", "waldo@waldo-quuix.mount"); + expect("waldo", "/", ".mount", "waldo@-.mount"); + expect("wa--ldo", "/--", ".mount", "wa--ldo@\\x2d\\x2d.mount"); + + puts("-------------------------------------------------"); +#undef expect +#define expect(pattern) \ + { \ + char _cleanup_free_ *k, *t; \ + assert_se(t = unit_name_mangle(pattern)); \ + assert_se(k = unit_name_mangle(t)); \ + puts(t); \ + assert_se(streq(t, k)); \ + } + + expect("/home"); + expect("/dev/sda"); + expect("üxknürz.service"); + expect("foobar-meh...waldi.service"); + expect("_____####----.....service"); + expect("_____##@;;;,,,##----.....service"); + expect("xxx@@@@/////\\\\\\\\\\yyy.service"); return 0; } |