83 lines
2.2 KiB
C
83 lines
2.2 KiB
C
#ifndef MK_TEST_PATH_H
|
|
#define MK_TEST_PATH_H
|
|
|
|
#include <check.h>
|
|
#include <path.h>
|
|
|
|
START_TEST(path_check_local)
|
|
{
|
|
ck_assert(true == path_is_local("./hello/world"));
|
|
ck_assert(true == path_is_local("../hello/world"));
|
|
ck_assert(false == path_is_local(""));
|
|
ck_assert(false == path_is_local("hello/world"));
|
|
ck_assert(false == path_is_local("/hello/world"));
|
|
ck_assert(false == path_is_local("/../hello/world"));
|
|
}
|
|
END_TEST
|
|
|
|
START_TEST(test_path_get_mod_name)
|
|
{
|
|
size_t const SZ = MK_STRLEN;
|
|
char buffer[SZ];
|
|
|
|
path_get_mod_name("./hello/world", buffer, SZ);
|
|
ck_assert_str_eq("world", buffer);
|
|
|
|
path_get_mod_name("./hello/world/", buffer, SZ);
|
|
ck_assert_str_eq("world", buffer);
|
|
|
|
path_get_mod_name("./hello.ext", buffer, SZ);
|
|
ck_assert_str_eq("hello", buffer);
|
|
|
|
path_get_mod_name("./hello.ext/world.com", buffer, SZ);
|
|
ck_assert_str_eq("world", buffer);
|
|
|
|
path_get_mod_name("./hello.ext/world.com/", buffer, SZ);
|
|
ck_assert_str_eq("world", buffer);
|
|
}
|
|
END_TEST
|
|
|
|
START_TEST(test_path_apply_ext)
|
|
{
|
|
size_t const SZ = MK_STRLEN;
|
|
char buffer[SZ];
|
|
|
|
path_apply_ext("./hello/world", "abc", buffer, SZ);
|
|
ck_assert_str_eq("./hello/world.abc", buffer);
|
|
|
|
path_apply_ext("world.mk", "abc", buffer, SZ);
|
|
ck_assert_str_eq("world.abc", buffer);
|
|
|
|
path_apply_ext("./hello/world.xy", "xy", buffer, SZ);
|
|
ck_assert_str_eq("./hello/world.xy", buffer);
|
|
}
|
|
END_TEST
|
|
|
|
START_TEST(test_path_apply_prefix)
|
|
{
|
|
size_t const SZ = MK_STRLEN;
|
|
char buffer[SZ];
|
|
|
|
path_apply_prefix("./hello/world.so", "lib", buffer, SZ);
|
|
ck_assert_str_eq("./hello/libworld.so", buffer);
|
|
|
|
path_apply_prefix("./hello/libworld.so", "lib", buffer, SZ);
|
|
ck_assert_str_eq("./hello/libworld.so", buffer);
|
|
|
|
path_apply_prefix("./hello/alibworld.so", "lib", buffer, SZ);
|
|
ck_assert_str_eq("./hello/libalibworld.so", buffer);
|
|
}
|
|
END_TEST
|
|
|
|
void register_path(Suite* suite)
|
|
{
|
|
TCase* tcase = tcase_create("path");
|
|
suite_add_tcase(suite, tcase);
|
|
tcase_add_test(tcase, path_check_local);
|
|
tcase_add_test(tcase, test_path_get_mod_name);
|
|
tcase_add_test(tcase, test_path_apply_ext);
|
|
tcase_add_test(tcase, test_path_apply_prefix);
|
|
}
|
|
|
|
#endif
|