Application.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 <AzTest/Utils.h>
  12. class ApplicationTest
  13. : public UnitTest::FrameworkApplicationFixture
  14. {
  15. protected:
  16. void SetUp() override
  17. {
  18. FrameworkApplicationFixture::SetUp();
  19. if (auto settingsRegistry = AZ::SettingsRegistry::Get(); settingsRegistry != nullptr)
  20. {
  21. settingsRegistry->Set(AZ::SettingsRegistryMergeUtils::FilePathKey_CacheRootFolder, m_tempDirectory.GetDirectory());
  22. }
  23. if (auto fileIoBase = AZ::IO::FileIOBase::GetInstance(); fileIoBase != nullptr)
  24. {
  25. fileIoBase->SetAlias("@products@", m_tempDirectory.GetDirectory());
  26. }
  27. }
  28. void TearDown() override
  29. {
  30. FrameworkApplicationFixture::TearDown();
  31. }
  32. AZ::Test::ScopedAutoTempDirectory m_tempDirectory;
  33. };
  34. TEST_F(ApplicationTest, MakePathAssetRootRelative_AbsPath_Valid)
  35. {
  36. AZ::IO::Path inputPath = m_tempDirectory.GetDirectoryAsPath() / "TestA.txt";
  37. m_application->MakePathAssetRootRelative(inputPath.Native());
  38. EXPECT_EQ(inputPath, "testa.txt");
  39. }
  40. TEST_F(ApplicationTest, MakePathRelative_AbsPath_Valid)
  41. {
  42. AZ::IO::Path inputPath = m_tempDirectory.GetDirectoryAsPath() / "TestA.txt";
  43. m_application->MakePathRelative(inputPath.Native(), m_tempDirectory.GetDirectory());
  44. EXPECT_EQ(inputPath, "TestA.txt");
  45. }
  46. TEST_F(ApplicationTest, MakePathRelative_AbsPath_RootLowerCase_Valid)
  47. {
  48. AZ::IO::Path root = m_tempDirectory.GetDirectory();
  49. AZStd::to_lower(root.Native());
  50. AZ::IO::Path inputPath = root / "TestA.txt";
  51. m_application->MakePathRelative(inputPath.Native(), root.c_str());
  52. EXPECT_EQ(inputPath, "TestA.txt");
  53. }
  54. TEST_F(ApplicationTest, MakePathAssetRootRelative_AbsPathWithSubFolders_Valid)
  55. {
  56. AZ::IO::Path inputPath = m_tempDirectory.GetDirectoryAsPath() / "Foo/TestA.txt";
  57. m_application->MakePathAssetRootRelative(inputPath.Native());
  58. EXPECT_EQ(inputPath, "foo/testa.txt");
  59. }
  60. TEST_F(ApplicationTest, MakePathRelative_AbsPathWithSubFolders_Valid)
  61. {
  62. AZ::IO::Path inputPath = m_tempDirectory.GetDirectoryAsPath() / "Foo/TestA.txt";
  63. m_application->MakePathRelative(inputPath.Native(), m_tempDirectory.GetDirectory());
  64. EXPECT_EQ(inputPath, "Foo/TestA.txt");
  65. }
  66. TEST_F(ApplicationTest, MakePathAssetRootRelative_RelPath_Valid)
  67. {
  68. AZStd::string inputPath("TestA.txt");
  69. m_application->MakePathAssetRootRelative(inputPath);
  70. EXPECT_EQ(inputPath, "testa.txt");
  71. }
  72. TEST_F(ApplicationTest, MakePathRelative_RelPath_Valid)
  73. {
  74. AZStd::string inputPath("TestA.txt");
  75. m_application->MakePathRelative(inputPath, m_tempDirectory.GetDirectory());
  76. EXPECT_EQ(inputPath, "TestA.txt");
  77. }
  78. TEST_F(ApplicationTest, MakePathAssetRootRelative_RelPathWithSubFolder_Valid)
  79. {
  80. AZStd::string inputPath("Foo/TestA.txt");
  81. m_application->MakePathAssetRootRelative(inputPath);
  82. EXPECT_EQ(inputPath, "foo/testa.txt");
  83. }
  84. TEST_F(ApplicationTest, MakePathRelative_RelPathWithSubFolder_Valid)
  85. {
  86. AZStd::string inputPath("Foo/TestA.txt");
  87. m_application->MakePathRelative(inputPath, m_tempDirectory.GetDirectory());
  88. EXPECT_EQ(inputPath, "Foo/TestA.txt");
  89. }
  90. TEST_F(ApplicationTest, MakePathAssetRootRelative_RelPathStartingWithSeparator_NotRelative)
  91. {
  92. // A path starting with a Posix path separator is an absolute path not relative
  93. // Therefore it can't be relative to the AssetPath
  94. AZStd::string inputPath("//TestA.txt");
  95. m_application->MakePathAssetRootRelative(inputPath);
  96. EXPECT_NE(inputPath, "testa.txt");
  97. }
  98. TEST_F(ApplicationTest, MakePathRelative_RelPathStartingWithSeparator_NotRelative)
  99. {
  100. // A path starting with a Posix path separator is an absolute path not relative
  101. // Therefore it can't be relative to the temporary directory
  102. AZStd::string inputPath("//TestA.txt");
  103. m_application->MakePathRelative(inputPath, m_tempDirectory.GetDirectory());
  104. EXPECT_NE(inputPath, "TestA.txt");
  105. }
  106. TEST_F(ApplicationTest, MakePathAssetRootRelative_RelPathWithSubFolderStartingWithSeparator_NotRelative)
  107. {
  108. // A path starting with a Posix path separator is an absolute path not relative
  109. // Therefore it can't be relative to the AssetPath
  110. AZStd::string inputPath("//Foo/TestA.txt");
  111. m_application->MakePathAssetRootRelative(inputPath);
  112. EXPECT_NE(inputPath, "foo/testa.txt");
  113. }
  114. TEST_F(ApplicationTest, MakePathRelative_RelPathWithSubFolderStartingWithSeparator_NotRelative)
  115. {
  116. // A path starting with a Posix path separator is an absolute path not relative
  117. // Therefore it can't be relative to the temporary directory
  118. AZStd::string inputPath("//Foo/TestA.txt");
  119. m_application->MakePathRelative(inputPath, m_tempDirectory.GetDirectory());
  120. EXPECT_NE(inputPath, "Foo/TestA.txt");
  121. }