forked from enlightenment/efl
beef inlist tests wrt safety pointers
SVN revision: 67409
This commit is contained in:
parent
e877d6617d
commit
63a5350974
|
@ -430,6 +430,8 @@ eina_inlist_find(Eina_Inlist *list, Eina_Inlist *item)
|
|||
{
|
||||
Eina_Inlist *l;
|
||||
|
||||
EINA_SAFETY_ON_NULL_RETURN_VAL(item, NULL);
|
||||
|
||||
for (l = list; l; l = l->next) {
|
||||
if (l == item)
|
||||
return item;
|
||||
|
@ -559,6 +561,9 @@ eina_inlist_sorted_insert(Eina_Inlist *list,
|
|||
int cur = 0;
|
||||
int count;
|
||||
|
||||
EINA_SAFETY_ON_NULL_RETURN_VAL(item, list);
|
||||
EINA_SAFETY_ON_NULL_RETURN_VAL(func, list);
|
||||
|
||||
if (!list) return eina_inlist_append(NULL, item);
|
||||
|
||||
if (!list->next)
|
||||
|
|
|
@ -34,6 +34,43 @@ struct _Eina_Test_Inlist
|
|||
EINA_INLIST;
|
||||
};
|
||||
|
||||
#ifdef EINA_SAFETY_CHECKS
|
||||
struct log_ctx {
|
||||
const char *msg;
|
||||
const char *fnc;
|
||||
Eina_Bool did;
|
||||
};
|
||||
|
||||
/* tests should not output on success, just uncomment this for debugging */
|
||||
//#define SHOW_LOG 1
|
||||
|
||||
static void
|
||||
_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__)
|
||||
{
|
||||
struct log_ctx *ctx = data;
|
||||
va_list cp_args;
|
||||
const char *str;
|
||||
|
||||
va_copy(cp_args, args);
|
||||
str = va_arg(cp_args, const char *);
|
||||
va_end(cp_args);
|
||||
|
||||
ck_assert_int_eq(level, EINA_LOG_LEVEL_ERR);
|
||||
ck_assert_str_eq(fmt, "%s");
|
||||
ck_assert_str_eq(ctx->msg, str);
|
||||
ck_assert_str_eq(ctx->fnc, fnc);
|
||||
ctx->did = EINA_TRUE;
|
||||
|
||||
#ifdef SHOW_LOG
|
||||
eina_log_print_cb_stderr(d, level, file, fnc, line, fmt, NULL, args);
|
||||
#else
|
||||
(void)d;
|
||||
(void)file;
|
||||
(void)line;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
static Eina_Test_Inlist *
|
||||
_eina_test_inlist_build(int i)
|
||||
{
|
||||
|
@ -52,6 +89,10 @@ START_TEST(eina_inlist_simple)
|
|||
Eina_Test_Inlist *tmp;
|
||||
Eina_Test_Inlist *prev;
|
||||
int i = 0;
|
||||
#ifdef EINA_SAFETY_CHECKS
|
||||
Eina_Inlist *bkp;
|
||||
struct log_ctx ctx;
|
||||
#endif
|
||||
|
||||
fail_if(!eina_init());
|
||||
|
||||
|
@ -106,16 +147,142 @@ START_TEST(eina_inlist_simple)
|
|||
}
|
||||
|
||||
#ifdef EINA_SAFETY_CHECKS
|
||||
bkp = lst;
|
||||
eina_log_print_cb_set(_eina_test_safety_print_cb, &ctx);
|
||||
|
||||
#define TEST_MAGIC_SAFETY(fn, _msg) \
|
||||
ctx.msg = _msg; \
|
||||
ctx.fnc = fn; \
|
||||
ctx.did = EINA_FALSE
|
||||
|
||||
#ifdef SHOW_LOG
|
||||
fprintf(stderr, "you should have a safety check failure below:\n");
|
||||
#endif
|
||||
{
|
||||
Eina_Inlist *tmp2 = eina_inlist_remove(NULL, EINA_INLIST_GET(tmp));
|
||||
Eina_Inlist *tmp2;
|
||||
|
||||
TEST_MAGIC_SAFETY("eina_inlist_remove",
|
||||
"safety check failed: list == NULL");
|
||||
|
||||
tmp2 = eina_inlist_remove(NULL, EINA_INLIST_GET(tmp));
|
||||
fail_if(tmp2 != NULL);
|
||||
fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED);
|
||||
fail_unless(ctx.did);
|
||||
}
|
||||
|
||||
fprintf(stderr, "you should have a safety check failure below:\n");
|
||||
#ifdef SHOW_LOG
|
||||
fprintf(stderr, "you should have a safety check failure below:\n");
|
||||
#endif
|
||||
TEST_MAGIC_SAFETY("eina_inlist_remove",
|
||||
"safety check failed: item == NULL");
|
||||
lst = eina_inlist_remove(lst, NULL);
|
||||
fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED);
|
||||
fail_unless(ctx.did);
|
||||
|
||||
#ifdef SHOW_LOG
|
||||
fprintf(stderr, "you should have a safety check failure below:\n");
|
||||
#endif
|
||||
TEST_MAGIC_SAFETY("eina_inlist_append",
|
||||
"safety check failed: new_l == NULL");
|
||||
lst = eina_inlist_append(lst, NULL);
|
||||
fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED);
|
||||
fail_unless(ctx.did);
|
||||
|
||||
#ifdef SHOW_LOG
|
||||
fprintf(stderr, "you should have a safety check failure below:\n");
|
||||
#endif
|
||||
TEST_MAGIC_SAFETY("eina_inlist_append_relative",
|
||||
"safety check failed: new_l == NULL");
|
||||
lst = eina_inlist_append_relative(lst, NULL, NULL);
|
||||
fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED);
|
||||
fail_unless(ctx.did);
|
||||
|
||||
#ifdef SHOW_LOG
|
||||
fprintf(stderr, "you should have a safety check failure below:\n");
|
||||
#endif
|
||||
TEST_MAGIC_SAFETY("eina_inlist_prepend",
|
||||
"safety check failed: new_l == NULL");
|
||||
lst = eina_inlist_prepend(lst, NULL);
|
||||
fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED);
|
||||
fail_unless(ctx.did);
|
||||
|
||||
#ifdef SHOW_LOG
|
||||
fprintf(stderr, "you should have a safety check failure below:\n");
|
||||
#endif
|
||||
TEST_MAGIC_SAFETY("eina_inlist_prepend_relative",
|
||||
"safety check failed: new_l == NULL");
|
||||
lst = eina_inlist_prepend_relative(lst, NULL, NULL);
|
||||
fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED);
|
||||
fail_unless(ctx.did);
|
||||
|
||||
#ifdef SHOW_LOG
|
||||
fprintf(stderr, "you should have a safety check failure below:\n");
|
||||
#endif
|
||||
TEST_MAGIC_SAFETY("eina_inlist_find",
|
||||
"safety check failed: item == NULL");
|
||||
lst = eina_inlist_find(lst, NULL);
|
||||
fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED);
|
||||
fail_unless(ctx.did);
|
||||
|
||||
#ifdef SHOW_LOG
|
||||
fprintf(stderr, "you should have a safety check failure below:\n");
|
||||
#endif
|
||||
TEST_MAGIC_SAFETY("eina_inlist_demote",
|
||||
"safety check failed: list == NULL");
|
||||
lst = eina_inlist_demote(NULL, NULL);
|
||||
fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED);
|
||||
fail_unless(ctx.did);
|
||||
|
||||
#ifdef SHOW_LOG
|
||||
fprintf(stderr, "you should have a safety check failure below:\n");
|
||||
#endif
|
||||
TEST_MAGIC_SAFETY("eina_inlist_demote",
|
||||
"safety check failed: item == NULL");
|
||||
lst = eina_inlist_demote((void*)1L, NULL);
|
||||
fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED);
|
||||
fail_unless(ctx.did);
|
||||
lst = NULL;
|
||||
|
||||
#ifdef SHOW_LOG
|
||||
fprintf(stderr, "you should have a safety check failure below:\n");
|
||||
#endif
|
||||
TEST_MAGIC_SAFETY("eina_inlist_promote",
|
||||
"safety check failed: list == NULL");
|
||||
lst = eina_inlist_promote(NULL, NULL);
|
||||
fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED);
|
||||
fail_unless(ctx.did);
|
||||
|
||||
#ifdef SHOW_LOG
|
||||
fprintf(stderr, "you should have a safety check failure below:\n");
|
||||
#endif
|
||||
TEST_MAGIC_SAFETY("eina_inlist_promote",
|
||||
"safety check failed: item == NULL");
|
||||
lst = eina_inlist_promote((void*)1L, NULL);
|
||||
fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED);
|
||||
fail_unless(ctx.did);
|
||||
lst = NULL;
|
||||
|
||||
#ifdef SHOW_LOG
|
||||
fprintf(stderr, "you should have a safety check failure below:\n");
|
||||
#endif
|
||||
TEST_MAGIC_SAFETY("eina_inlist_sorted_insert",
|
||||
"safety check failed: item == NULL");
|
||||
lst = eina_inlist_sorted_insert(NULL, NULL, NULL);
|
||||
fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED);
|
||||
fail_unless(ctx.did);
|
||||
|
||||
#ifdef SHOW_LOG
|
||||
fprintf(stderr, "you should have a safety check failure below:\n");
|
||||
#endif
|
||||
TEST_MAGIC_SAFETY("eina_inlist_sorted_insert",
|
||||
"safety check failed: func == NULL");
|
||||
lst = eina_inlist_sorted_insert(NULL, (void*)1L, NULL);
|
||||
fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED);
|
||||
fail_unless(ctx.did);
|
||||
lst = NULL;
|
||||
|
||||
eina_log_print_cb_set(eina_log_print_cb_stderr, NULL);
|
||||
lst = bkp;
|
||||
#endif
|
||||
|
||||
tmp = EINA_INLIST_CONTAINER_GET(lst, Eina_Test_Inlist);
|
||||
|
|
Loading…
Reference in New Issue