2 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <dali-test-suite-utils.h>
19 #include <dali-scene3d/public-api/loader/bvh-loader.h>
22 using namespace Dali::Scene3D::Loader;
24 int UtcDaliLoadBvh(void)
26 TestApplication application;
28 AnimationDefinition animDef = LoadBvh(TEST_RESOURCE_DIR "/test.bvh", "testBvh");
30 DALI_TEST_EQUAL(animDef.mName, "testBvh");
31 DALI_TEST_EQUAL(animDef.mDuration, 0.3f);
33 DALI_TEST_EQUAL(animDef.mProperties[0].mNodeName, "root");
34 DALI_TEST_EQUAL(animDef.mProperties[0].mPropertyName, "position");
35 DALI_TEST_EQUAL(animDef.mProperties[0].mKeyFrames.GetType(), Property::Type::VECTOR3);
36 DALI_TEST_EQUAL(animDef.mProperties[0].mTimePeriod.durationSeconds, 0.3f);
38 DALI_TEST_EQUAL(animDef.mProperties[1].mNodeName, "root");
39 DALI_TEST_EQUAL(animDef.mProperties[1].mPropertyName, "orientation");
40 DALI_TEST_EQUAL(animDef.mProperties[1].mKeyFrames.GetType(), Property::Type::ROTATION);
41 DALI_TEST_EQUAL(animDef.mProperties[1].mTimePeriod.durationSeconds, 0.3f);
43 DALI_TEST_EQUAL(animDef.mProperties[2].mNodeName, "first");
44 DALI_TEST_EQUAL(animDef.mProperties[2].mPropertyName, "position");
45 DALI_TEST_EQUAL(animDef.mProperties[2].mKeyFrames.GetType(), Property::Type::VECTOR3);
46 DALI_TEST_EQUAL(animDef.mProperties[2].mTimePeriod.durationSeconds, 0.3f);
48 DALI_TEST_EQUAL(animDef.mProperties[3].mNodeName, "first");
49 DALI_TEST_EQUAL(animDef.mProperties[3].mPropertyName, "orientation");
50 DALI_TEST_EQUAL(animDef.mProperties[3].mKeyFrames.GetType(), Property::Type::ROTATION);
51 DALI_TEST_EQUAL(animDef.mProperties[3].mTimePeriod.durationSeconds, 0.3f);
53 Actor root = Actor::New();
54 root.SetProperty(Actor::Property::NAME, "root");
56 Actor first = Actor::New();
57 first.SetProperty(Actor::Property::NAME, "first");
60 auto getActor = [&root](const std::string& name) {
61 return root.FindChildByName(name);
64 Animation animation = animDef.ReAnimate(getActor);
65 DALI_TEST_EQUAL(animation.GetDuration(), animDef.mDuration);
67 application.GetScene().Add(root);
69 application.SendNotification();
70 application.Render(20);
72 DALI_TEST_EQUALS(Vector2(0, 0), root.GetProperty<Vector2>(Actor::Property::POSITION), TEST_LOCATION);
73 DALI_TEST_EQUALS(Vector2(0, 0), first.GetProperty<Vector2>(Actor::Property::POSITION), TEST_LOCATION);
74 Vector3 rootWorldPositionBefore = root.GetProperty<Vector3>(Actor::Property::WORLD_POSITION);
75 Vector3 firstWorldPositionBefore = first.GetProperty<Vector3>(Actor::Property::WORLD_POSITION);
79 application.SendNotification();
80 application.Render(1000);
82 DALI_TEST_EQUALS(Vector2(0, 10), root.GetProperty<Vector2>(Actor::Property::POSITION), TEST_LOCATION);
83 DALI_TEST_EQUALS(Vector2(10, 0), first.GetProperty<Vector2>(Actor::Property::POSITION), TEST_LOCATION);
85 Vector3 rootWorldPositionAfter = root.GetProperty<Vector3>(Actor::Property::WORLD_POSITION);
86 Vector3 firstWorldPositionAfter = first.GetProperty<Vector3>(Actor::Property::WORLD_POSITION);
88 DALI_TEST_EQUALS(Vector3(0, 10, 0), rootWorldPositionAfter - rootWorldPositionBefore, TEST_LOCATION);
89 DALI_TEST_EQUALS(Vector3(10, 10, 0), firstWorldPositionAfter - firstWorldPositionBefore, TEST_LOCATION);
96 int UtcDaliLoadBvhFailed(void)
98 TestApplication application;
100 AnimationDefinition animDef = LoadBvh("/nothing.bvh", "testBvh");
101 DALI_TEST_EQUALS(0u, animDef.mProperties.size(), TEST_LOCATION);