comparison tests.c @ 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 31bc1ed07cf5
children 0c90dd46c49f
comparison
equal deleted inserted replaced
742:64af66cae541 743:e2873f764b63
3 #include "th_util.h" 3 #include "th_util.h"
4 #include "th_string.h" 4 #include "th_string.h"
5 #include "th_crypto.h" 5 #include "th_crypto.h"
6 #include "th_ioctx.h" 6 #include "th_ioctx.h"
7 #include "th_config.h" 7 #include "th_config.h"
8 #include "th_file.h"
8 #include "th_regex.h" 9 #include "th_regex.h"
9 10
10 11
11 #define SET_BUF_SIZE 128 12 #define SET_BUF_SIZE 128
12 #define SET_BUF_SIZE_2 ((SET_BUF_SIZE) + 32) 13 #define SET_BUF_SIZE_2 ((SET_BUF_SIZE) + 32)
792 arg_handle_opt, NULL, 0)) 793 arg_handle_opt, NULL, 0))
793 return 0; 794 return 0;
794 795
795 tprint(1, "Enabled test types are 0x%04x.\n", optFlags); 796 tprint(1, "Enabled test types are 0x%04x.\n", optFlags);
796 797
798 //
799 // File functions
800 //
801 if (test_set_start("file functions"))
802 {
803 char *home = th_get_home_dir(), *cfg = th_get_config_dir();
804 th_stat_data stat;
805 int res;
806
807 TEST1A("%s", home, !=, NULL);
808 TEST1A("%s", cfg, !=, NULL);
809
810 TEST1(th_stat_path(home, &stat) == true);
811 TEST1A("%d", (stat.flags & TH_IS_DIR), !=, 0);
812
813 TEST1(th_stat_path("/nonexist", &stat) == false);
814 TEST1(th_stat_path("/root", &stat) == true);
815 TEST1A("%d", (stat.flags & TH_IS_WRITABLE), ==, 0);
816
817 TEST1((res = th_mkdir_path("/tmp/thlibtest/foobar/baz", 0)) == THERR_OK);
818 TEST1A("%d", res, ==, THERR_OK);
819 if (res == THERR_OK)
820 {
821 TEST1(th_stat_path("/tmp/thlibtest/foobar/baz", &stat) == true);
822 TEST1A("%d", (stat.flags & TH_IS_DIR), !=, 0);
823 }
824 }
797 825
798 // 826 //
799 // Test series for printf() 827 // Test series for printf()
800 // 828 //
801 char *i_fmts[] = { "", "05", "6", ".4", "1.1", "1.0", "8.5", "08.5", "3", "2.1", "3", "1", "18", "018", ".0", "0" }; 829 char *i_fmts[] = { "", "05", "6", ".4", "1.1", "1.0", "8.5", "08.5", "3", "2.1", "3", "1", "18", "018", ".0", "0" };