chiark / gitweb /
util: be more picky when validating hostnames
[elogind.git] / src / test / test-strv.c
index 7f475a6f4cb3f71b282e4fe08dcd7b48d9676a71..2a1c0057cebce84b169a157b2d309b7b15cbe930 100644 (file)
@@ -27,7 +27,7 @@
 #include "strv.h"
 
 static void test_specifier_printf(void) {
-        char *w;
+        _cleanup_free_ char *w = NULL;
 
         const Specifier table[] = {
                 { 'a', specifier_string, (char*) "AAAA" },
@@ -36,8 +36,10 @@ static void test_specifier_printf(void) {
         };
 
         w = specifier_printf("xxx a=%a b=%b yyy", table, NULL);
-        printf("<%s>\n", w);
-        free(w);
+        puts(w);
+
+        assert_se(w);
+        assert_se(streq(w, "xxx a=AAAA b=BBBB yyy"));
 }
 
 static void test_strv_find(void) {
@@ -231,8 +233,23 @@ static void test_strv_append(void) {
         assert_se(streq(c[0], "test3"));
 }
 
+static void test_strv_foreach_pair(void) {
+        _cleanup_strv_free_ char **a = NULL;
+        char **x, **y;
+
+        a = strv_new("pair_one",   "pair_one",
+                     "pair_two",   "pair_two",
+                     "pair_three", "pair_three",
+                     NULL);
+
+        STRV_FOREACH_PAIR(x, y, a) {
+                assert_se(streq(*x, *y));
+        }
+}
+
 int main(int argc, char *argv[]) {
         test_specifier_printf();
+        test_strv_foreach_pair();
         test_strv_find();
         test_strv_find_prefix();
         test_strv_join();