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