chiark / gitweb /
test: add and improve hashmap tests
[elogind.git] / src / test / test-fileio.c
index 92aa794a9513a094b7eee19e2763bf5963acc36e..7e7b4ac45d37660f40e69c1296266cb15a4600b8 100644 (file)
@@ -90,7 +90,7 @@ static void test_parse_env_file(void) {
         assert_se(streq_ptr(a[9], "ten="));
         assert_se(a[10] == NULL);
 
-        strv_env_clean_log(a, "test");
+        strv_env_clean_log(a, NULL, "test");
 
         k = 0;
         STRV_FOREACH(i, b) {
@@ -246,25 +246,25 @@ static void test_status_field(void) {
 
         r = get_status_field("/proc/meminfo", "MemTotal:", &p);
         if (r != -ENOENT) {
-                assert(r == 0);
+                assert_se(r == 0);
                 puts(p);
                 assert_se(safe_atollu(p, &total) == 0);
         }
 
         r = get_status_field("/proc/meminfo", "\nBuffers:", &s);
         if (r != -ENOENT) {
-                assert(r == 0);
+                assert_se(r == 0);
                 puts(s);
                 assert_se(safe_atollu(s, &buffers) == 0);
         }
 
-        if (p && t)
-                assert(buffers < total);
+        if (p)
+                assert_se(buffers < total);
 
         /* Seccomp should be a good test for field full of zeros. */
         r = get_status_field("/proc/meminfo", "\nSeccomp:", &z);
         if (r != -ENOENT) {
-                assert(r == 0);
+                assert_se(r == 0);
                 puts(z);
                 assert_se(safe_atollu(z, &buffers) == 0);
         }
@@ -283,10 +283,10 @@ static void test_capeff(void) {
                 if (r == -ENOENT || r == -EPERM)
                         return;
 
-                assert(r == 0);
-                assert(*capeff);
+                assert_se(r == 0);
+                assert_se(*capeff);
                 p = capeff[strspn(capeff, DIGITS "abcdefABCDEF")];
-                assert(!p || isspace(p));
+                assert_se(!p || isspace(p));
         }
 }
 
@@ -303,7 +303,7 @@ static void test_write_string_stream(void) {
         assert_se(f);
         assert_se(write_string_stream(f, "boohoo") < 0);
 
-        f = fdopen(fd, "r+");
+        f = freopen(fn, "r+", f);
         assert_se(f);
 
         assert_se(write_string_stream(f, "boohoo") == 0);
@@ -317,8 +317,8 @@ static void test_write_string_stream(void) {
 
 static void test_write_string_file(void) {
         char fn[] = "/tmp/test-write_string_file-XXXXXX";
-        int fd;
-        char buf[64] = {0};
+        char buf[64] = {};
+        _cleanup_close_ int fd;
 
         fd = mkostemp_safe(fn, O_RDWR);
         assert_se(fd >= 0);
@@ -334,8 +334,7 @@ static void test_write_string_file(void) {
 static void test_sendfile_full(void) {
         char in_fn[] = "/tmp/test-sendfile_full-XXXXXX";
         char out_fn[] = "/tmp/test-sendfile_full-XXXXXX";
-        _cleanup_close_ int in_fd = -1;
-        int out_fd;
+        _cleanup_close_ int in_fd, out_fd;
         char text[] = "boohoo\nfoo\n\tbar\n";
         char buf[64] = {0};