SourceAssetReferenceTests.cpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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/UnitTest/TestTypes.h>
  10. #include <AssetManager/SourceAssetReference.h>
  11. #include "UnitTestUtilities.h"
  12. namespace UnitTests
  13. {
  14. using SourceAssetReferenceTests = ::UnitTest::LeakDetectionFixture;
  15. TEST_F(SourceAssetReferenceTests, Construct_AbsolutePath_Succeeds)
  16. {
  17. using namespace AssetProcessor;
  18. MockPathConversion mockPathConversion;
  19. constexpr const char* path = "c:/somepath/file.png";
  20. SourceAssetReference test1{ QString(path) };
  21. SourceAssetReference test2{ path };
  22. SourceAssetReference test3{ AZ::IO::Path(path) };
  23. EXPECT_EQ(test1.AbsolutePath(), path);
  24. EXPECT_EQ(test2.AbsolutePath(), path);
  25. EXPECT_EQ(test3.AbsolutePath(), path);
  26. EXPECT_EQ(test1.RelativePath(), "file.png");
  27. EXPECT_EQ(test1.ScanFolderPath(), "c:/somepath");
  28. EXPECT_EQ(test1.ScanFolderId(), 1);
  29. }
  30. TEST_F(SourceAssetReferenceTests, Construct_ScanFolderPath_Succeeds)
  31. {
  32. using namespace AssetProcessor;
  33. MockPathConversion mockPathConversion;
  34. constexpr const char* path = "c:/somepath/file.png";
  35. constexpr const char* scanfolder = "c:/somepath";
  36. constexpr const char* relative = "file.png";
  37. SourceAssetReference test1{ QString(scanfolder), QString(relative) };
  38. SourceAssetReference test2{ scanfolder, relative };
  39. SourceAssetReference test3{ AZ::IO::Path(scanfolder), AZ::IO::Path(relative) };
  40. EXPECT_EQ(test1.AbsolutePath(), path);
  41. EXPECT_EQ(test2.AbsolutePath(), path);
  42. EXPECT_EQ(test3.AbsolutePath(), path);
  43. EXPECT_EQ(test1.RelativePath(), relative);
  44. EXPECT_EQ(test1.ScanFolderPath(), scanfolder);
  45. EXPECT_EQ(test1.ScanFolderId(), 1);
  46. }
  47. TEST_F(SourceAssetReferenceTests, Construct_ScanFolderId_Succeeds)
  48. {
  49. using namespace AssetProcessor;
  50. MockPathConversion mockPathConversion;
  51. constexpr const char* path = "c:/somepath/file.png";
  52. constexpr const char* scanfolder = "c:/somepath";
  53. constexpr const char* relative = "file.png";
  54. SourceAssetReference test1{ 1, relative };
  55. EXPECT_EQ(test1.AbsolutePath(), path);
  56. EXPECT_EQ(test1.RelativePath(), relative);
  57. EXPECT_EQ(test1.ScanFolderPath(), scanfolder);
  58. EXPECT_EQ(test1.ScanFolderId(), 1);
  59. }
  60. TEST_F(SourceAssetReferenceTests, Copy_Succeeds)
  61. {
  62. using namespace AssetProcessor;
  63. MockPathConversion mockPathConversion;
  64. constexpr const char* path = "c:/somepath/file.png";
  65. SourceAssetReference test1{ QString(path) };
  66. auto test2 = test1;
  67. auto test3(test1);
  68. EXPECT_EQ(test1.AbsolutePath(), test2.AbsolutePath());
  69. EXPECT_EQ(test2.AbsolutePath(), test3.AbsolutePath());
  70. EXPECT_EQ(test1.RelativePath(), test2.RelativePath());
  71. EXPECT_EQ(test2.RelativePath(), test3.RelativePath());
  72. EXPECT_EQ(test1.ScanFolderPath(), test2.ScanFolderPath());
  73. EXPECT_EQ(test2.ScanFolderPath(), test3.ScanFolderPath());
  74. EXPECT_EQ(test1.ScanFolderId(), test2.ScanFolderId());
  75. EXPECT_EQ(test2.ScanFolderId(), test3.ScanFolderId());
  76. }
  77. TEST_F(SourceAssetReferenceTests, Move_Succeeds)
  78. {
  79. using namespace AssetProcessor;
  80. MockPathConversion mockPathConversion;
  81. constexpr const char* path = "c:/somepath/file.png";
  82. SourceAssetReference test1{ QString(path) };
  83. auto test2 = AZStd::move(test1);
  84. EXPECT_EQ(test2.AbsolutePath(), path);
  85. EXPECT_EQ(test2.RelativePath(), "file.png");
  86. EXPECT_EQ(test2.ScanFolderPath(), "c:/somepath");
  87. EXPECT_EQ(test2.ScanFolderId(), 1);
  88. auto test3(AZStd::move(test2));
  89. EXPECT_EQ(test3.AbsolutePath(), path);
  90. EXPECT_EQ(test3.RelativePath(), "file.png");
  91. EXPECT_EQ(test3.ScanFolderPath(), "c:/somepath");
  92. EXPECT_EQ(test3.ScanFolderId(), 1);
  93. }
  94. TEST_F(SourceAssetReferenceTests, BoolCheck_EmptyReference_ReturnsFalse)
  95. {
  96. using namespace AssetProcessor;
  97. SourceAssetReference test;
  98. EXPECT_FALSE(test);
  99. }
  100. TEST_F(SourceAssetReferenceTests, BoolCheck_ValidReference_ReturnsTrue)
  101. {
  102. using namespace AssetProcessor;
  103. MockPathConversion mockPathConversion;
  104. constexpr const char* path = "c:/somepath/file.png";
  105. SourceAssetReference test{ path };
  106. EXPECT_TRUE(test);
  107. }
  108. TEST_F(SourceAssetReferenceTests, SamePaths_AreEqual)
  109. {
  110. using namespace AssetProcessor;
  111. MockPathConversion mockPathConversion;
  112. constexpr const char* path = "c:/somepath/file.png";
  113. SourceAssetReference test1{ path };
  114. SourceAssetReference test2{ path };
  115. EXPECT_EQ(test1, test2);
  116. }
  117. TEST_F(SourceAssetReferenceTests, DifferentPaths_AreNotEqual)
  118. {
  119. using namespace AssetProcessor;
  120. MockPathConversion mockPathConversion;
  121. SourceAssetReference test1{ "c:/somepath/file.png" };
  122. SourceAssetReference test2{ "c:/somepath/file2.png" };
  123. EXPECT_NE(test1, test2);
  124. }
  125. TEST_F(SourceAssetReferenceTests, Comparison)
  126. {
  127. using namespace AssetProcessor;
  128. MockPathConversion mockPathConversion;
  129. SourceAssetReference test1{ "c:/somepath/file1.png" };
  130. SourceAssetReference test2{ "c:/somepath/file2.png" };
  131. EXPECT_LT(test1, test2);
  132. EXPECT_GT(test2, test1);
  133. }
  134. }