changeset 743:e2873f764b63

Add few simplistic tests of th_file module functions.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 14 Dec 2022 01:38:31 +0200
parents 64af66cae541
children 4181d43f91f9
files tests.c
diffstat 1 files changed, 28 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/tests.c	Wed Dec 14 01:38:08 2022 +0200
+++ b/tests.c	Wed Dec 14 01:38:31 2022 +0200
@@ -5,6 +5,7 @@
 #include "th_crypto.h"
 #include "th_ioctx.h"
 #include "th_config.h"
+#include "th_file.h"
 #include "th_regex.h"
 
 
@@ -794,6 +795,33 @@
 
     tprint(1, "Enabled test types are 0x%04x.\n", optFlags);
 
+    //
+    // File functions
+    //
+    if (test_set_start("file functions"))
+    {
+        char *home = th_get_home_dir(), *cfg = th_get_config_dir();
+        th_stat_data stat;
+        int res;
+
+        TEST1A("%s", home, !=, NULL);
+        TEST1A("%s", cfg, !=, NULL);
+
+        TEST1(th_stat_path(home, &stat) == true);
+        TEST1A("%d", (stat.flags & TH_IS_DIR), !=, 0);
+
+        TEST1(th_stat_path("/nonexist", &stat) == false);
+        TEST1(th_stat_path("/root", &stat) == true);
+        TEST1A("%d", (stat.flags & TH_IS_WRITABLE), ==, 0);
+
+        TEST1((res = th_mkdir_path("/tmp/thlibtest/foobar/baz", 0)) == THERR_OK);
+        TEST1A("%d", res, ==, THERR_OK);
+        if (res == THERR_OK)
+        {
+            TEST1(th_stat_path("/tmp/thlibtest/foobar/baz", &stat) == true);
+            TEST1A("%d", (stat.flags & TH_IS_DIR), !=, 0);
+        }
+    }
 
     //
     // Test series for printf()