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