[systemd-commits] src/test

Thomas H.P. Andersen phomes at kemper.freedesktop.org
Mon Feb 11 13:22:47 PST 2013


 src/test/test-env-replace.c |   10 ++++++++
 src/test/test-util.c        |   52 +++++++++++++++++++++++++++++++++-----------
 2 files changed, 49 insertions(+), 13 deletions(-)

New commits:
commit 8354c34e14799593c85a638ef543b378ac97c6fe
Author: Thomas Hindoe Paaboel Andersen <phomes at gmail.com>
Date:   Mon Feb 11 21:40:59 2013 +0100

    tests: more tests
    
    tests for:
     parse_boolean
     env_name_is_valid
    
    Also convert assert to assert_se to make sure they are run even with
    optimization. (see commit 9b5d6bd909855543cba75a4469bff6f82845cf0d)

diff --git a/src/test/test-env-replace.c b/src/test/test-env-replace.c
index d6cb289..0274e97 100644
--- a/src/test/test-env-replace.c
+++ b/src/test/test-env-replace.c
@@ -195,6 +195,15 @@ static void test_env_clean(void) {
         assert_se(e[5] == NULL);
 }
 
+static void test_env_name_is_valid(void) {
+        assert_se(env_name_is_valid("test"));
+
+        assert_se(!env_name_is_valid(NULL));
+        assert_se(!env_name_is_valid(""));
+        assert_se(!env_name_is_valid("5_starting_with_a_number_is_wrong"));
+        assert_se(!env_name_is_valid("#¤%&?_only_numbers_letters_and_underscore_allowed"));
+}
+
 int main(int argc, char *argv[]) {
         test_strv_env_delete();
         test_strv_env_unset();
@@ -203,6 +212,7 @@ int main(int argc, char *argv[]) {
         test_replace_env_arg();
         test_normalize_env_assignment();
         test_env_clean();
+        test_env_name_is_valid();
 
         return 0;
 }
diff --git a/src/test/test-util.c b/src/test/test-util.c
index ebbdcfc..476fa09 100644
--- a/src/test/test-util.c
+++ b/src/test/test-util.c
@@ -25,22 +25,47 @@
 #include "util.h"
 
 static void test_streq_ptr(void) {
-        assert(streq_ptr(NULL, NULL));
-        assert(!streq_ptr("abc", "cdef"));
+        assert_se(streq_ptr(NULL, NULL));
+        assert_se(!streq_ptr("abc", "cdef"));
 }
 
 static void test_first_word(void) {
-        assert(first_word("Hello", ""));
-        assert(first_word("Hello", "Hello"));
-        assert(first_word("Hello world", "Hello"));
-        assert(first_word("Hello\tworld", "Hello"));
-        assert(first_word("Hello\nworld", "Hello"));
-        assert(first_word("Hello\rworld", "Hello"));
-        assert(first_word("Hello ", "Hello"));
-
-        assert(!first_word("Hello", "Hellooo"));
-        assert(!first_word("Hello", "xxxxx"));
-        assert(!first_word("Hellooo", "Hello"));
+        assert_se(first_word("Hello", ""));
+        assert_se(first_word("Hello", "Hello"));
+        assert_se(first_word("Hello world", "Hello"));
+        assert_se(first_word("Hello\tworld", "Hello"));
+        assert_se(first_word("Hello\nworld", "Hello"));
+        assert_se(first_word("Hello\rworld", "Hello"));
+        assert_se(first_word("Hello ", "Hello"));
+
+        assert_se(!first_word("Hello", "Hellooo"));
+        assert_se(!first_word("Hello", "xxxxx"));
+        assert_se(!first_word("Hellooo", "Hello"));
+}
+
+static void test_parse_boolean(void) {
+        assert_se(parse_boolean("1") == 1);
+        assert_se(parse_boolean("y") == 1);
+        assert_se(parse_boolean("Y") == 1);
+        assert_se(parse_boolean("yes") == 1);
+        assert_se(parse_boolean("YES") == 1);
+        assert_se(parse_boolean("true") == 1);
+        assert_se(parse_boolean("TRUE") == 1);
+        assert_se(parse_boolean("on") == 1);
+        assert_se(parse_boolean("ON") == 1);
+
+        assert_se(parse_boolean("0") == 0);
+        assert_se(parse_boolean("n") == 0);
+        assert_se(parse_boolean("N") == 0);
+        assert_se(parse_boolean("no") == 0);
+        assert_se(parse_boolean("NO") == 0);
+        assert_se(parse_boolean("false") == 0);
+        assert_se(parse_boolean("FALSE") == 0);
+        assert_se(parse_boolean("off") == 0);
+        assert_se(parse_boolean("OFF") == 0);
+
+        assert_se(parse_boolean("garbage") < 0);
+        assert_se(parse_boolean("") < 0);
 }
 
 static void test_foreach_word_quoted(void) {
@@ -75,6 +100,7 @@ static void test_default_term_for_tty(void) {
 int main(int argc, char *argv[]) {
         test_streq_ptr();
         test_first_word();
+        test_parse_boolean();
         test_default_term_for_tty();
         test_foreach_word_quoted();
 



More information about the systemd-commits mailing list