summaryrefslogtreecommitdiff
path: root/src/tests/ecore/efl_app_test_env.c
blob: 63bad166a2b02e10788ee25f079609b797be20fb (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#include <stdio.h>
#include <unistd.h>
#define EFL_NOLEGACY_API_SUPPORT
#include <Efl_Core.h>
#include "efl_app_suite.h"
#include "../efl_check.h"

EFL_START_TEST(efl_core_env_test_set_get)
{
   Efl_Core_Env *env = efl_add_ref(EFL_CORE_ENV_CLASS, NULL);

   efl_core_env_set(env, "FOO", "bar");
   efl_core_env_set(env, "going", "home");
   efl_core_env_set(env, "Merry", "christmas");

   ck_assert_str_eq(efl_core_env_get(env, "FOO"), "bar");
   ck_assert_str_eq(efl_core_env_get(env, "going"), "home");
   ck_assert_str_eq(efl_core_env_get(env, "Merry"), "christmas");

   efl_core_env_unset(env, "Merry");

   ck_assert_str_eq(efl_core_env_get(env, "FOO"), "bar");
   ck_assert_str_eq(efl_core_env_get(env, "going"), "home");
   ck_assert_ptr_eq(efl_core_env_get(env, "Merry"), NULL);

   efl_unref(env);
}
EFL_END_TEST

EFL_START_TEST(efl_core_env_test_invalid_keys)
{
   Efl_Core_Env *env = efl_add_ref(EFL_CORE_ENV_CLASS, NULL);

#define CHECK(val) \
   efl_core_env_set(env, val, "TEST"); \
   ck_assert_ptr_eq(efl_core_env_get(env, val), NULL);

   CHECK("0foo");
   CHECK("foo bar");
   CHECK("foo!bar");

#undef CHECK


#define CHECK(val) \
   efl_core_env_set(env, val, "TEST"); \
   ck_assert_str_eq(efl_core_env_get(env, val), "TEST");

   CHECK("foo0");
   CHECK("foo_bar");

#undef CHECK

}
EFL_END_TEST

EFL_START_TEST(efl_core_env_test_clear)
{
   Efl_Core_Env *env = efl_add_ref(EFL_CORE_ENV_CLASS, NULL);

   efl_core_env_set(env, "FOO", "bar");
   efl_core_env_set(env, "going", "home");
   efl_core_env_set(env, "Merry", "christmas");

   efl_core_env_clear(env);

   ck_assert_ptr_eq(efl_core_env_get(env, "FOO"), NULL);
   ck_assert_ptr_eq(efl_core_env_get(env, "going"), NULL);
   ck_assert_ptr_eq(efl_core_env_get(env, "Merry"), NULL);

   efl_unref(env);
}
EFL_END_TEST

EFL_START_TEST(efl_core_env_test_fork)
{
   Efl_Core_Env *env_fork, *env = efl_add_ref(EFL_CORE_ENV_CLASS, NULL);

   efl_core_env_set(env, "FOO", "bar");
   efl_core_env_set(env, "going", "home");
   efl_core_env_set(env, "Merry", "christmas");

   env_fork = efl_duplicate(env);

   ck_assert_str_eq(efl_core_env_get(env_fork, "FOO"), "bar");
   ck_assert_str_eq(efl_core_env_get(env_fork, "going"), "home");
   ck_assert_str_eq(efl_core_env_get(env_fork, "Merry"), "christmas");

   efl_unref(env);
}
EFL_END_TEST

EFL_START_TEST(efl_core_env_test_process)
{
   Efl_Core_Env *env_fork, *env = efl_env_self(EFL_CORE_PROC_ENV_CLASS);

   ck_assert(env);

   ck_assert_str_eq(efl_core_env_get(env, "PATH"), getenv("PATH"));
   env_fork = efl_duplicate(env);
   ck_assert_str_eq(efl_core_env_get(env_fork, "PATH"), getenv("PATH"));

   efl_unref(env);
}
EFL_END_TEST

EFL_START_TEST(efl_core_env_test_undepend_fork)
{
   Efl_Core_Env *env_fork, *env = efl_env_self(EFL_CORE_PROC_ENV_CLASS);

   ck_assert(env);

   ck_assert_str_eq(efl_core_env_get(env, "PATH"), getenv("PATH"));
   env_fork = efl_duplicate(env);
   efl_core_env_set(env_fork, "PATH", "abc");
   ck_assert_str_eq(efl_core_env_get(env, "PATH"), getenv("PATH"));

   efl_unref(env);
   efl_unref(env_fork);
}
EFL_END_TEST

void efl_test_efl_env(TCase *tc)
{
   tcase_add_test(tc, efl_core_env_test_set_get);
   tcase_add_test(tc, efl_core_env_test_invalid_keys);
   tcase_add_test(tc, efl_core_env_test_clear);
   tcase_add_test(tc, efl_core_env_test_fork);
   tcase_add_test(tc, efl_core_env_test_process);
   tcase_add_test(tc, efl_core_env_test_undepend_fork);
}