aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests/eina/eina_test_vpath.c
blob: cad61bd831480784670291a46d1036bb9e20dc83 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#include <Eina.h>
#include <check.h>
#include "eina_suite.h"
#include <pwd.h>

EFL_START_TEST(eina_test_vpath_valid)
{
   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);
   ck_assert_str_eq(eina_vpath_resolve("${home}/bla"), test);
   ck_assert_str_eq(eina_vpath_resolve("/test/for/the/last/case"), "/test/for/the/last/case");
}
EFL_END_TEST

EFL_START_TEST(eina_test_vpath_invalid)
{
   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("${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);
}
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);

   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);
}
EFL_END_TEST

void eina_test_vpath(TCase *tc)
{
   tcase_add_test(tc, eina_test_vpath_invalid);
   tcase_add_test(tc, eina_test_vpath_valid);
   tcase_add_test(tc, eina_test_vpath_snprintf);
}