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