diff options
Diffstat (limited to 'libraries/eina/src/tests/eina_test_log.c')
-rw-r--r-- | libraries/eina/src/tests/eina_test_log.c | 235 |
1 files changed, 235 insertions, 0 deletions
diff --git a/libraries/eina/src/tests/eina_test_log.c b/libraries/eina/src/tests/eina_test_log.c new file mode 100644 index 0000000..ba17d5f --- /dev/null +++ b/libraries/eina/src/tests/eina_test_log.c | |||
@@ -0,0 +1,235 @@ | |||
1 | /* EINA - EFL data type library | ||
2 | * Copyright (C) 2008 Cedric Bail | ||
3 | * | ||
4 | * This library is free software; you can redistribute it and/or | ||
5 | * modify it under the terms of the GNU Lesser General Public | ||
6 | * License as published by the Free Software Foundation; either | ||
7 | * version 2.1 of the License, or (at your option) any later version. | ||
8 | * | ||
9 | * This library is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | * Lesser General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU Lesser General Public | ||
15 | * License along with this library; | ||
16 | * if not, see <http://www.gnu.org/licenses/>. | ||
17 | */ | ||
18 | |||
19 | #ifdef HAVE_CONFIG_H | ||
20 | # include "config.h" | ||
21 | #endif | ||
22 | |||
23 | #include <stdlib.h> | ||
24 | #include <stdio.h> | ||
25 | #include <string.h> | ||
26 | |||
27 | #include "eina_suite.h" | ||
28 | #include "Eina.h" | ||
29 | |||
30 | START_TEST(eina_log_macro) | ||
31 | { | ||
32 | fail_if(!eina_init()); | ||
33 | |||
34 | eina_log_level_set(EINA_LOG_LEVEL_DBG); | ||
35 | eina_log_print_cb_set(eina_log_print_cb_file, stderr); | ||
36 | |||
37 | EINA_LOG_CRIT("Critical message\n"); | ||
38 | EINA_LOG_ERR("An error\n"); | ||
39 | EINA_LOG_INFO("An info\n"); | ||
40 | EINA_LOG_WARN("A warning\n"); | ||
41 | EINA_LOG_DBG("A debug\n"); | ||
42 | |||
43 | eina_shutdown(); | ||
44 | } | ||
45 | END_TEST | ||
46 | |||
47 | START_TEST(eina_log_domains_macros) | ||
48 | { | ||
49 | fail_if(!eina_init()); | ||
50 | |||
51 | int d = eina_log_domain_register("MyDomain", EINA_COLOR_GREEN); | ||
52 | fail_if(d < 0); | ||
53 | |||
54 | EINA_LOG_DOM_CRIT(d, "A critical message\n"); | ||
55 | EINA_LOG_DOM_ERR(d, "An error\n"); | ||
56 | EINA_LOG_DOM_WARN(d, "A warning\n"); | ||
57 | EINA_LOG_DOM_DBG(d, "A debug\n"); | ||
58 | EINA_LOG_DOM_INFO(d, "An info\n"); | ||
59 | |||
60 | eina_shutdown(); | ||
61 | } | ||
62 | END_TEST | ||
63 | |||
64 | START_TEST(eina_log_domains_registry) | ||
65 | { | ||
66 | fail_if(!eina_init()); | ||
67 | |||
68 | int i; | ||
69 | int d[50]; | ||
70 | |||
71 | for (i = 0; i < 50; i++) | ||
72 | { | ||
73 | d[i] = eina_log_domain_register("Test", EINA_COLOR_GREEN); | ||
74 | fail_if(d[i] < 0); | ||
75 | } | ||
76 | |||
77 | for (i = 0; i < 50; i++) | ||
78 | eina_log_domain_unregister(d[i]); | ||
79 | |||
80 | eina_shutdown(); | ||
81 | } | ||
82 | END_TEST | ||
83 | |||
84 | START_TEST(eina_log_domains_slot_reuse) | ||
85 | { | ||
86 | fail_if(!eina_init()); | ||
87 | fail_if(!eina_threads_init()); | ||
88 | |||
89 | // Create 9 domains | ||
90 | int idx[9]; | ||
91 | int i; | ||
92 | |||
93 | for (i = 0; i < 9; i++) | ||
94 | { | ||
95 | idx[i] = eina_log_domain_register("Test1", EINA_COLOR_GREEN); | ||
96 | fail_if(idx[i] < 0); | ||
97 | } | ||
98 | |||
99 | // Slot 0 by default contains the global logger. The above code created | ||
100 | // domains for slots indexes from 1 to 9. | ||
101 | // | ||
102 | // The global logger allocated the first 8 initial slots. The 8th domain | ||
103 | // registered on the for loop will create 8 more slots. | ||
104 | // | ||
105 | // Test will just unregister a domain between 1 and 9 and assure that a new | ||
106 | // domain register will be placed on the available slot and not at the end. | ||
107 | |||
108 | int removed = idx[5]; | ||
109 | eina_log_domain_unregister(removed); | ||
110 | |||
111 | int new = eina_log_domain_register("Test Slot", EINA_COLOR_GREEN); | ||
112 | |||
113 | // Check for slot reuse | ||
114 | fail_if(new != removed); | ||
115 | |||
116 | eina_threads_shutdown(); | ||
117 | eina_shutdown(); | ||
118 | } | ||
119 | END_TEST | ||
120 | |||
121 | START_TEST(eina_log_level_indexes) | ||
122 | { | ||
123 | fail_if(!eina_init()); | ||
124 | fail_if(!eina_threads_init()); | ||
125 | fail_if(!eina_threads_init()); | ||
126 | |||
127 | int d = eina_log_domain_register("Levels", EINA_COLOR_GREEN); | ||
128 | fail_if(d < 0); | ||
129 | |||
130 | // Displayed unless user sets level lower than -1 | ||
131 | EINA_LOG(d, -1, "Negative index message\n"); | ||
132 | |||
133 | // Displayed only if user sets level 6 or higher | ||
134 | EINA_LOG(d, 6, "Higher level debug\n"); | ||
135 | |||
136 | eina_threads_shutdown(); | ||
137 | eina_threads_shutdown(); | ||
138 | eina_shutdown(); | ||
139 | } | ||
140 | END_TEST | ||
141 | |||
142 | START_TEST(eina_log_customize) | ||
143 | { | ||
144 | int d; | ||
145 | |||
146 | /* please don't define EINA_LOG_LEVELS for it */ | ||
147 | #define TEST_DOM "_Test_Log_Dom" | ||
148 | |||
149 | fail_if(!eina_init()); | ||
150 | |||
151 | #define test_set_get(func, val) \ | ||
152 | eina_log_ ## func ## _set(val); \ | ||
153 | fail_if(eina_log_ ## func ## _get() != val) | ||
154 | |||
155 | test_set_get(level, -1234); | ||
156 | test_set_get(level, 4567); | ||
157 | |||
158 | #define test_set_get_bool(func) \ | ||
159 | test_set_get(func, EINA_FALSE); \ | ||
160 | test_set_get(func, EINA_TRUE) | ||
161 | |||
162 | test_set_get_bool(color_disable); | ||
163 | test_set_get_bool(file_disable); | ||
164 | test_set_get_bool(function_disable); | ||
165 | test_set_get_bool(abort_on_critical); | ||
166 | |||
167 | test_set_get(abort_on_critical_level, -1234); | ||
168 | test_set_get(abort_on_critical_level, 4567); | ||
169 | |||
170 | fail_if(eina_log_domain_level_get(TEST_DOM) != eina_log_level_get()); | ||
171 | |||
172 | eina_log_domain_level_set(TEST_DOM, -123); | ||
173 | fail_if(eina_log_domain_level_get(TEST_DOM) != -123); | ||
174 | |||
175 | eina_log_domain_level_set(TEST_DOM, 890); | ||
176 | fail_if(eina_log_domain_level_get(TEST_DOM) != 890); | ||
177 | |||
178 | d = eina_log_domain_register(TEST_DOM, EINA_COLOR_GREEN); | ||
179 | fail_if(d < 0); | ||
180 | |||
181 | fail_if(eina_log_domain_level_get(TEST_DOM) != 890); | ||
182 | fail_if(eina_log_domain_registered_level_get(d) != 890); | ||
183 | |||
184 | eina_log_domain_unregister(d); | ||
185 | fputs("NOTE: You should see a failed safety check or " | ||
186 | "a crash if compiled without safety checks support.\n", | ||
187 | stderr); | ||
188 | eina_log_abort_on_critical_set(EINA_FALSE); | ||
189 | fail_if(eina_log_domain_registered_level_get(d) != EINA_LOG_LEVEL_UNKNOWN); | ||
190 | |||
191 | #undef test_set_get_bool | ||
192 | #undef test_set_get | ||
193 | |||
194 | eina_shutdown(); | ||
195 | } | ||
196 | END_TEST | ||
197 | |||
198 | START_TEST(eina_log_level_name) | ||
199 | { | ||
200 | char name[4]; | ||
201 | |||
202 | fail_if(!eina_init()); | ||
203 | |||
204 | #define tst(level, str) \ | ||
205 | eina_log_level_name_get(level, name); \ | ||
206 | fail_if(strcmp(name, str) != 0) | ||
207 | |||
208 | tst(0, "CRI"); | ||
209 | tst(1, "ERR"); | ||
210 | tst(2, "WRN"); | ||
211 | tst(3, "INF"); | ||
212 | tst(4, "DBG"); | ||
213 | tst(5, "005"); | ||
214 | tst(12, "012"); | ||
215 | tst(369, "369"); | ||
216 | tst(-1, "-01"); | ||
217 | tst(-48, "-48"); | ||
218 | |||
219 | #undef tst | ||
220 | |||
221 | eina_shutdown(); | ||
222 | } | ||
223 | END_TEST | ||
224 | |||
225 | void | ||
226 | eina_test_log(TCase *tc) | ||
227 | { | ||
228 | tcase_add_test(tc, eina_log_macro); | ||
229 | tcase_add_test(tc, eina_log_domains_macros); | ||
230 | tcase_add_test(tc, eina_log_domains_registry); | ||
231 | tcase_add_test(tc, eina_log_domains_slot_reuse); | ||
232 | tcase_add_test(tc, eina_log_level_indexes); | ||
233 | tcase_add_test(tc, eina_log_customize); | ||
234 | tcase_add_test(tc, eina_log_level_name); | ||
235 | } | ||