Application.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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 "FrameworkApplicationFixture.h"
  9. #include <AzCore/IO/FileIO.h>
  10. #include <AzCore/Settings/SettingsRegistryMergeUtils.h>
  11. #include <AzCore/StringFunc/StringFunc.h>
  12. #include <AzTest/Utils.h>
  13. class ApplicationTest
  14. : public UnitTest::FrameworkApplicationFixture
  15. {
  16. protected:
  17. void SetUp() override
  18. {
  19. FrameworkApplicationFixture::SetUp();
  20. if (auto settingsRegistry = AZ::SettingsRegistry::Get(); settingsRegistry != nullptr)
  21. {
  22. settingsRegistry->Set(AZ::SettingsRegistryMergeUtils::FilePathKey_CacheRootFolder, m_tempDirectory.GetDirectory());
  23. }
  24. if (auto fileIoBase = AZ::IO::FileIOBase::GetInstance(); fileIoBase != nullptr)
  25. {
  26. fileIoBase->SetAlias("@products@", m_tempDirectory.GetDirectory());
  27. }
  28. }
  29. void TearDown() override
  30. {
  31. FrameworkApplicationFixture::TearDown();
  32. }
  33. AZStd::string m_root;
  34. AZ::Test::ScopedAutoTempDirectory m_tempDirectory;
  35. };
  36. TEST_F(ApplicationTest, MakePathAssetRootRelative_AbsPath_Valid)
  37. {
  38. AZStd::string inputPath;
  39. AZ::StringFunc::Path::ConstructFull(m_tempDirectory.GetDirectory(), "TestA.txt", inputPath, true);
  40. m_application->MakePathAssetRootRelative(inputPath);
  41. EXPECT_EQ(inputPath, "testa.txt");
  42. }
  43. TEST_F(ApplicationTest, MakePathRelative_AbsPath_Valid)
  44. {
  45. AZStd::string inputPath;
  46. AZ::StringFunc::Path::ConstructFull(m_tempDirectory.GetDirectory(), "TestA.txt", inputPath, true);
  47. m_application->MakePathRelative(inputPath, m_tempDirectory.GetDirectory());
  48. EXPECT_EQ(inputPath, "TestA.txt");
  49. }
  50. TEST_F(ApplicationTest, MakePathAssetRootRelative_AbsPath_RootLowerCase_Valid)
  51. {
  52. AZStd::string inputPath;
  53. AZStd::string root = m_tempDirectory.GetDirectory();
  54. AZStd::to_lower(root.begin(), root.end());
  55. AZ::StringFunc::Path::ConstructFull(root.c_str(), "TestA.txt", inputPath, true);
  56. m_application->MakePathAssetRootRelative(inputPath);
  57. EXPECT_EQ(inputPath, "testa.txt");
  58. }
  59. TEST_F(ApplicationTest, MakePathRelative_AbsPath_RootLowerCase_Valid)
  60. {
  61. AZStd::string inputPath;
  62. AZStd::string root = m_tempDirectory.GetDirectory();
  63. AZStd::to_lower(root.begin(), root.end());
  64. AZ::StringFunc::Path::ConstructFull(root.c_str(), "TestA.txt", inputPath, true);
  65. m_application->MakePathRelative(inputPath, root.c_str());
  66. EXPECT_EQ(inputPath, "TestA.txt");
  67. }
  68. TEST_F(ApplicationTest, MakePathAssetRootRelative_AbsPathWithSubFolders_Valid)
  69. {
  70. AZStd::string inputPath;
  71. AZ::StringFunc::Path::ConstructFull(m_tempDirectory.GetDirectory(), "Foo/TestA.txt", inputPath, true);
  72. m_application->MakePathAssetRootRelative(inputPath);
  73. EXPECT_EQ(inputPath, "foo/testa.txt");
  74. }
  75. TEST_F(ApplicationTest, MakePathRelative_AbsPathWithSubFolders_Valid)
  76. {
  77. AZStd::string inputPath;
  78. AZ::StringFunc::Path::ConstructFull(m_tempDirectory.GetDirectory(), "Foo/TestA.txt", inputPath, true);
  79. m_application->MakePathRelative(inputPath, m_tempDirectory.GetDirectory());
  80. EXPECT_EQ(inputPath, "Foo/TestA.txt");
  81. }
  82. TEST_F(ApplicationTest, MakePathAssetRootRelative_RelPath_Valid)
  83. {
  84. AZStd::string inputPath("TestA.txt");
  85. m_application->MakePathAssetRootRelative(inputPath);
  86. EXPECT_EQ(inputPath, "testa.txt");
  87. }
  88. TEST_F(ApplicationTest, MakePathRelative_RelPath_Valid)
  89. {
  90. AZStd::string inputPath("TestA.txt");
  91. m_application->MakePathRelative(inputPath, m_tempDirectory.GetDirectory());
  92. EXPECT_EQ(inputPath, "TestA.txt");
  93. }
  94. TEST_F(ApplicationTest, MakePathAssetRootRelative_RelPathWithSubFolder_Valid)
  95. {
  96. AZStd::string inputPath("Foo/TestA.txt");
  97. m_application->MakePathAssetRootRelative(inputPath);
  98. EXPECT_EQ(inputPath, "foo/testa.txt");
  99. }
  100. TEST_F(ApplicationTest, MakePathRelative_RelPathWithSubFolder_Valid)
  101. {
  102. AZStd::string inputPath("Foo/TestA.txt");
  103. m_application->MakePathRelative(inputPath, m_tempDirectory.GetDirectory());
  104. EXPECT_EQ(inputPath, "Foo/TestA.txt");
  105. }
  106. TEST_F(ApplicationTest, MakePathAssetRootRelative_RelPathStartingWithSeparator_Valid)
  107. {
  108. AZStd::string inputPath("//TestA.txt");
  109. m_application->MakePathAssetRootRelative(inputPath);
  110. EXPECT_EQ(inputPath, "testa.txt");
  111. }
  112. TEST_F(ApplicationTest, MakePathRelative_RelPathStartingWithSeparator_Valid)
  113. {
  114. AZStd::string inputPath("//TestA.txt");
  115. m_application->MakePathRelative(inputPath, m_tempDirectory.GetDirectory());
  116. EXPECT_EQ(inputPath, "TestA.txt");
  117. }
  118. TEST_F(ApplicationTest, MakePathAssetRootRelative_RelPathWithSubFolderStartingWithSeparator_Valid)
  119. {
  120. AZStd::string inputPath("//Foo/TestA.txt");
  121. m_application->MakePathAssetRootRelative(inputPath);
  122. EXPECT_EQ(inputPath, "foo/testa.txt");
  123. }
  124. TEST_F(ApplicationTest, MakePathRelative_RelPathWithSubFolderStartingWithSeparator_Valid)
  125. {
  126. AZStd::string inputPath("//Foo/TestA.txt");
  127. m_application->MakePathRelative(inputPath, m_tempDirectory.GetDirectory());
  128. EXPECT_EQ(inputPath, "Foo/TestA.txt");
  129. }