mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-01-08 15:20:45 +01:00
Merge pull request #13243 from nlebeck/stringutil-tests
Add some unit test coverage of the `SplitPath` function
This commit is contained in:
commit
05cad38abc
@ -81,3 +81,114 @@ TEST(StringUtil, GetEscapedHtml)
|
|||||||
EXPECT_EQ(Common::GetEscapedHtml("&<>'\""), "&<>'"");
|
EXPECT_EQ(Common::GetEscapedHtml("&<>'\""), "&<>'"");
|
||||||
EXPECT_EQ(Common::GetEscapedHtml("&&&"), "&&&");
|
EXPECT_EQ(Common::GetEscapedHtml("&&&"), "&&&");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(StringUtil, SplitPath)
|
||||||
|
{
|
||||||
|
std::string path;
|
||||||
|
std::string filename;
|
||||||
|
std::string extension;
|
||||||
|
EXPECT_TRUE(SplitPath("/usr/lib/some_file.txt", &path, &filename, &extension));
|
||||||
|
EXPECT_EQ(path, "/usr/lib/");
|
||||||
|
EXPECT_EQ(filename, "some_file");
|
||||||
|
EXPECT_EQ(extension, ".txt");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(StringUtil, SplitPathNullOutputPathAllowed)
|
||||||
|
{
|
||||||
|
std::string filename;
|
||||||
|
std::string extension;
|
||||||
|
EXPECT_TRUE(SplitPath("/usr/lib/some_file.txt", /*path=*/nullptr, &filename, &extension));
|
||||||
|
EXPECT_EQ(filename, "some_file");
|
||||||
|
EXPECT_EQ(extension, ".txt");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(StringUtil, SplitPathNullOutputFilenameAllowed)
|
||||||
|
{
|
||||||
|
std::string path;
|
||||||
|
std::string extension;
|
||||||
|
EXPECT_TRUE(SplitPath("/usr/lib/some_file.txt", &path, /*filename=*/nullptr, &extension));
|
||||||
|
EXPECT_EQ(path, "/usr/lib/");
|
||||||
|
EXPECT_EQ(extension, ".txt");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(StringUtil, SplitPathNullOutputExtensionAllowed)
|
||||||
|
{
|
||||||
|
std::string path;
|
||||||
|
std::string filename;
|
||||||
|
EXPECT_TRUE(SplitPath("/usr/lib/some_file.txt", &path, &filename, /*extension=*/nullptr));
|
||||||
|
EXPECT_EQ(path, "/usr/lib/");
|
||||||
|
EXPECT_EQ(filename, "some_file");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(StringUtil, SplitPathReturnsFalseIfFullPathIsEmpty)
|
||||||
|
{
|
||||||
|
std::string path;
|
||||||
|
std::string filename;
|
||||||
|
std::string extension;
|
||||||
|
EXPECT_FALSE(SplitPath(/*full_path=*/"", &path, &filename, &extension));
|
||||||
|
EXPECT_EQ(path, "");
|
||||||
|
EXPECT_EQ(filename, "");
|
||||||
|
EXPECT_EQ(extension, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(StringUtil, SplitPathNoPath)
|
||||||
|
{
|
||||||
|
std::string path;
|
||||||
|
std::string filename;
|
||||||
|
std::string extension;
|
||||||
|
EXPECT_TRUE(SplitPath("some_file.txt", &path, &filename, &extension));
|
||||||
|
EXPECT_EQ(path, "");
|
||||||
|
EXPECT_EQ(filename, "some_file");
|
||||||
|
EXPECT_EQ(extension, ".txt");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(StringUtil, SplitPathNoFileName)
|
||||||
|
{
|
||||||
|
std::string path;
|
||||||
|
std::string filename;
|
||||||
|
std::string extension;
|
||||||
|
EXPECT_TRUE(SplitPath("/usr/lib/.txt", &path, &filename, &extension));
|
||||||
|
EXPECT_EQ(path, "/usr/lib/");
|
||||||
|
EXPECT_EQ(filename, "");
|
||||||
|
EXPECT_EQ(extension, ".txt");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(StringUtil, SplitPathNoExtension)
|
||||||
|
{
|
||||||
|
std::string path;
|
||||||
|
std::string filename;
|
||||||
|
std::string extension;
|
||||||
|
EXPECT_TRUE(SplitPath("/usr/lib/some_file", &path, &filename, &extension));
|
||||||
|
EXPECT_EQ(path, "/usr/lib/");
|
||||||
|
EXPECT_EQ(filename, "some_file");
|
||||||
|
EXPECT_EQ(extension, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(StringUtil, SplitPathDifferentPathLengths)
|
||||||
|
{
|
||||||
|
std::string path;
|
||||||
|
std::string filename;
|
||||||
|
std::string extension;
|
||||||
|
EXPECT_TRUE(SplitPath("/usr/some_file.txt", &path, &filename, &extension));
|
||||||
|
EXPECT_EQ(path, "/usr/");
|
||||||
|
EXPECT_EQ(filename, "some_file");
|
||||||
|
EXPECT_EQ(extension, ".txt");
|
||||||
|
|
||||||
|
EXPECT_TRUE(SplitPath("/usr/lib/foo/some_file.txt", &path, &filename, &extension));
|
||||||
|
EXPECT_EQ(path, "/usr/lib/foo/");
|
||||||
|
EXPECT_EQ(filename, "some_file");
|
||||||
|
EXPECT_EQ(extension, ".txt");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(StringUtil, SplitPathBackslashesNotRecognizedAsSeparators)
|
||||||
|
{
|
||||||
|
std::string path;
|
||||||
|
std::string filename;
|
||||||
|
std::string extension;
|
||||||
|
EXPECT_TRUE(SplitPath("\\usr\\some_file.txt", &path, &filename, &extension));
|
||||||
|
EXPECT_EQ(path, "");
|
||||||
|
EXPECT_EQ(filename, "\\usr\\some_file");
|
||||||
|
EXPECT_EQ(extension, ".txt");
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: add `SplitPath` test coverage for paths containing Windows drives, e.g., "C:".
|
||||||
|
Loading…
Reference in New Issue
Block a user