From f06eedf3c339af6647fc216ca06f29de53831c70 Mon Sep 17 00:00:00 2001 From: Vivek Ellur Date: Mon, 9 Nov 2015 16:17:24 -0800 Subject: [PATCH] eina: add test case for eina list reverse iterator Summary: Added test case for eina_list_iterator_reversed_new function Signed-off-by: Vivek Ellur Reviewers: cedric Subscribers: cedric Differential Revision: https://phab.enlightenment.org/D3281 Signed-off-by: Cedric BAIL --- src/tests/eina/eina_test_iterator.c | 66 +++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/src/tests/eina/eina_test_iterator.c b/src/tests/eina/eina_test_iterator.c index 4c14dec..5c4b88d 100644 --- a/src/tests/eina/eina_test_iterator.c +++ b/src/tests/eina/eina_test_iterator.c @@ -287,6 +287,71 @@ START_TEST(eina_iterator_list_simple) } END_TEST +static Eina_Bool +eina_reverse_iterator_list_data_check(EINA_UNUSED const Eina_List *list, + int *data, + int *fdata) +{ + switch (*fdata) + { + case 0: fail_if(*data != 1337); break; + + case 1: fail_if(*data != 1); break; + + case 2: fail_if(*data != 42); break; + + case 3: fail_if(*data != 6); break; + + case 4: fail_if(*data != 9); break; + + case 5: fail_if(*data != 7); break; + + case 6: fail_if(*data != 81); break; + } + + (*fdata)++; + + return EINA_TRUE; +} + +START_TEST(eina_reverse_iterator_list_simple) +{ + Eina_List *list = NULL; + Eina_Iterator *it; + int data[] = { 6, 9, 42, 1, 7, 1337, 81, 1664 }; + int i = 0; + + eina_init(); + + list = eina_list_append(list, &data[0]); + fail_if(list == NULL); + + list = eina_list_prepend(list, &data[1]); + fail_if(list == NULL); + + list = eina_list_append(list, &data[2]); + fail_if(list == NULL); + + list = eina_list_append(list, &data[3]); + fail_if(list == NULL); + + list = eina_list_prepend(list, &data[4]); + fail_if(list == NULL); + + list = eina_list_append(list, &data[5]); + fail_if(list == NULL); + + list = eina_list_prepend(list, &data[6]); + fail_if(list == NULL); + + it = eina_list_iterator_reversed_new(list); + fail_if(!it); + + eina_iterator_foreach(it, EINA_EACH_CB(eina_reverse_iterator_list_data_check), &i); + eina_iterator_free(it); +} +END_TEST + typedef struct _Eina_Rbtree_Int Eina_Rbtree_Int; struct _Eina_Rbtree_Int { @@ -461,5 +526,6 @@ eina_test_iterator(TCase *tc) tcase_add_test(tc, eina_iterator_hash_simple); tcase_add_test(tc, eina_iterator_inlist_simple); tcase_add_test(tc, eina_iterator_list_simple); + tcase_add_test(tc, eina_reverse_iterator_list_simple); tcase_add_test(tc, eina_iterator_rbtree_simple); } -- 2.7.4