summaryrefslogtreecommitdiff
path: root/legacy
diff options
context:
space:
mode:
authorGustavo Sverzut Barbieri <barbieri@gmail.com>2012-01-21 03:59:03 +0000
committerGustavo Sverzut Barbieri <barbieri@gmail.com>2012-01-21 03:59:03 +0000
commite877d6617d85a37723c0f4d9776f06ed5c1a6c9c (patch)
treee574321b0bbe4870091e1806d00dbef7840d634d /legacy
parentcdac7c3864799d61f362d9cfbf1c586b6cc5d12e (diff)
improve magic tests, check output to see if it happened
SVN revision: 67408
Diffstat (limited to 'legacy')
-rw-r--r--legacy/eina/src/tests/eina_test_magic.c110
1 files changed, 110 insertions, 0 deletions
diff --git a/legacy/eina/src/tests/eina_test_magic.c b/legacy/eina/src/tests/eina_test_magic.c
index d2c3d49284..d0a374e77c 100644
--- a/legacy/eina/src/tests/eina_test_magic.c
+++ b/legacy/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
43struct 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
52static 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
78static 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
43START_TEST(eina_magic_simple) 104START_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}
90END_TEST 200END_TEST