2 * Copyright (c) 2023 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-toolkit-test-suite-utils.h>
19 #include <dali-toolkit/dali-toolkit.h>
24 #include <toolkit-event-thread-callback.h>
26 #include <dali-scene3d/public-api/model-motion/motion-data.h>
27 #include <dali-scene3d/public-api/model-motion/motion-value.h>
29 #include <dali-scene3d/public-api/model-motion/motion-index/blend-shape-index.h>
30 #include <dali-scene3d/public-api/model-motion/motion-index/motion-index.h>
31 #include <dali-scene3d/public-api/model-motion/motion-index/motion-transform-index.h>
34 using namespace Dali::Toolkit;
35 using namespace Dali::Scene3D;
37 void model_motion_motion_data_startup(void)
39 test_return_value = TET_UNDEF;
42 void model_motion_motion_data_cleanup(void)
44 test_return_value = TET_PASS;
49 const char* TEST_BVH_FILE_NAME = TEST_RESOURCE_DIR "/test.bvh";
50 const char* TEST_FACIAL_FILE_NAME = TEST_RESOURCE_DIR "/facial-blendshape-animation.json";
52 std::string ReadBufferFromFile(const std::string& url)
54 std::string rawString;
55 std::fstream fileStream;
57 fileStream.open(url, std::ios::in | std::ios::binary);
58 if(!fileStream.is_open())
60 DALI_LOG_WARNING("stream open failed for: \"%s\", in mode: \"%d\".\n", url.c_str(), static_cast<int>(std::ios::in | std::ios::binary));
63 // get length of file:
64 fileStream.seekg(0, std::ios::end);
65 auto length = fileStream.tellg();
66 fileStream.seekg(0, std::ios::beg);
68 rawString.resize(length);
69 fileStream.read(rawString.data(), length);
77 static bool gLoadCompleted = false;
78 void OnLoadCompleted(MotionData data)
80 gLoadCompleted = true;
84 // Positive test case for a method
85 int UtcDaliMotionDataNew(void)
87 ToolkitTestApplication application;
88 tet_infoline(" UtcDaliMotionDataNew");
90 float expectDuration = 0.0f;
91 MotionData motionData = MotionData::New();
92 DALI_TEST_CHECK(motionData);
93 DALI_TEST_EQUALS(motionData.GetDuration(), expectDuration, TEST_LOCATION);
95 expectDuration = 10.0f;
96 motionData = MotionData::New(expectDuration);
97 DALI_TEST_CHECK(motionData);
98 DALI_TEST_EQUALS(motionData.GetDuration(), expectDuration, TEST_LOCATION);
102 int UtcDaliMotionDataDownCast(void)
104 ToolkitTestApplication application;
105 tet_infoline(" UtcDaliMotionDataDownCast");
107 MotionData motionData = MotionData::New();
108 BaseHandle handle(motionData);
110 MotionData motionData2 = MotionData::DownCast(handle);
111 DALI_TEST_CHECK(motionData);
112 DALI_TEST_CHECK(motionData2);
113 DALI_TEST_CHECK(motionData2 == motionData);
117 int UtcDaliMotionDataTypeRegistry(void)
119 ToolkitTestApplication application;
121 TypeRegistry typeRegistry = TypeRegistry::Get();
122 DALI_TEST_CHECK(typeRegistry);
124 TypeInfo typeInfo = typeRegistry.GetTypeInfo("MotionData");
125 DALI_TEST_CHECK(typeInfo);
127 BaseHandle handle = typeInfo.CreateInstance();
128 DALI_TEST_CHECK(handle);
130 MotionData motionData = MotionData::DownCast(handle);
131 DALI_TEST_CHECK(motionData);
136 int UtcDaliMotionDataCopyAndAssignment(void)
138 ToolkitTestApplication application;
140 MotionData motionData = MotionData::New();
141 DALI_TEST_CHECK(motionData);
143 MotionData copy(motionData);
144 DALI_TEST_CHECK(motionData == copy);
147 DALI_TEST_CHECK(!assign);
150 DALI_TEST_CHECK(assign == motionData);
155 int UtcDaliMotionDataMoveConstructor(void)
157 ToolkitTestApplication application;
159 MotionData motionData = MotionData::New();
160 DALI_TEST_EQUALS(1, motionData.GetBaseObject().ReferenceCount(), TEST_LOCATION);
162 MotionData moved = std::move(motionData);
163 DALI_TEST_CHECK(moved);
164 DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
165 DALI_TEST_CHECK(!motionData);
170 int UtcDaliMotionDataMoveAssignment(void)
172 ToolkitTestApplication application;
174 MotionData motionData = MotionData::New();
175 DALI_TEST_EQUALS(1, motionData.GetBaseObject().ReferenceCount(), TEST_LOCATION);
178 moved = std::move(motionData);
179 DALI_TEST_CHECK(moved);
180 DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
187 int UtcDaliMotionDataAddMotion(void)
189 ToolkitTestApplication application;
191 MotionData motionData = MotionData::New(3.0f);
193 const uint32_t countMax = 4;
194 MotionIndex index[countMax];
195 MotionValue value[countMax];
196 for(uint32_t i = 0u; i < countMax; ++i)
201 index[i] = BlendShapeIndex::New("node", 0);
205 index[i] = MotionTransformIndex::New("node", MotionTransformIndex::TransformType::POSITION_X);
211 value[i] = MotionValue::New(3.0f);
215 KeyFrames keyFrames = KeyFrames::New();
216 keyFrames.Add(0.0f, 9.0f);
217 keyFrames.Add(1.0f, 5.0f);
218 value[i] = MotionValue::New(keyFrames);
221 DALI_TEST_CHECK(index[i]);
222 DALI_TEST_CHECK(value[i]);
223 motionData.Add(index[i], value[i]);
225 DALI_TEST_EQUALS(i + 1, motionData.GetMotionCount(), TEST_LOCATION);
228 for(uint32_t i = 0u; i < countMax; ++i)
230 DALI_TEST_EQUALS(index[i], motionData.GetIndex(i), TEST_LOCATION);
231 DALI_TEST_EQUALS(value[i], motionData.GetValue(i), TEST_LOCATION);
234 DALI_TEST_CHECK(!motionData.GetIndex(countMax));
235 DALI_TEST_CHECK(!motionData.GetValue(countMax));
239 DALI_TEST_EQUALS(0u, motionData.GetMotionCount(), TEST_LOCATION);
240 DALI_TEST_CHECK(!motionData.GetIndex(0u));
241 DALI_TEST_CHECK(!motionData.GetValue(0u));
246 int UtcDaliMotionDataSetGetDuration(void)
248 ToolkitTestApplication application;
250 float expectDuration = 3.0f;
251 MotionData motionData = MotionData::New(expectDuration);
252 DALI_TEST_EQUALS(motionData.GetDuration(), expectDuration, TEST_LOCATION);
254 expectDuration = 7.0f;
255 motionData.SetDuration(expectDuration);
256 DALI_TEST_EQUALS(motionData.GetDuration(), expectDuration, TEST_LOCATION);
258 expectDuration = 1.0f;
259 motionData.SetDuration(expectDuration);
260 DALI_TEST_EQUALS(motionData.GetDuration(), expectDuration, TEST_LOCATION);
265 int UtcDaliMotionDataLoadBvhAndFacialAsync(void)
267 ToolkitTestApplication application;
269 for(uint32_t tc = 0; tc < 4; ++tc)
271 MotionData motionData = MotionData::New();
272 gLoadCompleted = false;
273 motionData.LoadCompletedSignal().Connect(&OnLoadCompleted);
280 motionData.LoadBvh(TEST_BVH_FILE_NAME);
285 motionData.LoadFacialAnimation(TEST_FACIAL_FILE_NAME);
290 std::string rawString = ReadBufferFromFile(TEST_BVH_FILE_NAME);
291 motionData.LoadBvhFromBuffer(reinterpret_cast<uint8_t*>(rawString.data()), static_cast<int>(rawString.length()));
296 std::string rawString = ReadBufferFromFile(TEST_FACIAL_FILE_NAME);
297 motionData.LoadFacialAnimationFromBuffer(reinterpret_cast<uint8_t*>(rawString.data()), static_cast<int>(rawString.length()));
302 DALI_TEST_EQUALS(gLoadCompleted, false, TEST_LOCATION);
304 application.SendNotification();
305 application.Render();
307 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
308 application.SendNotification();
309 application.Render();
311 // Check LoadCompletedSignal emitted.
312 DALI_TEST_EQUALS(gLoadCompleted, true, TEST_LOCATION);
314 // Check MotionData load successfully.
315 DALI_TEST_GREATER(motionData.GetMotionCount(), 0u, TEST_LOCATION);
321 int UtcDaliMotionDataLoadBvhAndFacialSync(void)
323 ToolkitTestApplication application;
325 for(uint32_t tc = 0; tc < 4; ++tc)
327 MotionData motionData = MotionData::New();
328 gLoadCompleted = false;
329 motionData.LoadCompletedSignal().Connect(&OnLoadCompleted);
336 motionData.LoadBvh(TEST_BVH_FILE_NAME, Vector3::ONE, true);
341 motionData.LoadFacialAnimation(TEST_FACIAL_FILE_NAME, true);
346 std::string rawString = ReadBufferFromFile(TEST_BVH_FILE_NAME);
347 motionData.LoadBvhFromBuffer(reinterpret_cast<uint8_t*>(rawString.data()), static_cast<int>(rawString.length()), Vector3::ONE, true);
352 std::string rawString = ReadBufferFromFile(TEST_FACIAL_FILE_NAME);
353 motionData.LoadFacialAnimationFromBuffer(reinterpret_cast<uint8_t*>(rawString.data()), static_cast<int>(rawString.length()), true);
358 // Check LoadCompletedSignal emitted.
359 DALI_TEST_EQUALS(gLoadCompleted, true, TEST_LOCATION);
361 // Check MotionData load successfully.
362 DALI_TEST_GREATER(motionData.GetMotionCount(), 0u, TEST_LOCATION);
368 int UtcDaliMotionDataLoadAsyncMultiple(void)
370 ToolkitTestApplication application;
372 MotionData motionData = MotionData::New();
373 gLoadCompleted = false;
374 motionData.LoadCompletedSignal().Connect(&OnLoadCompleted);
377 for(auto i = 0u; i < tryCount; ++i)
379 motionData.LoadBvh(TEST_BVH_FILE_NAME);
382 DALI_TEST_EQUALS(gLoadCompleted, false, TEST_LOCATION);
384 application.SendNotification();
385 application.Render();
387 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
388 application.SendNotification();
389 application.Render();
391 DALI_TEST_EQUALS(gLoadCompleted, true, TEST_LOCATION);
393 // Check MotionData load successfully.
394 DALI_TEST_GREATER(motionData.GetMotionCount(), 0u, TEST_LOCATION);
396 gLoadCompleted = false;
398 // Check if completed request comes only 1 time.
399 Test::WaitForEventThreadTrigger(1, 1);
400 application.SendNotification();
401 application.Render();
403 DALI_TEST_EQUALS(gLoadCompleted, false, TEST_LOCATION);
408 int UtcDaliMotionDataLoadBvhUseRootTranslationOnly(void)
410 ToolkitTestApplication application;
412 MotionData motionDataAllTranslation = MotionData::New();
413 motionDataAllTranslation.LoadBvh(TEST_BVH_FILE_NAME, false, Vector3::ONE, true);
415 DALI_TEST_EQUALS(motionDataAllTranslation.GetMotionCount(), 4, TEST_LOCATION);
417 MotionData motionDataOnlyRootTranslation = MotionData::New();
418 motionDataOnlyRootTranslation.LoadBvh(TEST_BVH_FILE_NAME, true, Vector3::ONE, true);
420 DALI_TEST_EQUALS(motionDataOnlyRootTranslation.GetMotionCount(), 3, TEST_LOCATION);
425 int UtcDaliMotionDataLoadBvhFromBufferUseRootTranslationOnly(void)
427 ToolkitTestApplication application;
429 std::string rawString = ReadBufferFromFile(TEST_BVH_FILE_NAME);
431 MotionData motionDataAllTranslation = MotionData::New();
432 motionDataAllTranslation.LoadBvhFromBuffer(reinterpret_cast<uint8_t*>(rawString.data()), static_cast<int>(rawString.length()), false, Vector3::ONE, true);
434 DALI_TEST_EQUALS(motionDataAllTranslation.GetMotionCount(), 4, TEST_LOCATION);
436 MotionData motionDataOnlyRootTranslation = MotionData::New();
437 motionDataOnlyRootTranslation.LoadBvhFromBuffer(reinterpret_cast<uint8_t*>(rawString.data()), static_cast<int>(rawString.length()), true, Vector3::ONE, true);
439 DALI_TEST_EQUALS(motionDataOnlyRootTranslation.GetMotionCount(), 3, TEST_LOCATION);