aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/eina/src/tests/eina_test_counter.c
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/eina/src/tests/eina_test_counter.c')
-rw-r--r--libraries/eina/src/tests/eina_test_counter.c92
1 files changed, 91 insertions, 1 deletions
diff --git a/libraries/eina/src/tests/eina_test_counter.c b/libraries/eina/src/tests/eina_test_counter.c
index 2a3f30d..4d956fd 100644
--- a/libraries/eina/src/tests/eina_test_counter.c
+++ b/libraries/eina/src/tests/eina_test_counter.c
@@ -27,6 +27,43 @@
27#include "Eina.h" 27#include "Eina.h"
28#include "eina_safety_checks.h" 28#include "eina_safety_checks.h"
29 29
30#ifdef EINA_SAFETY_CHECKS
31struct log_ctx {
32 const char *msg;
33 const char *fnc;
34 Eina_Bool did;
35};
36
37/* tests should not output on success, just uncomment this for debugging */
38//#define SHOW_LOG 1
39
40static void
41_eina_test_safety_print_cb(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__)
42{
43 struct log_ctx *ctx = data;
44 va_list cp_args;
45 const char *str;
46
47 va_copy(cp_args, args);
48 str = va_arg(cp_args, const char *);
49 va_end(cp_args);
50
51 ck_assert_int_eq(level, EINA_LOG_LEVEL_ERR);
52 ck_assert_str_eq(fmt, "%s");
53 ck_assert_str_eq(ctx->msg, str);
54 ck_assert_str_eq(ctx->fnc, fnc);
55 ctx->did = EINA_TRUE;
56
57#ifdef SHOW_LOG
58 eina_log_print_cb_stderr(d, level, file, fnc, line, fmt, NULL, args);
59#else
60 (void)d;
61 (void)file;
62 (void)line;
63#endif
64}
65#endif
66
30START_TEST(eina_counter_simple) 67START_TEST(eina_counter_simple)
31{ 68{
32 Eina_Counter *cnt; 69 Eina_Counter *cnt;
@@ -61,6 +98,7 @@ START_TEST(eina_counter_simple)
61 dump = eina_counter_dump(cnt); 98 dump = eina_counter_dump(cnt);
62 fail_if(!dump); 99 fail_if(!dump);
63 100
101 /* TODO: parse dump and check if it's right */
64 fprintf(stderr, "%s", dump); 102 fprintf(stderr, "%s", dump);
65 103
66 free(dump); 104 free(dump);
@@ -86,13 +124,65 @@ START_TEST(eina_counter_break)
86 124
87#ifdef EINA_SAFETY_CHECKS 125#ifdef EINA_SAFETY_CHECKS
88 { 126 {
127 struct log_ctx ctx;
89 char *dump; 128 char *dump;
90 129
130#define TEST_MAGIC_SAFETY(fn, _msg) \
131 ctx.msg = _msg; \
132 ctx.fnc = fn; \
133 ctx.did = EINA_FALSE
134
135 eina_log_print_cb_set(_eina_test_safety_print_cb, &ctx);
136
137#ifdef SHOW_LOG
91 fprintf(stderr, "you should have a safety check failure below:\n"); 138 fprintf(stderr, "you should have a safety check failure below:\n");
139#endif
140 TEST_MAGIC_SAFETY("eina_counter_new",
141 "safety check failed: name == NULL");
142 cnt = eina_counter_new(NULL);
143 fail_if(cnt);
144 fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED);
145 fail_unless(ctx.did);
146
147#ifdef SHOW_LOG
148 fprintf(stderr, "you should have a safety check failure below:\n");
149#endif
150 TEST_MAGIC_SAFETY("eina_counter_free",
151 "safety check failed: counter == NULL");
152 eina_counter_free(NULL);
153 fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED);
154 fail_unless(ctx.did);
155
156#ifdef SHOW_LOG
157 fprintf(stderr, "you should have a safety check failure below:\n");
158#endif
159 TEST_MAGIC_SAFETY("eina_counter_start",
160 "safety check failed: counter == NULL");
161 eina_counter_start(NULL);
162 fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED);
163 fail_unless(ctx.did);
164
165#ifdef SHOW_LOG
166 fprintf(stderr, "you should have a safety check failure below:\n");
167#endif
168 TEST_MAGIC_SAFETY("eina_counter_stop",
169 "safety check failed: counter == NULL");
170 eina_counter_stop(NULL, 0);
171 fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED);
172 fail_unless(ctx.did);
173
174
175#ifdef SHOW_LOG
176 fprintf(stderr, "you should have a safety check failure below:\n");
177#endif
178 TEST_MAGIC_SAFETY("eina_counter_dump",
179 "safety check failed: counter == NULL");
92 dump = eina_counter_dump(NULL); 180 dump = eina_counter_dump(NULL);
93 fail_if(dump); 181 fail_if(dump);
94 fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED); 182 fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED);
95 free(dump); 183 fail_unless(ctx.did);
184
185 eina_log_print_cb_set(eina_log_print_cb_stderr, NULL);
96 } 186 }
97#endif 187#endif
98 188