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