diff options
Diffstat (limited to 'libraries/eina/src/tests/eina_test_log.c')
-rw-r--r-- | libraries/eina/src/tests/eina_test_log.c | 217 |
1 files changed, 203 insertions, 14 deletions
diff --git a/libraries/eina/src/tests/eina_test_log.c b/libraries/eina/src/tests/eina_test_log.c index ba17d5f..e0f0363 100644 --- a/libraries/eina/src/tests/eina_test_log.c +++ b/libraries/eina/src/tests/eina_test_log.c | |||
@@ -27,18 +27,119 @@ | |||
27 | #include "eina_suite.h" | 27 | #include "eina_suite.h" |
28 | #include "Eina.h" | 28 | #include "Eina.h" |
29 | 29 | ||
30 | START_TEST(eina_log_macro) | 30 | struct 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 | |||
42 | static 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__) | ||
31 | { | 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 | |||
59 | static 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 | |||
75 | static 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 | |||
101 | START_TEST(eina_log_macro) | ||
102 | { | ||
103 | struct log_ctx ctx; | ||
104 | int oldlevel; | ||
105 | |||
32 | fail_if(!eina_init()); | 106 | fail_if(!eina_init()); |
33 | 107 | ||
108 | oldlevel = eina_log_level_get(); | ||
34 | eina_log_level_set(EINA_LOG_LEVEL_DBG); | 109 | eina_log_level_set(EINA_LOG_LEVEL_DBG); |
35 | eina_log_print_cb_set(eina_log_print_cb_file, stderr); | 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); | ||
36 | 126 | ||
37 | EINA_LOG_CRIT("Critical message\n"); | 127 | TEST_LOG_CTX(EINA_LOG_LEVEL_WARN, "A warning"); |
38 | EINA_LOG_ERR("An error\n"); | 128 | EINA_LOG_WARN("A warning"); |
39 | EINA_LOG_INFO("An info\n"); | 129 | fail_unless(ctx.did); |
40 | EINA_LOG_WARN("A warning\n"); | 130 | |
41 | EINA_LOG_DBG("A debug\n"); | 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); | ||
42 | 143 | ||
43 | eina_shutdown(); | 144 | eina_shutdown(); |
44 | } | 145 | } |
@@ -46,16 +147,54 @@ END_TEST | |||
46 | 147 | ||
47 | START_TEST(eina_log_domains_macros) | 148 | START_TEST(eina_log_domains_macros) |
48 | { | 149 | { |
150 | struct log_ctx ctx; | ||
151 | int oldlevel; | ||
152 | |||
49 | fail_if(!eina_init()); | 153 | fail_if(!eina_init()); |
50 | 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 | |||
51 | int d = eina_log_domain_register("MyDomain", EINA_COLOR_GREEN); | 160 | int d = eina_log_domain_register("MyDomain", EINA_COLOR_GREEN); |
52 | fail_if(d < 0); | 161 | fail_if(d < 0); |
53 | 162 | ||
54 | EINA_LOG_DOM_CRIT(d, "A critical message\n"); | 163 | /* make specific domain permissive */ |
55 | EINA_LOG_DOM_ERR(d, "An error\n"); | 164 | eina_log_domain_level_set("MyDomain", EINA_LOG_LEVEL_DBG); |
56 | EINA_LOG_DOM_WARN(d, "A warning\n"); | 165 | |
57 | EINA_LOG_DOM_DBG(d, "A debug\n"); | 166 | #define TEST_LOG_CTX(lvl, _msg) \ |
58 | EINA_LOG_DOM_INFO(d, "An info\n"); | 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); | ||
59 | 198 | ||
60 | eina_shutdown(); | 199 | eina_shutdown(); |
61 | } | 200 | } |
@@ -120,6 +259,8 @@ END_TEST | |||
120 | 259 | ||
121 | START_TEST(eina_log_level_indexes) | 260 | START_TEST(eina_log_level_indexes) |
122 | { | 261 | { |
262 | struct log_ctx ctx; | ||
263 | |||
123 | fail_if(!eina_init()); | 264 | fail_if(!eina_init()); |
124 | fail_if(!eina_threads_init()); | 265 | fail_if(!eina_threads_init()); |
125 | fail_if(!eina_threads_init()); | 266 | fail_if(!eina_threads_init()); |
@@ -127,11 +268,41 @@ START_TEST(eina_log_level_indexes) | |||
127 | int d = eina_log_domain_register("Levels", EINA_COLOR_GREEN); | 268 | int d = eina_log_domain_register("Levels", EINA_COLOR_GREEN); |
128 | fail_if(d < 0); | 269 | fail_if(d < 0); |
129 | 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 | |||
130 | // Displayed unless user sets level lower than -1 | 281 | // Displayed unless user sets level lower than -1 |
131 | EINA_LOG(d, -1, "Negative index message\n"); | 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); | ||
132 | 291 | ||
133 | // Displayed only if user sets level 6 or higher | 292 | // Displayed only if user sets level 6 or higher |
134 | EINA_LOG(d, 6, "Higher level debug\n"); | 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); | ||
135 | 306 | ||
136 | eina_threads_shutdown(); | 307 | eina_threads_shutdown(); |
137 | eina_threads_shutdown(); | 308 | eina_threads_shutdown(); |
@@ -141,6 +312,7 @@ END_TEST | |||
141 | 312 | ||
142 | START_TEST(eina_log_customize) | 313 | START_TEST(eina_log_customize) |
143 | { | 314 | { |
315 | struct log_ctx ctx; | ||
144 | int d; | 316 | int d; |
145 | 317 | ||
146 | /* please don't define EINA_LOG_LEVELS for it */ | 318 | /* please don't define EINA_LOG_LEVELS for it */ |
@@ -182,11 +354,28 @@ START_TEST(eina_log_customize) | |||
182 | fail_if(eina_log_domain_registered_level_get(d) != 890); | 354 | fail_if(eina_log_domain_registered_level_get(d) != 890); |
183 | 355 | ||
184 | eina_log_domain_unregister(d); | 356 | eina_log_domain_unregister(d); |
357 | |||
358 | #ifdef EINA_SAFETY_CHECKS | ||
359 | #ifdef SHOW_LOG | ||
185 | fputs("NOTE: You should see a failed safety check or " | 360 | fputs("NOTE: You should see a failed safety check or " |
186 | "a crash if compiled without safety checks support.\n", | 361 | "a crash if compiled without safety checks support.\n", |
187 | stderr); | 362 | stderr); |
363 | #endif | ||
188 | eina_log_abort_on_critical_set(EINA_FALSE); | 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; | ||
189 | fail_if(eina_log_domain_registered_level_get(d) != EINA_LOG_LEVEL_UNKNOWN); | 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 | ||
190 | 379 | ||
191 | #undef test_set_get_bool | 380 | #undef test_set_get_bool |
192 | #undef test_set_get | 381 | #undef test_set_get |