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