diff options
author | Mike Blumenkrantz <zmike@samsung.com> | 2020-01-03 10:06:40 -0500 |
---|---|---|
committer | Cedric BAIL <cedric.bail@free.fr> | 2020-01-09 10:27:45 -0800 |
commit | 91ed9b59d90b5fc65ad5b64f8beba96d608d31c0 (patch) | |
tree | e4694ee3c00673fd98133b55d06ffe037f1873af | |
parent | 52d0452f0ddfd0c9c4305c71914b963fab7d2230 (diff) |
elementary: start some collectionview tests
* basic test checking realize/unrealize signals
* selection model test
Reviewed-by: Cedric BAIL <cedric.bail@free.fr>
Differential Revision: https://phab.enlightenment.org/D11012
-rw-r--r-- | src/tests/elementary/efl_ui_suite.c | 1 | ||||
-rw-r--r-- | src/tests/elementary/efl_ui_suite.h | 1 | ||||
-rw-r--r-- | src/tests/elementary/efl_ui_test_collection_view.c | 158 | ||||
-rw-r--r-- | src/tests/elementary/meson.build | 1 |
4 files changed, 161 insertions, 0 deletions
diff --git a/src/tests/elementary/efl_ui_suite.c b/src/tests/elementary/efl_ui_suite.c index 9234d68a2f..4b8dc0dbbb 100644 --- a/src/tests/elementary/efl_ui_suite.c +++ b/src/tests/elementary/efl_ui_suite.c | |||
@@ -38,6 +38,7 @@ static const Efl_Test_Case etc[] = { | |||
38 | { "efl_ui_collection", efl_ui_test_item_container }, | 38 | { "efl_ui_collection", efl_ui_test_item_container }, |
39 | { "efl_ui_grid_container", efl_ui_test_grid_container }, | 39 | { "efl_ui_grid_container", efl_ui_test_grid_container }, |
40 | { "efl_ui_list_container", efl_ui_test_list_container }, | 40 | { "efl_ui_list_container", efl_ui_test_list_container }, |
41 | { "efl_ui_collection_view", efl_ui_test_collection_view }, | ||
41 | { "efl_ui_select_model", efl_ui_test_select_model }, | 42 | { "efl_ui_select_model", efl_ui_test_select_model }, |
42 | { "efl_ui_view_model", efl_ui_test_view_model }, | 43 | { "efl_ui_view_model", efl_ui_test_view_model }, |
43 | { "efl_ui_group_item", efl_ui_test_group_item }, | 44 | { "efl_ui_group_item", efl_ui_test_group_item }, |
diff --git a/src/tests/elementary/efl_ui_suite.h b/src/tests/elementary/efl_ui_suite.h index cb83a00ce7..c63df11bfb 100644 --- a/src/tests/elementary/efl_ui_suite.h +++ b/src/tests/elementary/efl_ui_suite.h | |||
@@ -46,6 +46,7 @@ void efl_ui_test_spin_button(TCase *tc); | |||
46 | void efl_ui_test_item_container(TCase *tc); | 46 | void efl_ui_test_item_container(TCase *tc); |
47 | void efl_ui_test_list_container(TCase *tc); | 47 | void efl_ui_test_list_container(TCase *tc); |
48 | void efl_ui_test_grid_container(TCase *tc); | 48 | void efl_ui_test_grid_container(TCase *tc); |
49 | void efl_ui_test_collection_view(TCase *tc); | ||
49 | void efl_ui_test_config(TCase *tc); | 50 | void efl_ui_test_config(TCase *tc); |
50 | void efl_ui_test_popup(TCase *tc); | 51 | void efl_ui_test_popup(TCase *tc); |
51 | void efl_ui_test_scroller(TCase *tc); | 52 | void efl_ui_test_scroller(TCase *tc); |
diff --git a/src/tests/elementary/efl_ui_test_collection_view.c b/src/tests/elementary/efl_ui_test_collection_view.c new file mode 100644 index 0000000000..8740fdb623 --- /dev/null +++ b/src/tests/elementary/efl_ui_test_collection_view.c | |||
@@ -0,0 +1,158 @@ | |||
1 | #ifdef HAVE_CONFIG_H | ||
2 | # include "elementary_config.h" | ||
3 | #endif | ||
4 | |||
5 | #include <Efl_Ui.h> | ||
6 | #include "efl_ui_suite.h" | ||
7 | |||
8 | #define NUM_ITEMS 50 | ||
9 | |||
10 | static Efl_Model* | ||
11 | _make_model(Efl_Ui_Win *win) | ||
12 | { | ||
13 | Eina_Value vi; | ||
14 | Efl_Generic_Model *model, *child; | ||
15 | unsigned int i; | ||
16 | |||
17 | model = efl_add(EFL_GENERIC_MODEL_CLASS, win); | ||
18 | model = efl_add(EFL_UI_VIEW_MODEL_CLASS, model, | ||
19 | efl_ui_view_model_set(efl_added, model)); | ||
20 | eina_value_setup(&vi, EINA_VALUE_TYPE_INT); | ||
21 | |||
22 | efl_ui_view_model_property_string_add(model, "relative", "Relative index ${child.index}", "WRONG", "WRONG"); | ||
23 | efl_ui_view_model_property_string_add(model, "title", "Initial index ${initial}", "WRONG", "WRONG"); | ||
24 | |||
25 | |||
26 | for (i = 0; i < (NUM_ITEMS); i++) | ||
27 | { | ||
28 | child = efl_model_child_add(model); | ||
29 | eina_value_set(&vi, i); | ||
30 | efl_model_property_set(child, "initial", &vi); | ||
31 | } | ||
32 | |||
33 | eina_value_flush(&vi); | ||
34 | return model; | ||
35 | } | ||
36 | |||
37 | static Eina_Value | ||
38 | _quit(Eo *obj, void *data EINA_UNUSED, const Eina_Value v) | ||
39 | { | ||
40 | efl_loop_quit(efl_loop_get(obj), v); | ||
41 | return v; | ||
42 | } | ||
43 | |||
44 | static Eina_Value | ||
45 | _children_get(Eo *obj EINA_UNUSED, void *data EINA_UNUSED, const Eina_Value v) | ||
46 | { | ||
47 | Efl_Model *child; | ||
48 | Eina_Future **all; | ||
49 | unsigned int i, len; | ||
50 | |||
51 | all = calloc(1 + 1, sizeof(Eina_Future*)); | ||
52 | if (!all) return eina_value_error_init(ENOMEM); | ||
53 | |||
54 | EINA_VALUE_ARRAY_FOREACH(&v, len, i, child) | ||
55 | { | ||
56 | Eina_Value *rel_val, *title_val; | ||
57 | char *relative, *title; | ||
58 | if (i != 5) continue; | ||
59 | rel_val = efl_model_property_get(child, "relative"); | ||
60 | title_val = efl_model_property_get(child, "title"); | ||
61 | relative = eina_value_to_string(rel_val); | ||
62 | title = eina_value_to_string(title_val); | ||
63 | |||
64 | ck_assert(eina_streq(relative, "Relative index 5")); | ||
65 | ck_assert(eina_streq(title, "Initial index 5")); | ||
66 | free(relative); | ||
67 | free(title); | ||
68 | break; | ||
69 | } | ||
70 | return EINA_VALUE_EMPTY; | ||
71 | } | ||
72 | |||
73 | EFL_START_TEST(test_efl_ui_collection_view_basic) | ||
74 | { | ||
75 | Efl_Ui_Win *win; | ||
76 | Efl_Model *model; | ||
77 | Efl_Ui_List_View *lv; | ||
78 | Efl_Ui_Factory *fl; | ||
79 | Eina_Future *f; | ||
80 | int count_realize = 0; | ||
81 | int count_unrealize = 0; | ||
82 | |||
83 | win = win_add(); | ||
84 | efl_gfx_entity_size_set(win, EINA_SIZE2D(100, 100)); | ||
85 | |||
86 | model = _make_model(win); | ||
87 | fl = efl_add(EFL_UI_LAYOUT_FACTORY_CLASS, win, | ||
88 | efl_ui_property_bind(efl_added, "text", "title"), | ||
89 | efl_ui_widget_factory_item_class_set(efl_added, EFL_UI_LIST_DEFAULT_ITEM_CLASS)); | ||
90 | |||
91 | lv = efl_add(EFL_UI_LIST_VIEW_CLASS, win, | ||
92 | efl_ui_collection_view_factory_set(efl_added, fl), | ||
93 | efl_ui_view_model_set(efl_added, model), | ||
94 | efl_event_callback_add(efl_added, EFL_UI_COLLECTION_VIEW_EVENT_ITEM_REALIZED, | ||
95 | (void*)event_callback_that_increments_an_int_when_called, &count_realize), | ||
96 | efl_event_callback_add(efl_added, EFL_UI_COLLECTION_VIEW_EVENT_ITEM_UNREALIZED, | ||
97 | (void*)event_callback_that_increments_an_int_when_called, &count_unrealize) | ||
98 | ); | ||
99 | efl_content_set(win, lv); | ||
100 | |||
101 | get_me_to_those_events(lv); | ||
102 | ck_assert_int_gt(count_realize, 0); | ||
103 | /* FIXME: this should eventually be eq(0) */ | ||
104 | ck_assert_int_gt(count_unrealize, 0); | ||
105 | |||
106 | f = efl_model_children_slice_get(lv, 0, efl_model_children_count_get(lv)); | ||
107 | f = efl_future_then(lv, f, .success_type = EINA_VALUE_TYPE_ARRAY, .success = _children_get); | ||
108 | ecore_main_loop_iterate(); | ||
109 | } | ||
110 | EFL_END_TEST | ||
111 | |||
112 | EFL_START_TEST(test_efl_ui_collection_view_select) | ||
113 | { | ||
114 | Efl_Ui_Win *win; | ||
115 | Efl_Model *model; | ||
116 | Efl_Ui_List_View *lv; | ||
117 | Efl_Ui_Factory *fl; | ||
118 | Eina_Value *sel_val; | ||
119 | unsigned long sel = 10000; | ||
120 | |||
121 | win = win_add(); | ||
122 | efl_gfx_entity_size_set(win, EINA_SIZE2D(100, 100)); | ||
123 | |||
124 | model = _make_model(win); | ||
125 | model = efl_add(EFL_UI_SELECT_MODEL_CLASS, efl_main_loop_get(), efl_ui_view_model_set(efl_added, model)); | ||
126 | fl = efl_add(EFL_UI_LAYOUT_FACTORY_CLASS, win, | ||
127 | efl_ui_property_bind(efl_added, "text", "title"), | ||
128 | efl_ui_widget_factory_item_class_set(efl_added, EFL_UI_LIST_DEFAULT_ITEM_CLASS)); | ||
129 | |||
130 | lv = efl_add(EFL_UI_LIST_VIEW_CLASS, win, | ||
131 | efl_ui_collection_view_factory_set(efl_added, fl), | ||
132 | efl_ui_view_model_set(efl_added, model) | ||
133 | ); | ||
134 | efl_content_set(win, lv); | ||
135 | |||
136 | get_me_to_those_events(lv); | ||
137 | |||
138 | /* nothing selected yet */ | ||
139 | sel_val = efl_model_property_get(model, "child.selected"); | ||
140 | ck_assert(eina_value_type_get(sel_val) == EINA_VALUE_TYPE_ERROR); | ||
141 | |||
142 | click_object_at(lv, 50, 5); | ||
143 | get_me_to_those_events(lv); | ||
144 | |||
145 | //efl_future_then(model, efl_model_property_ready_get(model, "child.selected"), .success = _quit); | ||
146 | //ecore_main_loop_begin(); | ||
147 | sel_val = efl_model_property_get(model, "child.selected"); | ||
148 | ck_assert(eina_value_type_get(sel_val) == EINA_VALUE_TYPE_ULONG); | ||
149 | ck_assert(eina_value_ulong_get(sel_val, &sel)); | ||
150 | ck_assert_int_eq(sel, 0); | ||
151 | } | ||
152 | EFL_END_TEST | ||
153 | |||
154 | void efl_ui_test_collection_view(TCase *tc) | ||
155 | { | ||
156 | tcase_add_test(tc, test_efl_ui_collection_view_basic); | ||
157 | tcase_add_test(tc, test_efl_ui_collection_view_select); | ||
158 | } | ||
diff --git a/src/tests/elementary/meson.build b/src/tests/elementary/meson.build index 7c7c62fdac..c3e85d92ef 100644 --- a/src/tests/elementary/meson.build +++ b/src/tests/elementary/meson.build | |||
@@ -150,6 +150,7 @@ efl_ui_suite_src = [ | |||
150 | 'efl_ui_test_slider.c', | 150 | 'efl_ui_test_slider.c', |
151 | 'efl_ui_test_collection_common.c', | 151 | 'efl_ui_test_collection_common.c', |
152 | 'efl_ui_test_collection.c', | 152 | 'efl_ui_test_collection.c', |
153 | 'efl_ui_test_collection_view.c', | ||
153 | 'efl_ui_test_list_collection.c', | 154 | 'efl_ui_test_list_collection.c', |
154 | 'efl_ui_test_grid_collection.c', | 155 | 'efl_ui_test_grid_collection.c', |
155 | 'efl_ui_test_position_manager_common.c', | 156 | 'efl_ui_test_position_manager_common.c', |