From 7a600416e131b33610b1c96a367b3cb2569f458e Mon Sep 17 00:00:00 2001 From: Cary Clark Date: Fri, 5 Jan 2018 10:55:28 -0500 Subject: allow both slash types Windows allows forwards and backwards slashes for path directory delimiters. R=halcanary@google.com Change-Id: Ie6f1257c98ac8e2468d9297b5dc391fd17f4ae82 Reviewed-on: https://skia-review.googlesource.com/90821 Reviewed-by: Hal Canary Commit-Queue: Cary Clark --- tests/OSPathTest.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'tests/OSPathTest.cpp') diff --git a/tests/OSPathTest.cpp b/tests/OSPathTest.cpp index 22deff80a5..74ca802304 100644 --- a/tests/OSPathTest.cpp +++ b/tests/OSPathTest.cpp @@ -32,7 +32,8 @@ static void test_dir_with_file(skiatest::Reporter* reporter, SkString dir, // fullName should be the combined size of dir and file, plus one if // dir did not include the final path separator. size_t expectedSize = dir.size() + filename.size(); - if (!dir.endsWith(SkOSPath::SEPARATOR) && !dir.isEmpty()) { + if (!dir.endsWith(SkOSPath::SEPARATOR) && ('\\' != SkOSPath::SEPARATOR || + !dir.endsWith('/')) && !dir.isEmpty()) { expectedSize++; } REPORTER_ASSERT(reporter, fullName.size() == expectedSize); @@ -46,7 +47,10 @@ static void test_dir_with_file(skiatest::Reporter* reporter, SkString dir, // dirname should be the same as dir with any trailing seperators removed. // Except when the the string is just "/". SkString strippedDir = dir; - while (strippedDir.size() > 2 && strippedDir[strippedDir.size() - 1] == SkOSPath::SEPARATOR) { + while (strippedDir.size() > 2 && + (strippedDir[strippedDir.size() - 1] == SkOSPath::SEPARATOR || + ('\\' == SkOSPath::SEPARATOR && + strippedDir[strippedDir.size() - 1] == '/'))) { strippedDir.remove(strippedDir.size() - 1, 1); } if (!dirname.equals(strippedDir)) { @@ -102,4 +106,13 @@ DEF_TEST(OSPath, reporter) { // Test that nullptr can be used for the directory and filename. SkString emptyPath = SkOSPath::Join(nullptr, nullptr); REPORTER_ASSERT(reporter, emptyPath.isEmpty()); + +#ifdef SK_BUILD_FOR_WIN + test_dir_with_file(reporter, SkString("dir/"), filename); + test_dir_with_file(reporter, SkString("dir/dir"), filename); + test_dir_with_file(reporter, SkString("dir\\dir/"), filename); + test_dir_with_file(reporter, SkString("dir/dir\\"), filename); + test_dir_with_file(reporter, SkString("dir\\dir/dir"), filename); + test_dir_with_file(reporter, SkString("dir/dir\\dir"), filename); +#endif } -- cgit v1.2.3