[systemd-commits] 2 commits - src/locale src/shared src/test src/timedate

Thomas H.P. Andersen phomes at kemper.freedesktop.org
Wed Feb 6 15:39:38 PST 2013


 src/locale/localectl.c      |    9 ++-------
 src/shared/strv.c           |   10 ++++++++++
 src/shared/strv.h           |    1 +
 src/test/test-env-replace.c |   22 ++++------------------
 src/test/test-strv.c        |   18 ++++++++++++++++++
 src/timedate/timedatectl.c  |    4 +---
 6 files changed, 36 insertions(+), 28 deletions(-)

New commits:
commit 10ddd913f0d13584e13b5e6bbcb381f1618c90c0
Author: Thomas Hindoe Paaboel Andersen <phomes at gmail.com>
Date:   Thu Feb 7 00:33:58 2013 +0100

    tests: move strv_parse_nulstr to test-strv, and actually test it
    
    The test was originally added with this commit message:
    "ask-password: supported plymouth cached passwords"

diff --git a/src/test/test-env-replace.c b/src/test/test-env-replace.c
index ad5c991..0bd42e3 100644
--- a/src/test/test-env-replace.c
+++ b/src/test/test-env-replace.c
@@ -47,15 +47,7 @@ int main(int argc, char *argv[]) {
                 NULL
         };
 
-        char **i, **r, *t, **a, **b;
-        const char nulstr[] = "fuck\0fuck2\0fuck3\0\0fuck5\0\0xxx";
-
-        a = strv_parse_nulstr(nulstr, sizeof(nulstr)-1);
-
-        STRV_FOREACH(i, a)
-                printf("nulstr--%s\n", *i);
-
-        strv_free(a);
+        char **r, *t, **a, **b;
 
         r = replace_env_argv((char**) line, (char**) env);
         strv_print(r);
diff --git a/src/test/test-strv.c b/src/test/test-strv.c
index 1df8157..07aac3a 100644
--- a/src/test/test-strv.c
+++ b/src/test/test-strv.c
@@ -100,6 +100,23 @@ static void test_strv_join(void) {
         assert(streq(t, ""));
 }
 
+static void test_strv_parse_nulstr(void) {
+        _cleanup_strv_free_ char **l = NULL;
+        const char nulstr[] = "fuck\0fuck2\0fuck3\0\0fuck5\0\0xxx";
+
+        l = strv_parse_nulstr(nulstr, sizeof(nulstr)-1);
+        puts("Parse nulstr:");
+        strv_print(l);
+
+        assert(streq(l[0], "fuck"));
+        assert(streq(l[1], "fuck2"));
+        assert(streq(l[2], "fuck3"));
+        assert(streq(l[3], ""));
+        assert(streq(l[4], "fuck5"));
+        assert(streq(l[5], ""));
+        assert(streq(l[6], "xxx"));
+}
+
 static void test_strv_overlap(void) {
         const char * const input_table[] = {
                 "one",
@@ -146,6 +163,7 @@ int main(int argc, char *argv[]) {
         test_strv_find();
         test_strv_find_prefix();
         test_strv_join();
+        test_strv_parse_nulstr();
         test_strv_overlap();
         test_strv_sort();
 

commit 7c2d80944afb4196f2eff614e8da1450dffcbeaa
Author: Thomas Hindoe Paaboel Andersen <phomes at gmail.com>
Date:   Thu Feb 7 00:15:27 2013 +0100

    strv: add strv_print
    
    Clearer, and spares the temp variable.

diff --git a/src/locale/localectl.c b/src/locale/localectl.c
index 290edcc..8c3c8e3 100644
--- a/src/locale/localectl.c
+++ b/src/locale/localectl.c
@@ -432,7 +432,6 @@ static int add_locales_from_libdir (Set *locales) {
 static int list_locales(DBusConnection *bus, char **args, unsigned n) {
         _cleanup_set_free_ Set *locales;
         _cleanup_strv_free_ char **l = NULL;
-        char **j;
         int r;
 
         locales = set_new(string_hash_func, string_compare_func);
@@ -455,8 +454,7 @@ static int list_locales(DBusConnection *bus, char **args, unsigned n) {
 
         pager_open_if_enabled();
 
-        STRV_FOREACH(j, l)
-                puts(*j);
+        strv_print(l);
 
         return 0;
 }
@@ -539,7 +537,6 @@ static int nftw_cb(
 
 static int list_vconsole_keymaps(DBusConnection *bus, char **args, unsigned n) {
         char _cleanup_strv_free_ **l = NULL;
-        char **i;
 
         keymaps = set_new(string_hash_func, string_compare_func);
         if (!keymaps)
@@ -566,9 +563,7 @@ static int list_vconsole_keymaps(DBusConnection *bus, char **args, unsigned n) {
 
         pager_open_if_enabled();
 
-        STRV_FOREACH(i, l)
-                puts(*i);
-
+        strv_print(l);
 
         return 0;
 }
diff --git a/src/shared/strv.c b/src/shared/strv.c
index 2d556f4..fc6104f 100644
--- a/src/shared/strv.c
+++ b/src/shared/strv.c
@@ -774,3 +774,13 @@ char **strv_sort(char **l) {
         qsort(l, strv_length(l), sizeof(char*), str_compare);
         return l;
 }
+
+void strv_print(char **l) {
+        char **s;
+
+        if (!l)
+                return;
+
+        STRV_FOREACH(s, l)
+                puts(*s);
+}
diff --git a/src/shared/strv.h b/src/shared/strv.h
index fd728ef..33c752a 100644
--- a/src/shared/strv.h
+++ b/src/shared/strv.h
@@ -87,3 +87,4 @@ bool strv_overlap(char **a, char **b);
 
 
 char **strv_sort(char **l);
+void strv_print(char **l);
diff --git a/src/test/test-env-replace.c b/src/test/test-env-replace.c
index cd596a6..ad5c991 100644
--- a/src/test/test-env-replace.c
+++ b/src/test/test-env-replace.c
@@ -58,10 +58,7 @@ int main(int argc, char *argv[]) {
         strv_free(a);
 
         r = replace_env_argv((char**) line, (char**) env);
-
-        STRV_FOREACH(i, r)
-                printf("%s\n", *i);
-
+        strv_print(r);
         strv_free(r);
 
         t = normalize_env_assignment("foo=bar");
@@ -127,16 +124,13 @@ int main(int argc, char *argv[]) {
         strv_free(a);
         strv_free(b);
 
-        STRV_FOREACH(i, r)
-                printf("%s\n", *i);
+        strv_print(r);
 
         printf("CLEANED UP:\n");
 
         r = strv_env_clean(r);
 
-        STRV_FOREACH(i, r)
-                printf("%s\n", *i);
-
+        strv_print(r);
         strv_free(r);
 
         return 0;
diff --git a/src/timedate/timedatectl.c b/src/timedate/timedatectl.c
index 281c052..f5b5f0c 100644
--- a/src/timedate/timedatectl.c
+++ b/src/timedate/timedatectl.c
@@ -425,7 +425,6 @@ static int list_timezones(DBusConnection *bus, char **args, unsigned n) {
         _cleanup_fclose_ FILE *f = NULL;
         _cleanup_strv_free_ char **zones = NULL;
         size_t n_zones = 0;
-        char **i;
 
         assert(args);
         assert(n == 1);
@@ -487,8 +486,7 @@ static int list_timezones(DBusConnection *bus, char **args, unsigned n) {
         pager_open_if_enabled();
 
         strv_sort(zones);
-        STRV_FOREACH(i, zones)
-                puts(*i);
+        strv_print(zones);
 
         return 0;
 }



More information about the systemd-commits mailing list