summaryrefslogtreecommitdiff
path: root/src/test/test-util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-07-18 20:22:29 +0200
committerLennart Poettering <lennart@poettering.net>2013-07-18 20:22:29 +0200
commitd4ac85c6f6d8547f8b835009ae431438de72df28 (patch)
treec18be6d1c1af7efaa740beeac594be8cd61d62e9 /src/test/test-util.c
parent2f5df74a5ec135ab2baebf26af6f088e5b4b8205 (diff)
util: add split_pair() for splitting foo=bar strings
Diffstat (limited to 'src/test/test-util.c')
-rw-r--r--src/test/test-util.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/test/test-util.c b/src/test/test-util.c
index 4768310fbe..315bc419c2 100644
--- a/src/test/test-util.c
+++ b/src/test/test-util.c
@@ -521,6 +521,28 @@ static void test_parse_user_at_host(void) {
assert_se(streq(host, "mikescomputer"));
}
+static void test_split_pair(void) {
+ _cleanup_free_ char *a = NULL, *b = NULL;
+
+ assert_se(split_pair("", "", &a, &b) == -EINVAL);
+ assert_se(split_pair("foo=bar", "", &a, &b) == -EINVAL);
+ assert_se(split_pair("", "=", &a, &b) == -EINVAL);
+ assert_se(split_pair("foo=bar", "=", &a, &b) >= 0);
+ assert_se(streq(a, "foo"));
+ assert_se(streq(b, "bar"));
+ free(a);
+ free(b);
+ assert_se(split_pair("==", "==", &a, &b) >= 0);
+ assert_se(streq(a, ""));
+ assert_se(streq(b, ""));
+ free(a);
+ free(b);
+
+ assert_se(split_pair("===", "==", &a, &b) >= 0);
+ assert_se(streq(a, ""));
+ assert_se(streq(b, "="));
+}
+
int main(int argc, char *argv[]) {
test_streq_ptr();
test_first_word();
@@ -555,6 +577,7 @@ int main(int argc, char *argv[]) {
test_strextend();
test_strrep();
test_parse_user_at_host();
+ test_split_pair();
return 0;
}