X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali-scene3d%2Futc-Dali-BvhLoader.cpp;h=b3958041a99a88a9ac40365d5967a9631237d6b8;hb=HEAD;hp=91fdb193cec47bd021a4e6978a211c3ff294337f;hpb=4d20f543c4b4d3a9d62ee2e8f33e732ffea88d92;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/automated-tests/src/dali-scene3d/utc-Dali-BvhLoader.cpp b/automated-tests/src/dali-scene3d/utc-Dali-BvhLoader.cpp index 91fdb19..b395804 100644 --- a/automated-tests/src/dali-scene3d/utc-Dali-BvhLoader.cpp +++ b/automated-tests/src/dali-scene3d/utc-Dali-BvhLoader.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,89 +15,176 @@ * */ -#include #include +#include + +#include using namespace Dali; using namespace Dali::Scene3D::Loader; -int UtcDaliLoadBvh(void) +namespace { - TestApplication application; - - AnimationDefinition animDef = LoadBvh(TEST_RESOURCE_DIR "/test.bvh", "testBvh"); - - DALI_TEST_EQUAL(animDef.mName, "testBvh"); - DALI_TEST_EQUAL(animDef.mDuration, 0.3f); - - DALI_TEST_EQUAL(animDef.mProperties[0].mNodeName, "root"); - DALI_TEST_EQUAL(animDef.mProperties[0].mPropertyName, "position"); - DALI_TEST_EQUAL(animDef.mProperties[0].mKeyFrames.GetType(), Property::Type::VECTOR3); - DALI_TEST_EQUAL(animDef.mProperties[0].mTimePeriod.durationSeconds, 0.3f); - - DALI_TEST_EQUAL(animDef.mProperties[1].mNodeName, "root"); - DALI_TEST_EQUAL(animDef.mProperties[1].mPropertyName, "orientation"); - DALI_TEST_EQUAL(animDef.mProperties[1].mKeyFrames.GetType(), Property::Type::ROTATION); - DALI_TEST_EQUAL(animDef.mProperties[1].mTimePeriod.durationSeconds, 0.3f); - - DALI_TEST_EQUAL(animDef.mProperties[2].mNodeName, "first"); - DALI_TEST_EQUAL(animDef.mProperties[2].mPropertyName, "position"); - DALI_TEST_EQUAL(animDef.mProperties[2].mKeyFrames.GetType(), Property::Type::VECTOR3); - DALI_TEST_EQUAL(animDef.mProperties[2].mTimePeriod.durationSeconds, 0.3f); - - DALI_TEST_EQUAL(animDef.mProperties[3].mNodeName, "first"); - DALI_TEST_EQUAL(animDef.mProperties[3].mPropertyName, "orientation"); - DALI_TEST_EQUAL(animDef.mProperties[3].mKeyFrames.GetType(), Property::Type::ROTATION); - DALI_TEST_EQUAL(animDef.mProperties[3].mTimePeriod.durationSeconds, 0.3f); - - Actor root = Actor::New(); - root.SetProperty(Actor::Property::NAME, "root"); - - Actor first = Actor::New(); - first.SetProperty(Actor::Property::NAME, "first"); - root.Add(first); - - auto getActor = [&root](const std::string& name) { - return root.FindChildByName(name); - }; +std::string ReadBufferFromFile(const std::string& url) +{ + std::string rawString; + std::fstream fileStream; - Animation animation = animDef.ReAnimate(getActor); - DALI_TEST_EQUAL(animation.GetDuration(), animDef.mDuration); + fileStream.open(url, std::ios::in | std::ios::binary); + if(!fileStream.is_open()) + { + DALI_LOG_WARNING("stream open failed for: \"%s\", in mode: \"%d\".\n", url.c_str(), static_cast(std::ios::in | std::ios::binary)); + } - application.GetScene().Add(root); + // get length of file: + fileStream.seekg(0, std::ios::end); + auto length = fileStream.tellg(); + fileStream.seekg(0, std::ios::beg); - application.SendNotification(); - application.Render(20); + rawString.resize(length); + fileStream.read(rawString.data(), length); - DALI_TEST_EQUALS(Vector2(0, 0), root.GetProperty(Actor::Property::POSITION), TEST_LOCATION); - DALI_TEST_EQUALS(Vector2(0, 0), first.GetProperty(Actor::Property::POSITION), TEST_LOCATION); - Vector3 rootWorldPositionBefore = root.GetProperty(Actor::Property::WORLD_POSITION); - Vector3 firstWorldPositionBefore = first.GetProperty(Actor::Property::WORLD_POSITION); + fileStream.close(); - animation.Play(); + return rawString; +} +} // namespace - application.SendNotification(); - application.Render(1000); +int UtcDaliLoadBvh(void) +{ + TestApplication application; - DALI_TEST_EQUALS(Vector2(0, 10), root.GetProperty(Actor::Property::POSITION), TEST_LOCATION); - DALI_TEST_EQUALS(Vector2(10, 0), first.GetProperty(Actor::Property::POSITION), TEST_LOCATION); + for(uint32_t tc = 0; tc < 2; ++tc) + { + AnimationDefinition animDef; + tet_printf("UtcDaliLoadBvh testcase %u\n", tc); + switch(tc) + { + case 0: // Load bvh from url + { + animDef = LoadBvh(TEST_RESOURCE_DIR "/test.bvh", "testBvh", false); + break; + } + case 1: // Load bvh from buffer stream. + { + std::string rawString = ReadBufferFromFile(TEST_RESOURCE_DIR "/test.bvh"); + animDef = LoadBvhFromBuffer(reinterpret_cast(rawString.data()), static_cast(rawString.length()), "testBvh", false); + break; + } + } + + DALI_TEST_EQUAL(animDef.GetName(), "testBvh"); + DALI_TEST_EQUAL(animDef.GetDuration(), 0.3f); + + DALI_TEST_EQUAL(animDef.GetPropertyAt(0).mNodeName, "root"); + DALI_TEST_EQUAL(animDef.GetPropertyAt(0).mPropertyName, "position"); + DALI_TEST_EQUAL(animDef.GetPropertyAt(0).mKeyFrames.GetType(), Property::Type::VECTOR3); + DALI_TEST_EQUAL(animDef.GetPropertyAt(0).mTimePeriod.durationSeconds, 0.3f); + + DALI_TEST_EQUAL(animDef.GetPropertyAt(1).mNodeName, "root"); + DALI_TEST_EQUAL(animDef.GetPropertyAt(1).mPropertyName, "orientation"); + DALI_TEST_EQUAL(animDef.GetPropertyAt(1).mKeyFrames.GetType(), Property::Type::ROTATION); + DALI_TEST_EQUAL(animDef.GetPropertyAt(1).mTimePeriod.durationSeconds, 0.3f); + + DALI_TEST_EQUAL(animDef.GetPropertyAt(2).mNodeName, "first"); + DALI_TEST_EQUAL(animDef.GetPropertyAt(2).mPropertyName, "position"); + DALI_TEST_EQUAL(animDef.GetPropertyAt(2).mKeyFrames.GetType(), Property::Type::VECTOR3); + DALI_TEST_EQUAL(animDef.GetPropertyAt(2).mTimePeriod.durationSeconds, 0.3f); + + DALI_TEST_EQUAL(animDef.GetPropertyAt(3).mNodeName, "first"); + DALI_TEST_EQUAL(animDef.GetPropertyAt(3).mPropertyName, "orientation"); + DALI_TEST_EQUAL(animDef.GetPropertyAt(3).mKeyFrames.GetType(), Property::Type::ROTATION); + DALI_TEST_EQUAL(animDef.GetPropertyAt(3).mTimePeriod.durationSeconds, 0.3f); + + Actor root = Actor::New(); + root.SetProperty(Actor::Property::NAME, "root"); + + Actor first = Actor::New(); + first.SetProperty(Actor::Property::NAME, "first"); + root.Add(first); + + auto getActor = [&root](const Dali::Scene3D::Loader::AnimatedProperty& property) { + return root.FindChildByName(property.mNodeName); + }; + + Animation animation = animDef.ReAnimate(getActor); + DALI_TEST_EQUAL(animation.GetDuration(), animDef.GetDuration()); + + application.GetScene().Add(root); + + application.SendNotification(); + application.Render(20); + + DALI_TEST_EQUALS(Vector2(0, 0), root.GetProperty(Actor::Property::POSITION), TEST_LOCATION); + DALI_TEST_EQUALS(Vector2(0, 0), first.GetProperty(Actor::Property::POSITION), TEST_LOCATION); + Vector3 rootWorldPositionBefore = root.GetProperty(Actor::Property::WORLD_POSITION); + Vector3 firstWorldPositionBefore = first.GetProperty(Actor::Property::WORLD_POSITION); + + animation.Play(); + + application.SendNotification(); + application.Render(1000); + + DALI_TEST_EQUALS(Vector2(0, 10), root.GetProperty(Actor::Property::POSITION), TEST_LOCATION); + DALI_TEST_EQUALS(Vector2(10, 0), first.GetProperty(Actor::Property::POSITION), TEST_LOCATION); + + Vector3 rootWorldPositionAfter = root.GetProperty(Actor::Property::WORLD_POSITION); + Vector3 firstWorldPositionAfter = first.GetProperty(Actor::Property::WORLD_POSITION); + + DALI_TEST_EQUALS(Vector3(0, 10, 0), rootWorldPositionAfter - rootWorldPositionBefore, TEST_LOCATION); + DALI_TEST_EQUALS(Vector3(10, 10, 0), firstWorldPositionAfter - firstWorldPositionBefore, TEST_LOCATION); + } - Vector3 rootWorldPositionAfter = root.GetProperty(Actor::Property::WORLD_POSITION); - Vector3 firstWorldPositionAfter = first.GetProperty(Actor::Property::WORLD_POSITION); + END_TEST; +} - DALI_TEST_EQUALS(Vector3(0, 10, 0), rootWorldPositionAfter - rootWorldPositionBefore, TEST_LOCATION); - DALI_TEST_EQUALS(Vector3(10, 10, 0), firstWorldPositionAfter - firstWorldPositionBefore, TEST_LOCATION); +int UtcDaliLoadBvhFailed01(void) +{ + TestApplication application; + AnimationDefinition animDef = LoadBvh("/nothing.bvh", "testBvh", false); + DALI_TEST_EQUALS(0u, animDef.GetPropertyCount(), TEST_LOCATION); END_TEST; } +int UtcDaliLoadBvhFailed02(void) +{ + TestApplication application; + AnimationDefinition animDef = LoadBvhFromBuffer(nullptr, 0, "testBvh", false); + DALI_TEST_EQUALS(0u, animDef.GetPropertyCount(), TEST_LOCATION); + END_TEST; +} -int UtcDaliLoadBvhFailed(void) +int UtcDaliLoadBvhFailed03(void) { TestApplication application; - AnimationDefinition animDef = LoadBvh("/nothing.bvh", "testBvh"); - DALI_TEST_EQUALS(0u, animDef.mProperties.size(), TEST_LOCATION); + tet_infoline("Parse error for hierarchy1"); + uint32_t caseHierarchyCount = 8; + for(uint32_t tc = 0; tc < caseHierarchyCount; ++tc) + { + tet_printf("Parse error for hierarchy %u\n", tc); + std::ostringstream oss; + oss << TEST_RESOURCE_DIR << "/test-invalid-hierarchy" << tc << ".bvh"; + AnimationDefinition animDef = LoadBvh(oss.str(), "testBvh", false); + DALI_TEST_EQUALS(0u, animDef.GetPropertyCount(), TEST_LOCATION); + } + + uint32_t caseMotionCount = 4; + for(uint32_t tc = 0; tc < caseMotionCount; ++tc) + { + tet_printf("Parse error for motion %u\n", tc); + std::ostringstream oss; + oss << TEST_RESOURCE_DIR << "/test-invalid-motion" << tc << ".bvh"; + AnimationDefinition animDef = LoadBvh(oss.str(), "testBvh", false); + DALI_TEST_EQUALS(0u, animDef.GetPropertyCount(), TEST_LOCATION); + } + + { + tet_infoline("empty file"); + AnimationDefinition animDef = LoadBvh(TEST_RESOURCE_DIR "/test-empty.bvh", "testBvh", false); + DALI_TEST_EQUALS(0u, animDef.GetPropertyCount(), TEST_LOCATION); + } END_TEST; -} +} \ No newline at end of file