Files
o3de/Gems/EMotionFX/Code/Tests/ProvidesUI/Motions/MotionPlaybacksTests.cpp
T
2021-03-08 14:30:57 -08:00

68 lines
3.7 KiB
C++

/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include <QTableWidget>
#include <QtTest>
#include <gtest/gtest.h>
#include <EMotionFX/Source/Actor.h>
#include <EMotionFX/Source/MotionManager.h>
#include <EMotionStudio/EMStudioSDK/Source/EMStudioManager.h>
#include <EMotionStudio/EMStudioSDK/Source/RenderPlugin/RenderPlugin.h>
#include <EMotionStudio/Plugins/StandardPlugins/Source/MotionWindow/MotionWindowPlugin.h>
#include <Tests/ProvidesUI/AnimGraph/PreviewMotionFixture.h>
#include <Tests/UI/UIFixture.h>
namespace EMotionFX
{
TEST_F(PreviewMotionFixture, MotionCanBePlayed)
{
/*
Test Case: C1797320
Motion playbacks with no corruption to animation
Motion can be played in the open gl viewport.
*/
RecordProperty("test_case_id", "C1797320");
// Check motion exists in motions window.
auto motionWindowPlugin = static_cast<EMStudio::MotionWindowPlugin*>(EMStudio::GetPluginManager()->FindActivePlugin(EMStudio::MotionWindowPlugin::CLASS_ID));
ASSERT_TRUE(motionWindowPlugin != nullptr) << "Could not find the Motion Window Plugin";
QTableWidget* table = qobject_cast<QTableWidget*>(FindTopLevelWidget("EMFX.MotionListWindow.MotionTable"));
ASSERT_TRUE(table) << "Could not find the Motion Table";
EXPECT_EQ(GetMotionManager().GetNumMotions(), 1) << "Expected to have no motions for the Manager";
EXPECT_EQ(table->rowCount(), 1) << "Expected the table to have no rows yet";
// Create actor and actor instance.
const char* actorFilename = "@devroot@/Gems/EMotionFX/Code/Tests/TestAssets/Rin/rin.actor";
AZStd::unique_ptr<EMotionFX::Actor> m_actor = EMotionFX::GetImporter().LoadActor(actorFilename);
EXPECT_TRUE(m_actor.get() != nullptr) << "Actor not loaded.";
EMotionFX::ActorInstance* m_actorInstance = ActorInstance::Create(m_actor.get());
EXPECT_TRUE(m_actorInstance != nullptr) << "Actor instance not created.";
AZStd::string result;
EXPECT_TRUE(CommandSystem::GetCommandManager()->ExecuteCommand(AZStd::string{ "Select -actorInstanceID " } + AZStd::to_string(m_actorInstance->GetID()), result)) << result.c_str();
// Double click on motion in motions window.
QTableWidgetItem* item = table->item(0, 0);
const auto rect = table->visualItemRect(item);
QTest::mouseClick(table->viewport(), Qt::LeftButton, {}, rect.center());
QTest::mouseDClick(table->viewport(), Qt::LeftButton, {}, rect.center());
// Check motion has been selected in render window.
EMStudio::EMStudioPlugin* plugin = EMStudio::GetPluginManager()->FindActivePlugin(static_cast<uint32>(EMStudio::RenderPlugin::CLASS_ID));
EXPECT_TRUE(plugin != nullptr) << "Render plugin not found.";
EMStudio::RenderPlugin* renderPlugin = static_cast<EMStudio::RenderPlugin*>(plugin);
CommandSystem::SelectionList* renderPluginSelectionList = renderPlugin->GetCurrentSelection();
EXPECT_TRUE(renderPluginSelectionList->GetSingleMotion()) << "Motion not selected in render window.";
EXPECT_TRUE(renderPluginSelectionList->GetSingleMotion()->GetFileName() == m_motionFileName) << "Motion file name does not match.";
}
}