NandPathsTest.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright 2016 Dolphin Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include <gtest/gtest.h>
  4. #include <string>
  5. #include "Common/NandPaths.h"
  6. static void TestEscapeAndUnescape(const std::string& unescaped, const std::string& escaped)
  7. {
  8. EXPECT_EQ(escaped, Common::EscapeFileName(unescaped));
  9. EXPECT_EQ(unescaped, Common::UnescapeFileName(escaped));
  10. }
  11. TEST(NandPaths, EscapeUnescape)
  12. {
  13. EXPECT_EQ("/a/__2e__/b/__3e__", Common::EscapePath("/a/./b/>"));
  14. EXPECT_EQ("/a/__2e____2e__/b/__3e__", Common::EscapePath("/a/../b/>"));
  15. EXPECT_EQ("/a/__2e____2e____2e__/b/__3e__", Common::EscapePath("/a/.../b/>"));
  16. EXPECT_EQ("/a/__2e____2e____2e____2e__/b/__3e__", Common::EscapePath("/a/..../b/>"));
  17. EXPECT_EQ("", Common::EscapePath(""));
  18. TestEscapeAndUnescape("", "");
  19. TestEscapeAndUnescape("regular string", "regular string");
  20. TestEscapeAndUnescape("a/../1b|", "a__2f__..__2f__1b__7c__");
  21. TestEscapeAndUnescape("__22__", "__5f____5f__22__5f____5f__");
  22. // The \0 can't be written in a regular string literal, otherwise it'll be treated as the end
  23. TestEscapeAndUnescape(std::string{'\0'} +
  24. "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
  25. "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"
  26. "\"*/:<>?\\_|\x7f",
  27. "__00____01____02____03____04____05____06____07__"
  28. "__08____09____0a____0b____0c____0d____0e____0f__"
  29. "__10____11____12____13____14____15____16____17__"
  30. "__18____19____1a____1b____1c____1d____1e____1f__"
  31. "__22____2a____2f____3a____3c____3e____3f____5c_____7c____7f__");
  32. // ^
  33. // There is a normal underscore here (not part of an escape sequence): |
  34. }