BundlingSystemComponentTests.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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 <AzCore/Component/ComponentApplication.h>
  10. #include <AzCore/Asset/AssetManager.h>
  11. #include <AzCore/Asset/AssetManagerComponent.h>
  12. #include <AzCore/Memory/PoolAllocator.h>
  13. #include <AzFramework/IO/LocalFileIO.h>
  14. #include <AzFramework/Archive/IArchive.h>
  15. #include <Bundling/BundlingSystemComponent.h>
  16. #include <LmbrCentral/Bundling/BundlingSystemComponentBus.h>
  17. #include <LmbrCentral.h>
  18. #include <ISystem.h>
  19. #include <AzCore/UnitTest/TestTypes.h>
  20. namespace UnitTest
  21. {
  22. class BundlingSystemComponentFixture :
  23. public ::testing::Test
  24. {
  25. public:
  26. BundlingSystemComponentFixture() = default;
  27. bool TestAsset(const char* assetPath)
  28. {
  29. AZ::IO::HandleType readHandle;
  30. AZ::IO::FileIOBase::GetInstance()->Open(assetPath, AZ::IO::OpenMode::ModeRead | AZ::IO::OpenMode::ModeBinary, readHandle);
  31. bool testResult = (readHandle != AZ::IO::InvalidHandle);
  32. AZ::IO::FileIOBase::GetInstance()->Close(readHandle);
  33. return testResult;
  34. }
  35. bool TestAssetId(const char* assetPath)
  36. {
  37. AZ::Data::AssetId testAssetId;
  38. AZ::Data::AssetCatalogRequestBus::BroadcastResult(testAssetId, &AZ::Data::AssetCatalogRequestBus::Events::GetAssetIdByPath, assetPath, AZ::Data::s_invalidAssetType, false);
  39. if (!testAssetId.IsValid())
  40. {
  41. return false;
  42. }
  43. AZ::Data::AssetInfo assetInfo;
  44. AZ::Data::AssetCatalogRequestBus::BroadcastResult(assetInfo, &AZ::Data::AssetCatalogRequestBus::Events::GetAssetInfoById, testAssetId);
  45. return assetInfo.m_relativePath == assetPath;
  46. }
  47. };
  48. TEST_F(BundlingSystemComponentFixture, DISABLED_HasBundle_LoadBundles_Success)
  49. {
  50. // This asset lives only within LmbrCentral/Assets/Test/Bundle/staticdata.pak which is copied to our
  51. // cache as test/bundle/staticdata.pak and should be loaded below
  52. const char testAssetPath[] = "staticdata/csv/bundlingsystemtestgameproperties.csv";
  53. EXPECT_FALSE(TestAsset(testAssetPath));
  54. LmbrCentral::BundlingSystemRequestBus::Broadcast(&LmbrCentral::BundlingSystemRequestBus::Events::LoadBundles, "test/bundle", ".pak");
  55. EXPECT_TRUE(TestAsset(testAssetPath));
  56. LmbrCentral::BundlingSystemRequestBus::Broadcast(&LmbrCentral::BundlingSystemRequestBus::Events::UnloadBundles);
  57. EXPECT_FALSE(TestAsset(testAssetPath));
  58. }
  59. TEST_F(BundlingSystemComponentFixture, DISABLED_HasBundle_LoadBundlesCatalogChecks_Success)
  60. {
  61. // This asset lives only within LmbrCentral/Assets/Test/Bundle/staticdata.pak which is copied to our
  62. // cache as test/bundle/staticdata.pak and should be loaded below
  63. // The Pak has a catalog describing the contents which should automatically update our central asset catalog
  64. const char testAssetPath[] = "staticdata/csv/bundlingsystemtestgameproperties.csv";
  65. const char noCatalogAsset[] = "staticdata/csv/gameproperties.csv";
  66. EXPECT_FALSE(TestAssetId(testAssetPath));
  67. EXPECT_FALSE(TestAssetId(noCatalogAsset));
  68. LmbrCentral::BundlingSystemRequestBus::Broadcast(&LmbrCentral::BundlingSystemRequestBus::Events::LoadBundles, "test/bundle", ".pak");
  69. EXPECT_TRUE(TestAssetId(testAssetPath));
  70. EXPECT_FALSE(TestAssetId(noCatalogAsset));
  71. EXPECT_TRUE(TestAsset(noCatalogAsset));
  72. LmbrCentral::BundlingSystemRequestBus::Broadcast(&LmbrCentral::BundlingSystemRequestBus::Events::UnloadBundles);
  73. EXPECT_FALSE(TestAssetId(testAssetPath));
  74. EXPECT_FALSE(TestAssetId(noCatalogAsset));
  75. EXPECT_FALSE(TestAsset(noCatalogAsset));
  76. }
  77. TEST_F(BundlingSystemComponentFixture, DISABLED_BundleSystemComponent_SingleUnloadCheckCatalog_Success)
  78. {
  79. // This asset lives only within LmbrCentral/Assets/Test/Bundle/staticdata.pak which is copied to our
  80. // cache as test/bundle/staticdata.pak and should be loaded below
  81. // The Pak has a catalog describing the contents which should automatically update our central asset catalog
  82. const char testCSVAsset[] = "staticdata/csv/bundlingsystemtestgameproperties.csv";
  83. const char testCSVAssetPak[] = "test/bundle/staticdata.pak";
  84. // This asset lives only within LmbrCentral/Assets/Test/Bundle/ping.pak
  85. const char testDDSAsset[] = "textures/test/ping.dds";
  86. const char testDDSAssetPak[] = "test/bundle/ping.pak";
  87. EXPECT_FALSE(TestAssetId(testCSVAsset));
  88. EXPECT_FALSE(TestAssetId(testDDSAsset));
  89. EXPECT_TRUE(gEnv->pCryPak->OpenPack("@products@", testDDSAssetPak));
  90. EXPECT_FALSE(TestAssetId(testCSVAsset));
  91. EXPECT_TRUE(TestAssetId(testDDSAsset));
  92. EXPECT_TRUE(gEnv->pCryPak->ClosePack(testDDSAssetPak));
  93. EXPECT_FALSE(TestAssetId(testCSVAsset));
  94. EXPECT_FALSE(TestAssetId(testDDSAsset));
  95. EXPECT_TRUE(gEnv->pCryPak->OpenPack("@products@", testCSVAssetPak));
  96. EXPECT_TRUE(TestAssetId(testCSVAsset));
  97. EXPECT_FALSE(TestAssetId(testDDSAsset));
  98. EXPECT_TRUE(gEnv->pCryPak->OpenPack("@products@", testDDSAssetPak));
  99. EXPECT_TRUE(TestAssetId(testCSVAsset));
  100. EXPECT_TRUE(TestAssetId(testDDSAsset));
  101. EXPECT_TRUE(gEnv->pCryPak->ClosePack(testDDSAssetPak));
  102. EXPECT_TRUE(TestAssetId(testCSVAsset));
  103. EXPECT_FALSE(TestAssetId(testDDSAsset));
  104. EXPECT_TRUE(gEnv->pCryPak->OpenPack("@products@", testDDSAssetPak));
  105. EXPECT_TRUE(TestAssetId(testCSVAsset));
  106. EXPECT_TRUE(TestAssetId(testDDSAsset));
  107. EXPECT_TRUE(gEnv->pCryPak->ClosePack(testCSVAssetPak));
  108. EXPECT_FALSE(TestAssetId(testCSVAsset));
  109. EXPECT_TRUE(TestAssetId(testDDSAsset));
  110. EXPECT_TRUE(gEnv->pCryPak->ClosePack(testDDSAssetPak));
  111. EXPECT_FALSE(TestAssetId(testCSVAsset));
  112. EXPECT_FALSE(TestAssetId(testDDSAsset));
  113. }
  114. TEST_F(BundlingSystemComponentFixture, DISABLED_BundleSystemComponent_SingleLoadAndBundleMode_Success)
  115. {
  116. // This asset lives only within LmbrCentral/Assets/Test/Bundle/staticdata.pak which is copied to our
  117. // cache as test/bundle/staticdata.pak and should be loaded below
  118. // The Pak has a catalog describing the contents which should automatically update our central asset catalog
  119. const char testCSVAsset[] = "staticdata/csv/bundlingsystemtestgameproperties.csv";
  120. const char testMTLAsset[] = "materials/water_test.mtl";
  121. const char testMTLAssetPak[] = "test/TestMaterials.pak";
  122. EXPECT_FALSE(TestAssetId(testCSVAsset));
  123. EXPECT_FALSE(TestAssetId(testMTLAsset));
  124. EXPECT_TRUE(gEnv->pCryPak->OpenPack("@products@", testMTLAssetPak));
  125. EXPECT_FALSE(TestAssetId(testCSVAsset));
  126. EXPECT_TRUE(TestAssetId(testMTLAsset));
  127. LmbrCentral::BundlingSystemRequestBus::Broadcast(&LmbrCentral::BundlingSystemRequestBus::Events::LoadBundles, "test/bundle", ".pak");
  128. EXPECT_TRUE(TestAssetId(testCSVAsset));
  129. EXPECT_TRUE(TestAssetId(testMTLAsset));
  130. LmbrCentral::BundlingSystemRequestBus::Broadcast(&LmbrCentral::BundlingSystemRequestBus::Events::UnloadBundles);
  131. EXPECT_FALSE(TestAssetId(testCSVAsset));
  132. EXPECT_TRUE(TestAssetId(testMTLAsset));
  133. EXPECT_TRUE(gEnv->pCryPak->ClosePack(testMTLAssetPak));
  134. EXPECT_FALSE(TestAssetId(testCSVAsset));
  135. EXPECT_FALSE(TestAssetId(testMTLAsset));
  136. }
  137. TEST_F(BundlingSystemComponentFixture, DISABLED_BundleSystemComponent_OpenClosePackCount_Match)
  138. {
  139. // This asset lives only within LmbrCentral/Assets/Test/Bundle/staticdata.pak which is copied to our
  140. // cache as test/bundle/staticdata.pak and should be loaded below
  141. // The Pak has a catalog describing the contents which should automatically update our central asset catalog
  142. const char testCSVAsset[] = "staticdata/csv/bundlingsystemtestgameproperties.csv";
  143. const char testCSVAssetPak[] = "test/bundle/staticdata.pak";
  144. // This asset lives only within LmbrCentral/Assets/Test/Bundle/ping.pak
  145. const char testDDSAssetPak[] = "test/bundle/ping.pak";
  146. size_t bundleCount{ 0 };
  147. LmbrCentral::BundlingSystemRequestBus::BroadcastResult(bundleCount,&LmbrCentral::BundlingSystemRequestBus::Events::GetOpenedBundleCount);
  148. EXPECT_EQ(bundleCount, 0);
  149. EXPECT_FALSE(TestAssetId(testCSVAsset));
  150. EXPECT_TRUE(gEnv->pCryPak->OpenPack("@products@", testDDSAssetPak));
  151. LmbrCentral::BundlingSystemRequestBus::BroadcastResult(bundleCount, &LmbrCentral::BundlingSystemRequestBus::Events::GetOpenedBundleCount);
  152. EXPECT_EQ(bundleCount, 1);
  153. EXPECT_TRUE(gEnv->pCryPak->ClosePack(testDDSAssetPak));
  154. LmbrCentral::BundlingSystemRequestBus::BroadcastResult(bundleCount, &LmbrCentral::BundlingSystemRequestBus::Events::GetOpenedBundleCount);
  155. EXPECT_EQ(bundleCount, 0);
  156. EXPECT_TRUE(gEnv->pCryPak->OpenPack("@products@", testCSVAssetPak));
  157. LmbrCentral::BundlingSystemRequestBus::BroadcastResult(bundleCount, &LmbrCentral::BundlingSystemRequestBus::Events::GetOpenedBundleCount);
  158. EXPECT_EQ(bundleCount, 1);
  159. EXPECT_TRUE(gEnv->pCryPak->OpenPack("@products@", testDDSAssetPak));
  160. LmbrCentral::BundlingSystemRequestBus::BroadcastResult(bundleCount, &LmbrCentral::BundlingSystemRequestBus::Events::GetOpenedBundleCount);
  161. EXPECT_EQ(bundleCount, 2);
  162. EXPECT_TRUE(gEnv->pCryPak->ClosePack(testDDSAssetPak));
  163. LmbrCentral::BundlingSystemRequestBus::BroadcastResult(bundleCount, &LmbrCentral::BundlingSystemRequestBus::Events::GetOpenedBundleCount);
  164. EXPECT_EQ(bundleCount, 1);
  165. EXPECT_TRUE(gEnv->pCryPak->OpenPack("@products@", testDDSAssetPak));
  166. LmbrCentral::BundlingSystemRequestBus::BroadcastResult(bundleCount, &LmbrCentral::BundlingSystemRequestBus::Events::GetOpenedBundleCount);
  167. EXPECT_EQ(bundleCount, 2);
  168. EXPECT_TRUE(gEnv->pCryPak->ClosePack(testCSVAssetPak));
  169. LmbrCentral::BundlingSystemRequestBus::BroadcastResult(bundleCount, &LmbrCentral::BundlingSystemRequestBus::Events::GetOpenedBundleCount);
  170. EXPECT_EQ(bundleCount, 1);
  171. EXPECT_TRUE(gEnv->pCryPak->ClosePack(testDDSAssetPak));
  172. LmbrCentral::BundlingSystemRequestBus::BroadcastResult(bundleCount, &LmbrCentral::BundlingSystemRequestBus::Events::GetOpenedBundleCount);
  173. EXPECT_EQ(bundleCount, 0);
  174. }
  175. TEST_F(BundlingSystemComponentFixture, DISABLED_BundleSystemComponent_SplitPakTestWithAsset_Success)
  176. {
  177. // This asset lives only within LmbrCentral/Assets/Test/SplitBundleTest/splitbundle__1.pak which is a dependent bundle of splitbundle.pak
  178. const char testDDSAsset_split[] = "textures/milestone2/am_floor_tile_ddna_test.dds.7";
  179. const char testDDSAssetPak[] = "test/splitbundletest/splitbundle.pak";
  180. size_t bundleCount{ 0 };
  181. LmbrCentral::BundlingSystemRequestBus::BroadcastResult(bundleCount, &LmbrCentral::BundlingSystemRequestBus::Events::GetOpenedBundleCount);
  182. EXPECT_EQ(bundleCount, 0);
  183. EXPECT_FALSE(TestAssetId(testDDSAsset_split));
  184. EXPECT_TRUE(gEnv->pCryPak->OpenPack("@products@", testDDSAssetPak));
  185. LmbrCentral::BundlingSystemRequestBus::BroadcastResult(bundleCount, &LmbrCentral::BundlingSystemRequestBus::Events::GetOpenedBundleCount);
  186. EXPECT_EQ(bundleCount, 2);
  187. EXPECT_TRUE(TestAssetId(testDDSAsset_split));
  188. EXPECT_TRUE(gEnv->pCryPak->ClosePack(testDDSAssetPak));
  189. LmbrCentral::BundlingSystemRequestBus::BroadcastResult(bundleCount, &LmbrCentral::BundlingSystemRequestBus::Events::GetOpenedBundleCount);
  190. EXPECT_EQ(bundleCount, 0);
  191. EXPECT_FALSE(TestAssetId(testDDSAsset_split));
  192. EXPECT_TRUE(gEnv->pCryPak->OpenPack("@products@", testDDSAssetPak));
  193. LmbrCentral::BundlingSystemRequestBus::BroadcastResult(bundleCount, &LmbrCentral::BundlingSystemRequestBus::Events::GetOpenedBundleCount);
  194. EXPECT_EQ(bundleCount, 2);
  195. EXPECT_TRUE(TestAssetId(testDDSAsset_split));
  196. EXPECT_TRUE(gEnv->pCryPak->ClosePack(testDDSAssetPak));
  197. LmbrCentral::BundlingSystemRequestBus::BroadcastResult(bundleCount, &LmbrCentral::BundlingSystemRequestBus::Events::GetOpenedBundleCount);
  198. EXPECT_EQ(bundleCount, 0);
  199. EXPECT_FALSE(TestAssetId(testDDSAsset_split));
  200. }
  201. // Verify that our bundles using catalogs of the same name work properly
  202. TEST_F(BundlingSystemComponentFixture, DISABLED_BundleSystemComponent_SharedCatalogName_Success)
  203. {
  204. // This bundle was built for PC but is generic and the test should work fine on other platforms
  205. // gamepropertioessmall_pc.pak has a smaller version of the gameproperties csv
  206. // gamepropertiesuserrequest_pc.pak has a bigger version of gameproperties and adds userrequest.csv
  207. const char testGamePropertiesAsset[] = "staticdata/test/gameproperties.csv";
  208. const char testUserRequestAsset[] = "staticdata/test/userrequest.csv";
  209. const char testGamePropertiesAssetPak[] = "test/bundle/gamepropertiessmall_pc.pak";
  210. const char testUserRequestAssetPak[] = "test/bundle/gamepropertiesuserrequest_pc.pak";
  211. EXPECT_FALSE(TestAssetId(testGamePropertiesAsset));
  212. EXPECT_FALSE(TestAssetId(testUserRequestAsset));
  213. EXPECT_TRUE(gEnv->pCryPak->OpenPack("@products@", testGamePropertiesAssetPak));
  214. EXPECT_TRUE(TestAssetId(testGamePropertiesAsset));
  215. EXPECT_FALSE(TestAssetId(testUserRequestAsset));
  216. AZ::Data::AssetId testAssetId;
  217. AZ::Data::AssetCatalogRequestBus::BroadcastResult(testAssetId, &AZ::Data::AssetCatalogRequestBus::Events::GetAssetIdByPath, testGamePropertiesAsset, AZ::Data::s_invalidAssetType, false);
  218. EXPECT_TRUE(testAssetId.IsValid());
  219. AZ::Data::AssetInfo assetInfo;
  220. AZ::Data::AssetCatalogRequestBus::BroadcastResult(assetInfo, &AZ::Data::AssetCatalogRequestBus::Events::GetAssetInfoById, testAssetId);
  221. EXPECT_NE(assetInfo.m_sizeBytes, 0);
  222. AZ::u64 assetSize1 = assetInfo.m_sizeBytes;
  223. EXPECT_TRUE(gEnv->pCryPak->OpenPack("@products@", testUserRequestAssetPak));
  224. EXPECT_TRUE(TestAssetId(testGamePropertiesAsset));
  225. EXPECT_TRUE(TestAssetId(testUserRequestAsset));
  226. AZ::Data::AssetCatalogRequestBus::BroadcastResult(assetInfo, &AZ::Data::AssetCatalogRequestBus::Events::GetAssetInfoById, testAssetId);
  227. AZ::u64 assetSize2 = assetInfo.m_sizeBytes;
  228. EXPECT_NE(assetSize1, assetSize2);
  229. EXPECT_TRUE(gEnv->pCryPak->ClosePack(testUserRequestAssetPak));
  230. EXPECT_TRUE(TestAssetId(testGamePropertiesAsset));
  231. EXPECT_FALSE(TestAssetId(testUserRequestAsset));
  232. AZ::Data::AssetCatalogRequestBus::BroadcastResult(assetInfo, &AZ::Data::AssetCatalogRequestBus::Events::GetAssetInfoById, testAssetId);
  233. EXPECT_EQ(assetSize1, assetInfo.m_sizeBytes);
  234. EXPECT_TRUE(gEnv->pCryPak->ClosePack(testGamePropertiesAssetPak));
  235. EXPECT_FALSE(TestAssetId(testGamePropertiesAsset));
  236. EXPECT_FALSE(TestAssetId(testUserRequestAsset));
  237. EXPECT_TRUE(gEnv->pCryPak->OpenPack("@products@", testUserRequestAssetPak));
  238. AZ::Data::AssetCatalogRequestBus::BroadcastResult(assetInfo, &AZ::Data::AssetCatalogRequestBus::Events::GetAssetInfoById, testAssetId);
  239. AZ::u64 assetSize3 = assetInfo.m_sizeBytes;
  240. EXPECT_EQ(assetSize3, assetSize2);
  241. EXPECT_TRUE(gEnv->pCryPak->OpenPack("@products@", testGamePropertiesAssetPak));
  242. AZ::Data::AssetCatalogRequestBus::BroadcastResult(assetInfo, &AZ::Data::AssetCatalogRequestBus::Events::GetAssetInfoById, testAssetId);
  243. AZ::u64 assetSize4 = assetInfo.m_sizeBytes;
  244. EXPECT_EQ(assetSize4, assetSize1);
  245. }
  246. }