[dali_1.9.18] Merge branch 'devel/master'
[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/dali.h>
19 #include <dali/devel-api/adaptor-framework/window-devel.h>
20 #include <dali/internal/system/linux/dali-ecore-x.h>
21 #include <dali-test-suite-utils.h>
22
23 namespace Dali
24 {
25 class DragAndDropDetector : public BaseHandle {}; // For UtcDaliWindowGetDragAndDropDetectorN
26 }
27
28 using namespace Dali;
29
30 void utc_dali_window_startup(void)
31 {
32   test_return_value = TET_UNDEF;
33 }
34
35 void utc_dali_window_cleanup(void)
36 {
37   test_return_value = TET_PASS;
38 }
39
40 namespace
41 {
42
43 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
44
45 } // unnamed namespace
46
47 extern "C"
48 {
49
50 Ecore_X_Screen* ecore_x_default_screen_get(void)
51 {
52   screenId += 8;
53   return (Ecore_X_Screen*)screenId;
54 }
55
56 void ecore_x_screen_size_get(const Ecore_X_Screen *screen, int *w, int *h)
57 {
58  *w = 100;
59  *h = 100;
60 }
61
62 Ecore_X_Window ecore_x_window_argb_new(Ecore_X_Window parent, int x, int y, int w, int h)
63 {
64   return 0;
65 }
66
67 }
68
69 int UtcDaliWindowConstructorP(void)
70 {
71   Dali::Window window;
72   DALI_TEST_CHECK( !window );
73   END_TEST;
74 }
75
76 int UtcDaliWindowCopyConstructorP(void)
77 {
78   Dali::Window window;
79   Dali::Window copy( window );
80   DALI_TEST_CHECK( copy == window );
81
82   END_TEST;
83 }
84
85 int UtcDaliWindowConstructorFromInternalPointerN(void)
86 {
87   Internal::Adaptor::Window* internalWindow = NULL;
88   Dali::Window window(internalWindow);
89   DALI_TEST_CHECK( !window ); // Should not reach here!
90
91   END_TEST;
92 }
93
94 int UtcDaliWindowAssignmentOperatorP(void)
95 {
96   const Dali::Window window;
97   Dali::Window copy;
98   DALI_TEST_CHECK( ! copy );
99   copy = window;
100   DALI_TEST_CHECK( copy == window );
101
102   END_TEST;
103 }
104
105 int UtcDaliWindowDestructorP(void)
106 {
107   Dali::Window* window = new Dali::Window();
108   delete window;
109
110   DALI_TEST_CHECK( true );
111   END_TEST;
112 }
113
114 int UtcDaliWindowNewN(void)
115 {
116   // Attempt to create a new window
117   try
118   {
119     PositionSize windowPosition(0, 0, 0, 0);
120     Dali::Window window = Dali::Window::New( windowPosition, "test-window", true );
121
122     tet_result( TET_FAIL );
123   }
124   catch ( DaliException& e )
125   {
126     DALI_TEST_ASSERT( e, "Failed to create X window", TEST_LOCATION );
127   }
128
129   // Attempt to create a new window
130   try
131   {
132     PositionSize windowPosition(0, 0, 0, 0);
133     Dali::Window window = Dali::Window::New( windowPosition, "test-window", "test-window-class", true );
134
135     tet_result( TET_FAIL );
136   }
137   catch ( DaliException& e )
138   {
139     DALI_TEST_ASSERT( e, "Failed to create X window", TEST_LOCATION );
140   }
141
142   END_TEST;
143 }
144
145 int UtcDaliWindowShowIndicatorN(void)
146 {
147   Dali::Window window;
148   try
149   {
150     window.ShowIndicator(Dali::Window::VISIBLE);
151     DALI_TEST_CHECK( false ); // Should not reach here!
152   }
153   catch( ... )
154   {
155     DALI_TEST_CHECK( true );
156   }
157
158   END_TEST;
159 }
160
161 int UtcDaliWindowSetIndicatorBgOpacityN(void)
162 {
163   Dali::Window window;
164   try
165   {
166     window.SetIndicatorBgOpacity(Dali::Window::OPAQUE);
167     DALI_TEST_CHECK( false ); // Should not reach here!
168   }
169   catch( ... )
170   {
171     DALI_TEST_CHECK( true );
172   }
173
174   END_TEST;
175 }
176
177 int UtcDaliWindowRotateIndicatorN(void)
178 {
179   Dali::Window window;
180   try
181   {
182     window.RotateIndicator(Dali::Window::PORTRAIT);
183     DALI_TEST_CHECK( false ); // Should not reach here!
184   }
185   catch( ... )
186   {
187     DALI_TEST_CHECK( true );
188   }
189
190   END_TEST;
191 }
192
193 int UtcDaliWindowSetClassN(void)
194 {
195   Dali::Window window;
196   try
197   {
198     window.SetClass("window-name", "window-class");
199     DALI_TEST_CHECK( false ); // Should not reach here!
200   }
201   catch( ... )
202   {
203     DALI_TEST_CHECK( true );
204   }
205
206   END_TEST;
207 }
208
209 int UtcDaliWindowRaiseN(void)
210 {
211   Dali::Window window;
212   try
213   {
214     window.Raise();
215     DALI_TEST_CHECK( false ); // Should not reach here!
216   }
217   catch( ... )
218   {
219     DALI_TEST_CHECK( true );
220   }
221
222   END_TEST;
223 }
224
225 int UtcDaliWindowLowerN(void)
226 {
227   Dali::Window window;
228   try
229   {
230     window.Lower();
231     DALI_TEST_CHECK( false ); // Should not reach here!
232   }
233   catch( ... )
234   {
235     DALI_TEST_CHECK( true );
236   }
237
238   END_TEST;
239 }
240
241 int UtcDaliWindowActivateN(void)
242 {
243   Dali::Window window;
244   try
245   {
246     window.Activate();
247     DALI_TEST_CHECK( false ); // Should not reach here!
248   }
249   catch( ... )
250   {
251     DALI_TEST_CHECK( true );
252   }
253
254   END_TEST;
255 }
256
257 int UtcDaliWindowAddAvailableOrientationN(void)
258 {
259   Dali::Window window;
260   try
261   {
262     window.AddAvailableOrientation(Dali::Window::PORTRAIT);
263     DALI_TEST_CHECK( false ); // Should not reach here!
264   }
265   catch( ... )
266   {
267     DALI_TEST_CHECK( true );
268   }
269
270   END_TEST;
271 }
272
273 int UtcDaliWindowRemoveAvailableOrientationN(void)
274 {
275   Dali::Window window;
276   try
277   {
278     window.RemoveAvailableOrientation(Dali::Window::PORTRAIT);
279     DALI_TEST_CHECK( false ); // Should not reach here!
280   }
281   catch( ... )
282   {
283     DALI_TEST_CHECK( true );
284   }
285
286   END_TEST;
287 }
288
289 int UtcDaliWindowSetPreferredOrientationN(void)
290 {
291   Dali::Window window;
292   try
293   {
294     window.SetPreferredOrientation(Dali::Window::PORTRAIT);
295     DALI_TEST_CHECK( false ); // Should not reach here!
296   }
297   catch( ... )
298   {
299     DALI_TEST_CHECK( true );
300   }
301
302   END_TEST;
303 }
304
305 int UtcDaliWindowGetPreferredOrientationN(void)
306 {
307   Dali::Window window;
308   try
309   {
310     Dali::Window::WindowOrientation orientation = window.GetPreferredOrientation();
311     DALI_TEST_CHECK( orientation == Dali::Window::PORTRAIT ); // Should not reach here!
312   }
313   catch( ... )
314   {
315     DALI_TEST_CHECK( true );
316   }
317
318   END_TEST;
319 }
320
321 int UtcDaliWindowGetDragAndDropDetectorN(void)
322 {
323   Dali::Window window;
324   try
325   {
326     DragAndDropDetector detector = window.GetDragAndDropDetector();
327     DALI_TEST_CHECK( !detector ); // Should not reach here!
328   }
329   catch( ... )
330   {
331     DALI_TEST_CHECK( true );
332   }
333
334   END_TEST;
335 }
336
337 int UtcDaliWindowGetNativeHandleN(void)
338 {
339   Dali::Window window;
340   try
341   {
342     Dali::Any handle = window.GetNativeHandle();
343     DALI_TEST_CHECK( false ); // Should not reach here!
344   }
345   catch( ... )
346   {
347     DALI_TEST_CHECK( true );
348   }
349
350   END_TEST;
351 }
352
353 int UtcDaliWindowSetAcceptFocusN(void)
354 {
355   Dali::Window window;
356   try
357   {
358     window.SetAcceptFocus( true );
359     DALI_TEST_CHECK( false ); // Should not reach here!
360   }
361   catch( ... )
362   {
363     DALI_TEST_CHECK( true );
364   }
365
366   END_TEST;
367 }
368
369 int UtcDaliWindowIsFocusAcceptableN(void)
370 {
371   Dali::Window window;
372   try
373   {
374     window.IsFocusAcceptable();
375     DALI_TEST_CHECK( false ); // Should not reach here!
376   }
377   catch( ... )
378   {
379     DALI_TEST_CHECK( true );
380   }
381
382   END_TEST;
383 }
384
385 int UtcDaliWindowIndicatorVisibilityChangedSignalN(void)
386 {
387   Dali::Window window;
388   try
389   {
390     window.IndicatorVisibilityChangedSignal();
391     DALI_TEST_CHECK( false ); // Should not reach here!
392   }
393   catch( ... )
394   {
395     DALI_TEST_CHECK( true );
396   }
397
398   END_TEST;
399 }
400
401 int UtcDaliWindowFocusChangedSignalN(void)
402 {
403   Dali::Window window;
404   try
405   {
406     window.FocusChangedSignal();
407     DALI_TEST_CHECK( false ); // Should not reach here!
408   }
409   catch( ... )
410   {
411     DALI_TEST_CHECK( true );
412   }
413
414   END_TEST;
415 }
416
417 int UtcDaliWindowPartialUpdate(void)
418 {
419   Dali::Window window;
420   try
421   {
422     std::vector<Rect<int>> damagedAreas;
423     DevelWindow::SetDamagedAreas(window, damagedAreas);
424     DALI_TEST_CHECK( false ); // Should not reach here!
425   }
426   catch( ... )
427   {
428     DALI_TEST_CHECK( true );
429   }
430
431   END_TEST;
432 }