diff options
Diffstat (limited to '')
-rw-r--r-- | libraries/eina/src/tests/eina_test_counter.c | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/libraries/eina/src/tests/eina_test_counter.c b/libraries/eina/src/tests/eina_test_counter.c new file mode 100644 index 0000000..2a3f30d --- /dev/null +++ b/libraries/eina/src/tests/eina_test_counter.c | |||
@@ -0,0 +1,108 @@ | |||
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 | START_TEST(eina_counter_simple) | ||
31 | { | ||
32 | Eina_Counter *cnt; | ||
33 | char *dump; | ||
34 | int i; | ||
35 | |||
36 | eina_init(); | ||
37 | |||
38 | cnt = eina_counter_new("eina_test"); | ||
39 | fail_if(!cnt); | ||
40 | |||
41 | eina_counter_start(cnt); | ||
42 | |||
43 | for (i = 0; i < 100000; ++i) | ||
44 | { | ||
45 | void *tmp = malloc(sizeof(long int)); | ||
46 | free(tmp); | ||
47 | } | ||
48 | |||
49 | eina_counter_stop(cnt, i); | ||
50 | |||
51 | eina_counter_start(cnt); | ||
52 | |||
53 | for (i = 0; i < 200000; ++i) | ||
54 | { | ||
55 | void *tmp = malloc(sizeof(long int)); | ||
56 | free(tmp); | ||
57 | } | ||
58 | |||
59 | eina_counter_stop(cnt, i); | ||
60 | |||
61 | dump = eina_counter_dump(cnt); | ||
62 | fail_if(!dump); | ||
63 | |||
64 | fprintf(stderr, "%s", dump); | ||
65 | |||
66 | free(dump); | ||
67 | |||
68 | eina_counter_free(cnt); | ||
69 | |||
70 | eina_shutdown(); | ||
71 | } | ||
72 | END_TEST | ||
73 | |||
74 | START_TEST(eina_counter_break) | ||
75 | { | ||
76 | Eina_Counter *cnt; | ||
77 | |||
78 | eina_init(); | ||
79 | |||
80 | cnt = eina_counter_new("eina_test"); | ||
81 | fail_if(!cnt); | ||
82 | |||
83 | eina_counter_stop(cnt, 10); | ||
84 | |||
85 | eina_counter_free(cnt); | ||
86 | |||
87 | #ifdef EINA_SAFETY_CHECKS | ||
88 | { | ||
89 | char *dump; | ||
90 | |||
91 | fprintf(stderr, "you should have a safety check failure below:\n"); | ||
92 | dump = eina_counter_dump(NULL); | ||
93 | fail_if(dump); | ||
94 | fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED); | ||
95 | free(dump); | ||
96 | } | ||
97 | #endif | ||
98 | |||
99 | eina_shutdown(); | ||
100 | } | ||
101 | END_TEST | ||
102 | |||
103 | void eina_test_counter(TCase *tc) | ||
104 | { | ||
105 | tcase_add_test(tc, eina_counter_simple); | ||
106 | tcase_add_test(tc, eina_counter_break); | ||
107 | } | ||
108 | |||