PrefabAssetPathChangeTests.cpp 4.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 <Prefab/PrefabAssetPathChangeTestFixture.h>
  9. namespace UnitTest
  10. {
  11. using PrefabAssetPathChangeTests = PrefabAssetPathChangeTestFixture;
  12. TEST_F(PrefabAssetPathChangeTests, ChangePrefabFileName)
  13. {
  14. const AZStd::string prefabFolderPath = "";
  15. const AZStd::string prefabFileName = "Prefab.prefab";
  16. const AZStd::string newPrefabFileName = "PrefabRenamed.prefab";
  17. InstanceOptionalReference prefabInstance = CreatePrefabInstance(prefabFolderPath, prefabFileName);
  18. ASSERT_TRUE(prefabInstance.has_value());
  19. AZ::IO::Path originalTemplateSourcePath = prefabInstance->get().GetTemplateSourcePath();
  20. EXPECT_EQ(originalTemplateSourcePath.Native(), prefabFileName);
  21. // Rename prefab file
  22. ChangePrefabFileName(prefabFolderPath, prefabFileName, newPrefabFileName);
  23. AZ::IO::Path newTemplateSourcePath = prefabInstance->get().GetTemplateSourcePath();
  24. EXPECT_EQ(newTemplateSourcePath.Native(), newPrefabFileName);
  25. EXPECT_NE(originalTemplateSourcePath, newTemplateSourcePath);
  26. }
  27. TEST_F(PrefabAssetPathChangeTests, ChangeFolderName)
  28. {
  29. const AZStd::string prefabFileName = "Prefab.prefab";
  30. const AZStd::string prefabFolderPath = "PrefabFolder";
  31. const AZStd::string newPrefabFolderPath = "PrefabFolderRenamed";
  32. InstanceOptionalReference prefabInstance = CreatePrefabInstance(prefabFolderPath, prefabFileName);
  33. ASSERT_TRUE(prefabInstance.has_value());
  34. AZ::IO::Path originalTemplateSourcePath = prefabInstance->get().GetTemplateSourcePath();
  35. EXPECT_EQ(originalTemplateSourcePath, GetPrefabFilePathForSerialization(prefabFolderPath, prefabFileName));
  36. ChangePrefabFolderPath(prefabFolderPath, newPrefabFolderPath);
  37. AZ::IO::Path newTemplateSourcePath = prefabInstance->get().GetTemplateSourcePath();
  38. EXPECT_EQ(newTemplateSourcePath, GetPrefabFilePathForSerialization(newPrefabFolderPath, prefabFileName));
  39. EXPECT_NE(originalTemplateSourcePath, newTemplateSourcePath);
  40. }
  41. TEST_F(PrefabAssetPathChangeTests, ChangeAncestorFolderName)
  42. {
  43. const AZStd::string prefabFileName = "Prefab.prefab";
  44. const AZStd::string prefabBaseFolder = "PrefabFolder";
  45. const AZStd::string newPrefabBaseFolder = "PrefabFolderRenamed";
  46. const AZStd::string prefabFolderPath = "PrefabFolder/PrefabSubfolder";
  47. const AZStd::string newPrefabFolderPath = "PrefabFolderRenamed/PrefabSubfolder";
  48. InstanceOptionalReference prefabInstance = CreatePrefabInstance(prefabFolderPath, prefabFileName);
  49. ASSERT_TRUE(prefabInstance.has_value());
  50. AZ::IO::Path originalTemplateSourcePath = prefabInstance->get().GetTemplateSourcePath();
  51. EXPECT_EQ(originalTemplateSourcePath, GetPrefabFilePathForSerialization(prefabFolderPath, prefabFileName));
  52. ChangePrefabFolderPath(prefabBaseFolder, newPrefabBaseFolder);
  53. AZ::IO::Path newTemplateSourcePath = prefabInstance->get().GetTemplateSourcePath();
  54. EXPECT_EQ(newTemplateSourcePath, GetPrefabFilePathForSerialization(newPrefabFolderPath, prefabFileName));
  55. EXPECT_NE(originalTemplateSourcePath, newTemplateSourcePath);
  56. }
  57. TEST_F(PrefabAssetPathChangeTests, MoveFolderWithMultiplePrefabsToAncestor)
  58. {
  59. const AZStd::string prefab1FileName = "Prefab1.prefab";
  60. const AZStd::string prefab2FileName = "Prefab2.prefab";
  61. const AZStd::string prefabFolderPath = "PrefabsFolder/PrefabsSubfolder";
  62. const AZStd::string newPrefabFolderPath = "PrefabsSubfolder";
  63. InstanceOptionalReference prefabInstance1 = CreatePrefabInstance(prefabFolderPath, prefab1FileName);
  64. ASSERT_TRUE(prefabInstance1.has_value());
  65. InstanceOptionalReference prefabInstance2 = CreatePrefabInstance(prefabFolderPath, prefab2FileName);
  66. ASSERT_TRUE(prefabInstance2.has_value());
  67. ChangePrefabFolderPath(prefabFolderPath, newPrefabFolderPath);
  68. AZ::IO::Path expectedInstance1Path = GetPrefabFilePathForSerialization(newPrefabFolderPath, prefab1FileName);
  69. AZ::IO::Path expectedInstance2Path = GetPrefabFilePathForSerialization(newPrefabFolderPath, prefab2FileName);
  70. EXPECT_EQ(prefabInstance1->get().GetTemplateSourcePath(), expectedInstance1Path);
  71. EXPECT_EQ(prefabInstance2->get().GetTemplateSourcePath(), expectedInstance2Path);
  72. }
  73. } // namespace UnitTest