#include "test_cpath.h" #include "cpath.h" #include "tester.h" #include #include #include TestFuncResult test_cpath_join_path(void) { char expected[4096] = {0}; char out[4096] = {0}; char tmp[1024] = {0}; sprintf(expected, "%chome%cabdelrahman%cDocuments", PATH_SEP, PATH_SEP, PATH_SEP); sprintf(tmp, "%c", PATH_SEP); wapp_cpath_join_path(out, tmp, "home", "abdelrahman", "Documents"); bool result = strcmp(out, expected) == 0; if (!result) { goto TEST_JOIN_PATH_EXIT; } memset(out, 0, strlen(out)); sprintf(expected, "home%cabdelrahman%cDocuments", PATH_SEP, PATH_SEP); wapp_cpath_join_path(out, "home", "abdelrahman", "Documents"); result = result && strcmp(out, expected) == 0; if (!result) { goto TEST_JOIN_PATH_EXIT; } memset(out, 0, strlen(out)); memset(tmp, 0, strlen(tmp)); sprintf(expected, "%chome%cabdelrahman%cDocuments", PATH_SEP, PATH_SEP, PATH_SEP); sprintf(tmp, "%chome", PATH_SEP); wapp_cpath_join_path(out, tmp, "abdelrahman", "Documents"); result = result && strcmp(out, expected) == 0; if (!result) { goto TEST_JOIN_PATH_EXIT; } memset(out, 0, strlen(out)); memset(tmp, 0, strlen(tmp)); sprintf(expected, "home%cabdelrahman%cDocuments", PATH_SEP, PATH_SEP); sprintf(tmp, "home%c", PATH_SEP); wapp_cpath_join_path(out, tmp, "abdelrahman", "Documents"); result = result && strcmp(out, expected) == 0; if (!result) { goto TEST_JOIN_PATH_EXIT; } memset(out, 0, strlen(out)); memset(tmp, 0, strlen(tmp)); sprintf(expected, "%chome", PATH_SEP); sprintf(tmp, "%chome", PATH_SEP); wapp_cpath_join_path(out, tmp, ""); result = result && strcmp(out, expected) == 0; if (!result) { goto TEST_JOIN_PATH_EXIT; } memset(out, 0, strlen(out)); sprintf(expected, ""); wapp_cpath_join_path(out, "", ""); result = result && strcmp(out, expected) == 0; if (!result) { goto TEST_JOIN_PATH_EXIT; } memset(out, 0, strlen(out)); sprintf(expected, "home"); wapp_cpath_join_path(out, "", "home"); result = result && strcmp(out, expected) == 0; TEST_JOIN_PATH_EXIT: return wapp_tester_result(result); } TestFuncResult test_cpath_dirname(void) { char dst[4096] = {0}; char expected[4096] = {0}; char tmp[1024] = {0}; sprintf(tmp, "%c", PATH_SEP); wapp_cpath_dirname(dst, tmp); bool result = strcmp(dst, tmp) == 0; if (!result) { goto TEST_DIRNAME_EXIT; } memset(dst, 0, strlen(dst)); wapp_cpath_dirname(dst, "home"); result = strcmp(dst, ".") == 0; if (!result) { goto TEST_DIRNAME_EXIT; } memset(dst, 0, strlen(dst)); wapp_cpath_dirname(dst, ""); result = strcmp(dst, ".") == 0; if (!result) { goto TEST_DIRNAME_EXIT; } memset(dst, 0, strlen(dst)); sprintf(tmp, "%chome%ctest", PATH_SEP, PATH_SEP); sprintf(expected, "%chome", PATH_SEP); wapp_cpath_dirname(dst, tmp); result = strcmp(dst, expected) == 0; if (!result) { goto TEST_DIRNAME_EXIT; } memset(dst, 0, strlen(dst)); memset(tmp, 0, strlen(tmp)); memset(expected, 0, strlen(expected)); sprintf(tmp, "%chome%ctest%c", PATH_SEP, PATH_SEP, PATH_SEP); sprintf(expected, "%chome", PATH_SEP); wapp_cpath_dirname(dst, tmp); result = strcmp(dst, expected) == 0; TEST_DIRNAME_EXIT: return wapp_tester_result(result); } TestFuncResult test_cpath_dirup(void) { char dst[4096] = {0}; char expected[4096] = {0}; char tmp[1024] = {0}; sprintf(tmp, "%c", PATH_SEP); wapp_cpath_dirup(dst, 3, tmp); bool result = strcmp(dst, tmp) == 0; if (!result) { goto TEST_DIRUP_EXIT; } memset(dst, 0, strlen(dst)); memset(tmp, 0, strlen(tmp)); sprintf(tmp, "%chome%cabdelrahman%cDocuments", PATH_SEP, PATH_SEP, PATH_SEP); sprintf(expected, "%c", PATH_SEP); wapp_cpath_dirup(dst, 3, tmp); result = strcmp(dst, expected) == 0; if (!result) { goto TEST_DIRUP_EXIT; } memset(dst, 0, strlen(dst)); memset(tmp, 0, strlen(tmp)); sprintf(tmp, "home%cabdelrahman%cDocuments", PATH_SEP, PATH_SEP); wapp_cpath_dirup(dst, 3, tmp); result = strcmp(dst, ".") == 0; if (!result) { goto TEST_DIRUP_EXIT; } memset(dst, 0, strlen(dst)); memset(tmp, 0, strlen(tmp)); memset(expected, 0, strlen(expected)); sprintf(tmp, "%chome%cabdelrahman%cDocuments", PATH_SEP, PATH_SEP, PATH_SEP); sprintf(expected, "%chome", PATH_SEP); wapp_cpath_dirup(dst, 2, tmp); result = strcmp(dst, expected) == 0; if (!result) { goto TEST_DIRUP_EXIT; } memset(dst, 0, strlen(dst)); memset(tmp, 0, strlen(tmp)); sprintf(tmp, "home%cabdelrahman%cDocuments", PATH_SEP, PATH_SEP); wapp_cpath_dirup(dst, 2, tmp); result = strcmp(dst, "home") == 0; TEST_DIRUP_EXIT: return wapp_tester_result(result); }