AssetValidationTest.cpp 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 <AssetSeedUtil.h>
  9. #include "AssetValidationTestShared.h"
  10. #include <AzFramework/Platform/PlatformDefaults.h>
  11. #include <AzFramework/Asset/AssetSeedList.h>
  12. #include <AzFramework/Gem/GemInfo.h>
  13. namespace UnitTest
  14. {
  15. bool AssetValidationTest::CreateDummyFile(const AZ::IO::Path& path, AZStd::string_view contents) const
  16. {
  17. AZ::IO::FileIOStream fileStream(path.c_str(), AZ::IO::OpenMode::ModeAppend | AZ::IO::OpenMode::ModeUpdate | AZ::IO::OpenMode::ModeCreatePath);
  18. return fileStream.Write(contents.size(), contents.data()) != 0;
  19. }
  20. TEST_F(AssetValidationTest, DefaultSeedList_ReturnsExpectedSeedLists)
  21. {
  22. AZStd::vector<AzFramework::GemInfo> gemInfo;
  23. const AZ::IO::Path gemSeedList = AZ::IO::Path(m_tempDir.GetDirectory()) / "mockGem" / AzFramework::GemInfo::GetGemAssetFolder()
  24. / AZ::IO::Path("seedList").ReplaceExtension(AssetValidation::AssetSeed::SeedFileExtension);
  25. const AZ::IO::Path engineSeedList = AZ::IO::Path(m_tempDir.GetDirectory()) / "Assets/Engine"
  26. / AZ::IO::Path("SeedAssetList").ReplaceExtension(AssetValidation::AssetSeed::SeedFileExtension);
  27. const AZ::SettingsRegistryInterface::FixedValueString projectName = AZ::Utils::GetProjectName();
  28. ASSERT_FALSE(projectName.empty());
  29. const AZ::IO::Path projectSeedList = AZ::IO::Path(m_tempDir.GetDirectory()) / projectName
  30. / AZ::IO::Path("SeedAssetList").ReplaceExtension(AssetValidation::AssetSeed::SeedFileExtension);
  31. ASSERT_TRUE(CreateDummyFile(gemSeedList, "Mock Gem Seed List"));
  32. ASSERT_TRUE(CreateDummyFile(engineSeedList, "Engine Seed List"));
  33. ASSERT_TRUE(CreateDummyFile(projectSeedList, "Project Seed List"));
  34. AzFramework::GemInfo mockGem("MockGem");
  35. mockGem.m_absoluteSourcePaths.push_back(AZ::IO::Path(m_tempDir.GetDirectory()) / "mockGem");
  36. gemInfo.push_back(mockGem);
  37. AZStd::vector<AZ::IO::Path> defaultSeedLists{ AZStd::from_range, AssetValidation::AssetSeed::GetDefaultSeedListFiles(gemInfo, AzFramework::PlatformFlags::Platform_PC) };
  38. ASSERT_THAT(defaultSeedLists, ::testing::UnorderedElementsAre(gemSeedList, engineSeedList, projectSeedList));
  39. }
  40. TEST_F(AssetValidationTest, SeedListDependencyTest_AddAndRemoveList_Success)
  41. {
  42. MockValidationComponent testComponent;
  43. AzFramework::AssetSeedList seedList;
  44. const char DummyAssetFile[] = "Dummy";
  45. seedList.push_back({ testComponent.m_assetIds[6], AzFramework::PlatformFlags::Platform_PC, DummyAssetFile });
  46. testComponent.TestAddSeedsFor(seedList, 2);
  47. testComponent.SeedMode();
  48. EXPECT_EQ(testComponent.IsKnownAsset("AssetPath5"), false);
  49. EXPECT_EQ(testComponent.IsKnownAsset("AssetPath6"), true);
  50. EXPECT_EQ(testComponent.IsKnownAsset("AssetPath8"), true);
  51. EXPECT_EQ(testComponent.IsKnownAsset("AssetPath9"), true);
  52. EXPECT_EQ(testComponent.IsKnownAsset("AssetPath10"), false);
  53. testComponent.TestRemoveSeedsFor(seedList, 0);
  54. EXPECT_EQ(testComponent.IsKnownAsset("AssetPath5"), false);
  55. EXPECT_EQ(testComponent.IsKnownAsset("AssetPath6"), true);
  56. EXPECT_EQ(testComponent.IsKnownAsset("AssetPath8"), true);
  57. EXPECT_EQ(testComponent.IsKnownAsset("AssetPath9"), true);
  58. EXPECT_EQ(testComponent.IsKnownAsset("AssetPath10"), false);
  59. testComponent.TestRemoveSeedsFor(seedList, 2);
  60. EXPECT_EQ(testComponent.IsKnownAsset("AssetPath5"), false);
  61. EXPECT_EQ(testComponent.IsKnownAsset("AssetPath6"), false);
  62. EXPECT_EQ(testComponent.IsKnownAsset("AssetPath8"), false);
  63. EXPECT_EQ(testComponent.IsKnownAsset("AssetPath9"), false);
  64. EXPECT_EQ(testComponent.IsKnownAsset("AssetPath10"), false);
  65. }
  66. TEST_F(AssetValidationTest, SeedAssetDependencyTest_AddSingleAsset_DependenciesFound)
  67. {
  68. MockValidationComponent testComponent;
  69. testComponent.AddSeedAssetId(testComponent.m_assetIds[8], 0);
  70. testComponent.SeedMode();
  71. EXPECT_EQ(testComponent.IsKnownAsset("AssetPath8"), true);
  72. EXPECT_EQ(testComponent.IsKnownAsset("AssetPath7"), false);
  73. EXPECT_EQ(testComponent.IsKnownAsset("AssetPath9"), true);
  74. EXPECT_EQ(testComponent.IsKnownAsset("AssetPath10"), false);
  75. }
  76. TEST_F(AssetValidationTest, SeedListDependencyTest_AddAndRemoveListPaths_Success)
  77. {
  78. MockValidationComponent testComponent;
  79. const char seedListPathName[] = "ValidPath";
  80. const char invalidSeedListPathName[] = "InvalidPath";
  81. AzFramework::AssetSeedList seedList;
  82. const char DummyAssetFile[] = "Dummy";
  83. seedList.push_back({ testComponent.m_assetIds[6], AzFramework::PlatformFlags::Platform_PC, DummyAssetFile });
  84. testComponent.m_validSeedList = seedList;
  85. testComponent.m_validSeedPath = seedListPathName;
  86. testComponent.TestAddSeedList(invalidSeedListPathName);
  87. testComponent.SeedMode();
  88. EXPECT_EQ(testComponent.IsKnownAsset("AssetPath5"), false);
  89. EXPECT_EQ(testComponent.IsKnownAsset("AssetPath6"), false);
  90. EXPECT_EQ(testComponent.IsKnownAsset("AssetPath8"), false);
  91. EXPECT_EQ(testComponent.IsKnownAsset("AssetPath9"), false);
  92. EXPECT_EQ(testComponent.IsKnownAsset("AssetPath10"), false);
  93. testComponent.TestAddSeedList(seedListPathName);
  94. EXPECT_EQ(testComponent.IsKnownAsset("AssetPath5"), false);
  95. EXPECT_EQ(testComponent.IsKnownAsset("AssetPath6"), true);
  96. EXPECT_EQ(testComponent.IsKnownAsset("AssetPath8"), true);
  97. EXPECT_EQ(testComponent.IsKnownAsset("AssetPath9"), true);
  98. EXPECT_EQ(testComponent.IsKnownAsset("AssetPath10"), false);
  99. testComponent.TestRemoveSeedList(invalidSeedListPathName);
  100. EXPECT_EQ(testComponent.IsKnownAsset("AssetPath5"), false);
  101. EXPECT_EQ(testComponent.IsKnownAsset("AssetPath6"), true);
  102. EXPECT_EQ(testComponent.IsKnownAsset("AssetPath8"), true);
  103. EXPECT_EQ(testComponent.IsKnownAsset("AssetPath9"), true);
  104. EXPECT_EQ(testComponent.IsKnownAsset("AssetPath10"), false);
  105. testComponent.TestRemoveSeedList(seedListPathName);
  106. EXPECT_EQ(testComponent.IsKnownAsset("AssetPath5"), false);
  107. EXPECT_EQ(testComponent.IsKnownAsset("AssetPath6"), false);
  108. EXPECT_EQ(testComponent.IsKnownAsset("AssetPath8"), false);
  109. EXPECT_EQ(testComponent.IsKnownAsset("AssetPath9"), false);
  110. EXPECT_EQ(testComponent.IsKnownAsset("AssetPath10"), false);
  111. }
  112. }
  113. AZ_UNIT_TEST_HOOK(DEFAULT_UNIT_TEST_ENV);