Page MenuHomePhabricator

New genlist group test (sane and insane)

File Metadata

Author
DaveMDS
Created
Apr 20 2018, 11:25 AM

New genlist group test (sane and insane)

/* gcc -o test_gl_group test_gl_group.c `pkg-config --libs --cflags elementary` */
#define EFL_ACCESS_BETA
#define EFL_ACCESS_PROTECTED
#include <Elementary.h>
static Evas_Object *win, *genlist;
static Elm_Gen_Item_Class itc;
static void
ck_assert_ptr_ne(void *p1, void *p2)
{
if (p1 == p2)
printf("FAILED\n");
else
printf("OK\n");
}
static void
ck_assert_ptr_eq(void *p1, void *p2)
{
if (p1 != p2)
printf("FAILED\n");
else
printf("OK\n");
}
static void
verify_group_api_insane(Elm_Object_Item *git)
{
Elm_Object_Item *it;
int i;
printf("\nINSANE TEST\n");
/* the last item is the group item
* this is not consistent with the visual layout but this is consistent with behavior since 1.0
*/
it = elm_genlist_last_item_get(genlist);
printf("test 1: ");
ck_assert_ptr_ne(it, NULL);
printf("test 2: ");
ck_assert_ptr_eq(it, git);
/* assert that the last item is actually the last item */
it = elm_genlist_item_next_get(git);
printf("test 3: ");
ck_assert_ptr_eq(it, NULL);
/* assert that the other items added to the list exist */
it = elm_genlist_item_prev_get(git);
printf("test 4: ");
ck_assert_ptr_ne(it, NULL);
/* assert that the parent of this item is the group item */
printf("test 5: ");
ck_assert_ptr_eq(elm_genlist_item_parent_get(it), git);
/* check that the first item in the list is a normal item */
it = elm_genlist_first_item_get(genlist);
printf("test 6: ");
ck_assert_ptr_eq(elm_genlist_item_parent_get(it), git);
/* verify list consistency */
for (i = 0; i < 9; i++)
{
it = elm_genlist_item_next_get(it);
printf("test 7: ");
ck_assert_ptr_eq(elm_genlist_item_parent_get(it), git);
}
it = elm_genlist_item_next_get(it);
/* verify once again that we have arrived at the group item */
printf("test 8: ");
ck_assert_ptr_eq(it, git);
}
static void
verify_group_api_sane(Elm_Object_Item *git)
{
Elm_Object_Item *it, *first_child;
int i;
printf("\nSANE TEST\n");
/* test first item is the group item */
it = elm_genlist_first_item_get(genlist);
printf("test 1: ");
ck_assert_ptr_eq(it, git);
printf("test 2: ");
ck_assert_ptr_eq(elm_object_item_data_get(it), NULL);
/* test last item is the last child item */
it = elm_genlist_last_item_get(genlist);
printf("test 3: ");
ck_assert_ptr_eq(elm_object_item_data_get(it), (void*)(uintptr_t)10);
printf("test 4: ");
it = elm_genlist_item_next_get(it);
ck_assert_ptr_eq(it, NULL);
/* test next item of group item is it's first child */
first_child = elm_genlist_item_next_get(git);
printf("test 5: ");
ck_assert_ptr_eq(elm_object_item_data_get(first_child), (void*)(uintptr_t)1);
/* test next item of first child is second child */
it = elm_genlist_item_next_get(first_child);
printf("test 6: ");
ck_assert_ptr_eq(elm_object_item_data_get(it), (void*)(uintptr_t)2);
/* test parent item of first, second and last child */
it = elm_genlist_item_parent_get(first_child);
printf("test 7: ");
ck_assert_ptr_eq(it, git);
printf("test 8: ");
it = elm_genlist_item_next_get(first_child);
it = elm_genlist_item_parent_get(it);
ck_assert_ptr_eq(it, git);
printf("test 9: ");
it = elm_genlist_last_item_get(genlist);
it = elm_genlist_item_parent_get(it);
ck_assert_ptr_eq(it, git);
}
int main(int argc, char **argv)
{
Elm_Object_Item *git;
int i;
fprintf(stderr, "Running on EFL: ");
system("pkg-config --modversion elementary");
elm_init(argc, argv);
win = elm_win_add(NULL, "genlist", ELM_WIN_BASIC);
genlist = elm_genlist_add(win);
git = elm_genlist_item_append(genlist, &itc, NULL, NULL, ELM_GENLIST_ITEM_GROUP, NULL, NULL);
for (i = 0; i < 10; i++)
elm_genlist_item_append(genlist, &itc, (void*)(uintptr_t)i+1, git, 0, NULL, NULL);
verify_group_api_insane(git);
verify_group_api_sane(git);
}

This is the test used to prove that T5938 is wrong.