summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRonny Chevalier <chevalier.ronny@gmail.com>2014-12-13 15:12:38 +0100
committerRonny Chevalier <chevalier.ronny@gmail.com>2014-12-13 15:12:38 +0100
commitfee0a921830166abffe5a806a512da6ceb2fe2eb (patch)
tree82c049f3778550d5293460e729c875e4374448ef
parent69adae5168da231c6cf319f708860954701b25ed (diff)
test-unit-name: add more tests
Add more test cases for: - unit_name_is_instance - unit_name_to_instance Add tests for: - unit_name_template - unit_name_is_template
-rw-r--r--src/test/test-unit-name.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/test/test-unit-name.c b/src/test/test-unit-name.c
index 65b6975a69..5c7f8b40f7 100644
--- a/src/test/test-unit-name.c
+++ b/src/test/test-unit-name.c
@@ -193,6 +193,7 @@ static int test_unit_printf(void) {
expect(u2, "%t", "/run/user/*");
manager_free(m);
+#undef expect
return 0;
}
@@ -262,6 +263,7 @@ static void test_unit_name_is_instance(void) {
assert_se(unit_name_is_instance("a-c_c01Aj@b05Dii_-oioi.service"));
assert_se(!unit_name_is_instance("a.service"));
+ assert_se(!unit_name_is_instance("a@.service"));
assert_se(!unit_name_is_instance("junk"));
assert_se(!unit_name_is_instance(""));
}
@@ -293,6 +295,11 @@ static void test_unit_name_to_instance(void) {
assert_se(streq(instance, "bar"));
free(instance);
+ r = unit_name_to_instance("foo@.service", &instance);
+ assert_se(r >= 0);
+ assert_se(streq(instance, ""));
+ free(instance);
+
r = unit_name_to_instance("fo0-stUff_b@b.e", &instance);
assert_se(r >= 0);
assert_se(streq(instance, "b"));
@@ -304,6 +311,9 @@ static void test_unit_name_to_instance(void) {
r = unit_name_to_instance("fooj@unk", &instance);
assert_se(r < 0);
+
+ r = unit_name_to_instance("foo@", &instance);
+ assert_se(r < 0);
}
static void test_unit_name_escape(void) {
@@ -314,6 +324,29 @@ static void test_unit_name_escape(void) {
assert_se(streq(r, "ab\\x2b\\x2dc.a-bc\\x40foo.service"));
}
+static void test_unit_name_template(void) {
+#define expect(name, expected) \
+ { \
+ _cleanup_free_ char *f = NULL; \
+ f = unit_name_template(name); \
+ assert_se(f); \
+ printf("got: %s, expected: %s\n", f, expected); \
+ assert_se(streq(f, expected)); \
+ }
+ expect("foo@bar.service", "foo@.service")
+ expect("foo.mount", "foo.mount")
+#undef expect
+}
+
+static void test_unit_name_is_template(void) {
+ assert_se(unit_name_is_template("foo@.service"));
+ assert_se(unit_name_is_template("bar@.path"));
+
+ assert_se(!unit_name_is_template("bar@i.mount"));
+ assert_se(!unit_name_is_template("bar@foobbbb.service"));
+ assert_se(!unit_name_is_template("barfoo.service"));
+}
+
int main(int argc, char* argv[]) {
int rc = 0;
test_replacements();
@@ -326,6 +359,8 @@ int main(int argc, char* argv[]) {
test_build_subslice();
test_unit_name_to_instance();
test_unit_name_escape();
+ test_unit_name_template();
+ test_unit_name_is_template();
return rc;
}