Add common enum type for Window
[platform/core/uifw/dali-adaptor.git] / automated-tests / src / dali-adaptor / utc-Dali-Window.cpp
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
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 <dali-test-suite-utils.h>
19 #include <dali/dali.h>
20 #include <dali/devel-api/adaptor-framework/window-devel.h>
21 #include <dali/internal/system/linux/dali-ecore-x.h>
22
23 using namespace Dali;
24
25 void utc_dali_window_startup(void)
26 {
27   test_return_value = TET_UNDEF;
28 }
29
30 void utc_dali_window_cleanup(void)
31 {
32   test_return_value = TET_PASS;
33 }
34
35 namespace
36 {
37 intptr_t screenId = 0; // intptr_t has the same size as a pointer and is platform independent so this can be returned as a pointer in ecore_x_default_screen_get below without compilation warnings
38
39 } // unnamed namespace
40
41 extern "C"
42 {
43   Ecore_X_Screen* ecore_x_default_screen_get(void)
44   {
45     screenId += 8;
46     return (Ecore_X_Screen*)screenId;
47   }
48
49   void ecore_x_screen_size_get(const Ecore_X_Screen* screen, int* w, int* h)
50   {
51     *w = 100;
52     *h = 100;
53   }
54
55   Ecore_X_Window ecore_x_window_argb_new(Ecore_X_Window parent, int x, int y, int w, int h)
56   {
57     return 0;
58   }
59 }
60
61 int UtcDaliWindowConstructorP(void)
62 {
63   Dali::Window window;
64   DALI_TEST_CHECK(!window);
65   END_TEST;
66 }
67
68 int UtcDaliWindowCopyConstructorP(void)
69 {
70   Dali::Window window;
71   Dali::Window copy(window);
72   DALI_TEST_CHECK(copy == window);
73
74   END_TEST;
75 }
76
77 int UtcDaliWindowConstructorFromInternalPointerN(void)
78 {
79   Internal::Adaptor::Window* internalWindow = NULL;
80   Dali::Window               window(internalWindow);
81   DALI_TEST_CHECK(!window); // Should not reach here!
82
83   END_TEST;
84 }
85
86 int UtcDaliWindowAssignmentOperatorP(void)
87 {
88   const Dali::Window window;
89   Dali::Window       copy;
90   DALI_TEST_CHECK(!copy);
91   copy = window;
92   DALI_TEST_CHECK(copy == window);
93
94   END_TEST;
95 }
96
97 int UtcDaliWindowDestructorP(void)
98 {
99   Dali::Window* window = new Dali::Window();
100   delete window;
101
102   DALI_TEST_CHECK(true);
103   END_TEST;
104 }
105
106 int UtcDaliWindowNewN(void)
107 {
108   // Attempt to create a new window
109   try
110   {
111     PositionSize windowPosition(0, 0, 0, 0);
112     Dali::Window window = Dali::Window::New(windowPosition, "test-window", true);
113
114     tet_result(TET_FAIL);
115   }
116   catch(DaliException& e)
117   {
118     DALI_TEST_ASSERT(e, "Failed to create X window", TEST_LOCATION);
119   }
120
121   // Attempt to create a new window
122   try
123   {
124     PositionSize windowPosition(0, 0, 0, 0);
125     Dali::Window window = Dali::Window::New(windowPosition, "test-window", "test-window-class", true);
126
127     tet_result(TET_FAIL);
128   }
129   catch(DaliException& e)
130   {
131     DALI_TEST_ASSERT(e, "Failed to create X window", TEST_LOCATION);
132   }
133
134   END_TEST;
135 }
136
137 int UtcDaliWindowSetClassN(void)
138 {
139   Dali::Window window;
140   try
141   {
142     window.SetClass("window-name", "window-class");
143     DALI_TEST_CHECK(false); // Should not reach here!
144   }
145   catch(...)
146   {
147     DALI_TEST_CHECK(true);
148   }
149
150   END_TEST;
151 }
152
153 int UtcDaliWindowRaiseN(void)
154 {
155   Dali::Window window;
156   try
157   {
158     window.Raise();
159     DALI_TEST_CHECK(false); // Should not reach here!
160   }
161   catch(...)
162   {
163     DALI_TEST_CHECK(true);
164   }
165
166   END_TEST;
167 }
168
169 int UtcDaliWindowLowerN(void)
170 {
171   Dali::Window window;
172   try
173   {
174     window.Lower();
175     DALI_TEST_CHECK(false); // Should not reach here!
176   }
177   catch(...)
178   {
179     DALI_TEST_CHECK(true);
180   }
181
182   END_TEST;
183 }
184
185 int UtcDaliWindowActivateN(void)
186 {
187   Dali::Window window;
188   try
189   {
190     window.Activate();
191     DALI_TEST_CHECK(false); // Should not reach here!
192   }
193   catch(...)
194   {
195     DALI_TEST_CHECK(true);
196   }
197
198   END_TEST;
199 }
200
201 int UtcDaliWindowAddAvailableOrientationN(void)
202 {
203   Dali::Window window;
204   try
205   {
206     window.AddAvailableOrientation(Dali::WindowOrientation::PORTRAIT);
207     DALI_TEST_CHECK(false); // Should not reach here!
208   }
209   catch(...)
210   {
211     DALI_TEST_CHECK(true);
212   }
213
214   END_TEST;
215 }
216
217 int UtcDaliWindowRemoveAvailableOrientationN(void)
218 {
219   Dali::Window window;
220   try
221   {
222     window.RemoveAvailableOrientation(Dali::WindowOrientation::PORTRAIT);
223     DALI_TEST_CHECK(false); // Should not reach here!
224   }
225   catch(...)
226   {
227     DALI_TEST_CHECK(true);
228   }
229
230   END_TEST;
231 }
232
233 int UtcDaliWindowSetPreferredOrientationN(void)
234 {
235   Dali::Window window;
236   try
237   {
238     window.SetPreferredOrientation(Dali::WindowOrientation::PORTRAIT);
239     DALI_TEST_CHECK(false); // Should not reach here!
240   }
241   catch(...)
242   {
243     DALI_TEST_CHECK(true);
244   }
245
246   END_TEST;
247 }
248
249 int UtcDaliWindowGetPreferredOrientationN(void)
250 {
251   Dali::Window window;
252   try
253   {
254     Dali::WindowOrientation orientation = window.GetPreferredOrientation();
255     DALI_TEST_CHECK(orientation == Dali::WindowOrientation::PORTRAIT); // Should not reach here!
256   }
257   catch(...)
258   {
259     DALI_TEST_CHECK(true);
260   }
261
262   END_TEST;
263 }
264
265 int UtcDaliWindowGetNativeHandleN(void)
266 {
267   Dali::Window window;
268   try
269   {
270     Dali::Any handle = window.GetNativeHandle();
271     DALI_TEST_CHECK(false); // Should not reach here!
272   }
273   catch(...)
274   {
275     DALI_TEST_CHECK(true);
276   }
277
278   END_TEST;
279 }
280
281 int UtcDaliWindowSetAcceptFocusN(void)
282 {
283   Dali::Window window;
284   try
285   {
286     window.SetAcceptFocus(true);
287     DALI_TEST_CHECK(false); // Should not reach here!
288   }
289   catch(...)
290   {
291     DALI_TEST_CHECK(true);
292   }
293
294   END_TEST;
295 }
296
297 int UtcDaliWindowIsFocusAcceptableN(void)
298 {
299   Dali::Window window;
300   try
301   {
302     window.IsFocusAcceptable();
303     DALI_TEST_CHECK(false); // Should not reach here!
304   }
305   catch(...)
306   {
307     DALI_TEST_CHECK(true);
308   }
309
310   END_TEST;
311 }
312
313 int UtcDaliWindowFocusChangeSignalN(void)
314 {
315   Dali::Window window;
316   try
317   {
318     window.FocusChangeSignal();
319     DALI_TEST_CHECK(false); // Should not reach here!
320   }
321   catch(...)
322   {
323     DALI_TEST_CHECK(true);
324   }
325
326   END_TEST;
327 }