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.c198
1 files changed, 0 insertions, 198 deletions
diff --git a/libraries/eina/src/tests/eina_test_counter.c b/libraries/eina/src/tests/eina_test_counter.c
deleted file mode 100644
index 4d956fd..0000000
--- a/libraries/eina/src/tests/eina_test_counter.c
+++ /dev/null
@@ -1,198 +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 <stdio.h>
24#include <stdlib.h>
25
26#include "eina_suite.h"
27#include "Eina.h"
28#include "eina_safety_checks.h"
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
67START_TEST(eina_counter_simple)
68{
69 Eina_Counter *cnt;
70 char *dump;
71 int i;
72
73 eina_init();
74
75 cnt = eina_counter_new("eina_test");
76 fail_if(!cnt);
77
78 eina_counter_start(cnt);
79
80 for (i = 0; i < 100000; ++i)
81 {
82 void *tmp = malloc(sizeof(long int));
83 free(tmp);
84 }
85
86 eina_counter_stop(cnt, i);
87
88 eina_counter_start(cnt);
89
90 for (i = 0; i < 200000; ++i)
91 {
92 void *tmp = malloc(sizeof(long int));
93 free(tmp);
94 }
95
96 eina_counter_stop(cnt, i);
97
98 dump = eina_counter_dump(cnt);
99 fail_if(!dump);
100
101 /* TODO: parse dump and check if it's right */
102 fprintf(stderr, "%s", dump);
103
104 free(dump);
105
106 eina_counter_free(cnt);
107
108 eina_shutdown();
109}
110END_TEST
111
112START_TEST(eina_counter_break)
113{
114 Eina_Counter *cnt;
115
116 eina_init();
117
118 cnt = eina_counter_new("eina_test");
119 fail_if(!cnt);
120
121 eina_counter_stop(cnt, 10);
122
123 eina_counter_free(cnt);
124
125#ifdef EINA_SAFETY_CHECKS
126 {
127 struct log_ctx ctx;
128 char *dump;
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
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");
180 dump = eina_counter_dump(NULL);
181 fail_if(dump);
182 fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED);
183 fail_unless(ctx.did);
184
185 eina_log_print_cb_set(eina_log_print_cb_stderr, NULL);
186 }
187#endif
188
189 eina_shutdown();
190}
191END_TEST
192
193void eina_test_counter(TCase *tc)
194{
195 tcase_add_test(tc, eina_counter_simple);
196 tcase_add_test(tc, eina_counter_break);
197}
198