3
0

CanAutoSaveFile.cpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <gtest/gtest.h>
  9. #include <QtTest>
  10. #include <Tests/UI/UIFixture.h>
  11. #include <EMotionStudio/EMStudioSDK/Source/EMStudioManager.h>
  12. #include <EMotionStudio/EMStudioSDK/Source/FileManager.h>
  13. #include <EMotionFX/CommandSystem/Source/CommandManager.h>
  14. #include <EMotionFX/Source/AnimGraphManager.h>
  15. namespace EMotionFX
  16. {
  17. TEST_F(UIFixture, CanAutoSaveAnimGraph)
  18. {
  19. RecordProperty("test_case_id", "C15192424");
  20. // Cache the anim graph manager
  21. AnimGraphManager& animGraphManager = GetAnimGraphManager();
  22. EMStudio::GetMainWindow()->ApplicationModeChanged("AnimGraph");
  23. // Load Rin anim graph.
  24. const char* rinGraph = "@gemroot:EMotionFX@/Code/Tests/TestAssets/Rin/rin.animgraph";
  25. const AZStd::string rinGraphPath = ResolvePath(rinGraph);
  26. AZStd::string command = AZStd::string::format("LoadAnimGraph -filename \"%s\"", rinGraphPath.c_str());
  27. AZStd::string result;
  28. EXPECT_TRUE(CommandSystem::GetCommandManager()->ExecuteCommand(command, result)) << result.c_str();
  29. // Expect the rin graph get loaded.
  30. AnimGraph* graphBeforeSave = animGraphManager.FindAnimGraphByFileName(rinGraphPath.c_str());
  31. EXPECT_TRUE(graphBeforeSave) << "Rin graph should be loaded";
  32. // Set the anim graph file dirty flag, so it will get picked up in autosave.
  33. graphBeforeSave->SetDirtyFlag(true);
  34. // Trigger auto save.
  35. EMStudio::GetMainWindow()->OnAutosaveTimeOut();
  36. // Verify that rin file is saved in the auto save.
  37. EMStudio::FileManager* fileManager = EMStudio::GetMainWindow()->GetFileManager();
  38. const AZStd::vector<AZStd::string>& savedSourceFile = fileManager->GetSavedSourceAssets();
  39. EXPECT_EQ(savedSourceFile.size(), 1) << "A graph should be auto saved in the file manager.";
  40. // Verify the source name, make sure it is the rin graph that get saved.
  41. const AZStd::string& autoSavedFile = savedSourceFile[0];
  42. size_t found = autoSavedFile.find("rin_Autosave");
  43. EXPECT_NE(found, AZStd::string::npos) << "The auto saved file should contain the rin_Autosave keyword.";
  44. // Verify if the autosave file exist on disk
  45. EXPECT_TRUE(QFile::exists(autoSavedFile.c_str())) << "Check that auto saved file exist.";
  46. }
  47. } // namespace EMotionFX