3
0

AssetUtilsTests.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 <Common/RPITestFixture.h>
  10. #include <Common/ErrorMessageFinder.h>
  11. #include <Atom/RPI.Edit/Common/AssetUtils.h>
  12. namespace UnitTest
  13. {
  14. using namespace AZ;
  15. using namespace RPI;
  16. class AssetUtilsTests
  17. : public RPITestFixture
  18. {
  19. protected:
  20. void SetUp() override
  21. {
  22. RPITestFixture::SetUp();
  23. }
  24. void TearDown() override
  25. {
  26. RPITestFixture::TearDown();
  27. }
  28. };
  29. TEST_F(AssetUtilsTests, TestSanitizeFilename)
  30. {
  31. static const char AllSupportedCharacters[] = "abcdefghijklmnopqrstufwxyz-ABCDEFGHIJKLMNOPQRSTUFWXYZ_0123456789.txt";
  32. EXPECT_STREQ("", AssetUtils::SanitizeFileName("").c_str());
  33. EXPECT_STREQ(AllSupportedCharacters, AssetUtils::SanitizeFileName(AllSupportedCharacters).c_str());
  34. EXPECT_STREQ("a_b_c_d_e_f_g_h_i_jklmnopqrstufwxyz", AssetUtils::SanitizeFileName(R"(a\b/c:d*e?f\"g<h>i|jklmnopqrstufwxyz)").c_str());
  35. EXPECT_STREQ("Hello_World", AssetUtils::SanitizeFileName(R"(Hello<::\*/::>World)").c_str());
  36. EXPECT_STREQ("CantEndWithDot", AssetUtils::SanitizeFileName("CantEndWithDot.").c_str());
  37. EXPECT_STREQ("Cant_Have_Multiple_Dots_", AssetUtils::SanitizeFileName("Cant..Have...Multiple....Dots...").c_str());
  38. EXPECT_STREQ("Prevent_MultipleUnderscores", AssetUtils::SanitizeFileName(R"(Prevent<::_\*/_::>MultipleUnderscores)").c_str());
  39. // These characters might be allowed by the OS, but they are prevented in FileDialog::GetSaveFileName
  40. EXPECT_STREQ("Other_Characters", AssetUtils::SanitizeFileName("Other~!@#$%^&*()+=[]{},;'`Characters").c_str());
  41. }
  42. }