From 0fbf1f87e964cfbd52990a0ee3dedbfab80b0a79 Mon Sep 17 00:00:00 2001 From: Marcel Hollerbach Date: Fri, 29 Mar 2019 08:14:05 +0100 Subject: [PATCH] elm: here comes a new testsuite We have two elementary test suite, what is more obvious than just adding a third one! This testsuite aims for establishing a standard behaviour for the interfaces we have added in efl now. This first part here brings a few testcases for Efl.Pack which are currently only passing for Efl.Ui.Box. More widgets will be added afterwards. The testcases themself are not defined after what worked or did not work, but rather what made sence (in my opinion ^_^). ref T7767 Reviewed-by: Mike Blumenkrantz Differential Revision: https://phab.enlightenment.org/D8518 --- src/tests/elementary/meson.build | 1 + src/tests/elementary/spec/efl_test_container.c | 56 ++++ src/tests/elementary/spec/efl_test_pack.c | 348 ++++++++++++++++++++ src/tests/elementary/spec/efl_test_pack_linear.c | 396 +++++++++++++++++++++++ src/tests/elementary/spec/efl_ui_spec_suite.c | 66 ++++ src/tests/elementary/spec/efl_ui_spec_suite.h | 26 ++ src/tests/elementary/spec/generator.py | 66 ++++ src/tests/elementary/spec/meson.build | 32 ++ 8 files changed, 991 insertions(+) create mode 100644 src/tests/elementary/spec/efl_test_container.c create mode 100644 src/tests/elementary/spec/efl_test_pack.c create mode 100644 src/tests/elementary/spec/efl_test_pack_linear.c create mode 100644 src/tests/elementary/spec/efl_ui_spec_suite.c create mode 100644 src/tests/elementary/spec/efl_ui_spec_suite.h create mode 100755 src/tests/elementary/spec/generator.py create mode 100644 src/tests/elementary/spec/meson.build diff --git a/src/tests/elementary/meson.build b/src/tests/elementary/meson.build index 51120be..edea953 100644 --- a/src/tests/elementary/meson.build +++ b/src/tests/elementary/meson.build @@ -167,3 +167,4 @@ test('efl-ui-suite', efl_ui_suite, install_data(files(['testdiff.diff', 'testfile-windows.txt', 'testfile-withblanks.txt', 'testfile.txt']), install_dir : join_paths(dir_data, 'elementary') ) +subdir('spec') diff --git a/src/tests/elementary/spec/efl_test_container.c b/src/tests/elementary/spec/efl_test_container.c new file mode 100644 index 0000000..ecef9b1 --- /dev/null +++ b/src/tests/elementary/spec/efl_test_container.c @@ -0,0 +1,56 @@ +#ifdef HAVE_CONFIG_H +# include "elementary_config.h" +#endif + +#include +#include "efl_ui_spec_suite.h" +#include "suite_helpers.h" + +void +efl_test_container_content_equal(Efl_Ui_Widget **wid, unsigned int len) +{ + Efl_Ui_Widget *c; + Eina_Iterator *iter; + unsigned int i; + Eina_List *tmp = NULL; + + ck_assert_int_eq(efl_content_count(widget), len); + iter = efl_content_iterate(widget); + EINA_ITERATOR_FOREACH(iter, c) + { + ck_assert_ptr_eq(eina_list_data_find(tmp, c), NULL); + tmp = eina_list_append(tmp, c); + } + eina_iterator_free(iter); + for (i = 0; i < len; ++i) + { + ck_assert_ptr_ne(eina_list_data_find(tmp, wid[i]), NULL); + tmp = eina_list_remove(tmp, wid[i]); + } + ck_assert_int_eq(eina_list_count(tmp), 0); +} + +typedef struct { + Eina_Bool *flag; + void *expected_event_data; +} Efl_Container_Event_Content; + +static void +_evt_called(void *data, const Efl_Event *ev) +{ + Efl_Container_Event_Content *content = data; + + *content->flag = EINA_TRUE; + ck_assert_ptr_eq(content->expected_event_data, ev->info); + efl_event_callback_del(ev->object, ev->desc, _evt_called, data); + free(data); +} + +void +efl_test_container_expect_evt_content_added(Efl_Ui_Widget *widget, const Efl_Event_Description *ev, Eina_Bool *flag, void *event_data) +{ + Efl_Container_Event_Content *c = calloc(1, sizeof(Efl_Container_Event_Content)); + c->flag = flag; + c->expected_event_data = event_data; + efl_event_callback_add(widget, ev, _evt_called, c); +} diff --git a/src/tests/elementary/spec/efl_test_pack.c b/src/tests/elementary/spec/efl_test_pack.c new file mode 100644 index 0000000..626e3e9 --- /dev/null +++ b/src/tests/elementary/spec/efl_test_pack.c @@ -0,0 +1,348 @@ +#ifdef HAVE_CONFIG_H +# include "elementary_config.h" +#endif + +#include +#include "efl_ui_spec_suite.h" +#include "suite_helpers.h" + +/* + In general: + - If a subobject is deleted the box simply forgets about it. Never return this element again container. +*/ + +EFL_START_TEST(base2) +{ + ck_assert(win); + ck_assert(widget); +} +EFL_END_TEST + +static void +_setup_std_pack(Efl_Ui_Widget *wid[3]) +{ + unsigned int i; + + for (i = 0; i < 3; ++i) + { + wid[i] = efl_add(WIDGET_CLASS, widget); + ck_assert_int_eq(efl_pack(widget, wid[i]), EINA_TRUE); + efl_gfx_entity_visible_set(widget, EINA_TRUE); + } +} + +/* + pack_clear function: + - each element must be deleted after the call + - the container must have 0 contents after the call + - the call must return true even if the container is empty +*/ + +EFL_START_TEST(pack_clear1) +{ + Efl_Ui_Widget *wid[3]; + unsigned int i; + + _setup_std_pack(wid); + + for (i = 0; i < sizeof(wid)/sizeof(Efl_Ui_Widget*); ++i) + { + efl_wref_add(wid[i], &wid[i]); + } + + ck_assert_int_eq(efl_pack_clear(widget), EINA_TRUE); + + for (i = 0; i < sizeof(wid)/sizeof(Efl_Ui_Widget*); ++i) + { + ck_assert_ptr_eq(wid[i], NULL); + } + + efl_test_container_content_equal(NULL, 0); +} +EFL_END_TEST + +EFL_START_TEST(pack_clear2) +{ + Efl_Ui_Widget *wid[3]; + + _setup_std_pack(wid); + + ck_assert_int_eq(efl_pack_clear(widget), EINA_TRUE); + ck_assert_int_eq(efl_pack_clear(widget), EINA_TRUE); + ck_assert_int_eq(efl_pack_clear(widget), EINA_TRUE); + ck_assert_int_eq(efl_pack_clear(widget), EINA_TRUE); + ck_assert_int_eq(efl_pack_clear(widget), EINA_TRUE); +} +EFL_END_TEST + +/* + unpack_all function: + - each element must have exactly one reference after the call + - the container must have 0 contents after the call + - the call must return true even if the container is empty +*/ + +EFL_START_TEST(unpack_all1) +{ + Efl_Ui_Widget *wid[3]; + unsigned int i; + + _setup_std_pack(wid); + + ck_assert_int_eq(efl_pack_unpack_all(widget), EINA_TRUE); + + for (i = 0; i < sizeof(wid)/sizeof(Efl_Ui_Widget*); ++i) + { + ck_assert_int_eq(efl_ref_count(wid[i]), 1); + } + efl_test_container_content_equal(NULL, 0); +} +EFL_END_TEST + +EFL_START_TEST(unpack_all2) +{ + Efl_Ui_Widget *wid[3]; + unsigned int i; + + _setup_std_pack(wid); + + ck_assert_int_eq(efl_pack_unpack_all(widget), EINA_TRUE); + ck_assert_int_eq(efl_pack_clear(widget), EINA_TRUE); + + for (i = 0; i < sizeof(wid)/sizeof(Efl_Ui_Widget*); ++i) + { + ck_assert_int_eq(efl_ref_count(wid[i]), 1); + } + efl_test_container_content_equal(NULL, 0); +} +EFL_END_TEST + +/* + unpack function: + - the element must have exactly one reference after the call + - the container must have one content less after the call + - the widget parent must be different from the parent + - unpacking something invalid can return EINA_FALSE but must not print an error +*/ + +EFL_START_TEST(unpack1) +{ + Efl_Ui_Widget *wid[3]; + _setup_std_pack(wid); + + ck_assert_int_eq(efl_pack_unpack(widget, wid[2]), EINA_TRUE); + ck_assert_ptr_ne(efl_ui_widget_parent_get(wid[2]), widget); + ck_assert_int_eq(efl_ref_count(wid[2]), 1); + efl_test_container_content_equal(wid, 2); +} +EFL_END_TEST + +EFL_START_TEST(unpack2) +{ + Efl_Ui_Widget *wid[3]; + _setup_std_pack(wid); + + ck_assert_int_eq(efl_pack_unpack(widget, wid[0]), EINA_TRUE); + ck_assert_int_eq(efl_pack(widget, wid[0]), EINA_TRUE); + ck_assert_int_eq(efl_pack_unpack(widget, wid[0]), EINA_TRUE); + ck_assert_int_eq(efl_pack(widget, wid[0]), EINA_TRUE); + + efl_test_container_content_equal(wid, 3); +} +EFL_END_TEST + +EFL_START_TEST(unpack3) +{ + Efl_Ui_Widget *wid[3], *invalid; + _setup_std_pack(wid); + + invalid = efl_add(WIDGET_CLASS, win); + ck_assert_int_eq(efl_pack_unpack(widget, wid[2]), EINA_TRUE); + EXPECT_ERROR_START; + ck_assert_int_eq(efl_pack_unpack(widget, wid[2]), EINA_FALSE); + EXPECT_ERROR_END; + EXPECT_ERROR_START; + ck_assert_int_eq(efl_pack_unpack(widget, wid[2]), EINA_FALSE); + EXPECT_ERROR_END; + EXPECT_ERROR_START; + ck_assert_int_eq(efl_pack_unpack(widget, (Eo*)0x111), EINA_FALSE); + EXPECT_ERROR_END; + EXPECT_ERROR_START; + ck_assert_int_eq(efl_pack_unpack(widget, invalid), EINA_FALSE); + EXPECT_ERROR_END; + efl_test_container_content_equal(wid, 2); +} +EFL_END_TEST + +/* + pack function: + - element must be added to the content of the container + - elements widget_parent must be the container + - double adding a widdget must error + - adding something invalid must error +*/ + +EFL_START_TEST(pack1) +{ + Efl_Ui_Widget *wid[3]; + unsigned int i; + + _setup_std_pack(wid); + + for (i = 0; i < sizeof(wid)/sizeof(Efl_Ui_Widget*); ++i) + { + ck_assert_int_eq(efl_ref_count(wid[i]), 1); + ck_assert_ptr_eq(efl_ui_widget_parent_get(wid[i]), widget); + } + + efl_test_container_content_equal(wid, 3); +} +EFL_END_TEST + +EFL_START_TEST(pack2) +{ + Efl_Ui_Widget *wid[3]; + _setup_std_pack(wid); + + EXPECT_ERROR_START; + ck_assert_int_eq(efl_pack(widget, wid[0]), EINA_FALSE); + EXPECT_ERROR_END; + efl_test_container_content_equal(wid, 3); +} +EFL_END_TEST + +EFL_START_TEST(pack3) +{ + Efl_Ui_Widget *wid[3]; + _setup_std_pack(wid); + + EXPECT_ERROR_START; + ck_assert_int_eq(efl_pack(widget, (Eo*)0x111F), EINA_FALSE); + EXPECT_ERROR_END; + EXPECT_ERROR_START; + ck_assert_int_eq(efl_pack(widget, widget), EINA_FALSE); + EXPECT_ERROR_END; + EXPECT_ERROR_START; + ck_assert_int_eq(efl_pack(widget, NULL), EINA_FALSE); + EXPECT_ERROR_END; + efl_test_container_content_equal(wid, 3); +} +EFL_END_TEST + +EFL_START_TEST(pack_align) +{ +#define TUPLE_CHECK(H,V,rh,rv) \ + do { \ + double v, h; \ + efl_pack_align_set(widget, H, V); \ + efl_pack_align_get(widget, &h, &v); \ + ck_assert(v == rv); \ + ck_assert(h == rh); \ + } while(0); + + TUPLE_CHECK( 1.0, 1.0, 1.0, 1.0); + TUPLE_CHECK( 0.0, 0.0, 0.0, 0.0); + TUPLE_CHECK(- 1.0, - 1.0, -1.0, -1.0); + TUPLE_CHECK(-42.0, -42.0, -1.0, -1.0); + TUPLE_CHECK( 42.0, 42.0, 1.0, 1.0); + TUPLE_CHECK(-42.0, 42.0, -1.0, 1.0); + TUPLE_CHECK( 42.0, -42.0, 1.0, -1.0); +#undef TUPLE_CHECK +} +EFL_END_TEST + +EFL_START_TEST(pack_padding) +{ +#define TUPLE_CHECK(H, V, rh, rv, S, rs) \ + do { \ + double v, h; \ + Eina_Bool r; \ + efl_pack_padding_set(widget, H, V, S); \ + efl_pack_padding_get(widget, &h, &v, &r); \ + ck_assert(v == rv); \ + ck_assert(h == rh); \ + ck_assert_int_eq(r, S); \ + } while(0); + + TUPLE_CHECK( 0.0, 0.0, 0.0, 0.0, EINA_TRUE, EINA_TRUE); + TUPLE_CHECK( -1.0, -123.0, 0.0, 0.0, EINA_FALSE, EINA_FALSE); + TUPLE_CHECK( -1.0, 123.0, 0.0, 123.0, EINA_FALSE, EINA_FALSE); +#undef TUPLE_CHECK +} +EFL_END_TEST + +EFL_START_TEST(evt_content_added) +{ + Eina_Bool called = EINA_TRUE; + Efl_Ui_Widget *wid = efl_add(WIDGET_CLASS, win); + efl_test_container_expect_evt_content_added(widget, EFL_CONTAINER_EVENT_CONTENT_ADDED, &called, wid); + efl_pack(widget, wid); + ck_assert_int_eq(called, EINA_TRUE); +} +EFL_END_TEST + +EFL_START_TEST(evt_content_removed) +{ + Eina_Bool called = EINA_TRUE; + Efl_Ui_Widget *wid[3]; + + _setup_std_pack(wid); + + efl_test_container_expect_evt_content_added(widget, EFL_CONTAINER_EVENT_CONTENT_REMOVED, &called, wid[1]); + efl_pack_unpack(widget, wid[1]); + ck_assert_int_eq(called, EINA_TRUE); +} +EFL_END_TEST + +EFL_START_TEST(child_killed) +{ + Efl_Ui_Widget *wid[3]; + _setup_std_pack(wid); + + efl_wref_add(wid[0], &wid[0]); + efl_del(wid[0]); + efl_test_container_content_equal(&wid[1], 2); + ck_assert_ptr_eq(wid[0], NULL); +} +EFL_END_TEST + +EFL_START_TEST(container_killed) +{ + Efl_Ui_Widget *wid[3]; + unsigned int i = 0; + + _setup_std_pack(wid); + + for (i = 0; i < sizeof(wid)/sizeof(Efl_Ui_Widget*); ++i) + { + efl_wref_add(wid[i], &wid[i]); + } + efl_del(widget); + for (i = 0; i < sizeof(wid)/sizeof(Efl_Ui_Widget*); ++i) + { + ck_assert_ptr_eq(wid[i], NULL); + } +} +EFL_END_TEST + +void +efl_pack_behavior_test(TCase *tc) +{ + tcase_add_test(tc, base2); + tcase_add_test(tc, pack_clear1); + tcase_add_test(tc, pack_clear2); + tcase_add_test(tc, unpack_all1); + tcase_add_test(tc, unpack_all2); + tcase_add_test(tc, unpack1); + tcase_add_test(tc, unpack2); + tcase_add_test(tc, unpack3); + tcase_add_test(tc, pack1); + tcase_add_test(tc, pack2); + tcase_add_test(tc, pack3); + tcase_add_test(tc, pack_align); + tcase_add_test(tc, pack_padding); + tcase_add_test(tc, evt_content_added); + tcase_add_test(tc, evt_content_removed); + tcase_add_test(tc, child_killed); + tcase_add_test(tc, container_killed); +} diff --git a/src/tests/elementary/spec/efl_test_pack_linear.c b/src/tests/elementary/spec/efl_test_pack_linear.c new file mode 100644 index 0000000..cf85f91 --- /dev/null +++ b/src/tests/elementary/spec/efl_test_pack_linear.c @@ -0,0 +1,396 @@ +#ifdef HAVE_CONFIG_H +# include "elementary_config.h" +#endif + +#include +#include "efl_ui_spec_suite.h" +#include "suite_helpers.h" +#include + +static void +_fill_array(Efl_Ui_Widget *wid[3]) +{ + for (int i = 0; i < 3; ++i) + { + wid[i] = efl_add(WIDGET_CLASS, win); + } +} + +static void +_ordering_equals(Efl_Ui_Widget **wid, unsigned int len) +{ + for (unsigned int i = 0; i < len; ++i) + { + ck_assert_ptr_eq(efl_pack_content_get(widget, i), wid[i]); + } + efl_test_container_content_equal(wid, len); +} + +EFL_START_TEST(pack_begin1) +{ + Efl_Ui_Widget *wid[3]; + Efl_Ui_Widget *inv = efl_add(WIDGET_CLASS, win); + + _fill_array(wid); + + for (int i = 2; i >= 0; i--) + { + efl_pack_begin(widget, wid[i]); + ck_assert_ptr_eq(efl_ui_widget_parent_get(wid[i]), widget); + } + _ordering_equals(wid, 3); + efl_pack_begin(widget, inv); + ck_assert_ptr_eq(efl_pack_content_get(widget, 0), inv); + Efl_Ui_Widget *wid2[] = {inv, wid[0], wid[1], wid[2]}; + _ordering_equals(wid2, 4); +} +EFL_END_TEST + +EFL_START_TEST(pack_begin2) +{ + Efl_Ui_Widget *wid[3]; + + _fill_array(wid); + + for (int i = 2; i >= 0; i--) + { + efl_pack_begin(widget, wid[i]); + ck_assert_ptr_eq(efl_ui_widget_parent_get(wid[i]), widget); + } + + EXPECT_ERROR_START; + ck_assert_int_eq(efl_pack_begin(widget, wid[0]), EINA_FALSE); + EXPECT_ERROR_END; + _ordering_equals(wid, 3); +} +EFL_END_TEST + +EFL_START_TEST(pack_end1) +{ + Efl_Ui_Widget *wid[3]; + Efl_Ui_Widget *inv = efl_add(WIDGET_CLASS, win); + + _fill_array(wid); + + for (int i = 0; i < 3; i++) + { + efl_pack_end(widget, wid[i]); + ck_assert_ptr_eq(efl_ui_widget_parent_get(wid[i]), widget); + } + + _ordering_equals(wid, 3); + efl_pack_end(widget, inv); + ck_assert_ptr_eq(efl_pack_content_get(widget, 3), inv); + Efl_Ui_Widget *wid2[] = {wid[0], wid[1], wid[2], inv}; + _ordering_equals(wid2, 4); +} +EFL_END_TEST + +EFL_START_TEST(pack_end2) +{ + Efl_Ui_Widget *wid[3]; + + _fill_array(wid); + + for (int i = 0; i < 3; i++) + { + efl_pack_end(widget, wid[i]); + ck_assert_ptr_eq(efl_ui_widget_parent_get(wid[i]), widget); + } + + EXPECT_ERROR_START; + ck_assert_int_eq(efl_pack_end(widget, wid[0]), EINA_FALSE); + EXPECT_ERROR_END; + _ordering_equals(wid, 3); +} +EFL_END_TEST + +EFL_START_TEST(pack_before1) +{ + Efl_Ui_Widget *wid[3]; + Efl_Ui_Widget *inv = efl_add(WIDGET_CLASS, win); + + _fill_array(wid); + + for (int i = 0; i < 3; i++) + efl_pack_end(widget, wid[i]); + + ck_assert_int_eq(efl_pack_before(widget, inv, wid[0]), EINA_TRUE); + ck_assert_ptr_eq(efl_ui_widget_parent_get(inv), widget); + Efl_Ui_Widget *wid2[] = {inv, wid[0], wid[1], wid[2]}; + _ordering_equals(wid2, 4); + efl_pack_unpack(widget, inv); + + ck_assert_int_eq(efl_pack_before(widget, inv, wid[2]), EINA_TRUE); + ck_assert_ptr_eq(efl_ui_widget_parent_get(inv), widget); + Efl_Ui_Widget *wid3[] = {wid[0], wid[1], inv, wid[2]}; + _ordering_equals(wid3, 4); +} +EFL_END_TEST + +EFL_START_TEST(pack_before2) +{ + Efl_Ui_Widget *wid[3]; + Efl_Ui_Widget *inv = efl_add(WIDGET_CLASS, win); + + _fill_array(wid); + + for (int i = 0; i < 3; i++) + efl_pack_end(widget, wid[i]); + + ck_assert_int_eq(efl_pack_before(widget, inv, wid[0]), EINA_TRUE); + ck_assert_ptr_eq(efl_ui_widget_parent_get(inv), widget); + Efl_Ui_Widget *wid2[] = {inv, wid[0], wid[1], wid[2]}; + _ordering_equals(wid2, 4); + + EXPECT_ERROR_START; + ck_assert_int_eq(efl_pack_before(widget, inv, wid[2]), EINA_FALSE); + EXPECT_ERROR_END; +} +EFL_END_TEST + +EFL_START_TEST(pack_after1) +{ + Efl_Ui_Widget *wid[3]; + Efl_Ui_Widget *inv = efl_add(WIDGET_CLASS, win); + + _fill_array(wid); + + for (int i = 0; i < 3; i++) + efl_pack_end(widget, wid[i]); + + ck_assert_int_eq(efl_pack_after(widget, inv, wid[0]), EINA_TRUE); + ck_assert_ptr_eq(efl_ui_widget_parent_get(inv), widget); + Efl_Ui_Widget *wid2[] = {wid[0], inv, wid[1], wid[2]}; + _ordering_equals(wid2, 4); + efl_pack_unpack(widget, inv); + + ck_assert_int_eq(efl_pack_after(widget, inv, wid[2]), EINA_TRUE); + ck_assert_ptr_eq(efl_ui_widget_parent_get(inv), widget); + Efl_Ui_Widget *wid3[] = {wid[0], wid[1], wid[2], inv}; + _ordering_equals(wid3, 4); +} +EFL_END_TEST + +EFL_START_TEST(pack_after2) +{ + Efl_Ui_Widget *wid[3]; + Efl_Ui_Widget *inv = efl_add(WIDGET_CLASS, win); + + _fill_array(wid); + + for (int i = 0; i < 3; i++) + efl_pack_end(widget, wid[i]); + + ck_assert_int_eq(efl_pack_after(widget, inv, wid[0]), EINA_TRUE); + ck_assert_ptr_eq(efl_ui_widget_parent_get(inv), widget); + Efl_Ui_Widget *wid2[] = {wid[0], inv, wid[1], wid[2]}; + _ordering_equals(wid2, 4); + + EXPECT_ERROR_START; + ck_assert_int_eq(efl_pack_after(widget, inv, wid[2]), EINA_FALSE); + EXPECT_ERROR_END; +} +EFL_END_TEST + +EFL_START_TEST(pack_at1) +{ + for (int x = -3; x < 3; ++x) + { + Efl_Ui_Widget *wid[3]; + Efl_Ui_Widget *inv = efl_add(WIDGET_CLASS, win); + unsigned int i; + + _fill_array(wid); + for (int i = 0; i < 3; i++) + efl_pack_end(widget, wid[i]); + + efl_pack_at(widget, inv, x); + ck_assert_ptr_eq(efl_ui_widget_parent_get(inv), widget); + + for (i = 0; i < 4; ++i) + { + Efl_Ui_Widget *w = efl_pack_content_get(widget, i); + unsigned int place_to_expect_inv = (3 + x) % 3; + if (i == place_to_expect_inv) + ck_assert_ptr_eq(w, inv); + else if (i < place_to_expect_inv) + ck_assert_ptr_eq(w, wid[i]); + else if (i > place_to_expect_inv) + ck_assert_ptr_eq(w, wid[i - 1]); + } + efl_pack_clear(widget); + } +} +EFL_END_TEST + +EFL_START_TEST(pack_at2) +{ + for (int x = -3; x < 3; ++x) + { + Efl_Ui_Widget *wid[3]; + Efl_Ui_Widget *inv = efl_add(WIDGET_CLASS, win); + unsigned int i; + + _fill_array(wid); + for (int i = 0; i < 3; i++) + efl_pack_end(widget, wid[i]); + + ck_assert_int_eq(efl_pack_at(widget, inv, x), EINA_TRUE); + ck_assert_ptr_eq(efl_ui_widget_parent_get(inv), widget); + + EXPECT_ERROR_START; + ck_assert_int_eq(efl_pack_at(widget, inv, x - 1), EINA_FALSE); + EXPECT_ERROR_END; + + for (i = 0; i < 4; ++i) + { + Efl_Ui_Widget *w = efl_pack_content_get(widget, i); + unsigned int place_to_expect_inv = (3 + x) % 3; + if (i == place_to_expect_inv) + ck_assert_ptr_eq(w, inv); + else if (i < place_to_expect_inv) + ck_assert_ptr_eq(w, wid[i]); + else if (i > place_to_expect_inv) + ck_assert_ptr_eq(w, wid[i - 1]); + } + efl_pack_clear(widget); + } +} +EFL_END_TEST + + +EFL_START_TEST(pack_at3) +{ + Efl_Ui_Widget *wid[3]; + Efl_Ui_Widget *inv = efl_add(WIDGET_CLASS, win); + Efl_Ui_Widget *inv2 = efl_add(WIDGET_CLASS, win); + + _fill_array(wid); + for (int i = 0; i < 3; i++) + efl_pack_end(widget, wid[i]); + + ck_assert_int_eq(efl_pack_at(widget, inv,-100000), EINA_TRUE); + ck_assert_ptr_eq(efl_ui_widget_parent_get(inv), widget); + ck_assert_int_eq(efl_pack_at(widget, inv2, 100000), EINA_TRUE); + ck_assert_ptr_eq(efl_ui_widget_parent_get(inv2), widget); + Efl_Ui_Widget *wid2[] = {inv, wid[0], wid[1], wid[2], inv2}; + _ordering_equals(wid2, 5); +} +EFL_END_TEST + +EFL_START_TEST(pack_content_get1) +{ + Efl_Ui_Widget *wid[3]; + + _fill_array(wid); + + for (int i = 0; i < 3; i++) + efl_pack_end(widget, wid[i]); + + for (int i = -100000; i <= 100000; i++) + { + if (i < -3) + ck_assert_ptr_eq(efl_pack_content_get(widget, i), efl_pack_content_get(widget, 0)); + else if (i >= -3 && i < 3) + ck_assert_ptr_eq(efl_pack_content_get(widget, i), wid[(i + 3) % 3]); + else + ck_assert_ptr_eq(efl_pack_content_get(widget, i), efl_pack_content_get(widget, 2)); + } +} +EFL_END_TEST + +EFL_START_TEST(pack_index_get1) +{ + Efl_Ui_Widget *wid[3]; + Efl_Ui_Widget *inv = efl_add(WIDGET_CLASS, win); + + _fill_array(wid); + for (int i = 0; i < 3; i++) + efl_pack_end(widget, wid[i]); + for (int i = 0; i < 3; i++) + ck_assert_int_eq(efl_pack_index_get(widget, wid[i]), i); + + ck_assert_int_eq(efl_pack_index_get(widget, (void*)0xAFFE), -1); + ck_assert_int_eq(efl_pack_index_get(widget, inv), -1); +} +EFL_END_TEST + +EFL_START_TEST(pack_unpack_at1) +{ + Efl_Ui_Widget *wid[3]; + + _fill_array(wid); + for (int i = 0; i < 3; i++) + efl_pack_end(widget, wid[i]); + for (int i = 0; i < 3; i++) + ck_assert_int_eq(efl_pack_index_get(widget, wid[i]), i); + + ck_assert_ptr_eq(efl_pack_unpack_at(widget, 1), wid[1]); + Efl_Ui_Widget *wid1[] = {wid[0], wid[2]}; + _ordering_equals(wid1, 2); + ck_assert_ptr_eq(efl_pack_unpack_at(widget, 1), wid[2]); + Efl_Ui_Widget *wid2[] = {wid[0]}; + _ordering_equals(wid2, 1); + ck_assert_ptr_eq(efl_pack_unpack_at(widget, 0), wid[0]); + Efl_Ui_Widget *wid3[] = {}; + _ordering_equals(wid3, 0); +} +EFL_END_TEST + + +EFL_START_TEST(pack_unpack_at2) +{ + Efl_Ui_Widget *wid[3]; + + _fill_array(wid); + for (int i = 0; i < 3; i++) + efl_pack_end(widget, wid[i]); + for (int i = 0; i < 3; i++) + ck_assert_int_eq(efl_pack_index_get(widget, wid[i]), i); + + ck_assert_ptr_eq(efl_pack_unpack_at(widget, 1), wid[1]); + efl_del(widget); + ck_assert_int_eq(efl_ref_count(wid[1]), 1); + ck_assert_int_eq(efl_ref_count(widget), 0); +} +EFL_END_TEST + +EFL_START_TEST(pack_unpack_at3) +{ + for (int x = -3; x < 3; ++x) + { + Efl_Ui_Widget *wid[3]; + + _fill_array(wid); + for (int i = 0; i < 3; i++) + efl_pack_end(widget, wid[i]); + ck_assert_ptr_eq(efl_pack_unpack_at(widget, x), wid[(3+x)%3]); + ck_assert_int_eq(efl_content_count(widget), 2); + ck_assert_ptr_ne(efl_ui_widget_parent_get(wid[(3+x)%3]), widget); + efl_pack_unpack_all(widget); + } +} +EFL_END_TEST + +void +efl_pack_linear_behavior_test(TCase *tc) +{ + tcase_add_test(tc, pack_begin1); + tcase_add_test(tc, pack_begin2); + tcase_add_test(tc, pack_end1); + tcase_add_test(tc, pack_end2); + tcase_add_test(tc, pack_before1); + tcase_add_test(tc, pack_before2); + tcase_add_test(tc, pack_after1); + tcase_add_test(tc, pack_after2); + tcase_add_test(tc, pack_at1); + tcase_add_test(tc, pack_at2); + tcase_add_test(tc, pack_at3); + tcase_add_test(tc, pack_content_get1); + tcase_add_test(tc, pack_index_get1); + tcase_add_test(tc, pack_unpack_at1); + tcase_add_test(tc, pack_unpack_at2); + tcase_add_test(tc, pack_unpack_at3); + efl_pack_behavior_test(tc); +} diff --git a/src/tests/elementary/spec/efl_ui_spec_suite.c b/src/tests/elementary/spec/efl_ui_spec_suite.c new file mode 100644 index 0000000..1b84cf5 --- /dev/null +++ b/src/tests/elementary/spec/efl_ui_spec_suite.c @@ -0,0 +1,66 @@ +#ifdef HAVE_CONFIG_H +# include "elementary_config.h" +#endif + +#include +#include "efl_ui_spec_suite.h" +#include "suite_helpers.h" +#include "eo_internal.h" + +Evas_Object *win = NULL; +Evas_Object *widget = NULL; + +EFL_CLASS_SIMPLE_CLASS(efl_ui_widget, "efl_ui_widget", EFL_UI_WIDGET_CLASS); + +static int tree_abort; +static int tree_abort_level; + +static void +_shutdown(void) +{ + eina_log_abort_on_critical_set(tree_abort); + eina_log_abort_on_critical_level_set(tree_abort_level); +} + +static void +_setup(void) +{ + tree_abort = eina_log_abort_on_critical_get(); + tree_abort_level = eina_log_abort_on_critical_level_get(); + eina_log_abort_on_critical_level_set(2); + eina_log_abort_on_critical_set(1); +} + +static void +_setup_window_and_widget(const Efl_Class *klass) +{ + ck_assert(!win); + ck_assert(!widget); + + win = win_add(); + widget = efl_add(klass, win); + efl_content_set(win, widget); + + ck_assert(win); + ck_assert(widget); +} + +#include "efl_ui_spec_suite_gen.x" +int +main(int argc, char **argv) +{ + int failed_count; + +#define LIST_DECL +#include "efl_ui_spec_suite_gen.x" + + if (!_efl_test_option_disp(argc, argv, etc)) + return 0; + + failed_count = suite_setup(EINA_FALSE); + + failed_count += _efl_suite_build_and_run(argc - 1, (const char **)argv + 1, + "Efl_Ui_Spec", etc, SUITE_INIT_FN(elm2), SUITE_SHUTDOWN_FN(elm)); + + return (failed_count == 0) ? 0 : 255; +} diff --git a/src/tests/elementary/spec/efl_ui_spec_suite.h b/src/tests/elementary/spec/efl_ui_spec_suite.h new file mode 100644 index 0000000..c8e008f --- /dev/null +++ b/src/tests/elementary/spec/efl_ui_spec_suite.h @@ -0,0 +1,26 @@ +#ifndef EFL_UI_SUITE_H +#define EFL_UI_SUITE_H + +#include + +#define EFL_NOLEGACY_API_SUPPORT +#include +#include "../efl_check.h" + +extern Evas_Object *win; +extern Evas_Object *widget; + +void efl_pack_behavior_test(TCase *tc); +void efl_pack_linear_behavior_test(TCase *tc); + + +void efl_test_container_content_equal(Efl_Ui_Widget **wid, unsigned int len); +void efl_test_container_expect_evt_content_added(Efl_Ui_Widget *widget, const Efl_Event_Description *ev, Eina_Bool *flag, void *event_data); + +Evas_Object * win_add(); + +const Efl_Class* efl_ui_widget_realized_class_get(void); + +#define WIDGET_CLASS efl_ui_widget_realized_class_get() + +#endif diff --git a/src/tests/elementary/spec/generator.py b/src/tests/elementary/spec/generator.py new file mode 100755 index 0000000..3554b31 --- /dev/null +++ b/src/tests/elementary/spec/generator.py @@ -0,0 +1,66 @@ +#!/usr/bin/python + +tests = [ + ["Efl.Pack_Linear" , "Efl.Ui.Box"], +] + +fixture_gen_template = """ +static void +_{}_fixture(void) +{{ + _setup_window_and_widget({}); +}} +""" + +tcase_gen_template = """ +static void +{}(TCase *tc) +{{ + tcase_add_checked_fixture(tc, _{}_fixture, NULL); + tcase_add_checked_fixture(tc, _setup, _shutdown); + {}(tc); +}} + +""" + +file_gen_template = """ +#ifdef LIST_DECL + {} +#else + {} +#endif +""" + +import sys + +list_of_tcases = "static const Efl_Test_Case etc[] = {\n" +list_entry = " {{ \"{}-{}\", {}}},\n" +generated_api = "" + +def interface_to_api(interface_name): + return interface_name+"_behavior_test" + +def to_func_name(class_name): + return class_name.replace('.','_').lower() + +def to_class_getter(class_name): + return class_name.replace('.','_').upper()+'_CLASS' + +widgets = [] + +for test in tests: + interface_test = to_func_name(test[0]) + for widget_class in test[1:]: + combo_name = "_{}_{}".format(to_func_name(interface_test), to_func_name(widget_class)); + list_of_tcases += list_entry.format(interface_test, to_func_name(widget_class), combo_name) + generated_api += tcase_gen_template.format(combo_name, to_func_name(widget_class), interface_to_api(interface_test)) + if widget_class not in widgets: + widgets += [widget_class] + +for widget in widgets: + generated_api = fixture_gen_template.format(to_func_name(widget), to_class_getter(widget)) + generated_api + +list_of_tcases += " { NULL, NULL }\n};" + +output = open(sys.argv[1], "w") +output.write(file_gen_template.format(list_of_tcases, generated_api)) diff --git a/src/tests/elementary/spec/meson.build b/src/tests/elementary/spec/meson.build new file mode 100644 index 0000000..495d864 --- /dev/null +++ b/src/tests/elementary/spec/meson.build @@ -0,0 +1,32 @@ +efl_ui_suite_behavior_src = [ + join_paths('..','suite_helpers.c'), + join_paths('..','suite_helpers.h'), + join_paths('..','elm_test_init.c'), + 'efl_ui_spec_suite.c', + 'efl_test_pack.c', + 'efl_test_pack_linear.c', + 'efl_test_container.c', +] + +test_generator = find_program('generator.py') + +generated_test_parts = custom_target('generate_test_suite', + output: 'efl_ui_spec_suite_gen.x', + command: [test_generator, '@OUTPUT@'], +) + +efl_ui_behavior_suite = executable('efl_ui_spec_suite', + efl_ui_suite_behavior_src + [generated_test_parts], + dependencies: [check, eina, elementary, elementary_deps], + include_directories : [config_dir] + [elementary_config_dir] + [include_directories('../')], + c_args : [ + '-DTESTS_BUILD_DIR="'+meson.current_build_dir()+'"', + '-DTESTS_SRC_DIR="'+meson.current_source_dir()+'"', + '-DELM_IMAGE_DATA_DIR="'+join_paths(meson.source_root(), 'data', 'elementary')+'"', + '-DELM_TEST_DATA_DIR="'+join_paths(meson.build_root(), 'data', 'elementary')+'"', + ] +) + +test('efl_ui_spec-suite', efl_ui_behavior_suite, + env : test_env +) -- 2.7.4