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