aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/eina/src/tests/eina_test_log.c
diff options
context:
space:
mode:
authorDavid Walter Seikel2013-01-13 17:29:19 +1000
committerDavid Walter Seikel2013-01-13 17:29:19 +1000
commit07274513e984f0b5544586c74508ccd16e7dcafa (patch)
treeb32ff2a9136fbc1a4a6a0ed1e4d79cde0f5f16d9 /libraries/eina/src/tests/eina_test_log.c
parentAdded Irrlicht 1.8, but without all the Windows binaries. (diff)
downloadSledjHamr-07274513e984f0b5544586c74508ccd16e7dcafa.zip
SledjHamr-07274513e984f0b5544586c74508ccd16e7dcafa.tar.gz
SledjHamr-07274513e984f0b5544586c74508ccd16e7dcafa.tar.bz2
SledjHamr-07274513e984f0b5544586c74508ccd16e7dcafa.tar.xz
Remove EFL, since it's been released now.
Diffstat (limited to '')
-rw-r--r--libraries/eina/src/tests/eina_test_log.c424
1 files changed, 0 insertions, 424 deletions
diff --git a/libraries/eina/src/tests/eina_test_log.c b/libraries/eina/src/tests/eina_test_log.c
deleted file mode 100644
index e0f0363..0000000
--- a/libraries/eina/src/tests/eina_test_log.c
+++ /dev/null
@@ -1,424 +0,0 @@
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
30struct log_ctx {
31 int level;
32 int line;
33 const char *msg;
34 const char *fnc;
35 const char *dom;
36 Eina_Bool did;
37};
38
39/* tests should not output on success, just uncomment this for debugging */
40//#define SHOW_LOG 1
41
42static void
43_eina_test_log(const Eina_Log_Domain *d, Eina_Log_Level level, const char *file, const char *fnc, int line, const char *fmt, void *data, va_list args __UNUSED__)
44{
45 struct log_ctx *ctx = data;
46 ck_assert_int_eq(ctx->level, level);
47 ck_assert_int_eq(ctx->line, line);
48 ck_assert_str_eq(ctx->msg, fmt);
49 ck_assert_str_eq(ctx->fnc, fnc);
50 ck_assert_str_eq(file, __FILE__);
51 ctx->did = EINA_TRUE;
52#ifdef SHOW_LOG
53 eina_log_print_cb_stderr(d, level, file, fnc, line, fmt, NULL, args);
54#else
55 (void)d;
56#endif
57}
58
59static void
60_eina_test_log_domain(const Eina_Log_Domain *d, Eina_Log_Level level, const char *file, const char *fnc, int line, const char *fmt, void *data, va_list args __UNUSED__)
61{
62 struct log_ctx *ctx = data;
63 ck_assert_int_eq(ctx->level, level);
64 ck_assert_int_eq(ctx->line, line);
65 ck_assert_str_eq(ctx->msg, fmt);
66 ck_assert_str_eq(ctx->fnc, fnc);
67 ck_assert_str_eq(file, __FILE__);
68 ck_assert_str_eq(ctx->dom, d->name);
69 ctx->did = EINA_TRUE;
70#ifdef SHOW_LOG
71 eina_log_print_cb_stderr(d, level, file, fnc, line, fmt, NULL, args);
72#endif
73}
74
75static void
76_eina_test_log_safety(const Eina_Log_Domain *d, Eina_Log_Level level, const char *file, const char *fnc, int line, const char *fmt, void *data, va_list args __UNUSED__)
77{
78 struct log_ctx *ctx = data;
79 va_list cp_args;
80 const char *str;
81
82 va_copy(cp_args, args);
83 str = va_arg(cp_args, const char *);
84 va_end(cp_args);
85
86 ck_assert_int_eq(ctx->level, level);
87 ck_assert_str_eq(fmt, "%s");
88 ck_assert_str_eq(ctx->msg, str);
89 ck_assert_str_eq(ctx->fnc, fnc);
90 ctx->did = EINA_TRUE;
91
92#ifdef SHOW_LOG
93 eina_log_print_cb_stderr(d, level, file, fnc, line, fmt, NULL, args);
94#else
95 (void)d;
96 (void)file;
97 (void)line;
98#endif
99}
100
101START_TEST(eina_log_macro)
102{
103 struct log_ctx ctx;
104 int oldlevel;
105
106 fail_if(!eina_init());
107
108 oldlevel = eina_log_level_get();
109 eina_log_level_set(EINA_LOG_LEVEL_DBG);
110 eina_log_print_cb_set(_eina_test_log, &ctx);
111
112#define TEST_LOG_CTX(lvl, _msg) \
113 ctx.level = lvl; \
114 ctx.line = __LINE__ + 1; \
115 ctx.msg = _msg; \
116 ctx.fnc = __FUNCTION__; \
117 ctx.did = EINA_FALSE
118
119 TEST_LOG_CTX(EINA_LOG_LEVEL_CRITICAL, "Critical message");
120 EINA_LOG_CRIT("Critical message");
121 fail_unless(ctx.did);
122
123 TEST_LOG_CTX(EINA_LOG_LEVEL_ERR, "An error");
124 EINA_LOG_ERR("An error");
125 fail_unless(ctx.did);
126
127 TEST_LOG_CTX(EINA_LOG_LEVEL_WARN, "A warning");
128 EINA_LOG_WARN("A warning");
129 fail_unless(ctx.did);
130
131 TEST_LOG_CTX(EINA_LOG_LEVEL_INFO, "An info");
132 EINA_LOG_INFO("An info");
133 fail_unless(ctx.did);
134
135 TEST_LOG_CTX(EINA_LOG_LEVEL_DBG, "A debug");
136 EINA_LOG_DBG("A debug");
137 fail_unless(ctx.did);
138
139#undef TEST_LOG_CTX
140
141 eina_log_print_cb_set(eina_log_print_cb_stderr, NULL);
142 eina_log_level_set(oldlevel);
143
144 eina_shutdown();
145}
146END_TEST
147
148START_TEST(eina_log_domains_macros)
149{
150 struct log_ctx ctx;
151 int oldlevel;
152
153 fail_if(!eina_init());
154
155 /* make global log level blocker */
156 oldlevel = eina_log_level_get();
157 eina_log_level_set(EINA_LOG_LEVEL_CRITICAL);
158 eina_log_print_cb_set(_eina_test_log_domain, &ctx);
159
160 int d = eina_log_domain_register("MyDomain", EINA_COLOR_GREEN);
161 fail_if(d < 0);
162
163 /* make specific domain permissive */
164 eina_log_domain_level_set("MyDomain", EINA_LOG_LEVEL_DBG);
165
166#define TEST_LOG_CTX(lvl, _msg) \
167 ctx.level = lvl; \
168 ctx.line = __LINE__ + 1; \
169 ctx.msg = _msg; \
170 ctx.fnc = __FUNCTION__; \
171 ctx.dom = "MyDomain"; \
172 ctx.did = EINA_FALSE
173
174 TEST_LOG_CTX(EINA_LOG_LEVEL_CRITICAL, "A critical message");
175 EINA_LOG_DOM_CRIT(d, "A critical message");
176 fail_unless(ctx.did);
177
178 TEST_LOG_CTX(EINA_LOG_LEVEL_ERR, "An error");
179 EINA_LOG_DOM_ERR(d, "An error");
180 fail_unless(ctx.did);
181
182 TEST_LOG_CTX(EINA_LOG_LEVEL_WARN, "A warning");
183 EINA_LOG_DOM_WARN(d, "A warning");
184 fail_unless(ctx.did);
185
186 TEST_LOG_CTX(EINA_LOG_LEVEL_INFO, "An info");
187 EINA_LOG_DOM_INFO(d, "An info");
188 fail_unless(ctx.did);
189
190 TEST_LOG_CTX(EINA_LOG_LEVEL_DBG, "A debug");
191 EINA_LOG_DOM_DBG(d, "A debug");
192 fail_unless(ctx.did);
193
194#undef TEST_LOG_CTX
195
196 eina_log_print_cb_set(eina_log_print_cb_stderr, NULL);
197 eina_log_level_set(oldlevel);
198
199 eina_shutdown();
200}
201END_TEST
202
203START_TEST(eina_log_domains_registry)
204{
205 fail_if(!eina_init());
206
207 int i;
208 int d[50];
209
210 for (i = 0; i < 50; i++)
211 {
212 d[i] = eina_log_domain_register("Test", EINA_COLOR_GREEN);
213 fail_if(d[i] < 0);
214 }
215
216 for (i = 0; i < 50; i++)
217 eina_log_domain_unregister(d[i]);
218
219 eina_shutdown();
220}
221END_TEST
222
223START_TEST(eina_log_domains_slot_reuse)
224{
225 fail_if(!eina_init());
226 fail_if(!eina_threads_init());
227
228 // Create 9 domains
229 int idx[9];
230 int i;
231
232 for (i = 0; i < 9; i++)
233 {
234 idx[i] = eina_log_domain_register("Test1", EINA_COLOR_GREEN);
235 fail_if(idx[i] < 0);
236 }
237
238 // Slot 0 by default contains the global logger. The above code created
239 // domains for slots indexes from 1 to 9.
240 //
241 // The global logger allocated the first 8 initial slots. The 8th domain
242 // registered on the for loop will create 8 more slots.
243 //
244 // Test will just unregister a domain between 1 and 9 and assure that a new
245 // domain register will be placed on the available slot and not at the end.
246
247 int removed = idx[5];
248 eina_log_domain_unregister(removed);
249
250 int new = eina_log_domain_register("Test Slot", EINA_COLOR_GREEN);
251
252 // Check for slot reuse
253 fail_if(new != removed);
254
255 eina_threads_shutdown();
256 eina_shutdown();
257}
258END_TEST
259
260START_TEST(eina_log_level_indexes)
261{
262 struct log_ctx ctx;
263
264 fail_if(!eina_init());
265 fail_if(!eina_threads_init());
266 fail_if(!eina_threads_init());
267
268 int d = eina_log_domain_register("Levels", EINA_COLOR_GREEN);
269 fail_if(d < 0);
270
271 eina_log_print_cb_set(_eina_test_log_domain, &ctx);
272
273#define TEST_LOG_CTX(lvl, _msg) \
274 ctx.level = lvl; \
275 ctx.line = __LINE__ + 1; \
276 ctx.msg = _msg; \
277 ctx.fnc = __FUNCTION__; \
278 ctx.dom = "Levels"; \
279 ctx.did = EINA_FALSE;
280
281 // Displayed unless user sets level lower than -1
282 eina_log_domain_level_set("Levels", -1);
283 TEST_LOG_CTX(-1, "Negative index message");
284 EINA_LOG(d, -1, "Negative index message");
285 fail_unless(ctx.did);
286
287 eina_log_domain_level_set("Levels", -2);
288 TEST_LOG_CTX(-1, "Negative index message");
289 EINA_LOG(d, -1, "Negative index message");
290 fail_if(ctx.did);
291
292 // Displayed only if user sets level 6 or higher
293 eina_log_domain_level_set("Levels", 6);
294 TEST_LOG_CTX(6, "Higher level debug");
295 EINA_LOG(d, 6, "Higher level debug");
296 fail_unless(ctx.did);
297
298 eina_log_domain_level_set("Levels", 5);
299 TEST_LOG_CTX(6, "Higher level debug");
300 EINA_LOG(d, 6, "Higher level debug");
301 fail_if(ctx.did);
302
303#undef TEST_LOG_CTX
304
305 eina_log_print_cb_set(eina_log_print_cb_stderr, NULL);
306
307 eina_threads_shutdown();
308 eina_threads_shutdown();
309 eina_shutdown();
310}
311END_TEST
312
313START_TEST(eina_log_customize)
314{
315 struct log_ctx ctx;
316 int d;
317
318 /* please don't define EINA_LOG_LEVELS for it */
319#define TEST_DOM "_Test_Log_Dom"
320
321 fail_if(!eina_init());
322
323#define test_set_get(func, val) \
324 eina_log_ ## func ## _set(val); \
325 fail_if(eina_log_ ## func ## _get() != val)
326
327 test_set_get(level, -1234);
328 test_set_get(level, 4567);
329
330#define test_set_get_bool(func) \
331 test_set_get(func, EINA_FALSE); \
332 test_set_get(func, EINA_TRUE)
333
334 test_set_get_bool(color_disable);
335 test_set_get_bool(file_disable);
336 test_set_get_bool(function_disable);
337 test_set_get_bool(abort_on_critical);
338
339 test_set_get(abort_on_critical_level, -1234);
340 test_set_get(abort_on_critical_level, 4567);
341
342 fail_if(eina_log_domain_level_get(TEST_DOM) != eina_log_level_get());
343
344 eina_log_domain_level_set(TEST_DOM, -123);
345 fail_if(eina_log_domain_level_get(TEST_DOM) != -123);
346
347 eina_log_domain_level_set(TEST_DOM, 890);
348 fail_if(eina_log_domain_level_get(TEST_DOM) != 890);
349
350 d = eina_log_domain_register(TEST_DOM, EINA_COLOR_GREEN);
351 fail_if(d < 0);
352
353 fail_if(eina_log_domain_level_get(TEST_DOM) != 890);
354 fail_if(eina_log_domain_registered_level_get(d) != 890);
355
356 eina_log_domain_unregister(d);
357
358#ifdef EINA_SAFETY_CHECKS
359#ifdef SHOW_LOG
360 fputs("NOTE: You should see a failed safety check or "
361 "a crash if compiled without safety checks support.\n",
362 stderr);
363#endif
364 eina_log_abort_on_critical_set(EINA_FALSE);
365 eina_log_function_disable_set(EINA_FALSE);
366
367 eina_log_print_cb_set(_eina_test_log_safety, &ctx);
368 ctx.level = EINA_LOG_LEVEL_ERR;
369 ctx.msg = "safety check failed: _log_domains[domain].deleted is true";
370 ctx.fnc = "eina_log_domain_registered_level_get";
371 ctx.did = EINA_FALSE;
372 fail_if(eina_log_domain_registered_level_get(d) != EINA_LOG_LEVEL_UNKNOWN);
373 fail_unless(ctx.did);
374
375 eina_log_print_cb_set(eina_log_print_cb_stderr, NULL);
376#else
377#warning "Compiled without safety checks"
378#endif
379
380#undef test_set_get_bool
381#undef test_set_get
382
383 eina_shutdown();
384}
385END_TEST
386
387START_TEST(eina_log_level_name)
388{
389 char name[4];
390
391 fail_if(!eina_init());
392
393#define tst(level, str) \
394 eina_log_level_name_get(level, name); \
395 fail_if(strcmp(name, str) != 0)
396
397 tst(0, "CRI");
398 tst(1, "ERR");
399 tst(2, "WRN");
400 tst(3, "INF");
401 tst(4, "DBG");
402 tst(5, "005");
403 tst(12, "012");
404 tst(369, "369");
405 tst(-1, "-01");
406 tst(-48, "-48");
407
408#undef tst
409
410 eina_shutdown();
411}
412END_TEST
413
414void
415eina_test_log(TCase *tc)
416{
417 tcase_add_test(tc, eina_log_macro);
418 tcase_add_test(tc, eina_log_domains_macros);
419 tcase_add_test(tc, eina_log_domains_registry);
420 tcase_add_test(tc, eina_log_domains_slot_reuse);
421 tcase_add_test(tc, eina_log_level_indexes);
422 tcase_add_test(tc, eina_log_customize);
423 tcase_add_test(tc, eina_log_level_name);
424}