# HG changeset patch # User Matti Hamalainen # Date 1670974711 -7200 # Node ID e2873f764b63b02a50002de5ee45ac8675f17d8a # Parent 64af66cae5419be2e801ce6c67ffd416d4e851e4 Add few simplistic tests of th_file module functions. diff -r 64af66cae541 -r e2873f764b63 tests.c --- 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()