Merge "Use existing callback ID for recurring callbacks" into devel/master
[platform/core/uifw/dali-adaptor.git] / automated-tests / src / dali-adaptor / utc-Dali-Gl-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/gl-window.h>
20 #include <dali/internal/system/linux/dali-ecore-x.h>
21 #include <dali-test-suite-utils.h>
22 #include <adaptor-test-application.h>
23
24
25 using namespace Dali;
26
27 void utc_dali_glwindow_startup(void)
28 {
29   test_return_value = TET_UNDEF;
30 }
31
32 void utc_dali_glwindow_cleanup(void)
33 {
34   test_return_value = TET_PASS;
35 }
36
37 int UtcDaliGlWindowConstructorP(void)
38 {
39   Dali::GlWindow window;
40   DALI_TEST_CHECK( !window );
41   END_TEST;
42 }
43
44 int UtcDaliGlWindowCopyConstructorP(void)
45 {
46   Dali::GlWindow window;
47   Dali::GlWindow copy( window );
48   DALI_TEST_CHECK( copy == window );
49
50   END_TEST;
51 }
52
53 int UtcDaliGlWindowConstructorFromInternalPointerN(void)
54 {
55   Internal::Adaptor::GlWindow* internalWindow = NULL;
56   Dali::GlWindow window(internalWindow);
57   DALI_TEST_CHECK( !window );
58
59   END_TEST;
60 }
61
62 int UtcDaliGlWindowAssignmentOperatorP(void)
63 {
64   const Dali::GlWindow window;
65   Dali::GlWindow copy;
66   DALI_TEST_CHECK( ! copy );
67   copy = window;
68   DALI_TEST_CHECK( copy == window );
69
70   END_TEST;
71 }
72
73 int UtcDaliGlWindowDestructorP(void)
74 {
75   Dali::GlWindow* window = new Dali::GlWindow();
76   delete window;
77
78   DALI_TEST_CHECK( true );
79   END_TEST;
80 }
81
82 int UtcDaliGlWindowNew1(void)
83 {
84   try
85   {
86     PositionSize windowPosition(0, 0, 10, 10);
87     Dali::GlWindow window = Dali::GlWindow::New( windowPosition, "test-window", "test-window-class", true );
88     tet_result( TET_FAIL );
89   }
90   catch ( DaliException& e )
91   {
92     DALI_TEST_ASSERT( e, "Failed to create X window", TEST_LOCATION );
93   }
94
95   END_TEST;
96 }
97
98 int UtcDaliGlWindowNew2(void)
99 {
100   try
101   {
102     PositionSize windowPosition(20, 10, 10, 10);
103     Dali::GlWindow window = Dali::GlWindow::New( windowPosition, "test-window", "test-window-class", true );
104
105     tet_result( TET_FAIL );
106   }
107   catch ( DaliException& e )
108   {
109     DALI_TEST_ASSERT( e, "Failed to create X window", TEST_LOCATION );
110   }
111   END_TEST;
112 }
113
114 int UtcDaliGlWindowSetEglConfigGles20(void)
115 {
116   Dali::GlWindow window;
117   try
118   {
119     window.SetEglConfig( true, true, 0, Dali::GlWindow::GlesVersion::VERSION_2_0 );
120
121     DALI_TEST_CHECK( false);
122   }
123   catch( ... )
124   {
125     DALI_TEST_CHECK( true );
126   }
127   END_TEST;
128 }
129
130 int UtcDaliGlWindowSetEglConfigGles30(void)
131 {
132   Dali::GlWindow window;
133   try
134   {
135     window.SetEglConfig( true, true, 0, Dali::GlWindow::GlesVersion::VERSION_3_0 );
136
137     DALI_TEST_CHECK( false );
138   }
139   catch( ... )
140   {
141     DALI_TEST_CHECK( true );
142   }
143   END_TEST;
144 }
145
146 int UtcDaliGlWindowRaise(void)
147 {
148   Dali::GlWindow window;
149
150   try
151   {
152     window.Raise();
153
154     DALI_TEST_CHECK( false );
155   }
156   catch( ... )
157   {
158     DALI_TEST_CHECK( true );
159   }
160   END_TEST;
161 }
162
163 int UtcDaliGlWindowLower(void)
164 {
165   Dali::GlWindow window;
166
167   try
168   {
169     window.Lower();
170
171     DALI_TEST_CHECK( false );
172   }
173   catch( ... )
174   {
175     DALI_TEST_CHECK( true );
176   }
177   END_TEST;
178 }
179
180 int UtcDaliGlWindowActivate(void)
181 {
182   Dali::GlWindow window;
183
184   try
185   {
186     window.Activate();
187
188     DALI_TEST_CHECK( false );
189   }
190   catch( ... )
191   {
192     DALI_TEST_CHECK( true );
193   }
194   END_TEST;
195 }
196
197 int UtcDaliGlWindowShow(void)
198 {
199   Dali::GlWindow window;
200
201   try
202   {
203     window.Show();
204
205     DALI_TEST_CHECK( false );
206   }
207   catch( ... )
208   {
209     DALI_TEST_CHECK( true );
210   }
211   END_TEST;
212 }
213
214 int UtcDaliGlWindowHide(void)
215 {
216   Dali::GlWindow window;
217
218   try
219   {
220     window.Hide();
221
222     DALI_TEST_CHECK( false );
223   }
224   catch( ... )
225   {
226     DALI_TEST_CHECK( true );
227   }
228   END_TEST;
229 }
230
231 int UtcDaliGlWindowSetGetPositionSize(void)
232 {
233   Dali::GlWindow window;
234
235   try
236   {
237     PositionSize setPositionSize( 0, 0, 100, 100);
238     window.SetPositionSize( setPositionSize );
239     PositionSize getPositionSize = window.GetPositionSize();
240     DALI_TEST_CHECK( setPositionSize == getPositionSize );
241
242     setPositionSize.x = 10;
243     setPositionSize.y = 20;
244     window.SetPositionSize( setPositionSize );
245     getPositionSize = window.GetPositionSize();
246     DALI_TEST_CHECK( setPositionSize == getPositionSize );
247
248     setPositionSize.width = 50;
249     setPositionSize.height = 50;
250     window.SetPositionSize( setPositionSize );
251     getPositionSize = window.GetPositionSize();
252     DALI_TEST_CHECK( setPositionSize == getPositionSize );
253
254     setPositionSize.x = 0;
255     setPositionSize.y = 0;
256     setPositionSize.width = 100;
257     setPositionSize.height = 100;
258     window.SetPositionSize( setPositionSize );
259     getPositionSize = window.GetPositionSize();
260     DALI_TEST_CHECK( setPositionSize == getPositionSize );
261
262     DALI_TEST_CHECK( false );
263   }
264   catch( ... )
265   {
266     DALI_TEST_CHECK( true );
267   }
268   END_TEST;
269 }
270
271 int UtcDaliGlWindowSetInputRegion(void)
272 {
273   Dali::GlWindow window;
274
275   try
276   {
277     window.SetInputRegion(  Rect< int >( 0, 0, 100, 10 )  );
278
279     DALI_TEST_CHECK( false );
280   }
281   catch( ... )
282   {
283     DALI_TEST_CHECK( true );
284   }
285   END_TEST;
286 }
287
288 int UtcDaliGlWindowOpaqueState(void)
289 {
290   Dali::GlWindow window;
291
292   try
293   {
294     bool opaquestate = window.IsOpaqueState();
295     DALI_TEST_CHECK( opaquestate == true );
296
297     DALI_TEST_CHECK( false );
298   }
299   catch( ... )
300   {
301     DALI_TEST_CHECK( true );
302   }
303   END_TEST;
304 }
305
306 int UtcDaliGlWindowSetAvailableOrientations(void)
307 {
308   Dali::GlWindow window;
309
310   try
311   {
312     Dali::Vector< Dali::WindowOrientation> orientations;
313     orientations.PushBack( Dali::WindowOrientation::PORTRAIT );
314     orientations.PushBack( Dali::WindowOrientation::LANDSCAPE );
315     orientations.PushBack( Dali::WindowOrientation::PORTRAIT_INVERSE );
316     orientations.PushBack( Dali::WindowOrientation::LANDSCAPE_INVERSE );
317     orientations.PushBack( Dali::WindowOrientation::NO_ORIENTATION_PREFERENCE );
318     orientations.PushBack( Dali::WindowOrientation::PORTRAIT );
319     orientations.PushBack( Dali::WindowOrientation::LANDSCAPE );
320     orientations.PushBack( Dali::WindowOrientation::PORTRAIT_INVERSE );
321     window.SetAvailableOrientations(orientations);
322
323     DALI_TEST_CHECK( false );
324   }
325   catch( ... )
326   {
327     DALI_TEST_CHECK( true );
328   }
329   END_TEST;
330 }
331
332 int UtcDaliGlWindowSetPreferredOrientation(void)
333 {
334   Dali::GlWindow window;
335
336   try
337   {
338     window.SetPreferredOrientation(Dali::WindowOrientation::PORTRAIT);
339
340     DALI_TEST_CHECK( false );
341   }
342   catch( ... )
343   {
344     DALI_TEST_CHECK( true );
345   }
346   END_TEST;
347 }
348
349 int UtcDaliGlWindowSetPreferredOrientation1(void)
350 {
351   Dali::GlWindow window;
352
353   try
354   {
355     window.SetPreferredOrientation(Dali::WindowOrientation::NO_ORIENTATION_PREFERENCE);
356
357     DALI_TEST_CHECK( false );
358   }
359   catch( ... )
360   {
361     DALI_TEST_CHECK( true );
362   }
363   END_TEST;
364 }
365
366 int UtcDaliWindowGetCurrentOrientation(void)
367 {
368   Dali::GlWindow window;
369
370   try
371   {
372     Dali::WindowOrientation orientation = window.GetCurrentOrientation();
373     DALI_TEST_CHECK( orientation == Dali::WindowOrientation::PORTRAIT );
374
375     DALI_TEST_CHECK( false );
376   }
377   catch( ... )
378   {
379     DALI_TEST_CHECK( true );
380   }
381   END_TEST;
382 }
383
384 // Internal callback function
385 void glInit(void)
386 {
387 }
388
389 int glRenderFrame(void)
390 {
391   static unsigned int retFlag = 0;
392   return retFlag++;
393 }
394
395 void glTerminate(void)
396 {
397 }
398
399 int UtcDaliGlWindowRegisterGlCallback(void)
400 {
401   Dali::GlWindow window;
402
403   try
404   {
405     window.RegisterGlCallback( Dali::MakeCallback( glInit ), Dali::MakeCallback( glRenderFrame ), Dali::MakeCallback( glTerminate ) );
406
407     DALI_TEST_CHECK( false );
408   }
409   catch( ... )
410   {
411     DALI_TEST_CHECK( true );
412   }
413   END_TEST;
414 }
415
416 int UtcDaliGlWindowRenderOnce(void)
417 {
418   Dali::GlWindow window;
419
420   try
421   {
422     window.RegisterGlCallback( Dali::MakeCallback( glInit ), Dali::MakeCallback( glRenderFrame ), Dali::MakeCallback( glTerminate ) );
423     window.RenderOnce();
424
425     DALI_TEST_CHECK( false );
426   }
427   catch( ... )
428   {
429     DALI_TEST_CHECK( true );
430   }
431   END_TEST;
432 }
433
434 int UtcDaliGlWindowGetSupportedAuxiliaryHintCount(void)
435 {
436   Dali::GlWindow window;
437
438   try
439   {
440     window.GetSupportedAuxiliaryHintCount();
441
442     DALI_TEST_CHECK( false );
443   }
444   catch( ... )
445   {
446     DALI_TEST_CHECK( true );
447   }
448   END_TEST;
449 }
450
451 int UtcDaliGlWindowGetSupportedAuxiliaryHint(void)
452 {
453   Dali::GlWindow window;
454
455   try
456   {
457     window.GetSupportedAuxiliaryHint( 0 );
458
459     DALI_TEST_CHECK( false );
460   }
461   catch( ... )
462   {
463     DALI_TEST_CHECK( true );
464   }
465   END_TEST;
466 }
467
468 int UtcDaliGlWindowAddAuxiliaryHint(void)
469 {
470   Dali::GlWindow window;
471
472   try
473   {
474     window.AddAuxiliaryHint( "stack_pop_to", "1" );
475
476     DALI_TEST_CHECK( false );
477   }
478   catch( ... )
479   {
480     DALI_TEST_CHECK( true );
481   }
482   END_TEST;
483 }
484
485 int UtcDaliGlWindowRemoveAuxiliaryHint(void)
486 {
487   Dali::GlWindow window;
488
489   try
490   {
491     window.RemoveAuxiliaryHint( 0 );
492
493     DALI_TEST_CHECK( false );
494   }
495   catch( ... )
496   {
497     DALI_TEST_CHECK( true );
498   }
499   END_TEST;
500 }
501
502 int UtcDaliGlWindowSetAuxiliaryHintValue(void)
503 {
504   Dali::GlWindow window;
505
506   try
507   {
508     window.SetAuxiliaryHintValue( 0,  "0" );
509
510     DALI_TEST_CHECK( false );
511   }
512   catch( ... )
513   {
514     DALI_TEST_CHECK( true );
515   }
516   END_TEST;
517 }
518
519 int UtcDaliGlWindowGetAuxiliaryHintValue(void)
520 {
521   Dali::GlWindow window;
522
523   try
524   {
525     window.GetAuxiliaryHintValue( 0 );
526
527     DALI_TEST_CHECK( false );
528   }
529   catch( ... )
530   {
531     DALI_TEST_CHECK( true );
532   }
533   END_TEST;
534 }
535
536 int UtcDaliGlWindowGetAuxiliaryHintId(void)
537 {
538   Dali::GlWindow window;
539
540   try
541   {
542     window.GetAuxiliaryHintId( "0" );
543
544     DALI_TEST_CHECK( false );
545   }
546   catch( ... )
547   {
548     DALI_TEST_CHECK( true );
549   }
550   END_TEST;
551 }
552
553 int UtcDaliGlWindowFocusChangeSignal(void)
554 {
555   Dali::GlWindow window;
556
557   try
558   {
559     window.FocusChangeSignal();
560
561     DALI_TEST_CHECK( false );
562   }
563   catch( ... )
564   {
565     DALI_TEST_CHECK( true );
566   }
567   END_TEST;
568 }
569
570 int UtcDaliGlWindowResizeSignal(void)
571 {
572   Dali::GlWindow window;
573
574   try
575   {
576     window.ResizeSignal();
577
578     DALI_TEST_CHECK( false );
579   }
580   catch( ... )
581   {
582     DALI_TEST_CHECK( true );
583   }
584   END_TEST;
585 }
586
587 int UtcDaliGlWindowKeyEventSignal(void)
588 {
589   Dali::GlWindow window;
590
591   try
592   {
593     window.KeyEventSignal();
594
595     DALI_TEST_CHECK( false );
596   }
597   catch( ... )
598   {
599     DALI_TEST_CHECK( true );
600   }
601   END_TEST;
602 }
603
604 int UtcDaliGlWindowTouchedSignal(void)
605 {
606   Dali::GlWindow window;
607
608   try
609   {
610     window.TouchedSignal();
611
612     DALI_TEST_CHECK( false );
613   }
614   catch( ... )
615   {
616     DALI_TEST_CHECK( true );
617   }
618   END_TEST;
619 }
620
621 int UtcDaliGlWindowVisibilityChangedSignal(void)
622 {
623   Dali::GlWindow window;
624
625   try
626   {
627     window.VisibilityChangedSignal();
628
629     DALI_TEST_CHECK( false );
630   }
631   catch( ... )
632   {
633     DALI_TEST_CHECK( true );
634   }
635   END_TEST;
636 }