Fix coding rule disobey
[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         } else if (w == 720 && h == 1280) {
70                 if (s_info.animation_type == TYPE_ON)
71                         return 7;
72                 else
73                         return 3;
74         } else {
75                 if (s_info.animation_type == TYPE_ON)
76                         return 7;
77                 else
78                         return 3;
79         }
80 }
81
82 static unit_case_func_t __continue_check_finish_on_animation(void *data)
83 {
84         int is_finished = -1;
85
86         vconf_get_int(VCONFKEY_BOOT_ANIMATION_FINISHED, &is_finished);
87         TEST_ASSERT_EQUAL_INT(1, is_finished);
88
89         TEST_ASSERT_TRUE(s_info.is_exit == true);
90
91         TEST_CASE_DONE(s_info.group);
92 }
93
94 extern Evas_Object *__t__get_window(void);
95 extern Evas_Object *__t__get_display_block(void);
96 static unit_case_func_t __continue_check_finish_off_animation(void *data)
97 {
98         int rx, ry, rw, rh;
99         int screen_w, screen_h;
100
101         Evas_Object *window = __t__get_window();
102         TEST_ASSERT_TRUE(window != NULL);
103         elm_win_screen_size_get(window, NULL, NULL, &screen_w, &screen_h);
104
105         Evas_Object *display_block = __t__get_display_block();
106         TEST_ASSERT_TRUE(display_block != NULL);
107
108         evas_object_geometry_get(display_block, &rx, &ry, &rw, &rh);
109         TEST_ASSERT_EQUAL_INT(0, rx);
110         TEST_ASSERT_EQUAL_INT(0, ry);
111         TEST_ASSERT_EQUAL_INT(screen_w, rw);
112         TEST_ASSERT_EQUAL_INT(screen_h, rh);
113         TEST_ASSERT_TRUE(evas_object_visible_get(display_block));
114
115         TEST_CASE_DONE(s_info.group);
116 }
117
118 extern Evas_Object *__t__get_layout(void);
119 extern char * __t__get_layout_file_name(int animation_type, int w, int h);
120 static unit_case_func_t __continue_check_animation_layout(void *data)
121 {
122         int rx, ry, rw, rh;
123         int screen_w, screen_h;
124
125         Evas_Object *window = __t__get_window();
126         TEST_ASSERT_TRUE(window != NULL);
127
128         elm_win_screen_size_get(window, NULL, NULL, &screen_w, &screen_h);
129
130         evas_object_geometry_get(window, &rx, &ry, &rw, &rh);
131         TEST_ASSERT_EQUAL_INT(0, rx);
132         TEST_ASSERT_EQUAL_INT(0, ry);
133         TEST_ASSERT_EQUAL_INT(screen_w, rw);
134         TEST_ASSERT_EQUAL_INT(screen_h, rh);
135         TEST_ASSERT_TRUE(evas_object_visible_get(window));
136
137         Evas_Object *layout = __t__get_layout();
138         TEST_ASSERT_TRUE(layout != NULL);
139         evas_object_geometry_get(layout, &rx, &ry, &rw, &rh);
140         TEST_ASSERT_EQUAL_INT(0, rx);
141         TEST_ASSERT_EQUAL_INT(0, ry);
142         TEST_ASSERT_EQUAL_INT(screen_w, rw);
143         TEST_ASSERT_EQUAL_INT(screen_h, rh);
144         TEST_ASSERT_TRUE(evas_object_visible_get(layout));
145
146         const char *file_name = NULL;
147         elm_layout_file_get(layout, &file_name, NULL);
148         char * expected_file_name = __t__get_layout_file_name(s_info.animation_type, screen_w, screen_h);
149         TEST_ASSERT_EQUAL_STRING(expected_file_name, file_name);
150         free(expected_file_name);
151
152         int current_step = (int)data;
153         if (current_step < __get_step_max(screen_w, screen_h))
154                 TEST_CASE_CONTINUE(0.8, __continue_check_animation_layout, (void*)(current_step + 1));
155
156         if (s_info.animation_type == TYPE_ON)
157                 TEST_CASE_CONTINUE(0.8, __continue_check_finish_on_animation, NULL);
158
159         TEST_CASE_CONTINUE(0.8, __continue_check_finish_off_animation, NULL);
160 }
161
162 static unit_case_func_t __case_check_animation(void *data)
163 {
164         int is_finished = -1;
165
166         vconf_get_int(VCONFKEY_BOOT_ANIMATION_FINISHED, &is_finished);
167         TEST_ASSERT_EQUAL_INT(0, is_finished);
168
169         boot_exit = test_elm_exit;
170         s_info.is_exit = false;
171
172         s_info.animation_type = (int)data;
173         animation_init(s_info.animation_type);
174
175         /* 0.8 because boot-animation take 6 sec, we should not use divisor */
176         TEST_CASE_CONTINUE(0.8, __continue_check_animation_layout, (void*)1);
177 }
178
179 void group_feature_on_off_animation(unit_group_t * group)
180 {
181         s_info.group = group;
182         s_info.group->set_up = __set_up;
183         s_info.group->tear_down = __tear_down;
184
185         TEST_CASE_ADD(s_info.group, __case_check_animation, (void*)TYPE_ON);
186         TEST_CASE_ADD(s_info.group, __case_check_animation, (void*)TYPE_OFF);
187
188         TEST_GROUP_RUN(s_info.group);
189 }
190
191 #endif
192