2018-02-18 13:12:58 -08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <Eina.h>
|
|
|
|
#include <check.h>
|
2018-03-26 11:19:28 -07:00
|
|
|
#include "eina_suite.h"
|
2018-08-20 09:56:51 -07:00
|
|
|
#include <pwd.h>
|
2018-02-18 13:12:58 -08:00
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(eina_test_vpath_valid)
|
2018-02-18 13:12:58 -08:00
|
|
|
{
|
|
|
|
char test[PATH_MAX];
|
|
|
|
|
|
|
|
ck_assert_str_eq(eina_vpath_resolve("/"), "/");
|
|
|
|
ck_assert_str_eq(eina_vpath_resolve("./"), "./");
|
|
|
|
ck_assert_str_eq(eina_vpath_resolve("..bla"), "..bla");
|
|
|
|
ck_assert_str_eq(eina_vpath_resolve(".bla"), ".bla");
|
|
|
|
|
|
|
|
snprintf(test, sizeof(test), "%s/", eina_environment_home_get());
|
|
|
|
ck_assert_str_eq(eina_vpath_resolve("~/"), test);
|
|
|
|
|
|
|
|
snprintf(test, sizeof(test), "%s/bla", eina_environment_home_get());
|
|
|
|
ck_assert_str_eq(eina_vpath_resolve("(:home:)/bla"), test);
|
2019-05-10 14:42:57 -07:00
|
|
|
ck_assert_str_eq(eina_vpath_resolve("${home}/bla"), test);
|
2018-08-20 09:56:51 -07:00
|
|
|
ck_assert_str_eq(eina_vpath_resolve("/test/for/the/last/case"), "/test/for/the/last/case");
|
2018-02-18 13:12:58 -08:00
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
2018-02-18 13:12:58 -08:00
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(eina_test_vpath_invalid)
|
2018-02-18 13:12:58 -08:00
|
|
|
{
|
2018-02-22 15:37:11 -08:00
|
|
|
ck_assert_ptr_eq(eina_vpath_resolve("(:asdfasdfafasdf"), NULL);
|
|
|
|
ck_assert_ptr_eq(eina_vpath_resolve("(:missing_slash:)"), NULL);
|
|
|
|
ck_assert_ptr_eq(eina_vpath_resolve("(:"), NULL);
|
|
|
|
ck_assert_ptr_eq(eina_vpath_resolve("(:home:)"), NULL);
|
|
|
|
ck_assert_ptr_eq(eina_vpath_resolve("(:wrong_meta_key:)/"), NULL);
|
2019-05-10 14:42:57 -07:00
|
|
|
ck_assert_ptr_eq(eina_vpath_resolve("${asdfasdfafasdf"), NULL);
|
|
|
|
ck_assert_ptr_eq(eina_vpath_resolve("${missing_slash}"), NULL);
|
|
|
|
ck_assert_ptr_eq(eina_vpath_resolve("${"), NULL);
|
|
|
|
ck_assert_ptr_eq(eina_vpath_resolve("${home}"), NULL);
|
|
|
|
ck_assert_ptr_eq(eina_vpath_resolve("${wrong_meta_key}/"), NULL);
|
|
|
|
ck_assert_ptr_eq(eina_vpath_resolve("${home:)"), NULL);
|
|
|
|
ck_assert_ptr_eq(eina_vpath_resolve("${wrong_meta_key:)/"), NULL);
|
2018-08-20 09:56:51 -07:00
|
|
|
}
|
|
|
|
EFL_END_TEST
|
|
|
|
|
|
|
|
|
|
|
|
EFL_START_TEST(eina_test_vpath_snprintf)
|
|
|
|
{
|
|
|
|
char *string = "blablabla";
|
|
|
|
int x = 1337;
|
|
|
|
char buf[PATH_MAX];
|
|
|
|
char cmp[PATH_MAX];
|
|
|
|
|
|
|
|
eina_vpath_resolve_snprintf(buf, sizeof(buf), "(:home:)/%s/%d/", string, x);
|
|
|
|
snprintf(cmp, sizeof(cmp), "%s/%s/%d/", eina_environment_home_get(), string, x);
|
|
|
|
ck_assert_str_eq(buf, cmp);
|
2019-05-10 14:42:57 -07:00
|
|
|
|
|
|
|
eina_vpath_resolve_snprintf(buf, sizeof(buf), "${home}/%s/%d/", string, x);
|
|
|
|
snprintf(cmp, sizeof(cmp), "%s/%s/%d/", eina_environment_home_get(), string, x);
|
|
|
|
ck_assert_str_eq(buf, cmp);
|
2018-08-20 09:56:51 -07:00
|
|
|
}
|
|
|
|
EFL_END_TEST
|
|
|
|
|
2018-02-18 13:12:58 -08:00
|
|
|
void eina_test_vpath(TCase *tc)
|
|
|
|
{
|
|
|
|
tcase_add_test(tc, eina_test_vpath_invalid);
|
|
|
|
tcase_add_test(tc, eina_test_vpath_valid);
|
2018-08-20 09:56:51 -07:00
|
|
|
tcase_add_test(tc, eina_test_vpath_snprintf);
|
2018-02-18 13:12:58 -08:00
|
|
|
}
|