From 2638802ccd0d0776ebf1867181d4e3950a147074 Mon Sep 17 00:00:00 2001 From: gramanas Date: Sat, 10 Nov 2018 22:47:03 +0200 Subject: Home dir --- unit/ck-test.c | 52 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 15 deletions(-) (limited to 'unit/ck-test.c') diff --git a/unit/ck-test.c b/unit/ck-test.c index 1264431..8d8ee08 100644 --- a/unit/ck-test.c +++ b/unit/ck-test.c @@ -3,38 +3,60 @@ #include #include "cklist.h" +#include "ckutil.h" /* total number of unit tests */ #define TOTAL 2 -#define CK_UNIT_TESTS \ - X(ck_list_init, "Basic cklist test") \ - X(ck_list_exists, "Test list exists function") +#define CK_UNIT_TESTS \ + X(ck_list_test, "Basic cklist test") \ + X(ck_str_utils_test, "Test string utility functions") \ -void ck_list_init() { - cklist *ckl1 = list_make_new(); +void ck_list_test() { + /* init and add */ + cklist *ckl = list_make_new(); cklist *ckl2 = list_make_and_add("first"); list_add(ckl2, "second"); - list_add(ckl1, "first"); - list_add(ckl1, "second"); - assert(strcmp(list_get_at(ckl1, 0), + list_add(ckl, "first"); + list_add(ckl, "second"); + assert(strcmp(list_get_at(ckl, 0), list_get_at(ckl2, 0)) == 0); - assert(strcmp(list_get_at(ckl1, 1), + assert(strcmp(list_get_at(ckl, 1), list_get_at(ckl2, 1)) == 0); - list_free(ckl1); list_free(ckl2); -} -void ck_list_exists() { - cklist *ckl = list_make_new(); - list_add(ckl, "first"); - list_add(ckl, "second"); + /* exists */ assert(list_exists(ckl, "first")); assert(list_exists(ckl, "second")); assert(!list_exists(ckl, "thrid")); list_free(ckl); } +void ck_str_utils_test() { + /* make_ck_config_name */ + char ck_conf_path[STR_M]; + str_make_ck_config_name(ck_conf_path, "/test/path/.config", "emacs"); + assert(strcmp(ck_conf_path, "emacs/.config") == 0); + + /* str_is_empty */ + assert(str_is_empty("")); + assert(str_is_empty(" ")); + assert(str_is_empty("\t")); + + /* swap ~ and home */ + char str[STR_M] = ""; + char str2[STR_M] = ""; + /* getenv("HOME") -> /home/user */ + char home[STR_S] = "/home/user"; + char testpath[STR_S] = "/home/user/file"; + assert(swap_home_with_tilde(str, testpath, home) == 0); + assert(strcmp(str, "~/file") == 0); + assert(swap_tilde_with_home(str2, str, home) == 0); + assert(strcmp(str2, testpath) == 0); + assert(swap_home_with_tilde(str, "/not/starting/with/home", home)); + assert(swap_tilde_with_home(str2, "/not/starting/with/tilde", home)); +} + int main() { int count = 1; #define X(TEST, DESC) \ -- cgit v1.2.3