CopyDependencyBuilderTest.cpp 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117
  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 <AzTest/AzTest.h>
  9. #include <AzTest/Utils.h>
  10. #include <AzCore/PlatformId/PlatformId.h>
  11. #include <AzCore/UnitTest/UnitTest.h>
  12. #include <AzCore/IO/Path/Path.h>
  13. #include <AzFramework/IO/LocalFileIO.h>
  14. #include <AzFramework/Asset/XmlSchemaAsset.h>
  15. #include <AzFramework/StringFunc/StringFunc.h>
  16. #include <AzCore/Serialization/SerializeContext.h>
  17. #include <AzCore/Component/ComponentApplication.h>
  18. #include <AzCore/UnitTest/TestTypes.h>
  19. #include <AzCore/UnitTest/UnitTest.h>
  20. #include <AzCore/Utils/Utils.h>
  21. #include <Builders/CopyDependencyBuilder/CfgBuilderWorker/CfgBuilderWorker.h>
  22. #include <Builders/CopyDependencyBuilder/FontBuilderWorker/FontBuilderWorker.h>
  23. #include <Builders/CopyDependencyBuilder/SchemaBuilderWorker/SchemaBuilderWorker.h>
  24. #include <Builders/CopyDependencyBuilder/XmlBuilderWorker/XmlBuilderWorker.h>
  25. #include <Builders/CopyDependencyBuilder/EmfxWorkspaceBuilderWorker/EmfxWorkspaceBuilderWorker.h>
  26. namespace UnitTest
  27. {
  28. using namespace CopyDependencyBuilder;
  29. using namespace AZ;
  30. using namespace AssetBuilderSDK;
  31. class CopyDependencyBuilderTest
  32. : public UnitTest::LeakDetectionFixture
  33. , public UnitTest::TraceBusRedirector
  34. , private AzToolsFramework::AssetSystemRequestBus::Handler
  35. {
  36. protected:
  37. void SetUp() override
  38. {
  39. m_app.reset(aznew AZ::ComponentApplication());
  40. AZ::ComponentApplication::Descriptor desc;
  41. desc.m_useExistingAllocator = true;
  42. AZ::ComponentApplication::StartupParameters startupParameters;
  43. startupParameters.m_loadSettingsRegistry = false;
  44. m_app->Create(desc, startupParameters);
  45. if constexpr (AZ::g_currentPlatform == AZ::PlatformID::PLATFORM_WINDOWS_64)
  46. {
  47. m_currentPlatform = "pc";
  48. }
  49. else
  50. {
  51. m_currentPlatform = AZ::GetPlatformName(AZ::g_currentPlatform);
  52. AZStd::to_lower(m_currentPlatform.begin(), m_currentPlatform.end());
  53. }
  54. // Startup default local FileIO (hits OSAllocator) if not already setup.
  55. auto fileIo = AZ::IO::FileIOBase::GetInstance();
  56. if (fileIo == nullptr)
  57. {
  58. fileIo = aznew AZ::IO::LocalFileIO();
  59. AZ::IO::FileIOBase::SetInstance(fileIo);
  60. }
  61. const AZStd::string engineRoot = AZ::Test::GetEngineRootPath();
  62. AZ::IO::FileIOBase::GetInstance()->SetAlias("@engroot@", engineRoot.c_str());
  63. AZ::IO::Path assetRoot(AZ::Utils::GetProjectPath());
  64. assetRoot /= "Cache";
  65. AZ::IO::FileIOBase::GetInstance()->SetAlias("@products@", assetRoot.c_str());
  66. // Set the @gemroot:<gem-name> alias for active gems
  67. if (auto settingsRegistry = AZ::SettingsRegistry::Get(); settingsRegistry != nullptr)
  68. {
  69. AZ::Test::AddActiveGem("LmbrCentral", *settingsRegistry, fileIo);
  70. }
  71. SerializeContext* serializeContext;
  72. ComponentApplicationBus::BroadcastResult(serializeContext, &ComponentApplicationRequests::GetSerializeContext);
  73. ASSERT_TRUE(serializeContext);
  74. AzFramework::VersionSearchRule::Reflect(serializeContext);
  75. AzFramework::XmlSchemaAttribute::Reflect(serializeContext);
  76. AzFramework::XmlSchemaElement::Reflect(serializeContext);
  77. AzFramework::MatchingRule::Reflect(serializeContext);
  78. AzFramework::SearchRuleDefinition::Reflect(serializeContext);
  79. AzFramework::DependencySearchRule::Reflect(serializeContext);
  80. AzFramework::XmlSchemaAsset::Reflect(serializeContext);
  81. AZ::Debug::TraceMessageBus::Handler::BusConnect();
  82. AzToolsFramework::AssetSystemRequestBus::Handler::BusConnect();
  83. }
  84. void TearDown() override
  85. {
  86. AzToolsFramework::AssetSystemRequestBus::Handler::BusDisconnect();
  87. AZ::Debug::TraceMessageBus::Handler::BusDisconnect();
  88. delete AZ::IO::FileIOBase::GetInstance();
  89. AZ::IO::FileIOBase::SetInstance(nullptr);
  90. m_app->Destroy();
  91. m_app = nullptr;
  92. }
  93. static constexpr char testFileFolder[] = "@gemroot:LmbrCentral@/Code/Tests/";
  94. AZStd::string GetFullPath(AZStd::string_view fileName)
  95. {
  96. return AZStd::string::format("%s%.*s", testFileFolder, aznumeric_cast<int>(fileName.size()), fileName.data());
  97. }
  98. void TestFailureCase(CopyDependencyBuilderWorker* worker, AZStd::string_view fileName, bool expectedResult = false)
  99. {
  100. AssetBuilderSDK::ProductPathDependencySet resolvedPaths;
  101. AZStd::vector<AssetBuilderSDK::ProductDependency> productDependencies;
  102. AssetBuilderSDK::ProcessJobRequest request;
  103. request.m_fullPath = GetFullPath(fileName);
  104. request.m_sourceFile = fileName;
  105. request.m_platformInfo.m_identifier = m_currentPlatform;
  106. bool result = worker->ParseProductDependencies(request, productDependencies, resolvedPaths);
  107. ASSERT_EQ(result, expectedResult);
  108. ASSERT_EQ(resolvedPaths.size(), 0);
  109. ASSERT_EQ(productDependencies.size(), 0);
  110. }
  111. void TestSuccessCase(
  112. CopyDependencyBuilderWorker* worker,
  113. AZStd::string_view fileName,
  114. const AZStd::vector<const char*>& expectedPathDependencies)
  115. {
  116. AZStd::vector<AssetBuilderSDK::ProductDependency> expectedProductDependencies;
  117. TestSuccessCase(worker, fileName, expectedPathDependencies, expectedProductDependencies);
  118. }
  119. void TestSuccessCase(
  120. CopyDependencyBuilderWorker* worker,
  121. AZStd::string_view fileName,
  122. const AZStd::vector<const char*>& expectedPathDependencies,
  123. const AZStd::vector<AssetBuilderSDK::ProductDependency>& expectedProductDependencies,
  124. const AZStd::string watchFolder = {})
  125. {
  126. AssetBuilderSDK::ProductPathDependencySet resolvedPaths;
  127. AZStd::vector<AssetBuilderSDK::ProductDependency> productDependencies;
  128. size_t referencedFilePathsCount = expectedPathDependencies.size();
  129. size_t referencedProductDependenciesCount = expectedProductDependencies.size();
  130. AssetBuilderSDK::ProductPathDependencySet expectedResolvedPaths;
  131. for (const char* path : expectedPathDependencies)
  132. {
  133. expectedResolvedPaths.emplace(path, AssetBuilderSDK::ProductPathDependencyType::ProductFile);
  134. }
  135. AssetBuilderSDK::ProcessJobRequest request;
  136. request.m_fullPath = GetFullPath(fileName);
  137. request.m_sourceFile = fileName;
  138. request.m_platformInfo.m_identifier = m_currentPlatform;
  139. request.m_watchFolder = watchFolder;
  140. bool result = worker->ParseProductDependencies(request, productDependencies, resolvedPaths);
  141. ASSERT_TRUE(result);
  142. ASSERT_EQ(resolvedPaths.size(), referencedFilePathsCount);
  143. ASSERT_EQ(productDependencies.size(), referencedProductDependenciesCount);
  144. if (referencedFilePathsCount > 0)
  145. {
  146. for (const AssetBuilderSDK::ProductPathDependency& dependency : expectedResolvedPaths)
  147. {
  148. ASSERT_TRUE(resolvedPaths.find(dependency) != resolvedPaths.end()) << "Expected path dependency is not found in the process result";
  149. }
  150. }
  151. if (referencedProductDependenciesCount > 0)
  152. {
  153. for (const AssetBuilderSDK::ProductDependency& dependency : productDependencies)
  154. {
  155. bool expectedDependencyExists = false;
  156. for (const AssetBuilderSDK::ProductDependency& expectedProductDependency : expectedProductDependencies)
  157. {
  158. if (expectedProductDependency.m_dependencyId == dependency.m_dependencyId
  159. && expectedProductDependency.m_flags == dependency.m_flags)
  160. {
  161. expectedDependencyExists = true;
  162. break;
  163. }
  164. }
  165. ASSERT_TRUE(expectedDependencyExists) << "Expected product dependency is not found in the process result";
  166. }
  167. }
  168. }
  169. void TestSuccessCase(CopyDependencyBuilderWorker* worker, AZStd::string_view fileName, const char* expectedFile)
  170. {
  171. AZStd::vector<const char*> expectedFiles;
  172. expectedFiles.push_back(expectedFile);
  173. AZStd::vector<AssetBuilderSDK::ProductDependency> expectedProductDependencies;
  174. TestSuccessCase(worker, fileName, expectedFiles, expectedProductDependencies);
  175. }
  176. void TestSuccessCaseNoDependencies(CopyDependencyBuilderWorker* worker, AZStd::string_view fileName)
  177. {
  178. AZStd::vector<const char*> expectedFiles;
  179. AZStd::vector<AssetBuilderSDK::ProductDependency> expectedProductDependencies;
  180. TestSuccessCase(worker, fileName, expectedFiles, expectedProductDependencies);
  181. }
  182. //////////////////////////////////////////////////////////////////////////
  183. // AzToolsFramework::AssetSystem::AssetSystemRequestBus::Handler overrides
  184. bool GetRelativeProductPathFromFullSourceOrProductPath([[maybe_unused]] const AZStd::string& fullPath, [[maybe_unused]] AZStd::string& relativeProductPath) override { return true; }
  185. bool GenerateRelativeSourcePath(
  186. [[maybe_unused]] const AZStd::string& sourcePath, [[maybe_unused]] AZStd::string& relativePath,
  187. [[maybe_unused]] AZStd::string& watchFolder) override { return true; }
  188. bool GetFullSourcePathFromRelativeProductPath([[maybe_unused]] const AZStd::string& relPath, [[maybe_unused]] AZStd::string& fullSourcePath) override { return true; }
  189. bool GetAssetInfoById([[maybe_unused]] const AZ::Data::AssetId& assetId, [[maybe_unused]] const AZ::Data::AssetType& assetType, [[maybe_unused]] const AZStd::string& platformName, [[maybe_unused]] AZ::Data::AssetInfo& assetInfo, [[maybe_unused]] AZStd::string& rootFilePath) override { return true; }
  190. bool GetSourceInfoBySourcePath([[maybe_unused]] const char* sourcePath, [[maybe_unused]] AZ::Data::AssetInfo& assetInfo, [[maybe_unused]] AZStd::string& watchFolder) override { return true; }
  191. bool GetSourceInfoBySourceUUID([[maybe_unused]] const AZ::Uuid& sourceUuid, [[maybe_unused]] AZ::Data::AssetInfo& assetInfo, [[maybe_unused]] AZStd::string& watchFolder) override { return true; }
  192. bool GetScanFolders([[maybe_unused]] AZStd::vector<AZStd::string>& scanFolders) override { return true; }
  193. bool IsAssetPlatformEnabled([[maybe_unused]] const char* platform) override { return true; }
  194. int GetPendingAssetsForPlatform([[maybe_unused]] const char* platform) override { return 0; }
  195. bool GetAssetsProducedBySourceUUID([[maybe_unused]] const AZ::Uuid& sourceUuid, [[maybe_unused]] AZStd::vector<AZ::Data::AssetInfo>& productsAssetInfo) override { return true; }
  196. bool GetAssetSafeFolders(AZStd::vector<AZStd::string>& assetSafeFolders) override
  197. {
  198. char resolvedBuffer[AZ_MAX_PATH_LEN] = { 0 };
  199. AZ::IO::FileIOBase::GetInstance()->ResolvePath(GetFullPath("Xmls").c_str(), resolvedBuffer, AZ_MAX_PATH_LEN);
  200. assetSafeFolders.emplace_back(resolvedBuffer);
  201. return true;
  202. }
  203. bool ClearFingerprintForAsset([[maybe_unused]] const AZStd::string& sourcePath) override { return false; }
  204. // When supressing AZ_Errors to count how many occur,
  205. // you need to tell it you expect double the number of errors.
  206. const int SuppressedErrorMultiplier = 2;
  207. AZStd::unique_ptr<AZ::ComponentApplication> m_app;
  208. AZStd::string m_currentPlatform;
  209. };
  210. TEST_F(CopyDependencyBuilderTest, TestCfgBuilderWorker_EmptyCfg_NoDependenciesNoErrors)
  211. {
  212. ProductPathDependencySet resolvedPaths;
  213. bool result = CfgBuilderWorker::ParseProductDependenciesFromCfgContents(
  214. "arbitraryFileName",
  215. "",
  216. resolvedPaths);
  217. ASSERT_TRUE(result);
  218. ASSERT_EQ(resolvedPaths.size(), 0);
  219. }
  220. struct CfgTestHelper
  221. {
  222. AZStd::string m_command;
  223. ProductPathDependency m_expectedDependency;
  224. };
  225. AZStd::string ConstructCfgFromHelpers(const AZStd::vector<CfgTestHelper>& helpers)
  226. {
  227. AZStd::string result;
  228. for (const CfgTestHelper& helper : helpers)
  229. {
  230. result += AZStd::string::format("%s=%s\n", helper.m_command.c_str(), helper.m_expectedDependency.m_dependencyPath.c_str());
  231. }
  232. return result;
  233. }
  234. TEST_F(CopyDependencyBuilderTest, TestXmlBuilderWorker_VegetationDescriptorProduct_AssetTypeValid)
  235. {
  236. const char vegDescriptorTestName[] = "somefile.vegdescriptorlist";
  237. AZ::Data::AssetType vegDescriptorListType("{60961B36-E3CA-4877-B197-1462C1363F6E}"); // DescriptorListAsset in Vegetation Gem
  238. XmlBuilderWorker testBuilder;
  239. AZ::Data::AssetType parsedAssetType = testBuilder.GetAssetType(vegDescriptorTestName);
  240. ASSERT_EQ(parsedAssetType, vegDescriptorListType);
  241. }
  242. TEST_F(CopyDependencyBuilderTest, TestXmlBuilderWorker_InvalidExtensionProduct_AssetTypeNull)
  243. {
  244. const char nullTestType[] = "somefile.vegdescriptorlist2";
  245. AZ::Data::AssetType nullType = AZ::Data::AssetType::CreateNull();
  246. XmlBuilderWorker testBuilder;
  247. AZ::Data::AssetType parsedAssetType = testBuilder.GetAssetType(nullTestType);
  248. ASSERT_EQ(parsedAssetType, nullType);
  249. }
  250. TEST_F(CopyDependencyBuilderTest, TestCfgBuilderWorker_ValidCommands_CorrectDependencies)
  251. {
  252. // Testing every row of the supported config files and supported extensions won't accomplish
  253. // much besides forcing someone to keep two lists in sync. If these test cases work (source extension, product extensions), then the system works.
  254. AZStd::vector<CfgTestHelper> commands =
  255. {
  256. { "game_load_screen_uicanvas_path", { "somefile.uicanvas", ProductPathDependencyType::ProductFile }},
  257. { "sys_splashscreen", { "arbitraryFile.bmp", ProductPathDependencyType::SourceFile } },
  258. };
  259. ProductPathDependencySet resolvedPaths;
  260. bool result = CfgBuilderWorker::ParseProductDependenciesFromCfgContents(
  261. "arbitraryFileName",
  262. ConstructCfgFromHelpers(commands),
  263. resolvedPaths);
  264. ASSERT_TRUE(result);
  265. ASSERT_EQ(resolvedPaths.size(), commands.size());
  266. for (CfgTestHelper& helper : commands)
  267. {
  268. // Paths are stored in lowercase in the database
  269. AZStd::to_lower(helper.m_expectedDependency.m_dependencyPath.begin(), helper.m_expectedDependency.m_dependencyPath.end());
  270. ProductPathDependencySet::iterator foundFile = resolvedPaths.find(helper.m_expectedDependency);
  271. ASSERT_NE(foundFile, resolvedPaths.end());
  272. }
  273. }
  274. TEST_F(CopyDependencyBuilderTest, TestCfgBuilderWorker_CommentedCommand_NoDependenciesNoError)
  275. {
  276. const AZStd::vector<CfgTestHelper> commands =
  277. {
  278. // Test product file types
  279. { "--game_load_screen_uicanvas_path", { "somefile.uicanvas", ProductPathDependencyType::ProductFile }},
  280. { "--sys_splashscreen", { "arbitraryFile.bmp", ProductPathDependencyType::SourceFile } },
  281. };
  282. ProductPathDependencySet resolvedPaths;
  283. bool result = CfgBuilderWorker::ParseProductDependenciesFromCfgContents(
  284. "arbitraryFileName",
  285. ConstructCfgFromHelpers(commands),
  286. resolvedPaths);
  287. ASSERT_TRUE(result);
  288. // Both commands were commented out, so there should be no resolved paths.
  289. ASSERT_EQ(resolvedPaths.size(), 0);
  290. }
  291. TEST_F(CopyDependencyBuilderTest, TestCfgBuilderWorker_ValidCommandInvalidValue_NoDependenciesError)
  292. {
  293. const AZStd::vector<CfgTestHelper> commands =
  294. {
  295. { "game_load_screen_uicanvas_path", { "Invalid string with illegal characters!", ProductPathDependencyType::ProductFile }}
  296. };
  297. ProductPathDependencySet resolvedPaths;
  298. AZ_TEST_START_ASSERTTEST;
  299. bool result = CfgBuilderWorker::ParseProductDependenciesFromCfgContents(
  300. "arbitraryFileName",
  301. ConstructCfgFromHelpers(commands),
  302. resolvedPaths);
  303. // Expected: 1 error, on the illegal characters in the command's value.
  304. AZ_TEST_STOP_ASSERTTEST(1 * SuppressedErrorMultiplier);
  305. ASSERT_FALSE(result);
  306. ASSERT_EQ(resolvedPaths.size(), 0);
  307. }
  308. TEST_F(CopyDependencyBuilderTest, TestCfgBuilderWorker_ValidCommandEmptyValue_NoDependenciesError)
  309. {
  310. const AZStd::vector<CfgTestHelper> commands =
  311. {
  312. { "game_load_screen_uicanvas_path", { "", ProductPathDependencyType::ProductFile }}
  313. };
  314. ProductPathDependencySet resolvedPaths;
  315. AZ_TEST_START_ASSERTTEST;
  316. bool result = CfgBuilderWorker::ParseProductDependenciesFromCfgContents(
  317. "arbitraryFileName",
  318. ConstructCfgFromHelpers(commands),
  319. resolvedPaths);
  320. // Expected: 1 error, on the empty value.
  321. AZ_TEST_STOP_ASSERTTEST(1 * SuppressedErrorMultiplier);
  322. ASSERT_FALSE(result);
  323. ASSERT_EQ(resolvedPaths.size(), 0);
  324. }
  325. TEST_F(CopyDependencyBuilderTest, TestCfgBuilderWorker_UnhandledCommandValidData_NoDependenciesNoError)
  326. {
  327. const AZStd::vector<CfgTestHelper> commands =
  328. {
  329. { "command_that_does_not_exist", { "thislookslikea.file", ProductPathDependencyType::ProductFile }}
  330. };
  331. ProductPathDependencySet resolvedPaths;
  332. bool result = CfgBuilderWorker::ParseProductDependenciesFromCfgContents(
  333. "arbitraryFileName",
  334. ConstructCfgFromHelpers(commands),
  335. resolvedPaths);
  336. ASSERT_TRUE(result);
  337. ASSERT_EQ(resolvedPaths.size(), 0);
  338. }
  339. TEST_F(CopyDependencyBuilderTest, TestCfgBuilderWorker_ValidCommandsInvalidExtension_ErrorNoDependencies)
  340. {
  341. // Testing every row of the supported config files and supported extensions won't accomplish
  342. // much besides forcing someone to keep two lists in sync. If these test cases work (source extension, product extensions), then the system works.
  343. AZStd::vector<CfgTestHelper> commands =
  344. {
  345. { "game_load_screen_uicanvas_path", { "somefile.badextension", ProductPathDependencyType::ProductFile }}
  346. };
  347. ProductPathDependencySet resolvedPaths;
  348. AZ_TEST_START_ASSERTTEST;
  349. bool result = CfgBuilderWorker::ParseProductDependenciesFromCfgContents(
  350. "arbitraryFileName",
  351. ConstructCfgFromHelpers(commands),
  352. resolvedPaths);
  353. // Expected: 1 error, on the invalid extension.
  354. AZ_TEST_STOP_ASSERTTEST(1 * SuppressedErrorMultiplier);
  355. ASSERT_FALSE(result);
  356. ASSERT_EQ(resolvedPaths.size(), 0);
  357. }
  358. TEST_F(CopyDependencyBuilderTest, TestFontfamilyAsset_MultipleDependencies_OutputProductDependencies)
  359. {
  360. // Tests processing a FontFamilyExample.fontfamily file containing multiple dependencies
  361. // Should output 4 dependencies
  362. AZStd::vector<const char*> expectedPaths = {
  363. "Fonts/fontexample-regular.font",
  364. "Fonts/fontexample-bold.font",
  365. "Fonts/fontexample-italic.font",
  366. "Fonts/fontexample-bolditalic.font"
  367. };
  368. AZStd::string fileName = "Fonts/FontFamilyExample.fontfamily";
  369. FontBuilderWorker builderWorker;
  370. AZStd::vector<AssetBuilderSDK::ProductDependency> expectedProductDependencies;
  371. TestSuccessCase(&builderWorker, fileName, expectedPaths, expectedProductDependencies);
  372. }
  373. TEST_F(CopyDependencyBuilderTest, TestFontAsset_SingleDependency_OutputProductDependency)
  374. {
  375. // Tests processing a FontExample.font file containing 1 dependency
  376. // Should output 1 dependency
  377. AZStd::string fileName = "Fonts/FontExample.font";
  378. FontBuilderWorker builderWorker;
  379. TestSuccessCase(&builderWorker, fileName, "Fonts/FontExample.ttf");
  380. }
  381. TEST_F(CopyDependencyBuilderTest, TestFontAsset_NoDependency_OutputNoProductDependencies)
  382. {
  383. // Tests processing a FontExampleNoDependency.font file containing 0 dependency
  384. // Should output 0 dependencies and return true
  385. AZStd::string fileName = "Fonts/FontExampleNoDependency.font";
  386. FontBuilderWorker builderWorker;
  387. TestSuccessCaseNoDependencies(&builderWorker, fileName);
  388. }
  389. TEST_F(CopyDependencyBuilderTest, TestFontAsset_InvalidFilePath_OutputNoProductDependencies)
  390. {
  391. // Tests passing an invalid file path in
  392. // Should output 0 dependency and return false
  393. AZStd::string fileName = "Fonts/InvalidPathExample.font";
  394. FontBuilderWorker builderWorker;
  395. TestFailureCase(&builderWorker, fileName);
  396. }
  397. TEST_F(CopyDependencyBuilderTest, TestFontAsset_EmptyFile_OutputNoProductDependencies)
  398. {
  399. // Tests passing an empty file in
  400. // Should output 0 dependency and return false
  401. AZStd::string fileName = "Fonts/EmptyFontExample.font";
  402. FontBuilderWorker builderWorker;
  403. TestFailureCase(&builderWorker, fileName);
  404. }
  405. TEST_F(CopyDependencyBuilderTest, TestXmlAsset_ExcludedSourceFilePath_NoProductDependencies)
  406. {
  407. AZStd::vector<const char*> expectedPaths;
  408. AZStd::string fileName = "Xmls/ExcludedFilePathExample.xml";
  409. XmlBuilderWorker builderWorker;
  410. builderWorker.AddSchemaFileDirectory(GetFullPath("Xmls/Schema/WithVersionConstraints"));
  411. AZStd::vector<AssetBuilderSDK::ProductDependency> expectedProductDependencies;
  412. TestSuccessCase(&builderWorker, fileName, expectedPaths, expectedProductDependencies);
  413. }
  414. TEST_F(CopyDependencyBuilderTest, TestXmlAsset_InvalidSchemaFormat_NoProductDependencies)
  415. {
  416. AZStd::vector<const char*> expectedPaths;
  417. AZStd::string fileName = "Xmls/XmlExample.xml";
  418. XmlBuilderWorker builderWorker;
  419. AZStd::string fullPath = GetFullPath("Xmls/Schema/Invalid/InvalidFormat");
  420. builderWorker.AddSchemaFileDirectory(fullPath);
  421. AZ_TEST_START_TRACE_SUPPRESSION;
  422. // The expected result is true because the invalid schema doesn't mean this XML file itself has failed to parse, it may be matched
  423. // by other schemas.
  424. TestFailureCase(&builderWorker, fileName, /*expectedResult*/ true);
  425. // Three errors occur: RapidXML parse error (unexpected end of data), ObjectStream XML parse error and schema file loading error
  426. AZ_TEST_STOP_TRACE_SUPPRESSION(3 * SuppressedErrorMultiplier);
  427. }
  428. TEST_F(CopyDependencyBuilderTest, TestXmlAsset_InvalidSourceFilePath_NoProductDependencies)
  429. {
  430. AZStd::string fileName = "Xmls/InvalidFilePathExample.xml";
  431. XmlBuilderWorker builderWorker;
  432. builderWorker.AddSchemaFileDirectory(GetFullPath("Xmls/Schema/WithoutVersionConstraints/FullFeatured"));
  433. AZStd::vector<const char*> expectedPaths;
  434. AZStd::vector<AssetBuilderSDK::ProductDependency> expectedProductDependencies;
  435. AZ_TEST_START_TRACE_SUPPRESSION;
  436. TestSuccessCase(&builderWorker, fileName, expectedPaths, expectedProductDependencies);
  437. // One error occurs: Cannot open the source file
  438. AZ_TEST_STOP_TRACE_SUPPRESSION(1 * SuppressedErrorMultiplier);
  439. }
  440. TEST_F(CopyDependencyBuilderTest, TestXmlAsset_InvalidSourceFileVersionNumberFormat_NoProductDependencies)
  441. {
  442. AZStd::vector<const char*> expectedPaths;
  443. AZStd::string fileName = "Xmls/XmlExampleInvalidVersionNumberFormat.xml";
  444. XmlBuilderWorker builderWorker;
  445. builderWorker.AddSchemaFileDirectory(GetFullPath("Xmls/Schema/WithVersionConstraints"));
  446. AZStd::vector<AssetBuilderSDK::ProductDependency> expectedProductDependencies;
  447. TestSuccessCase(&builderWorker, fileName, expectedPaths, expectedProductDependencies);
  448. }
  449. TEST_F(CopyDependencyBuilderTest, TestXmlAsset_NoMatchedSchema_NoProductDependencies)
  450. {
  451. AZStd::vector<const char*> expectedPaths;
  452. AZStd::string fileName = "Xmls/NoMatchedSchemaExample.xml";
  453. XmlBuilderWorker builderWorker;
  454. builderWorker.AddSchemaFileDirectory(GetFullPath("Xmls/Schema/WithoutVersionConstraints/FullFeatured"));
  455. AZStd::vector<AssetBuilderSDK::ProductDependency> expectedProductDependencies;
  456. TestSuccessCase(&builderWorker, fileName, expectedPaths, expectedProductDependencies);
  457. }
  458. TEST_F(CopyDependencyBuilderTest, TestXmlAsset_SchemaMissingRules_NoProductDependencies)
  459. {
  460. AZStd::vector<const char*> expectedPaths;
  461. AZStd::string fileName = "Xmls/XmlExample.xml";
  462. XmlBuilderWorker builderWorker;
  463. builderWorker.AddSchemaFileDirectory(GetFullPath("Xmls/Schema/Invalid/MissingRules"));
  464. AZ_TEST_START_TRACE_SUPPRESSION;
  465. TestFailureCase(&builderWorker, fileName, true);
  466. // One error occurs: Matching rules are missing
  467. AZ_TEST_STOP_TRACE_SUPPRESSION(1 * SuppressedErrorMultiplier);
  468. }
  469. TEST_F(CopyDependencyBuilderTest, TestXmlAsset_SchemaEmptyAttributeValue_OutputProductDependencies)
  470. {
  471. AZStd::vector<const char*> expectedPaths = {
  472. "dependency2.txt",
  473. "dependency3.txt",
  474. "dependency4.txt",
  475. "dependency5.txt",
  476. "dependency6.txt",
  477. "dependency7.txt"
  478. };
  479. AZStd::string fileName = "Xmls/XmlExampleEmptyAttributeValue.xml";
  480. XmlBuilderWorker builderWorker;
  481. builderWorker.AddSchemaFileDirectory(GetFullPath("Xmls/Schema/WithoutVersionConstraints/FullFeatured"));
  482. AZStd::vector<AssetBuilderSDK::ProductDependency> expectedProductDependencies;
  483. TestSuccessCase(&builderWorker, fileName, expectedPaths, expectedProductDependencies);
  484. }
  485. TEST_F(CopyDependencyBuilderTest, TestXmlAsset_DependencySearchRuleForSpecificAttribute_OutputProductDependencies)
  486. {
  487. AZStd::vector<const char*> expectedPaths = {
  488. "dependency1.txt",
  489. "dependency2.txt",
  490. "dependency6.txt",
  491. "dependency7.txt"
  492. };
  493. AZStd::string fileName = "Xmls/XmlExampleWithoutVersion.xml";
  494. XmlBuilderWorker builderWorker;
  495. builderWorker.AddSchemaFileDirectory(GetFullPath("Xmls/Schema/WithoutVersionConstraints/SpecificAttribute"));
  496. AZStd::vector<AssetBuilderSDK::ProductDependency> expectedProductDependencies;
  497. TestSuccessCase(&builderWorker, fileName, expectedPaths, expectedProductDependencies);
  498. }
  499. TEST_F(CopyDependencyBuilderTest, TestXmlAsset_DependencySearchRuleForSpecificElement_OutputProductDependencies)
  500. {
  501. AZStd::vector<const char*> expectedPaths = {
  502. "dependency3.txt",
  503. "dependency4.txt",
  504. "dependency5.txt"
  505. };
  506. AZStd::string fileName = "Xmls/XmlExampleWithoutVersion.xml";
  507. XmlBuilderWorker builderWorker;
  508. builderWorker.AddSchemaFileDirectory(GetFullPath("Xmls/Schema/WithoutVersionConstraints/SpecificElement"));
  509. AZStd::vector<AssetBuilderSDK::ProductDependency> expectedProductDependencies;
  510. TestSuccessCase(&builderWorker, fileName, expectedPaths, expectedProductDependencies);
  511. }
  512. TEST_F(CopyDependencyBuilderTest, TestXmlAsset_DependencySearchRuleRelativeToXmlRootNode_OutputProductDependencies)
  513. {
  514. AZStd::vector<const char*> expectedPaths = {
  515. "dependency1.txt",
  516. "dependency2.txt"
  517. };
  518. AZStd::string fileName = "Xmls/XmlExampleWithoutVersion.xml";
  519. XmlBuilderWorker builderWorker;
  520. builderWorker.AddSchemaFileDirectory(GetFullPath("Xmls/Schema/WithoutVersionConstraints/RelativeToXmlRootNode"));
  521. AZStd::vector<AssetBuilderSDK::ProductDependency> expectedProductDependencies;
  522. TestSuccessCase(&builderWorker, fileName, expectedPaths, expectedProductDependencies);
  523. }
  524. TEST_F(CopyDependencyBuilderTest, TestXmlAsset_DependencySearchRuleWithExpectedExtension_OutputProductDependencies)
  525. {
  526. AZStd::string fileName = "Xmls/XmlExampleWithoutExtension.xml";
  527. XmlBuilderWorker builderWorker;
  528. builderWorker.AddSchemaFileDirectory(GetFullPath("Xmls/Schema/WithoutVersionConstraints/ExpectedExtension"));
  529. TestSuccessCase(&builderWorker, fileName, "dependency2.txt");
  530. }
  531. // The schema supports different extensions at the same location in the file.
  532. // This matches the behavior of systems like materials referencing textures: They can reference the source (png/tif) or product (dds)
  533. TEST_F(CopyDependencyBuilderTest, TestXmlAsset_MultipleOverlappingOptionalExtensions_OutputProductDependencies)
  534. {
  535. AZStd::vector<const char*> expectedPaths = {
  536. "Extension1.ext1",
  537. "Extension2.ext2"
  538. };
  539. AZStd::string fileName = "Xmls/XmlExampleMultipleMatchingExtensions.xml";
  540. XmlBuilderWorker builderWorker;
  541. builderWorker.AddSchemaFileDirectory(GetFullPath("Xmls/Schema/WithoutVersionConstraints/MultipleExtensionsSamePath"));
  542. AZStd::vector<AssetBuilderSDK::ProductDependency> expectedProductDependencies;
  543. TestSuccessCase(&builderWorker, fileName, expectedPaths, expectedProductDependencies);
  544. }
  545. TEST_F(CopyDependencyBuilderTest, TestXmlAsset_DependencySearchRuleWithOptionalAttribute_OutputProductDependencies)
  546. {
  547. AZStd::vector<const char*> expectedPaths = {
  548. "dependency1.txt",
  549. "dependency2.txt"
  550. };
  551. AZStd::string fileName = "Xmls/XmlExampleWithoutVersion.xml";
  552. XmlBuilderWorker builderWorker;
  553. builderWorker.AddSchemaFileDirectory(GetFullPath("Xmls/Schema/WithoutVersionConstraints/OptionalAttribute"));
  554. AZStd::vector<AssetBuilderSDK::ProductDependency> expectedProductDependencies;
  555. TestSuccessCase(&builderWorker, fileName, expectedPaths, expectedProductDependencies);
  556. }
  557. TEST_F(CopyDependencyBuilderTest, TestXmlAsset_DependencySearchRuleWithMissingRequiredAttribute_NoProductDependencies)
  558. {
  559. AZStd::vector<const char*> expectedPaths;
  560. AZStd::string fileName = "Xmls/XmlExampleWithoutVersion.xml";
  561. XmlBuilderWorker builderWorker;
  562. builderWorker.AddSchemaFileDirectory(GetFullPath("Xmls/Schema/WithoutVersionConstraints/RequiredAttribute"));
  563. AZStd::vector<AssetBuilderSDK::ProductDependency> expectedProductDependencies;
  564. TestSuccessCase(&builderWorker, fileName, expectedPaths, expectedProductDependencies);
  565. }
  566. TEST_F(CopyDependencyBuilderTest, TestXmlAsset_DependencySearchRuleWithOptionalElement_OutputProductDependencies)
  567. {
  568. AZStd::vector<const char*> expectedPaths = {
  569. "dependency1.txt",
  570. "dependency2.txt"
  571. };
  572. AZStd::string fileName = "Xmls/XmlExampleWithoutVersion.xml";
  573. XmlBuilderWorker builderWorker;
  574. builderWorker.AddSchemaFileDirectory(GetFullPath("Xmls/Schema/WithoutVersionConstraints/OptionalElement"));
  575. AZStd::vector<AssetBuilderSDK::ProductDependency> expectedProductDependencies;
  576. TestSuccessCase(&builderWorker, fileName, expectedPaths, expectedProductDependencies);
  577. }
  578. TEST_F(CopyDependencyBuilderTest, TestXmlAsset_DependencySearchRuleWithMissingRequiredElement_NoProductDependencies)
  579. {
  580. AZStd::vector<const char*> expectedPaths;
  581. AZStd::string fileName = "Xmls/XmlExampleWithoutVersion.xml";
  582. XmlBuilderWorker builderWorker;
  583. builderWorker.AddSchemaFileDirectory(GetFullPath("Xmls/Schema/WithoutVersionConstraints/RequiredElements"));
  584. AZStd::vector<AssetBuilderSDK::ProductDependency> expectedProductDependencies;
  585. TestSuccessCase(&builderWorker, fileName, expectedPaths, expectedProductDependencies);
  586. }
  587. TEST_F(CopyDependencyBuilderTest, TestXmlAsset_SourceFileWithoutVersionSchemaWithVersionConstraints_NoProductDependencies)
  588. {
  589. AZStd::vector<const char*> expectedPaths;
  590. AZStd::string fileName = "Xmls/XmlExampleWithoutVersion.xml";
  591. XmlBuilderWorker builderWorker;
  592. builderWorker.AddSchemaFileDirectory(GetFullPath("Xmls/Schema/WithVersionConstraints"));
  593. AZStd::vector<AssetBuilderSDK::ProductDependency> expectedProductDependencies;
  594. TestSuccessCase(&builderWorker, fileName, expectedPaths, expectedProductDependencies);
  595. }
  596. TEST_F(CopyDependencyBuilderTest, TestXmlAsset_SourceFileWithVersionOutOfRangeSchemaWithVersionConstraints_NoProductDependencies)
  597. {
  598. AZStd::vector<const char*> expectedPaths;
  599. AZStd::string fileName = "Xmls/XmlExampleVersionOutOfRange.xml";
  600. XmlBuilderWorker builderWorker;
  601. builderWorker.AddSchemaFileDirectory(GetFullPath("Xmls/Schema/WithVersionConstraints"));
  602. AZStd::vector<AssetBuilderSDK::ProductDependency> expectedProductDependencies;
  603. TestSuccessCase(&builderWorker, fileName, expectedPaths, expectedProductDependencies);
  604. }
  605. TEST_F(CopyDependencyBuilderTest, TestXmlAsset_SourceFileWithVersionSchemaWithVersionConstraints_OutputProductDependencies)
  606. {
  607. AZStd::vector<const char*> expectedPaths = {
  608. "dependency1.txt",
  609. "dependency2.txt",
  610. "dependency3.txt",
  611. "dependency4.txt",
  612. "dependency5.txt",
  613. "dependency6.txt",
  614. "dependency7.txt"
  615. };
  616. AZStd::string fileName = "Xmls/XmlExample.xml";
  617. XmlBuilderWorker builderWorker;
  618. builderWorker.AddSchemaFileDirectory(GetFullPath("Xmls/Schema/WithVersionConstraints"));
  619. AZStd::vector<AssetBuilderSDK::ProductDependency> expectedProductDependencies;
  620. TestSuccessCase(&builderWorker, fileName, expectedPaths, expectedProductDependencies);
  621. }
  622. TEST_F(CopyDependencyBuilderTest, TestXmlAsset_SourceFileWithOneVersionPartSchemaWithVersionConstraints_OutputProductDependencies)
  623. {
  624. AZStd::vector<const char*> expectedPaths = {
  625. "dependency1.txt",
  626. "dependency2.txt",
  627. "dependency3.txt",
  628. "dependency4.txt",
  629. "dependency5.txt",
  630. "dependency6.txt",
  631. "dependency7.txt"
  632. };
  633. AZStd::string fileName = "Xmls/XmlExampleWithOneVersionPart.xml";
  634. XmlBuilderWorker builderWorker;
  635. builderWorker.AddSchemaFileDirectory(GetFullPath("Xmls/Schema/WithVersionConstraints"));
  636. AZStd::vector<AssetBuilderSDK::ProductDependency> expectedProductDependencies;
  637. TestSuccessCase(&builderWorker, fileName, expectedPaths, expectedProductDependencies);
  638. }
  639. TEST_F(CopyDependencyBuilderTest, TestXmlAsset_SourceFileWithTwoVersionPartsSchemaWithVersionConstraints_OutputProductDependencies)
  640. {
  641. AZStd::vector<const char*> expectedPaths = {
  642. "dependency1.txt",
  643. "dependency2.txt",
  644. "dependency3.txt",
  645. "dependency4.txt",
  646. "dependency5.txt",
  647. "dependency6.txt",
  648. "dependency7.txt"
  649. };
  650. AZStd::string fileName = "Xmls/XmlExampleWithTwoVersionParts.xml";
  651. XmlBuilderWorker builderWorker;
  652. builderWorker.AddSchemaFileDirectory(GetFullPath("Xmls/Schema/WithVersionConstraints"));
  653. AZStd::vector<AssetBuilderSDK::ProductDependency> expectedProductDependencies;
  654. TestSuccessCase(&builderWorker, fileName, expectedPaths, expectedProductDependencies);
  655. }
  656. TEST_F(CopyDependencyBuilderTest, TestXmlAsset_SourceFileWithThreeVersionPartsSchemaWithVersionConstraints_OutputProductDependencies)
  657. {
  658. AZStd::vector<const char*> expectedPaths = {
  659. "dependency1.txt",
  660. "dependency2.txt",
  661. "dependency3.txt",
  662. "dependency4.txt",
  663. "dependency5.txt",
  664. "dependency6.txt",
  665. "dependency7.txt"
  666. };
  667. AZStd::string fileName = "Xmls/XmlExampleWithThreeVersionParts.xml";
  668. XmlBuilderWorker builderWorker;
  669. builderWorker.AddSchemaFileDirectory(GetFullPath("Xmls/Schema/WithVersionConstraints"));
  670. AZStd::vector<AssetBuilderSDK::ProductDependency> expectedProductDependencies;
  671. TestSuccessCase(&builderWorker, fileName, expectedPaths, expectedProductDependencies);
  672. }
  673. TEST_F(CopyDependencyBuilderTest, TestXmlAsset_SourceFileWithInvalidVersionPartsCountSchemaWithVersionConstraints_OutputNoProductDependencies)
  674. {
  675. AZStd::vector<const char*> expectedPaths;
  676. AZStd::string fileName = "Xmls/XmlExampleWithInvalidVersionPartsCount.xml";
  677. XmlBuilderWorker builderWorker;
  678. builderWorker.AddSchemaFileDirectory(GetFullPath("Xmls/Schema/WithVersionConstraints"));
  679. AZStd::vector<AssetBuilderSDK::ProductDependency> expectedProductDependencies;
  680. TestSuccessCase(&builderWorker, fileName, expectedPaths, expectedProductDependencies);
  681. }
  682. TEST_F(CopyDependencyBuilderTest, TestXmlAsset_SourceFileWithInvalidVersionPartsSeparatorSchemaWithVersionConstraints_OutputNoProductDependencies)
  683. {
  684. AZStd::vector<const char*> expectedPaths;
  685. AZStd::string fileName = "Xmls/XmlExampleWithInvalidVersionPartsSeparator.xml";
  686. XmlBuilderWorker builderWorker;
  687. builderWorker.AddSchemaFileDirectory(GetFullPath("Xmls/Schema/WithVersionConstraints"));
  688. AZStd::vector<AssetBuilderSDK::ProductDependency> expectedProductDependencies;
  689. TestSuccessCase(&builderWorker, fileName, expectedPaths, expectedProductDependencies);
  690. }
  691. TEST_F(CopyDependencyBuilderTest, TestXmlAsset_SourceFileWithVersionSchemaWithoutVersionConstraints_OutputProductDependencies)
  692. {
  693. AZStd::vector<const char*> expectedPaths = {
  694. "dependency1.txt",
  695. "dependency2.txt",
  696. "dependency3.txt",
  697. "dependency4.txt",
  698. "dependency5.txt",
  699. "dependency6.txt",
  700. "dependency7.txt"
  701. };
  702. AZStd::string fileName = "Xmls/XmlExample.xml";
  703. XmlBuilderWorker builderWorker;
  704. builderWorker.AddSchemaFileDirectory(GetFullPath("Xmls/Schema/WithoutVersionConstraints/FullFeatured"));
  705. AZStd::vector<AssetBuilderSDK::ProductDependency> expectedProductDependencies;
  706. TestSuccessCase(&builderWorker, fileName, expectedPaths, expectedProductDependencies);
  707. }
  708. TEST_F(CopyDependencyBuilderTest, TestXmlAsset_SourceFileWithoutVersionSchemaWithoutVersionConstraints_OutputProductDependencies)
  709. {
  710. AZStd::vector<const char*> expectedPaths = {
  711. "dependency1.txt",
  712. "dependency2.txt",
  713. "dependency3.txt",
  714. "dependency4.txt",
  715. "dependency5.txt",
  716. "dependency6.txt",
  717. "dependency7.txt"
  718. };
  719. AZStd::string fileName = "Xmls/XmlExampleWithoutVersion.xml";
  720. XmlBuilderWorker builderWorker;
  721. builderWorker.AddSchemaFileDirectory(GetFullPath("Xmls/Schema/WithoutVersionConstraints/FullFeatured"));
  722. AZStd::vector<AssetBuilderSDK::ProductDependency> expectedProductDependencies;
  723. TestSuccessCase(&builderWorker, fileName, expectedPaths, expectedProductDependencies);
  724. }
  725. TEST_F(CopyDependencyBuilderTest, TestXmlAsset_CreateJobsWithValidSourceFile_OutputSourceDependencies)
  726. {
  727. AssetBuilderSDK::CreateJobsRequest request;
  728. AssetBuilderSDK::CreateJobsResponse response;
  729. request.m_sourceFile = "Tests/Xmls/XmlExampleWithoutVersion.xml";
  730. request.m_watchFolder = "@gemroot:LmbrCentral@/Code/";
  731. XmlBuilderWorker builderWorker;
  732. builderWorker.AddSchemaFileDirectory(GetFullPath("Xmls/Schema/WithoutVersionConstraints/FullFeatured"));
  733. builderWorker.CreateJobs(request, response);
  734. ASSERT_TRUE(response.m_sourceFileDependencyList.size() == 1);
  735. AZStd::vector<AZStd::string> splitedPathList;
  736. AzFramework::StringFunc::Tokenize(response.m_sourceFileDependencyList[0].m_sourceFileDependencyPath.c_str(), splitedPathList, AZStd::string::format("%c%c",AZ_CORRECT_FILESYSTEM_SEPARATOR, AZ_WRONG_FILESYSTEM_SEPARATOR).c_str());
  737. ASSERT_EQ(splitedPathList.back(), "Schema.xmlschema");
  738. }
  739. TEST_F(CopyDependencyBuilderTest, TestXmlAsset_ProductPathRelativeToSourceAssetFolder_OutputProductDependencies)
  740. {
  741. AZStd::string product = GetFullPath("Xmls/dependency1.txt");
  742. AZStd::vector<const char*> expectedPaths = {
  743. product.c_str()
  744. };
  745. AZStd::string fileName = "Xmls/XmlExample.xml";
  746. XmlBuilderWorker builderWorker;
  747. builderWorker.AddSchemaFileDirectory(GetFullPath("Xmls/Schema/WithoutVersionConstraints/PathRelativeToSourceAssetFolder"));
  748. }
  749. TEST_F(CopyDependencyBuilderTest, TestXmlAsset_ProductPathRelativeToProductAssetFolder_OutputProductDependencies)
  750. {
  751. AZStd::string product = "Xmls/dependency1.txt";
  752. AZStd::vector<const char*> expectedPaths = {
  753. product.c_str()
  754. };
  755. AZStd::string fileName = "Xmls/XmlExample.xml";
  756. XmlBuilderWorker builderWorker;
  757. builderWorker.AddSchemaFileDirectory(GetFullPath("Xmls/Schema/WithoutVersionConstraints/PathRelativeToProductAssetFolder"));
  758. AZStd::vector<AssetBuilderSDK::ProductDependency> expectedProductDependencies;
  759. TestSuccessCase(&builderWorker, fileName, expectedPaths, expectedProductDependencies, testFileFolder);
  760. }
  761. TEST_F(CopyDependencyBuilderTest, TestXmlAsset_ProductDependencyWithAssetId_OutputProductDependencies)
  762. {
  763. AZStd::string product = GetFullPath("Xmls/dependency1.txt");
  764. AZStd::vector<const char*> expectedPaths;
  765. AZ::Data::AssetId expectedAssetId;
  766. expectedAssetId.m_guid = AZ::Uuid("00000000-0000-0000-0000-000000000000");
  767. expectedAssetId.m_subId = 0;
  768. AZStd::vector<AssetBuilderSDK::ProductDependency> expectedProductDependencies;
  769. expectedProductDependencies.emplace_back(AssetBuilderSDK::ProductDependency(expectedAssetId, {}));
  770. AZStd::string fileName = "Xmls/XmlExampleWithAssetId.xml";
  771. XmlBuilderWorker builderWorker;
  772. builderWorker.AddSchemaFileDirectory(GetFullPath("Xmls/Schema/WithoutVersionConstraints/ProductDependencyWithAssetId"));
  773. TestSuccessCase(&builderWorker, fileName, expectedPaths, expectedProductDependencies);
  774. }
  775. TEST_F(CopyDependencyBuilderTest, TestXmlAsset_MatchRegexMatches_OutputProductDependencies)
  776. {
  777. AZStd::vector<const char*> expectedPaths = {
  778. "Extension1.ext1"
  779. };
  780. AZStd::string fileName = "Xmls/XmlExampleMultipleMatchingExtensions.xml";
  781. XmlBuilderWorker builderWorker;
  782. builderWorker.AddSchemaFileDirectory(GetFullPath("Xmls/Schema/WithoutVersionConstraints/MatchPattern"));
  783. TestSuccessCase(&builderWorker, fileName, expectedPaths);
  784. }
  785. TEST_F(CopyDependencyBuilderTest, TestXmlAsset_MatchRegexNoMatches_NoProductDependencies)
  786. {
  787. AZStd::string fileName = "Xmls/XmlExample.xml";
  788. XmlBuilderWorker builderWorker;
  789. builderWorker.AddSchemaFileDirectory(GetFullPath("Xmls/Schema/WithoutVersionConstraints/MatchPattern"));
  790. TestSuccessCaseNoDependencies(&builderWorker, fileName);
  791. }
  792. TEST_F(CopyDependencyBuilderTest, TestXmlAsset_FindAndReplace_OutputProductDependencies)
  793. {
  794. AZStd::vector<const char*> expectedPaths = {
  795. "hello.ext1",
  796. "hello.ext2"
  797. };
  798. AZStd::string fileName = "Xmls/XmlExampleMultipleMatchingExtensions.xml";
  799. XmlBuilderWorker builderWorker;
  800. builderWorker.AddSchemaFileDirectory(GetFullPath("Xmls/Schema/WithoutVersionConstraints/FindAndReplace"));
  801. TestSuccessCase(&builderWorker, fileName, expectedPaths);
  802. }
  803. TEST_F(CopyDependencyBuilderTest, TestSchemaAsset_ValidMatchingRules_OutputReverseSourceDependencies)
  804. {
  805. AZStd::vector<AZStd::string> expectedPaths = {
  806. "NoMatchedSchemaExample.xml",
  807. "XmlExample.xml",
  808. "XmlExampleEmptyAttributeValue.xml",
  809. "XmlExampleInvalidVersionNumberFormat.xml",
  810. "XmlExampleMultipleMatchingExtensions.xml",
  811. "XmlExampleVersionOutOfRange.xml",
  812. "XmlExampleWithoutExtension.xml",
  813. "XmlExampleWithoutVersion.xml",
  814. "XmlExampleWithOneVersionPart.xml",
  815. "XmlExampleWithTwoVersionParts.xml",
  816. "XmlExampleWithThreeVersionParts.xml",
  817. "XmlExampleWithInvalidVersionPartsSeparator.xml",
  818. "XmlExampleWithInvalidVersionPartsCount.xml",
  819. "XmlExampleWithAssetId.xml",
  820. };
  821. AZStd::string fileName = "Xmls/XmlExampleWithoutVersion.xml";
  822. SchemaBuilderWorker builderWorker;
  823. AssetBuilderSDK::ProcessJobRequest request;
  824. AssetBuilderSDK::ProcessJobResponse response;
  825. request.m_fullPath = GetFullPath("Xmls/Schema/WithoutVersionConstraints/FullFeatured/Schema.xmlschema");
  826. request.m_sourceFile = "Xmls/Schema/WithoutVersionConstraints/FullFeatured/Schema.xmlschema";
  827. request.m_platformInfo.m_identifier = m_currentPlatform;
  828. builderWorker.ProcessJob(request, response);
  829. ASSERT_TRUE(response.m_sourcesToReprocess.size() == expectedPaths.size());
  830. for (const AZStd::string& reverseSourceDependency : response.m_sourcesToReprocess)
  831. {
  832. AZStd::vector<AZStd::string> splitedPathList;
  833. AzFramework::StringFunc::Tokenize(reverseSourceDependency.c_str(), splitedPathList, AZStd::string::format("%c%c", AZ_CORRECT_FILESYSTEM_SEPARATOR, AZ_WRONG_FILESYSTEM_SEPARATOR).c_str());
  834. ASSERT_TRUE(AZStd::find(expectedPaths.begin(), expectedPaths.end(), splitedPathList.back()) != expectedPaths.end());
  835. }
  836. }
  837. TEST_F(CopyDependencyBuilderTest, TestSchemaAsset_InvalidFormat_OutputReverseSourceDependencies)
  838. {
  839. AZStd::string fileName = "Xmls/XmlExampleWithoutVersion.xml";
  840. SchemaBuilderWorker builderWorker;
  841. AssetBuilderSDK::ProcessJobRequest request;
  842. AssetBuilderSDK::ProcessJobResponse response;
  843. request.m_fullPath = GetFullPath("Xmls/Schema/Invalid/InvalidFormat/Schema.xmlschema");
  844. request.m_sourceFile = "Xmls/Schema/Invalid/InvalidFormat/Schema.xmlschema";
  845. request.m_platformInfo.m_identifier = m_currentPlatform;
  846. AZ_TEST_START_TRACE_SUPPRESSION;
  847. builderWorker.ProcessJob(request, response);
  848. // Three errors: One from LoadObjectFromFileInPlace, one is from GetReverseSourceDependencies and the other from ProcessJob
  849. AZ_TEST_STOP_TRACE_SUPPRESSION(3 * SuppressedErrorMultiplier);
  850. ASSERT_TRUE(response.m_sourcesToReprocess.size() == 0);
  851. }
  852. TEST_F(CopyDependencyBuilderTest, TestSchemaAsset_SchemaMissingRules_OutputReverseSourceDependencies)
  853. {
  854. AZStd::string fileName = "Xmls/XmlExampleWithoutVersion.xml";
  855. SchemaBuilderWorker builderWorker;
  856. AssetBuilderSDK::ProcessJobRequest request;
  857. AssetBuilderSDK::ProcessJobResponse response;
  858. request.m_fullPath = GetFullPath("Xmls/Schema/Invalid/MissingRules/Schema.xmlschema");
  859. request.m_sourceFile = "Xmls/Schema/Invalid/MissingRules/Schema.xmlschema";
  860. request.m_platformInfo.m_identifier = m_currentPlatform;
  861. AZ_TEST_START_TRACE_SUPPRESSION;
  862. builderWorker.ProcessJob(request, response);
  863. AZ_TEST_STOP_TRACE_SUPPRESSION(SuppressedErrorMultiplier);
  864. ASSERT_TRUE(response.m_sourcesToReprocess.size() == 0);
  865. }
  866. TEST_F(CopyDependencyBuilderTest, TestEmfxWorkSpace_ProductDependencies_Valid)
  867. {
  868. AZStd::set<AZStd::string> expectedProductPathDependencies = {
  869. "foo.actor",
  870. "foo.motionset",
  871. "foo.animgraph",
  872. };
  873. AZStd::vector<AssetBuilderSDK::ProductDependency> expectedProductDependencies;
  874. AZStd::string fileName = "EmfxWorkSpace/productdependencies.emfxworkspace";
  875. EmfxWorkspaceBuilderWorker builderWorker;
  876. AssetBuilderSDK::ProcessJobRequest request;
  877. AssetBuilderSDK::ProcessJobResponse response;
  878. request.m_fullPath = GetFullPath("EmfxWorkSpace/productdependencies.emfxworkspace");
  879. request.m_sourceFile = "EmfxWorkSpace/productdependencies.emfxworkspace";
  880. request.m_platformInfo.m_identifier = m_currentPlatform;
  881. builderWorker.ProcessJob(request, response);
  882. ASSERT_EQ(response.m_outputProducts.size(), 1);
  883. ASSERT_EQ(response.m_outputProducts[0].m_pathDependencies.size(), 3);
  884. for (const auto& productDependenciesPath : response.m_outputProducts[0].m_pathDependencies)
  885. {
  886. ASSERT_TRUE(expectedProductPathDependencies.find(productDependenciesPath.m_dependencyPath) != expectedProductPathDependencies.end());
  887. ASSERT_TRUE(productDependenciesPath.m_dependencyType == ProductPathDependencyType::ProductFile);
  888. }
  889. }
  890. TEST_F(CopyDependencyBuilderTest, TestEmfxWorkSpace_NoProductDependencies_Valid)
  891. {
  892. AZStd::vector<AssetBuilderSDK::ProductDependency> expectedProductDependencies;
  893. AZStd::string fileName = "EmfxWorkSpace/noproductdependencies.emfxworkspace";
  894. EmfxWorkspaceBuilderWorker builderWorker;
  895. AssetBuilderSDK::ProcessJobRequest request;
  896. AssetBuilderSDK::ProcessJobResponse response;
  897. request.m_fullPath = GetFullPath("EmfxWorkSpace/noproductdependencies.emfxworkspace");
  898. request.m_sourceFile = "EmfxWorkSpace/noproductdependencies.emfxworkspace";
  899. request.m_platformInfo.m_identifier = m_currentPlatform;
  900. builderWorker.ProcessJob(request, response);
  901. ASSERT_EQ(response.m_outputProducts.size(), 1);
  902. ASSERT_EQ(response.m_outputProducts[0].m_pathDependencies.size(), 0);
  903. }
  904. }