Page MenuHomePhabricator

Simple genlist group test

File Metadata

Author
DaveMDS
Created
Apr 14 2018, 9:55 AM

Simple genlist group test

/* 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(Elm_Object_Item *git)
{
Elm_Object_Item *it;
int i;
/* 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);
}
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, NULL, git, 0, NULL, NULL);
verify_group_api(git);
}