Debian Codegraph @

Source/UnitTests/Common/NandPathsTest.cpp

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