chiark / gitweb /
resolved: fix cname handling
[elogind.git] / src / test / test-util.c
index dbc7cfe39789aaecc888daa4e91e31329a848e75..9a28ef9eec4a2d73075ab50acf4fec523f31ca73 100644 (file)
@@ -129,6 +129,7 @@ static void test_parse_boolean(void) {
 
         assert_se(parse_boolean("garbage") < 0);
         assert_se(parse_boolean("") < 0);
+        assert_se(parse_boolean("full") < 0);
 }
 
 static void test_parse_pid(void) {
@@ -297,14 +298,16 @@ static void test_undecchar(void) {
 
 static void test_cescape(void) {
         _cleanup_free_ char *escaped;
-        escaped = cescape("abc\\\"\b\f\n\r\t\v\a\003\177\234\313");
+
+        assert_se(escaped = cescape("abc\\\"\b\f\n\r\t\v\a\003\177\234\313"));
         assert_se(streq(escaped, "abc\\\\\\\"\\b\\f\\n\\r\\t\\v\\a\\003\\177\\234\\313"));
 }
 
 static void test_cunescape(void) {
         _cleanup_free_ char *unescaped;
-        unescaped = cunescape("abc\\\\\\\"\\b\\f\\a\\n\\r\\t\\v\\003\\177\\234\\313");
-        assert_se(streq(unescaped, "abc\\\"\b\f\a\n\r\t\v\003\177\234\313"));
+
+        assert_se(unescaped = cunescape("abc\\\\\\\"\\b\\f\\a\\n\\r\\t\\v\\003\\177\\234\\313\\000\\x00"));
+        assert_se(streq(unescaped, "abc\\\"\b\f\a\n\r\t\v\003\177\234\313\\000\\x00"));
 }
 
 static void test_foreach_word(void) {
@@ -729,6 +732,20 @@ static void test_filename_is_safe(void) {
         assert_se(filename_is_safe("o.o"));
 }
 
+static void test_string_has_cc(void) {
+        assert_se(string_has_cc("abc\1", NULL));
+        assert_se(string_has_cc("abc\x7f", NULL));
+        assert_se(string_has_cc("abc\x7f", NULL));
+        assert_se(string_has_cc("abc\t\x7f", "\t"));
+        assert_se(string_has_cc("abc\t\x7f", "\t"));
+        assert_se(string_has_cc("\x7f", "\t"));
+        assert_se(string_has_cc("\x7f", "\t\a"));
+
+        assert_se(!string_has_cc("abc\t\t", "\t"));
+        assert_se(!string_has_cc("abc\t\t\a", "\t\a"));
+        assert_se(!string_has_cc("a\ab\tc", "\t\a"));
+}
+
 static void test_ascii_strlower(void) {
         char a[] = "AabBcC Jk Ii Od LKJJJ kkd LK";
         assert_se(streq(ascii_strlower(a), "aabbcc jk ii od lkjjj kkd lk"));
@@ -935,6 +952,7 @@ int main(int argc, char *argv[]) {
         test_log2i();
         test_foreach_string();
         test_filename_is_safe();
+        test_string_has_cc();
         test_ascii_strlower();
         test_files_same();
         test_is_valid_documentation_url();