diff options
author | David Walter Seikel | 2012-04-22 09:19:23 +1000 |
---|---|---|
committer | David Walter Seikel | 2012-04-22 09:19:23 +1000 |
commit | c963d75dfdeec11f82e79e727062fbf89afa2c04 (patch) | |
tree | 895633dbf641110be46f117c29890c49b3ffc0bd /libraries/eina/src/tests/eina_test_magic.c | |
parent | Adding the new extantz viewer and grid manager. (diff) | |
download | SledjHamr-c963d75dfdeec11f82e79e727062fbf89afa2c04.zip SledjHamr-c963d75dfdeec11f82e79e727062fbf89afa2c04.tar.gz SledjHamr-c963d75dfdeec11f82e79e727062fbf89afa2c04.tar.bz2 SledjHamr-c963d75dfdeec11f82e79e727062fbf89afa2c04.tar.xz |
Update EFL to latest beta.
Diffstat (limited to '')
-rw-r--r-- | libraries/eina/src/tests/eina_test_magic.c | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/libraries/eina/src/tests/eina_test_magic.c b/libraries/eina/src/tests/eina_test_magic.c index d2c3d49..d0a374e 100644 --- a/libraries/eina/src/tests/eina_test_magic.c +++ b/libraries/eina/src/tests/eina_test_magic.c | |||
@@ -40,21 +40,95 @@ struct _Eina_Magic_Struct | |||
40 | EINA_MAGIC | 40 | EINA_MAGIC |
41 | }; | 41 | }; |
42 | 42 | ||
43 | struct log_ctx { | ||
44 | const char *msg; | ||
45 | const char *fnc; | ||
46 | Eina_Bool did; | ||
47 | }; | ||
48 | |||
49 | /* tests should not output on success, just uncomment this for debugging */ | ||
50 | //#define SHOW_LOG 1 | ||
51 | |||
52 | static void | ||
53 | _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__) | ||
54 | { | ||
55 | struct log_ctx *ctx = data; | ||
56 | va_list cp_args; | ||
57 | const char *str; | ||
58 | |||
59 | va_copy(cp_args, args); | ||
60 | str = va_arg(cp_args, const char *); | ||
61 | va_end(cp_args); | ||
62 | |||
63 | ck_assert_int_eq(level, EINA_LOG_LEVEL_ERR); | ||
64 | ck_assert_str_eq(fmt, "%s"); | ||
65 | ck_assert_str_eq(ctx->msg, str); | ||
66 | ck_assert_str_eq(ctx->fnc, fnc); | ||
67 | ctx->did = EINA_TRUE; | ||
68 | |||
69 | #ifdef SHOW_LOG | ||
70 | eina_log_print_cb_stderr(d, level, file, fnc, line, fmt, NULL, args); | ||
71 | #else | ||
72 | (void)d; | ||
73 | (void)file; | ||
74 | (void)line; | ||
75 | #endif | ||
76 | } | ||
77 | |||
78 | static void | ||
79 | _eina_test_magic_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__) | ||
80 | { | ||
81 | struct log_ctx *ctx = data; | ||
82 | |||
83 | ck_assert_int_eq(level, EINA_LOG_LEVEL_CRITICAL); | ||
84 | ck_assert_str_eq(ctx->msg, fmt); | ||
85 | ck_assert_str_eq(ctx->fnc, fnc); | ||
86 | ctx->did = EINA_TRUE; | ||
87 | |||
88 | #ifdef SHOW_LOG | ||
89 | eina_log_print_cb_stderr(d, level, file, fnc, line, fmt, NULL, args); | ||
90 | #else | ||
91 | (void)d; | ||
92 | (void)file; | ||
93 | (void)line; | ||
94 | #endif | ||
95 | } | ||
96 | |||
97 | #ifdef EINA_SAFETY_CHECKS | ||
98 | #define TEST_MAGIC_SAFETY(fn, _msg) \ | ||
99 | ctx.msg = _msg; \ | ||
100 | ctx.fnc = fn; \ | ||
101 | ctx.did = EINA_FALSE | ||
102 | #endif | ||
103 | |||
43 | START_TEST(eina_magic_simple) | 104 | START_TEST(eina_magic_simple) |
44 | { | 105 | { |
45 | Eina_Magic_Struct *ems = NULL; | 106 | Eina_Magic_Struct *ems = NULL; |
107 | struct log_ctx ctx; | ||
46 | 108 | ||
47 | eina_init(); | 109 | eina_init(); |
48 | 110 | ||
111 | eina_log_print_cb_set(_eina_test_safety_print_cb, &ctx); | ||
112 | |||
49 | eina_magic_string_set(EINA_MAGIC_TEST, EINA_MAGIC_STRING); | 113 | eina_magic_string_set(EINA_MAGIC_TEST, EINA_MAGIC_STRING); |
50 | 114 | ||
51 | #ifdef EINA_SAFETY_CHECKS | 115 | #ifdef EINA_SAFETY_CHECKS |
116 | #ifdef SHOW_LOG | ||
52 | fprintf(stderr, "you should have a safety check failure below:\n"); | 117 | fprintf(stderr, "you should have a safety check failure below:\n"); |
118 | #endif | ||
119 | TEST_MAGIC_SAFETY("eina_magic_string_set", | ||
120 | "safety check failed: magic_name == NULL"); | ||
53 | eina_magic_string_set(EINA_MAGIC_TEST2, NULL); | 121 | eina_magic_string_set(EINA_MAGIC_TEST2, NULL); |
54 | fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED); | 122 | fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED); |
123 | fail_unless(ctx.did); | ||
55 | 124 | ||
125 | #ifdef SHOW_LOG | ||
56 | fprintf(stderr, "you should have a safety check failure below:\n"); | 126 | fprintf(stderr, "you should have a safety check failure below:\n"); |
127 | #endif | ||
128 | TEST_MAGIC_SAFETY("eina_magic_string_set", | ||
129 | "safety check failed: magic_name == NULL"); | ||
57 | eina_magic_string_set(EINA_MAGIC_TEST2, NULL); | 130 | eina_magic_string_set(EINA_MAGIC_TEST2, NULL); |
131 | fail_unless(ctx.did); | ||
58 | fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED); | 132 | fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED); |
59 | #endif | 133 | #endif |
60 | 134 | ||
@@ -64,10 +138,22 @@ START_TEST(eina_magic_simple) | |||
64 | fail_if(strcmp(eina_magic_string_get( | 138 | fail_if(strcmp(eina_magic_string_get( |
65 | EINA_MAGIC_TEST), EINA_MAGIC_STRING) != 0); | 139 | EINA_MAGIC_TEST), EINA_MAGIC_STRING) != 0); |
66 | 140 | ||
141 | eina_log_print_cb_set(_eina_test_magic_print_cb, &ctx); | ||
142 | |||
67 | #ifdef EINA_MAGIC_DEBUG | 143 | #ifdef EINA_MAGIC_DEBUG |
68 | fail_if(EINA_MAGIC_CHECK(ems, EINA_MAGIC_TEST)); | 144 | fail_if(EINA_MAGIC_CHECK(ems, EINA_MAGIC_TEST)); |
145 | #ifdef SHOW_LOG | ||
69 | fprintf(stderr, "you should see 'Input handle pointer is NULL' below\n"); | 146 | fprintf(stderr, "you should see 'Input handle pointer is NULL' below\n"); |
147 | #endif | ||
148 | TEST_MAGIC_SAFETY(__FUNCTION__, | ||
149 | "*** Eina Magic Check Failed !!!\n" | ||
150 | " Input handle pointer is NULL !\n" | ||
151 | "*** NAUGHTY PROGRAMMER!!!\n" | ||
152 | "*** SPANK SPANK SPANK!!!\n" | ||
153 | "*** Now go fix your code. Tut tut tut!\n" | ||
154 | "\n"); | ||
70 | EINA_MAGIC_FAIL(ems, EINA_MAGIC_TEST); | 155 | EINA_MAGIC_FAIL(ems, EINA_MAGIC_TEST); |
156 | fail_unless(ctx.did); | ||
71 | 157 | ||
72 | ems = malloc(sizeof (Eina_Magic_Struct)); | 158 | ems = malloc(sizeof (Eina_Magic_Struct)); |
73 | fail_if(!ems); | 159 | fail_if(!ems); |
@@ -76,15 +162,39 @@ START_TEST(eina_magic_simple) | |||
76 | fail_if(!EINA_MAGIC_CHECK(ems, EINA_MAGIC_TEST)); | 162 | fail_if(!EINA_MAGIC_CHECK(ems, EINA_MAGIC_TEST)); |
77 | 163 | ||
78 | EINA_MAGIC_SET(ems, EINA_MAGIC_NONE); | 164 | EINA_MAGIC_SET(ems, EINA_MAGIC_NONE); |
165 | #ifdef SHOW_LOG | ||
79 | fprintf(stderr, | 166 | fprintf(stderr, |
80 | "you should see 'Input handle has already been freed' below\n"); | 167 | "you should see 'Input handle has already been freed' below\n"); |
168 | #endif | ||
169 | TEST_MAGIC_SAFETY(__FUNCTION__, | ||
170 | "*** Eina Magic Check Failed !!!\n" | ||
171 | " Input handle has already been freed!\n" | ||
172 | "*** NAUGHTY PROGRAMMER!!!\n" | ||
173 | "*** SPANK SPANK SPANK!!!\n" | ||
174 | "*** Now go fix your code. Tut tut tut!\n" | ||
175 | "\n"); | ||
81 | EINA_MAGIC_FAIL(ems, EINA_MAGIC_TEST); | 176 | EINA_MAGIC_FAIL(ems, EINA_MAGIC_TEST); |
177 | fail_unless(ctx.did); | ||
82 | 178 | ||
83 | EINA_MAGIC_SET(ems, 42424242); | 179 | EINA_MAGIC_SET(ems, 42424242); |
180 | #ifdef SHOW_LOG | ||
84 | fprintf(stderr, "you should see 'Input handle is wrong type' below\n"); | 181 | fprintf(stderr, "you should see 'Input handle is wrong type' below\n"); |
182 | #endif | ||
183 | TEST_MAGIC_SAFETY(__FUNCTION__, | ||
184 | "*** Eina Magic Check Failed !!!\n" | ||
185 | " Input handle is wrong type\n" | ||
186 | " Expected: %08x - %s\n" | ||
187 | " Supplied: %08x - %s\n" | ||
188 | "*** NAUGHTY PROGRAMMER!!!\n" | ||
189 | "*** SPANK SPANK SPANK!!!\n" | ||
190 | "*** Now go fix your code. Tut tut tut!\n" | ||
191 | "\n"); | ||
85 | EINA_MAGIC_FAIL(ems, EINA_MAGIC_TEST); | 192 | EINA_MAGIC_FAIL(ems, EINA_MAGIC_TEST); |
193 | fail_unless(ctx.did); | ||
86 | #endif | 194 | #endif |
87 | 195 | ||
196 | eina_log_print_cb_set(eina_log_print_cb_stderr, NULL); | ||
197 | |||
88 | eina_shutdown(); | 198 | eina_shutdown(); |
89 | } | 199 | } |
90 | END_TEST | 200 | END_TEST |