Add group_feature_all_page_back
[profile/mobile/apps/native/homescreen-efl.git] / test / feature_test / group_feature_all_page_back.c
1 #include "test.h"
2 #if TEST_MODE
3
4 #include "feature_test.h"
5 #include "cluster_view.h"
6 #include "view.h"
7 #include "homescreen-efl.h"
8
9 #include <Elementary.h>
10 #include <string.h>
11
12 extern void __t__cluster_view_scroll_to_page(int page_idx, bool animation);
13 extern int __t__cluster_view_get_current_page();
14 extern Evas_Object * __t__cluster_view_get_scroller(void);
15 extern cluster_page_t *__t__cluster_view_page_new(void);
16
17 static const int CASE_COUNT = 6;
18 static void __case_scroll_to_page(bool * is_passed);
19 static void __case_scroll_to_2_page(bool * is_passed);
20 static void __case_show_all_page(bool * is_passed);
21 static void __case_click_back_key(bool * is_passed);
22
23 static struct {
24         Ecore_Timer * group_timer;
25         unit_group_t * group;
26         int current_case;
27         void(*case_pool[CASE_COUNT + 1])(bool * is_passed);
28 } s_info = {
29         .group_timer = NULL,
30         .group = NULL,
31         .current_case = 0,
32         .case_pool = {
33                                         __case_scroll_to_page,
34                                         __case_scroll_to_2_page,
35                                         __case_show_all_page,
36                                         __case_click_back_key,
37                                         __case_show_all_page,
38                                         __case_click_back_key,
39                                         NULL,
40                                 },
41 };
42
43 static Eina_Bool __group_timer_callback(void * data);
44
45 static void __set_up(void) { unit_clear_log(); }
46 static void __tear_down(void) { unit_clear_log(); }
47
48 static void __case_scroll_to_page(bool * is_passed)
49 {
50         __t__cluster_view_scroll_to_page(0, false);
51         TEST_ASSERT_EQUAL_INT(0, __t__cluster_view_get_current_page());
52
53         __t__cluster_view_scroll_to_page(1, false);
54         TEST_ASSERT_EQUAL_INT(1, __t__cluster_view_get_current_page());
55
56         __t__cluster_view_scroll_to_page(2, false);
57         TEST_ASSERT_EQUAL_INT(2, __t__cluster_view_get_current_page());
58
59         __t__cluster_view_scroll_to_page(3, false);
60         TEST_ASSERT_EQUAL_INT(3, __t__cluster_view_get_current_page());
61
62         __t__cluster_view_scroll_to_page(5, false);
63         TEST_ASSERT_EQUAL_INT(5, __t__cluster_view_get_current_page());
64
65         __t__cluster_view_scroll_to_page(2, false);
66         TEST_ASSERT_EQUAL_INT(2, __t__cluster_view_get_current_page());
67
68         __t__cluster_view_scroll_to_page(0, false);
69         TEST_ASSERT_EQUAL_INT(0, __t__cluster_view_get_current_page());
70
71         Evas_Object * scroller = __t__cluster_view_get_scroller();
72         elm_scroller_page_show(scroller, 0, 0);
73         int page = -1;
74         elm_scroller_current_page_get(scroller, &page, NULL);
75         TEST_ASSERT_EQUAL_INT(0, page);
76
77         elm_scroller_page_show(scroller, 1, 0);
78         elm_scroller_current_page_get(scroller, &page, NULL);
79         TEST_ASSERT_EQUAL_INT(1, page);
80
81         elm_scroller_page_show(scroller, 3, 0);
82         elm_scroller_current_page_get(scroller, &page, NULL);
83         TEST_ASSERT_EQUAL_INT(3, page);
84
85         *is_passed = true;
86
87 }
88
89 static void __case_scroll_to_2_page(bool * is_passed)
90 {
91         __t__cluster_view_scroll_to_page(1, true);
92
93         char buf[1024] = { 0, };
94         strcat(buf, "bring in 1 page\n");
95         TEST_ASSERT_EQUAL_LOG(buf);
96
97         *is_passed = true;
98 }
99
100 static void __case_show_all_page(bool * is_passed)
101 {
102         Evas_Object * scroller = __t__cluster_view_get_scroller();
103
104         TEST_ASSERT_TRUE(evas_object_visible_get(scroller) == EINA_TRUE);
105         TEST_ASSERT_EQUAL_INT(VIEW_STATE_NORMAL, cluster_view_get_state());
106         TEST_ASSERT_EQUAL_INT(1, __t__cluster_view_get_current_page());
107
108         cluster_view_set_state(VIEW_STATE_ALL_PAGE);
109
110         TEST_ASSERT_EQUAL_INT(VIEW_STATE_ALL_PAGE, cluster_view_get_state());
111
112         *is_passed = true;
113 }
114
115 static void __case_click_back_key(bool * is_passed)
116 {
117         TEST_ASSERT_EQUAL_INT(VIEW_STATE_ALL_PAGE, cluster_view_get_state());
118         TEST_ASSERT_EQUAL_INT(1, __t__cluster_view_get_current_page());
119
120         homescreen_efl_hw_back_key_release();
121
122         TEST_ASSERT_EQUAL_INT(VIEW_STATE_NORMAL, cluster_view_get_state());
123         TEST_ASSERT_EQUAL_INT(1, __t__cluster_view_get_current_page());
124
125         Evas_Object * scroller = __t__cluster_view_get_scroller();
126         TEST_ASSERT_TRUE(evas_object_visible_get(scroller) == EINA_FALSE);
127
128         *is_passed = true;
129 }
130
131 void group_feature_all_page_back(unit_group_t * group)
132 {
133         __t__cluster_view_page_new();
134         __t__cluster_view_page_new();
135         __t__cluster_view_page_new();
136         __t__cluster_view_page_new();
137         __t__cluster_view_page_new();
138         __t__cluster_view_page_new();
139         __t__cluster_view_page_new();
140
141
142         if (s_info.group_timer) {
143                 ecore_timer_del(s_info.group_timer);
144                 s_info.group_timer = NULL;
145         }
146
147         s_info.current_case = 0;
148         s_info.group = group;
149         s_info.group_timer = ecore_timer_add(1.5, __group_timer_callback, NULL);
150 }
151
152 static Eina_Bool __group_timer_callback(void * data)
153 {
154         if (s_info.case_pool[s_info.current_case] == NULL) {
155                 s_info.group->finish(s_info.group);
156
157                 s_info.group_timer = NULL;
158                 return ECORE_CALLBACK_CANCEL;
159         }
160
161         TEST_CASE(s_info.group, s_info.case_pool[s_info.current_case]);
162         s_info.current_case += 1;
163
164         return ECORE_CALLBACK_RENEW;
165 }
166
167 #endif
168