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