DALi Version 2.2.11
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-scene3d / utc-Dali-Model.cpp
1 /*
2  * Copyright (c) 2022 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-toolkit-test-suite-utils.h>
19 #include <dali-toolkit/dali-toolkit.h>
20 #include <stdlib.h>
21 #include <iostream>
22
23 #include <dali-toolkit/devel-api/focus-manager/keyboard-focus-manager-devel.h>
24 #include <dali/integration-api/events/touch-event-integ.h>
25 #include <toolkit-event-thread-callback.h>
26
27 #include <dali-scene3d/public-api/controls/model/model.h>
28
29 using namespace Dali;
30 using namespace Dali::Toolkit;
31
32 void model_startup(void)
33 {
34   test_return_value = TET_UNDEF;
35 }
36
37 void model_cleanup(void)
38 {
39   test_return_value = TET_PASS;
40 }
41
42 namespace
43 {
44 const bool DEFAULT_MODEL_CHILDREN_SENSITIVE = false;
45 const bool DEFAULT_MODEL_CHILDREN_FOCUSABLE = false;
46 /**
47  * For the AnimatedCube.gltf and its Assets
48  * Donated by Norbert Nopper for glTF testing.
49  * Take from https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0/AnimatedCube
50  */
51 const char* TEST_GLTF_FILE_NAME                    = TEST_RESOURCE_DIR "/AnimatedCube.gltf";
52 const char* TEST_GLTF_ANIMATION_TEST_FILE_NAME     = TEST_RESOURCE_DIR "/animationTest.gltf";
53 const char* TEST_GLTF_MULTIPLE_PRIMITIVE_FILE_NAME = TEST_RESOURCE_DIR "/simpleMultiplePrimitiveTest.gltf";
54 const char* TEST_DLI_FILE_NAME                     = TEST_RESOURCE_DIR "/arc.dli";
55 const char* TEST_DLI_EXERCISE_FILE_NAME            = TEST_RESOURCE_DIR "/exercise.dli";
56 /**
57  * For the diffuse and specular cube map texture.
58  * These textures are based off version of Wave engine sample
59  * Take from https://github.com/WaveEngine/Samples
60  *
61  * Copyright (c) 2022 Wave Coorporation
62  *
63  * Permission is hereby granted, free of charge, to any person obtaining a copy
64  * of this software and associated documentation files (the "Software"), to
65  * deal in the Software without restriction, including without limitation the
66  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
67  * sell copies of the Software, and to permit persons to whom the Software is
68  * furnished to do so, subject to the following conditions:
69  *
70  * The above copyright notice and this permission notice shall be included in
71  * all copies or substantial portions of the Software.
72  *
73  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
74  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
75  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
76  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
77  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
78  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
79  * THE SOFTWARE.
80  */
81 const char* TEST_DIFFUSE_TEXTURE  = TEST_RESOURCE_DIR "/forest_irradiance.ktx";
82 const char* TEST_SPECULAR_TEXTURE = TEST_RESOURCE_DIR "/forest_radiance.ktx";
83
84 bool gTouchCallBackCalled = false;
85 bool TestTouchCallback(Actor, const TouchEvent&)
86 {
87   gTouchCallBackCalled = true;
88   return true;
89 }
90
91 bool gFocusChangedCallBackCalled = false;
92 void TestFocusChangedCallback(Actor, Actor)
93 {
94   gFocusChangedCallBackCalled = true;
95 }
96
97 // For ResourceReady
98 static bool gOnRelayoutCallBackCalled = false;
99 void        OnRelayoutCallback(Actor actor)
100 {
101   gOnRelayoutCallBackCalled = true;
102 }
103
104 static bool gResourceReadyCalled = false;
105 void        OnResourceReady(Control control)
106 {
107   gResourceReadyCalled = true;
108 }
109
110 } // namespace
111
112 // Negative test case for a method
113 int UtcDaliModelUninitialized(void)
114 {
115   ToolkitTestApplication application;
116   tet_infoline(" UtcDaliModelUninitialized");
117
118   Scene3D::Model model;
119
120   try
121   {
122     // New() must be called to create a Model or it wont be valid.
123     Actor a = Actor::New();
124     model.Add(a);
125     DALI_TEST_CHECK(false);
126   }
127   catch(Dali::DaliException& e)
128   {
129     // Tests that a negative test of an assertion succeeds
130     DALI_TEST_PRINT_ASSERT(e);
131     DALI_TEST_CHECK(!model);
132   }
133   END_TEST;
134 }
135
136 // Positive test case for a method
137 int UtcDaliModelNew(void)
138 {
139   ToolkitTestApplication application;
140   tet_infoline(" UtcDaliModelNew");
141
142   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
143   DALI_TEST_CHECK(model);
144   END_TEST;
145 }
146
147 // Positive test case for a method
148 int UtcDaliModelDownCast(void)
149 {
150   ToolkitTestApplication application;
151   tet_infoline(" UtcDaliModelDownCast");
152
153   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
154   BaseHandle     handle(model);
155
156   Scene3D::Model model2 = Scene3D::Model::DownCast(handle);
157   DALI_TEST_CHECK(model);
158   DALI_TEST_CHECK(model2);
159   DALI_TEST_CHECK(model2 == model);
160   END_TEST;
161 }
162
163 int UtcDaliModelTypeRegistry(void)
164 {
165   ToolkitTestApplication application;
166
167   TypeRegistry typeRegistry = TypeRegistry::Get();
168   DALI_TEST_CHECK(typeRegistry);
169
170   TypeInfo typeInfo = typeRegistry.GetTypeInfo("Model");
171   DALI_TEST_CHECK(typeInfo);
172
173   BaseHandle handle = typeInfo.CreateInstance();
174   DALI_TEST_CHECK(handle);
175
176   Scene3D::Model model = Scene3D::Model::DownCast(handle);
177   DALI_TEST_CHECK(model);
178
179   END_TEST;
180 }
181
182 // Positive test case for a method
183 int UtcDaliModelAddRemove(void)
184 {
185   ToolkitTestApplication application;
186   tet_infoline(" UtcDaliModelAddRemove");
187
188   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
189   DALI_TEST_CHECK(model);
190
191   Actor actor = Actor::New();
192   DALI_TEST_CHECK(!actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
193
194   model.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
195   model.SetProperty(Actor::Property::SIZE, application.GetScene().GetSize());
196   model.Add(actor);
197   application.GetScene().Add(model);
198
199   DALI_TEST_CHECK(actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
200
201   model.Remove(actor);
202
203   DALI_TEST_CHECK(!actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
204   END_TEST;
205 }
206
207 int UtcDaliModelCopyAndAssignment(void)
208 {
209   ToolkitTestApplication application;
210
211   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
212   DALI_TEST_CHECK(model);
213
214   Scene3D::Model copy(model);
215   DALI_TEST_CHECK(model == copy);
216
217   Scene3D::Model assign;
218   DALI_TEST_CHECK(!assign);
219
220   assign = copy;
221   DALI_TEST_CHECK(assign == model);
222
223   END_TEST;
224 }
225
226 int UtcDaliModelMoveConstructor(void)
227 {
228   ToolkitTestApplication application;
229
230   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
231   DALI_TEST_EQUALS(1, model.GetBaseObject().ReferenceCount(), TEST_LOCATION);
232   model.SetProperty(Actor::Property::SENSITIVE, false);
233   DALI_TEST_CHECK(false == model.GetProperty<bool>(Actor::Property::SENSITIVE));
234
235   Scene3D::Model moved = std::move(model);
236   DALI_TEST_CHECK(moved);
237   DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
238   DALI_TEST_CHECK(false == moved.GetProperty<bool>(Actor::Property::SENSITIVE));
239   DALI_TEST_CHECK(!model);
240
241   END_TEST;
242 }
243
244 int UtcDaliModelMoveAssignment(void)
245 {
246   ToolkitTestApplication application;
247
248   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
249   DALI_TEST_EQUALS(1, model.GetBaseObject().ReferenceCount(), TEST_LOCATION);
250   model.SetProperty(Actor::Property::SENSITIVE, false);
251   DALI_TEST_CHECK(false == model.GetProperty<bool>(Actor::Property::SENSITIVE));
252
253   Scene3D::Model moved;
254   moved = std::move(model);
255   DALI_TEST_CHECK(moved);
256   DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
257   DALI_TEST_CHECK(false == moved.GetProperty<bool>(Actor::Property::SENSITIVE));
258   DALI_TEST_CHECK(!model);
259
260   END_TEST;
261 }
262
263 int UtcDaliModelOnScene01(void)
264 {
265   ToolkitTestApplication application;
266
267   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
268   application.GetScene().Add(model);
269
270   gResourceReadyCalled = false;
271   model.ResourceReadySignal().Connect(&OnResourceReady);
272   DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
273
274   application.SendNotification();
275   application.Render();
276
277   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
278   application.SendNotification();
279   application.Render();
280
281   DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
282
283   uint32_t modelCount = model.GetModelRoot().GetChildCount();
284   DALI_TEST_EQUALS(1, modelCount, TEST_LOCATION);
285   END_TEST;
286 }
287
288 int UtcDaliModelOnScene02(void)
289 {
290   ToolkitTestApplication application;
291
292   Scene3D::Model model = Scene3D::Model::New(TEST_DLI_FILE_NAME);
293   application.GetScene().Add(model);
294
295   gResourceReadyCalled = false;
296   model.ResourceReadySignal().Connect(&OnResourceReady);
297   DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
298
299   application.SendNotification();
300   application.Render();
301
302   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
303   application.SendNotification();
304   application.Render();
305
306   DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
307
308   uint32_t modelCount = model.GetModelRoot().GetChildCount();
309   DALI_TEST_EQUALS(1, modelCount, TEST_LOCATION);
310
311   Actor   rootActor = model.GetModelRoot();
312   Vector3 rootSize  = rootActor.GetProperty<Vector3>(Dali::Actor::Property::SIZE);
313   DALI_TEST_EQUALS(Vector3(2, 2, 1), rootSize, TEST_LOCATION);
314
315   END_TEST;
316 }
317
318 int UtcDaliModelOnSizeSet(void)
319 {
320   ToolkitTestApplication application;
321
322   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
323
324   application.GetScene().Add(model);
325
326   application.SendNotification();
327   application.Render();
328
329   Vector2 size(200.0f, 300.0f);
330   model.SetProperty(Actor::Property::SIZE, size);
331
332   application.SendNotification();
333   application.Render();
334
335   DALI_TEST_EQUALS(model.GetCurrentProperty<Vector2>(Actor::Property::SIZE), size, TEST_LOCATION);
336
337   END_TEST;
338 }
339
340 int UtcDaliModelGetNaturalSize(void)
341 {
342   ToolkitTestApplication application;
343
344   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
345
346   Vector3 naturalSize = model.GetNaturalSize();
347   DALI_TEST_EQUALS(Vector3::ZERO, naturalSize, TEST_LOCATION);
348
349   application.GetScene().Add(model);
350
351   gResourceReadyCalled = false;
352   model.ResourceReadySignal().Connect(&OnResourceReady);
353   DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
354
355   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
356   application.SendNotification();
357
358   DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
359
360   naturalSize = model.GetNaturalSize();
361   DALI_TEST_EQUALS(Vector3(2, 2, 2), naturalSize, TEST_LOCATION);
362
363   Actor root = model.GetModelRoot();
364   DALI_TEST_CHECK(root);
365
366   END_TEST;
367 }
368
369 int UtcDaliModelSetImageBasedLightSource01(void)
370 {
371   ToolkitTestApplication application;
372
373   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
374   application.GetScene().Add(model);
375
376   gResourceReadyCalled = false;
377   model.ResourceReadySignal().Connect(&OnResourceReady);
378   DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
379
380   application.SendNotification();
381   application.Render();
382
383   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
384   application.SendNotification();
385   application.Render();
386
387   DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
388
389   Actor meshActor = model.FindChildByName("AnimatedCube");
390   DALI_TEST_CHECK(meshActor);
391
392   Renderer renderer = meshActor.GetRendererAt(0u);
393   DALI_TEST_CHECK(renderer);
394
395   TextureSet textureSet = renderer.GetTextures();
396   DALI_TEST_EQUALS(textureSet.GetTextureCount(), 9u, TEST_LOCATION);
397
398   Texture diffuseTexture  = textureSet.GetTexture(7u);
399   Texture specularTexture = textureSet.GetTexture(8u);
400
401   gResourceReadyCalled = false;
402   DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
403   model.SetImageBasedLightSource(TEST_DIFFUSE_TEXTURE, TEST_SPECULAR_TEXTURE);
404
405   application.SendNotification();
406   application.Render();
407
408   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
409   application.SendNotification();
410   application.Render();
411
412   DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
413
414   Texture newDiffuseTexture  = textureSet.GetTexture(7u);
415   Texture newSpecularTexture = textureSet.GetTexture(8u);
416
417   DALI_TEST_NOT_EQUALS(diffuseTexture, newDiffuseTexture, 0.0f, TEST_LOCATION);
418   DALI_TEST_NOT_EQUALS(specularTexture, newSpecularTexture, 0.0f, TEST_LOCATION);
419
420   model.Unparent();
421   model.Reset();
422   END_TEST;
423 }
424
425 int UtcDaliModelSetImageBasedLightSource02(void)
426 {
427   ToolkitTestApplication application;
428
429   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
430   application.GetScene().Add(model);
431
432   gResourceReadyCalled = false;
433   model.ResourceReadySignal().Connect(&OnResourceReady);
434   DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
435
436   application.SendNotification();
437   application.Render();
438
439   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
440   application.SendNotification();
441   application.Render();
442
443   DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
444
445   Actor meshActor = model.FindChildByName("AnimatedCube");
446   DALI_TEST_CHECK(meshActor);
447
448   Renderer renderer = meshActor.GetRendererAt(0u);
449   DALI_TEST_CHECK(renderer);
450
451   TextureSet textureSet = renderer.GetTextures();
452   DALI_TEST_EQUALS(textureSet.GetTextureCount(), 9u, TEST_LOCATION);
453
454   Texture diffuseTexture  = textureSet.GetTexture(7u);
455   Texture specularTexture = textureSet.GetTexture(8u);
456
457   // if url is empty, loading is not requested.
458   model.SetImageBasedLightSource("", "");
459
460   Texture newDiffuseTexture  = textureSet.GetTexture(7u);
461   Texture newSpecularTexture = textureSet.GetTexture(8u);
462
463   DALI_TEST_EQUALS(diffuseTexture, newDiffuseTexture, TEST_LOCATION);
464   DALI_TEST_EQUALS(specularTexture, newSpecularTexture, TEST_LOCATION);
465
466   END_TEST;
467 }
468
469 int UtcDaliModelSetImageBasedLightSource03(void)
470 {
471   ToolkitTestApplication application;
472
473   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
474   application.GetScene().Add(model);
475
476   gResourceReadyCalled = false;
477   model.ResourceReadySignal().Connect(&OnResourceReady);
478   DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
479
480   application.SendNotification();
481   application.Render();
482
483   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
484   application.SendNotification();
485   application.Render();
486
487   DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
488
489   Actor meshActor = model.FindChildByName("AnimatedCube");
490   DALI_TEST_CHECK(meshActor);
491
492   Renderer renderer = meshActor.GetRendererAt(0u);
493   DALI_TEST_CHECK(renderer);
494
495   TextureSet textureSet = renderer.GetTextures();
496   DALI_TEST_EQUALS(textureSet.GetTextureCount(), 9u, TEST_LOCATION);
497
498   Texture diffuseTexture  = textureSet.GetTexture(7u);
499   Texture specularTexture = textureSet.GetTexture(8u);
500
501   gResourceReadyCalled = false;
502   DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
503   model.SetImageBasedLightSource("dummy.ktx", "dummy.ktx");
504
505   application.SendNotification();
506   application.Render();
507
508   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
509   application.SendNotification();
510   application.Render();
511
512   DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
513
514   Texture newDiffuseTexture  = textureSet.GetTexture(7u);
515   Texture newSpecularTexture = textureSet.GetTexture(8u);
516
517   DALI_TEST_EQUALS(diffuseTexture, newDiffuseTexture, TEST_LOCATION);
518   DALI_TEST_EQUALS(specularTexture, newSpecularTexture, TEST_LOCATION);
519
520   END_TEST;
521 }
522
523 int UtcDaliModelSetImageBasedLightSource04(void)
524 {
525   ToolkitTestApplication application;
526
527   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
528   model.SetImageBasedLightSource(TEST_DIFFUSE_TEXTURE, TEST_SPECULAR_TEXTURE);
529   application.GetScene().Add(model);
530
531   gResourceReadyCalled = false;
532   model.ResourceReadySignal().Connect(&OnResourceReady);
533   DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
534
535   application.SendNotification();
536   application.Render();
537
538   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
539   application.SendNotification();
540   application.Render();
541
542   DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
543   END_TEST;
544 }
545
546 int UtcDaliModelImageBasedFactor(void)
547 {
548   ToolkitTestApplication application;
549
550   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
551
552   DALI_TEST_EQUALS(model.GetImageBasedLightScaleFactor(), 1.0f, TEST_LOCATION);
553
554   model.SetImageBasedLightScaleFactor(0.5f);
555   DALI_TEST_EQUALS(model.GetImageBasedLightScaleFactor(), 0.5f, TEST_LOCATION);
556   END_TEST;
557 }
558
559 int UtcDaliModelChildrenSensitive01(void)
560 {
561   ToolkitTestApplication application;
562
563   Scene3D::Model view = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
564   view.SetProperty(Dali::Actor::Property::SIZE, Vector3(100, 100, 100));
565   view.SetProperty(Dali::Actor::Property::POSITION, Vector3(0, 0, 0));
566   view.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
567   view.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
568
569   // Get default vaule.
570   DALI_TEST_EQUALS(view.GetChildrenSensitive(), DEFAULT_MODEL_CHILDREN_SENSITIVE, TEST_LOCATION);
571
572   // Allow children actor's event before on scene.
573   view.SetChildrenSensitive(true);
574   DALI_TEST_EQUALS(view.GetChildrenSensitive(), true, TEST_LOCATION);
575   application.GetScene().Add(view);
576
577   gResourceReadyCalled = false;
578   view.ResourceReadySignal().Connect(&OnResourceReady);
579   DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
580
581   application.SendNotification();
582   application.Render();
583
584   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
585   application.SendNotification();
586   application.Render();
587
588   DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
589
590   Actor meshActor = view.FindChildByName("AnimatedCube");
591   DALI_TEST_CHECK(meshActor);
592
593   // connect hit-test signal
594   gTouchCallBackCalled = false;
595   meshActor.TouchedSignal().Connect(TestTouchCallback);
596
597   Vector2 sceneSize = application.GetScene().GetSize();
598
599   // Try to touch center of scene.
600   Dali::Integration::Point point;
601   point.SetState(PointState::DOWN);
602   point.SetScreenPosition(sceneSize * 0.5f);
603   Dali::Integration::TouchEvent event;
604   event.AddPoint(point);
605
606   // flush the queue and render once
607   application.SendNotification();
608   application.Render();
609
610   // Not touched yet.
611   DALI_TEST_CHECK(!gTouchCallBackCalled);
612   application.ProcessEvent(event);
613   // Touched.
614   DALI_TEST_CHECK(gTouchCallBackCalled);
615
616   // Clear
617   gTouchCallBackCalled = false;
618
619   // Block children actor's event
620   view.SetChildrenSensitive(false);
621   DALI_TEST_EQUALS(view.GetChildrenSensitive(), false, TEST_LOCATION);
622
623   // flush the queue and render once
624   application.SendNotification();
625   application.Render();
626
627   // Not touched yet.
628   DALI_TEST_CHECK(!gTouchCallBackCalled);
629   application.ProcessEvent(event);
630   // Also not touched.
631   DALI_TEST_CHECK(!gTouchCallBackCalled);
632
633   // Clear
634   gTouchCallBackCalled = false;
635
636   // Allow again
637   view.SetChildrenSensitive(true);
638   DALI_TEST_EQUALS(view.GetChildrenSensitive(), true, TEST_LOCATION);
639
640   // flush the queue and render once
641   application.SendNotification();
642   application.Render();
643
644   // Not touched yet.
645   DALI_TEST_CHECK(!gTouchCallBackCalled);
646   application.ProcessEvent(event);
647   // Touched.
648   DALI_TEST_CHECK(gTouchCallBackCalled);
649
650   // Clear
651   gTouchCallBackCalled = false;
652
653   END_TEST;
654 }
655
656 int UtcDaliModelChildrenSensitive02(void)
657 {
658   ToolkitTestApplication application;
659
660   Scene3D::Model view = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
661   view.SetProperty(Dali::Actor::Property::SIZE, Vector3(100, 100, 100));
662   view.SetProperty(Dali::Actor::Property::POSITION, Vector3(0, 0, 0));
663   view.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
664   view.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
665
666   // Get vaule.
667   DALI_TEST_EQUALS(view.GetChildrenSensitive(), DEFAULT_MODEL_CHILDREN_SENSITIVE, TEST_LOCATION);
668
669   // Block children actor's event before on scene.
670   view.SetChildrenSensitive(false);
671   DALI_TEST_EQUALS(view.GetChildrenSensitive(), false, TEST_LOCATION);
672   application.GetScene().Add(view);
673
674   gResourceReadyCalled = false;
675   view.ResourceReadySignal().Connect(&OnResourceReady);
676   DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
677
678   application.SendNotification();
679   application.Render();
680
681   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
682   application.SendNotification();
683   application.Render();
684
685   DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
686
687   Actor meshActor = view.FindChildByName("AnimatedCube");
688   DALI_TEST_CHECK(meshActor);
689
690   // connect hit-test signal
691   gTouchCallBackCalled = false;
692   meshActor.TouchedSignal().Connect(TestTouchCallback);
693
694   Vector2 sceneSize = application.GetScene().GetSize();
695
696   // Try to touch center of scene.
697   Dali::Integration::Point point;
698   point.SetState(PointState::DOWN);
699   point.SetScreenPosition(sceneSize * 0.5f);
700   Dali::Integration::TouchEvent event;
701   event.AddPoint(point);
702
703   // flush the queue and render once
704   application.SendNotification();
705   application.Render();
706
707   // Not touched yet.
708   DALI_TEST_CHECK(!gTouchCallBackCalled);
709   application.ProcessEvent(event);
710   // Also not touched.
711   DALI_TEST_CHECK(!gTouchCallBackCalled);
712
713   // Clear
714   gTouchCallBackCalled = false;
715
716   // Allow again
717   view.SetChildrenSensitive(true);
718   DALI_TEST_EQUALS(view.GetChildrenSensitive(), true, TEST_LOCATION);
719
720   // flush the queue and render once
721   application.SendNotification();
722   application.Render();
723
724   // Not touched yet.
725   DALI_TEST_CHECK(!gTouchCallBackCalled);
726   application.ProcessEvent(event);
727   // Touched.
728   DALI_TEST_CHECK(gTouchCallBackCalled);
729
730   // Clear
731   gTouchCallBackCalled = false;
732
733   END_TEST;
734 }
735
736 int UtcDaliModelChildrenFocusable01(void)
737 {
738   ToolkitTestApplication application;
739
740   Scene3D::Model view = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
741   view.SetProperty(Dali::Actor::Property::SIZE, Vector3(100, 100, 100));
742   view.SetProperty(Dali::Actor::Property::POSITION, Vector3(0, 0, 0));
743   view.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
744   view.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
745
746   // Get vaule. Default is false.
747   DALI_TEST_EQUALS(view.GetChildrenFocusable(), DEFAULT_MODEL_CHILDREN_FOCUSABLE, TEST_LOCATION);
748
749   // Allow children actor's focus before on scene.
750   view.SetChildrenFocusable(true);
751   DALI_TEST_EQUALS(view.GetChildrenFocusable(), true, TEST_LOCATION);
752   application.GetScene().Add(view);
753
754   gResourceReadyCalled = false;
755   view.ResourceReadySignal().Connect(&OnResourceReady);
756   DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
757
758   application.SendNotification();
759   application.Render();
760
761   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
762   application.SendNotification();
763   application.Render();
764
765   DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
766
767   Actor meshActor = view.FindChildByName("AnimatedCube");
768   DALI_TEST_CHECK(meshActor);
769
770   // Enable the default algorithm
771   KeyboardFocusManager manager = KeyboardFocusManager::Get();
772   DALI_TEST_CHECK(manager);
773   Dali::Toolkit::DevelKeyboardFocusManager::EnableDefaultAlgorithm(manager, true);
774
775   // connect focusable signal
776   gFocusChangedCallBackCalled = false;
777   meshActor.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
778   manager.FocusChangedSignal().Connect(TestFocusChangedCallback);
779
780   // Initialize with some left-positioned actor
781   Control focusStartActor = Control::New();
782   focusStartActor.SetProperty(Dali::Actor::Property::SIZE, Vector3(100, 100, 100));
783   focusStartActor.SetProperty(Dali::Actor::Property::POSITION, Vector3(-200, 0, 0));
784   focusStartActor.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
785   focusStartActor.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
786   focusStartActor.SetProperty(Dali::Actor::Property::KEYBOARD_FOCUSABLE, true);
787   application.GetScene().Add(focusStartActor);
788
789   // Clear
790   manager.ClearFocus();
791   manager.SetCurrentFocusActor(focusStartActor);
792   gFocusChangedCallBackCalled = false;
793
794   // flush the queue and render once
795   application.SendNotification();
796   application.Render();
797
798   // Focusable view find success
799   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
800   DALI_TEST_CHECK(gFocusChangedCallBackCalled);
801
802   // Clear
803   manager.ClearFocus();
804   manager.SetCurrentFocusActor(focusStartActor);
805   gFocusChangedCallBackCalled = false;
806
807   // Block children actor's focus
808   view.SetChildrenFocusable(false);
809   DALI_TEST_EQUALS(view.GetChildrenFocusable(), false, TEST_LOCATION);
810
811   // flush the queue and render once
812   application.SendNotification();
813   application.Render();
814
815   // Focusable view find failed
816   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
817   DALI_TEST_CHECK(!gFocusChangedCallBackCalled);
818
819   // Clear
820   manager.ClearFocus();
821   manager.SetCurrentFocusActor(focusStartActor);
822   gFocusChangedCallBackCalled = false;
823
824   // Allow again
825   view.SetChildrenFocusable(true);
826   DALI_TEST_EQUALS(view.GetChildrenFocusable(), true, TEST_LOCATION);
827
828   // flush the queue and render once
829   application.SendNotification();
830   application.Render();
831
832   // Focusable view find success
833   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
834   DALI_TEST_CHECK(gFocusChangedCallBackCalled);
835
836   // Clear
837   manager.ClearFocus();
838   manager.SetCurrentFocusActor(focusStartActor);
839   gFocusChangedCallBackCalled = false;
840
841   END_TEST;
842 }
843
844 int UtcDaliModelModelChildrenFocusable02(void)
845 {
846   ToolkitTestApplication application;
847
848   Scene3D::Model view = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
849   view.SetProperty(Dali::Actor::Property::SIZE, Vector3(100, 100, 100));
850   view.SetProperty(Dali::Actor::Property::POSITION, Vector3(0, 0, 0));
851   view.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
852   view.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
853
854   // Get vaule. Default is true.
855   DALI_TEST_EQUALS(view.GetChildrenFocusable(), DEFAULT_MODEL_CHILDREN_FOCUSABLE, TEST_LOCATION);
856
857   // Block children actor's focus before on scene.
858   view.SetChildrenFocusable(false);
859   DALI_TEST_EQUALS(view.GetChildrenFocusable(), false, TEST_LOCATION);
860   application.GetScene().Add(view);
861
862   gResourceReadyCalled = false;
863   view.ResourceReadySignal().Connect(&OnResourceReady);
864   DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
865
866   application.SendNotification();
867   application.Render();
868
869   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
870   application.SendNotification();
871   application.Render();
872
873   DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
874
875   Actor meshActor = view.FindChildByName("AnimatedCube");
876   DALI_TEST_CHECK(meshActor);
877
878   // Enable the default algorithm
879   KeyboardFocusManager manager = KeyboardFocusManager::Get();
880   DALI_TEST_CHECK(manager);
881   Dali::Toolkit::DevelKeyboardFocusManager::EnableDefaultAlgorithm(manager, true);
882
883   // connect focusable signal
884   gFocusChangedCallBackCalled = false;
885   meshActor.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
886   manager.FocusChangedSignal().Connect(TestFocusChangedCallback);
887
888   // Initialize with some left-positioned actor
889   Control focusStartActor = Control::New();
890   focusStartActor.SetProperty(Dali::Actor::Property::SIZE, Vector3(100, 100, 100));
891   focusStartActor.SetProperty(Dali::Actor::Property::POSITION, Vector3(-200, 0, 0));
892   focusStartActor.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
893   focusStartActor.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
894   focusStartActor.SetProperty(Dali::Actor::Property::KEYBOARD_FOCUSABLE, true);
895   application.GetScene().Add(focusStartActor);
896
897   // Clear
898   manager.ClearFocus();
899   manager.SetCurrentFocusActor(focusStartActor);
900   gFocusChangedCallBackCalled = false;
901
902   // flush the queue and render once
903   application.SendNotification();
904   application.Render();
905
906   // Focusable view find failed
907   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
908   DALI_TEST_CHECK(!gFocusChangedCallBackCalled);
909
910   // Clear
911   manager.ClearFocus();
912   manager.SetCurrentFocusActor(focusStartActor);
913   gFocusChangedCallBackCalled = false;
914
915   // Allow again
916   view.SetChildrenFocusable(true);
917   DALI_TEST_EQUALS(view.GetChildrenFocusable(), true, TEST_LOCATION);
918
919   // flush the queue and render once
920   application.SendNotification();
921   application.Render();
922
923   // Focusable view find success
924   DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
925   DALI_TEST_CHECK(gFocusChangedCallBackCalled);
926
927   // Clear
928   manager.ClearFocus();
929   manager.SetCurrentFocusActor(focusStartActor);
930   gFocusChangedCallBackCalled = false;
931
932   END_TEST;
933 }
934
935 int UtcDaliModelAnimation01(void)
936 {
937   ToolkitTestApplication application;
938
939   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
940   model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
941   application.GetScene().Add(model);
942
943   gResourceReadyCalled = false;
944   model.ResourceReadySignal().Connect(&OnResourceReady);
945   DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
946
947   application.SendNotification();
948   application.Render();
949
950   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
951   application.SendNotification();
952   application.Render();
953
954   DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
955
956   uint32_t animationCount = model.GetAnimationCount();
957   DALI_TEST_EQUALS(1, animationCount, TEST_LOCATION);
958
959   Animation animationByIndex = model.GetAnimation(0u);
960   DALI_TEST_CHECK(animationByIndex);
961
962   Animation animationByName = model.GetAnimation("animation_AnimatedCube");
963   DALI_TEST_CHECK(animationByName);
964   DALI_TEST_EQUALS(animationByIndex, animationByName, TEST_LOCATION);
965
966   END_TEST;
967 }
968
969 int UtcDaliModelAnimation02(void)
970 {
971   ToolkitTestApplication application;
972
973   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_ANIMATION_TEST_FILE_NAME);
974   model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
975   application.GetScene().Add(model);
976
977   gResourceReadyCalled = false;
978   model.ResourceReadySignal().Connect(&OnResourceReady);
979   DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
980
981   application.SendNotification();
982   application.Render();
983
984   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
985   application.SendNotification();
986   application.Render();
987
988   uint32_t animationCount = model.GetAnimationCount();
989   DALI_TEST_EQUALS(9, animationCount, TEST_LOCATION);
990
991   Animation animation1 = model.GetAnimation("Step Scale");
992   DALI_TEST_CHECK(animation1);
993   DALI_TEST_EQUALS(1.66667f, animation1.GetDuration(), 0.001f, TEST_LOCATION);
994
995   Animation animation2 = model.GetAnimation("CubicSpline Scale");
996   DALI_TEST_CHECK(animation2);
997   DALI_TEST_EQUALS(1.66667f, animation2.GetDuration(), 0.001f, TEST_LOCATION);
998
999   DALI_TEST_NOT_EQUALS(animation1, animation2, 0.0f, TEST_LOCATION);
1000
1001   END_TEST;
1002 }
1003
1004 int UtcDaliModelAnimation03(void)
1005 {
1006   ToolkitTestApplication application;
1007
1008   Scene3D::Model model = Scene3D::Model::New(TEST_DLI_EXERCISE_FILE_NAME);
1009   model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
1010   application.GetScene().Add(model);
1011
1012   gResourceReadyCalled = false;
1013   model.ResourceReadySignal().Connect(&OnResourceReady);
1014   DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1015
1016   application.SendNotification();
1017   application.Render();
1018
1019   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1020   application.SendNotification();
1021   application.Render();
1022
1023   DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
1024
1025   uint32_t animationCount = model.GetAnimationCount();
1026   DALI_TEST_EQUALS(18, animationCount, TEST_LOCATION);
1027
1028   Animation animationByIndex = model.GetAnimation(0u);
1029   DALI_TEST_CHECK(animationByIndex);
1030
1031   Animation animationByName = model.GetAnimation("idleClip");
1032   DALI_TEST_CHECK(animationByName);
1033   DALI_TEST_EQUALS(animationByIndex, animationByName, TEST_LOCATION);
1034
1035   END_TEST;
1036 }
1037
1038 int UtcDaliModelMultiplePrimitives(void)
1039 {
1040   ToolkitTestApplication application;
1041
1042   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_MULTIPLE_PRIMITIVE_FILE_NAME);
1043   model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
1044   application.GetScene().Add(model);
1045
1046   gResourceReadyCalled = false;
1047   model.ResourceReadySignal().Connect(&OnResourceReady);
1048   DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1049
1050   application.SendNotification();
1051   application.Render();
1052
1053   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1054   application.SendNotification();
1055   application.Render();
1056
1057   Actor actor = model.FindChildByName("rootNode");
1058
1059   DALI_TEST_EQUALS(0, actor.GetChildCount(), TEST_LOCATION);
1060   DALI_TEST_EQUALS(2, actor.GetRendererCount(), TEST_LOCATION);
1061
1062   END_TEST;
1063 }
1064
1065 int UtcDaliModelColorMode(void)
1066 {
1067   ToolkitTestApplication application;
1068
1069   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
1070   model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
1071   model.SetProperty(Dali::Actor::Property::COLOR, Color::RED);
1072   application.GetScene().Add(model);
1073
1074   gResourceReadyCalled = false;
1075   model.ResourceReadySignal().Connect(&OnResourceReady);
1076   DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1077
1078   application.SendNotification();
1079   application.Render();
1080
1081   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1082   application.SendNotification();
1083   application.Render();
1084
1085   Actor actor = model.FindChildByName("AnimatedCube");
1086   Vector4 childColor = actor[Dali::Actor::Property::COLOR];
1087   Vector4 childWorldColor = actor[Dali::Actor::Property::WORLD_COLOR];
1088
1089   DALI_TEST_EQUALS(childColor, Color::WHITE, TEST_LOCATION);
1090   DALI_TEST_EQUALS(childWorldColor, Color::RED, TEST_LOCATION);
1091
1092   END_TEST;
1093 }
1094 int UtcDaliModelResourceReady(void)
1095 {
1096   ToolkitTestApplication application;
1097
1098   gOnRelayoutCallBackCalled = false;
1099   gResourceReadyCalled      = false;
1100   Scene3D::Model model      = Scene3D::Model::New(TEST_GLTF_ANIMATION_TEST_FILE_NAME);
1101   model.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1102   model.OnRelayoutSignal().Connect(OnRelayoutCallback);
1103   model.ResourceReadySignal().Connect(OnResourceReady);
1104   DALI_TEST_EQUALS(model.IsResourceReady(), false, TEST_LOCATION);
1105
1106   // Sanity check
1107   DALI_TEST_CHECK(!gOnRelayoutCallBackCalled);
1108   DALI_TEST_CHECK(!gResourceReadyCalled);
1109
1110   application.GetScene().Add(model);
1111
1112   application.SendNotification();
1113   application.Render();
1114
1115   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1116   application.SendNotification();
1117   application.Render();
1118
1119   DALI_TEST_EQUALS(gOnRelayoutCallBackCalled, false, TEST_LOCATION);
1120   DALI_TEST_EQUALS(model.IsResourceReady(), true, TEST_LOCATION);
1121   DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
1122
1123   END_TEST;
1124 }