chiark / gitweb /
test-fileio: Remove dead check
[elogind.git] / src / test / test-util.c
index 80425ca61a3aa176ae7e7564147e756e0f02e732..1311184815e31d082fafe599acfec0a700feaf68 100644 (file)
@@ -131,6 +131,19 @@ static void test_container_of(void) {
                                v1) == &myval);
 }
 
+static void test_alloca(void) {
+        static const uint8_t zero[997] = { };
+        char *t;
+
+        t = alloca_align(17, 512);
+        assert_se(!((uintptr_t)t & 0xff));
+        memzero(t, 17);
+
+        t = alloca0_align(997, 1024);
+        assert_se(!((uintptr_t)t & 0x1ff));
+        assert_se(!memcmp(t, zero, 997));
+}
+
 static void test_first_word(void) {
         assert_se(first_word("Hello", ""));
         assert_se(first_word("Hello", "Hello"));
@@ -843,11 +856,27 @@ static void test_is_valid_documentation_url(void) {
 }
 
 static void test_file_in_same_dir(void) {
-        assert_se(streq(file_in_same_dir("/", "a"), "/a"));
-        assert_se(streq(file_in_same_dir("/", "/a"), "/a"));
-        assert_se(streq(file_in_same_dir("", "a"), "a"));
-        assert_se(streq(file_in_same_dir("a/", "a"), "a/a"));
-        assert_se(streq(file_in_same_dir("bar/foo", "bar"), "bar/bar"));
+        char *t;
+
+        t = file_in_same_dir("/", "a");
+        assert_se(streq(t, "/a"));
+        free(t);
+
+        t = file_in_same_dir("/", "/a");
+        assert_se(streq(t, "/a"));
+        free(t);
+
+        t = file_in_same_dir("", "a");
+        assert_se(streq(t, "a"));
+        free(t);
+
+        t = file_in_same_dir("a/", "a");
+        assert_se(streq(t, "a/a"));
+        free(t);
+
+        t = file_in_same_dir("bar/foo", "bar");
+        assert_se(streq(t, "bar/bar"));
+        free(t);
 }
 
 static void test_endswith(void) {
@@ -1239,11 +1268,13 @@ static void test_unquote_many_words(void) {
         assert_se(unquote_many_words(&p, &a, NULL) == 1);
         assert_se(p == original+7);
         assert_se(streq_ptr(a, "foobar"));
+        free(a);
 
         p = original = "     foobar    ";
         assert_se(unquote_many_words(&p, &a, NULL) == 1);
         assert_se(p == original+15);
         assert_se(streq_ptr(a, "foobar"));
+        free(a);
 }
 
 int main(int argc, char *argv[]) {
@@ -1254,6 +1285,7 @@ int main(int argc, char *argv[]) {
         test_align_power2();
         test_max();
         test_container_of();
+        test_alloca();
         test_first_word();
         test_close_many();
         test_parse_boolean();