567be2b9126782f074266f8a9f11104b96b4a679
[apps/native/boot-animation.git] / test / feature_test / group_feature_on_off_animation.c
1 /*
2  * Copyright (c) 2009-2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include "test.h"
19 #if TEST_MODE
20
21 #include "feature_test.h"
22 #include "boot.h"
23 #include "animation.h"
24
25 #include <Elementary.h>
26 #include <vconf.h>
27
28 static struct {
29         int animation_type;
30         bool is_exit;
31         unit_group_t * group;
32 } s_info = {
33         .animation_type = 0,
34         .is_exit = false,
35         .group = NULL,
36 };
37
38 static void test_elm_exit(void)
39 {
40         s_info.is_exit = true;
41 }
42
43 static void __set_up(void)
44 {
45         s_info.is_exit = false;
46         boot_exit = test_elm_exit;
47         vconf_set_int(VCONFKEY_BOOT_ANIMATION_FINISHED, 0);
48
49         ecore_timer_add(0.1, s_info.group->set_up_complete, s_info.group);
50 }
51
52 static void __tear_down(void)
53 {
54         boot_exit = elm_exit;
55         s_info.group->tear_down_complete(s_info.group);
56 }
57
58 static int __get_step_max(int w, int h)
59 {
60         if (w == 360 && h == 360) {
61                 return 3;
62         } else if (w == 360 && h == 480) {
63                 return 3;
64         } else if (w == 480 && h == 800) {
65                 if (s_info.animation_type == TYPE_ON) {
66                         return 4;
67                 } else {
68                         return 3;
69                 }
70         } else if (w == 720 && h == 1280) {
71                 if (s_info.animation_type == TYPE_ON) {
72                         return 7;
73                 } else {
74                         return 3;
75                 }
76         } else {
77                 if (s_info.animation_type == TYPE_ON) {
78                         return 7;
79                 } else {
80                         return 3;
81                 }
82         }
83 }
84
85 static unit_case_func_t __continue_check_finish_on_animation(void *data)
86 {
87         int is_finished = -1;
88
89         vconf_get_int(VCONFKEY_BOOT_ANIMATION_FINISHED, &is_finished);
90         TEST_ASSERT_EQUAL_INT(1, is_finished);
91
92         TEST_ASSERT_TRUE(s_info.is_exit == true);
93
94         TEST_CASE_DONE(s_info.group);
95 }
96
97 extern Evas_Object *__t__get_window(void);
98 extern Evas_Object *__t__get_display_block(void);
99 static unit_case_func_t __continue_check_finish_off_animation(void *data)
100 {
101         int rx, ry, rw, rh;
102         int screen_w, screen_h;
103
104         Evas_Object *window = __t__get_window();
105         TEST_ASSERT_TRUE(window != NULL);
106         elm_win_screen_size_get(window, NULL, NULL, &screen_w, &screen_h);
107
108         Evas_Object *display_block = __t__get_display_block();
109         TEST_ASSERT_TRUE(display_block != NULL);
110
111         evas_object_geometry_get(display_block, &rx, &ry, &rw, &rh);
112         TEST_ASSERT_EQUAL_INT(0, rx);
113         TEST_ASSERT_EQUAL_INT(0, ry);
114         TEST_ASSERT_EQUAL_INT(screen_w, rw);
115         TEST_ASSERT_EQUAL_INT(screen_h, rh);
116         TEST_ASSERT_TRUE(evas_object_visible_get(display_block));
117
118         TEST_CASE_DONE(s_info.group);
119 }
120
121 extern Evas_Object *__t__get_layout(void);
122 extern char * __t__get_layout_file_name(int animation_type, int w, int h);
123 static unit_case_func_t __continue_check_animation_layout(void *data)
124 {
125         int rx, ry, rw, rh;
126         int screen_w, screen_h;
127
128         Evas_Object *window = __t__get_window();
129         TEST_ASSERT_TRUE(window != NULL);
130
131         elm_win_screen_size_get(window, NULL, NULL, &screen_w, &screen_h);
132
133         evas_object_geometry_get(window, &rx, &ry, &rw, &rh);
134         TEST_ASSERT_EQUAL_INT(0, rx);
135         TEST_ASSERT_EQUAL_INT(0, ry);
136         TEST_ASSERT_EQUAL_INT(screen_w, rw);
137         TEST_ASSERT_EQUAL_INT(screen_h, rh);
138         TEST_ASSERT_TRUE(evas_object_visible_get(window));
139
140         Evas_Object *layout = __t__get_layout();
141         TEST_ASSERT_TRUE(layout != NULL);
142         evas_object_geometry_get(layout, &rx, &ry, &rw, &rh);
143         TEST_ASSERT_EQUAL_INT(0, rx);
144         TEST_ASSERT_EQUAL_INT(0, ry);
145         TEST_ASSERT_EQUAL_INT(screen_w, rw);
146         TEST_ASSERT_EQUAL_INT(screen_h, rh);
147         TEST_ASSERT_TRUE(evas_object_visible_get(layout));
148
149         const char *file_name = NULL;
150         elm_layout_file_get(layout, &file_name, NULL);
151         char * expected_file_name = __t__get_layout_file_name(s_info.animation_type, screen_w, screen_h);
152         TEST_ASSERT_EQUAL_STRING(expected_file_name, file_name);
153         free(expected_file_name);
154
155         int current_step = (int)data;
156         if (current_step < __get_step_max(screen_w, screen_h)) {
157                 TEST_CASE_CONTINUE(0.8, __continue_check_animation_layout, (void*)(current_step + 1));
158         }
159
160         if (s_info.animation_type == TYPE_ON)
161                 TEST_CASE_CONTINUE(0.8, __continue_check_finish_on_animation, NULL);
162
163         TEST_CASE_CONTINUE(0.8, __continue_check_finish_off_animation, NULL);
164 }
165
166 static unit_case_func_t __case_check_animation(void *data)
167 {
168         int is_finished = -1;
169
170         vconf_get_int(VCONFKEY_BOOT_ANIMATION_FINISHED, &is_finished);
171         TEST_ASSERT_EQUAL_INT(0, is_finished);
172
173         boot_exit = test_elm_exit;
174         s_info.is_exit = false;
175
176         s_info.animation_type = (int)data;
177         animation_init(s_info.animation_type);
178
179         /* 0.8 because boot-animation take 6 sec, we should not use divisor */
180         TEST_CASE_CONTINUE(0.8, __continue_check_animation_layout, (void*)1);
181 }
182
183 void group_feature_on_off_animation(unit_group_t * group)
184 {
185         s_info.group = group;
186         s_info.group->set_up = __set_up;
187         s_info.group->tear_down = __tear_down;
188
189         TEST_CASE_ADD(s_info.group, __case_check_animation, (void*)TYPE_ON);
190         TEST_CASE_ADD(s_info.group, __case_check_animation, (void*)TYPE_OFF);
191
192         TEST_GROUP_RUN(s_info.group);
193 }
194
195 #endif
196