forked from enlightenment/efl
Add eina inlist tests suite, remove dead code and cleanup iterator.
SVN revision: 35302
This commit is contained in:
parent
280e9973e7
commit
5f783f52d8
|
@ -27,8 +27,8 @@ EAPI void * eina_inlist_find(void *in_list, void *in_item);
|
|||
|
||||
//typedef Eina_Bool (*Eina_Iterator_Func)(Eina_Inlist *l, void *data);
|
||||
|
||||
#define EINA_INLIST_ITER_NEXT(list, l) for (l = (Eina_Inlist *)list; l; l = l->next)
|
||||
#define EINA_INLIST_ITER_LAST(list, l) for (l = ((Eina_Inlist *)list)->last; l; l = l->prev)
|
||||
#define EINA_INLIST_ITER_NEXT(list, l) for (l = (void*)(Eina_Inlist *)list; l; l = (void*)((Eina_Inlist *)l)->next)
|
||||
#define EINA_INLIST_ITER_LAST(list, l) for (l = (void*)((Eina_Inlist *)list)->last; l; l = (void*)((Eina_Inlist *)l)->prev)
|
||||
|
||||
/** @} */
|
||||
|
||||
|
|
|
@ -96,16 +96,15 @@ EAPI void * eina_inlist_prepend_relative(void *in_list, void *in_item,
|
|||
relative->prev = new_l;
|
||||
if (new_l->prev) {
|
||||
new_l->prev->next = new_l;
|
||||
if (!new_l->next)
|
||||
list->last = new_l;
|
||||
/* new_l->next could not be NULL, as it was set to 'relative' */
|
||||
assert(new_l->next);
|
||||
return list;
|
||||
} else {
|
||||
if (!new_l->next)
|
||||
new_l->last = new_l;
|
||||
else {
|
||||
new_l->last = list->last;
|
||||
list->last = NULL;
|
||||
}
|
||||
/* new_l->next could not be NULL, as it was set to 'relative' */
|
||||
assert(new_l->next);
|
||||
|
||||
new_l->last = list->last;
|
||||
list->last = NULL;
|
||||
return new_l;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,9 @@ eina_suite.c \
|
|||
eina_test_stringshare.c \
|
||||
eina_test_array.c \
|
||||
eina_test_error.c \
|
||||
eina_test_magic.c
|
||||
eina_test_magic.c \
|
||||
eina_test_inlist.c
|
||||
|
||||
eina_suite_LDADD = @CHECK_LIBS@ $(top_builddir)/src/lib/libeina.la
|
||||
|
||||
EXTRA_DIST = eina_suite.h
|
||||
|
|
|
@ -12,6 +12,7 @@ static const Eina_Test_Case etc[] = {
|
|||
{ "String Share", eina_test_stringshare },
|
||||
{ "Error", eina_test_error },
|
||||
{ "Magic", eina_test_magic },
|
||||
{ "Inlist", eina_test_inlist },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
|
|
|
@ -11,5 +11,6 @@ void eina_test_stringshare(TCase *tc);
|
|||
void eina_test_array(TCase *tc);
|
||||
void eina_test_error(TCase *tc);
|
||||
void eina_test_magic(TCase *tc);
|
||||
void eina_test_inlist(TCase *tc);
|
||||
|
||||
#endif /* EINA_SUITE_H_ */
|
||||
|
|
|
@ -0,0 +1,94 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
#include "eina_suite.h"
|
||||
#include "eina_inlist.h"
|
||||
|
||||
typedef struct _Eina_Test_Inlist Eina_Test_Inlist;
|
||||
struct _Eina_Test_Inlist
|
||||
{
|
||||
Eina_Inlist list;
|
||||
int i;
|
||||
};
|
||||
|
||||
static Eina_Test_Inlist*
|
||||
_eina_test_inlist_build(int i)
|
||||
{
|
||||
Eina_Test_Inlist *tmp;
|
||||
|
||||
tmp = malloc(sizeof(Eina_Test_Inlist));
|
||||
fail_if(!tmp);
|
||||
tmp->i = i;
|
||||
|
||||
return tmp;
|
||||
}
|
||||
#include <stdio.h>
|
||||
START_TEST(eina_inlist_simple)
|
||||
{
|
||||
Eina_Test_Inlist *lst = NULL;
|
||||
Eina_Test_Inlist *tmp;
|
||||
Eina_Test_Inlist *prev;
|
||||
int i = 0;
|
||||
|
||||
tmp = _eina_test_inlist_build(42);
|
||||
lst = eina_inlist_append(lst, tmp);
|
||||
fail_if(!lst);
|
||||
|
||||
lst = eina_inlist_remove(lst, tmp);
|
||||
lst = eina_inlist_prepend(lst, tmp);
|
||||
|
||||
tmp = _eina_test_inlist_build(1664);
|
||||
lst = eina_inlist_append_relative(lst, tmp, lst);
|
||||
fail_if(!lst);
|
||||
fail_if(lst->i != 42);
|
||||
|
||||
prev = tmp;
|
||||
tmp = _eina_test_inlist_build(3227);
|
||||
lst = eina_inlist_prepend_relative(lst, tmp, prev);
|
||||
fail_if(!lst);
|
||||
fail_if(lst->i != 42);
|
||||
|
||||
lst = eina_inlist_remove(lst, tmp);
|
||||
|
||||
lst = eina_inlist_append_relative(lst, tmp, lst);
|
||||
lst = eina_inlist_remove(lst, tmp);
|
||||
|
||||
lst = eina_inlist_prepend_relative(lst, tmp, lst);
|
||||
|
||||
tmp = _eina_test_inlist_build(27);
|
||||
lst = eina_inlist_prepend_relative(lst, tmp, NULL);
|
||||
|
||||
tmp = _eina_test_inlist_build(81);
|
||||
lst = eina_inlist_append_relative(lst, tmp, NULL);
|
||||
|
||||
EINA_INLIST_ITER_NEXT(lst, tmp)
|
||||
{
|
||||
switch (i)
|
||||
{
|
||||
case 0: fail_if(tmp->i != 27); break;
|
||||
case 1: fail_if(tmp->i != 3227); break;
|
||||
case 2: fail_if(tmp->i != 42); break;
|
||||
case 3: fail_if(tmp->i != 1664); break;
|
||||
case 4: fail_if(tmp->i != 81); break;
|
||||
}
|
||||
|
||||
++i;
|
||||
}
|
||||
|
||||
eina_inlist_remove(NULL, tmp);
|
||||
lst = eina_inlist_remove(lst, NULL);
|
||||
|
||||
tmp = eina_inlist_find(lst, prev);
|
||||
eina_inlist_remove(lst, tmp);
|
||||
tmp = eina_inlist_find(lst, tmp);
|
||||
fail_if(tmp != NULL);
|
||||
|
||||
while (lst)
|
||||
lst = eina_inlist_remove(lst, lst);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
void
|
||||
eina_test_inlist(TCase *tc)
|
||||
{
|
||||
tcase_add_test(tc, eina_inlist_simple);
|
||||
}
|
Loading…
Reference in New Issue