From: Martin Storsjö Date: Thu, 15 Oct 2020 09:52:56 +0000 (+0300) Subject: [libcxx] [test] Fix path.decompose for windows X-Git-Tag: llvmorg-14-init~13221 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1adaf48d231d1dfbd7ff575e2d03c8b01a512fe7;p=platform%2Fupstream%2Fllvm.git [libcxx] [test] Fix path.decompose for windows Add ifdefs to the test reference tables for cases where paths are interpreted differently (paths that contain a root name). Fix test assumptions regarding has_root_name() and is_absolute() and add logic to verify the results of is_absolute() for the test cases in the table. Also add a testcase for the path "//net/", which seemed like an omission. Differential Revision: https://reviews.llvm.org/D89943 --- diff --git a/libcxx/test/std/input.output/filesystems/class.path/path.member/path.decompose/path.decompose.pass.cpp b/libcxx/test/std/input.output/filesystems/class.path/path.member/path.decompose/path.decompose.pass.cpp index af58d4e..3d80cc4 100644 --- a/libcxx/test/std/input.output/filesystems/class.path/path.member/path.decompose/path.decompose.pass.cpp +++ b/libcxx/test/std/input.output/filesystems/class.path/path.member/path.decompose/path.decompose.pass.cpp @@ -86,8 +86,15 @@ const PathDecomposeTestcase PathTestCases[] = , {"/foo/", {"/", "foo", ""}, "/", "", "/", "foo/", "/foo", ""} , {"foo/bar", {"foo","bar"}, "", "", "", "foo/bar", "foo", "bar"} , {"/foo//bar", {"/","foo","bar"}, "/", "", "/", "foo/bar", "/foo", "bar"} +#ifdef _WIN32 + , {"//net", {"//net"}, "//net", "//net", "", "", "//net", ""} + , {"//net/", {"//net", "/"}, "//net/", "//net", "/", "", "//net/", ""} + , {"//net/foo", {"//net", "/", "foo"}, "//net/", "//net", "/", "foo", "//net/", "foo"} +#else , {"//net", {"/", "net"}, "/", "", "/", "net", "/", "net"} + , {"//net/", {"/", "net", ""}, "/", "", "/", "net/", "//net", ""} , {"//net/foo", {"/", "net", "foo"}, "/", "", "/", "net/foo", "/net", "foo"} +#endif , {"///foo///", {"/", "foo", ""}, "/", "", "/", "foo///", "///foo", ""} , {"///foo///bar", {"/", "foo", "bar"}, "/", "", "/", "foo///bar", "///foo", "bar"} , {"/.", {"/", "."}, "/", "", "/", ".", "/", "."} @@ -100,6 +107,15 @@ const PathDecomposeTestcase PathTestCases[] = , {"foo/./bar", {"foo", ".", "bar"}, "", "", "", "foo/./bar", "foo/.", "bar"} , {"foo/../", {"foo", "..", ""}, "", "", "", "foo/../", "foo/..", ""} , {"foo/../bar", {"foo", "..", "bar"}, "", "", "", "foo/../bar", "foo/..", "bar"} +#ifdef _WIN32 + , {"c:", {"c:"}, "c:", "c:", "", "", "c:", ""} + , {"c:/", {"c:", "/"}, "c:/", "c:", "/", "", "c:/", ""} + , {"c:foo", {"c:", "foo"}, "c:", "c:", "", "foo", "c:", "foo"} + , {"c:/foo", {"c:", "/", "foo"}, "c:/", "c:", "/", "foo", "c:/", "foo"} + , {"c:foo/", {"c:", "foo", ""}, "c:", "c:", "", "foo/", "c:foo", ""} + , {"c:/foo/", {"c:", "/", "foo", ""}, "c:/", "c:", "/", "foo/", "c:/foo", ""} + , {"c:/foo/bar", {"c:", "/", "foo", "bar"}, "c:/", "c:", "/", "foo/bar", "c:/foo", "bar"} +#else , {"c:", {"c:"}, "", "", "", "c:", "", "c:"} , {"c:/", {"c:", ""}, "", "", "", "c:/", "c:", ""} , {"c:foo", {"c:foo"}, "", "", "", "c:foo", "", "c:foo"} @@ -107,13 +123,23 @@ const PathDecomposeTestcase PathTestCases[] = , {"c:foo/", {"c:foo", ""}, "", "", "", "c:foo/", "c:foo", ""} , {"c:/foo/", {"c:", "foo", ""}, "", "", "", "c:/foo/", "c:/foo", ""} , {"c:/foo/bar", {"c:", "foo", "bar"}, "", "", "", "c:/foo/bar", "c:/foo", "bar"} +#endif , {"prn:", {"prn:"}, "", "", "", "prn:", "", "prn:"} +#ifdef _WIN32 + , {"c:\\", {"c:", "\\"}, "c:\\", "c:", "\\", "", "c:\\", ""} + , {"c:\\foo", {"c:", "\\", "foo"}, "c:\\", "c:", "\\", "foo", "c:\\", "foo"} + , {"c:foo\\", {"c:", "foo", ""}, "c:", "c:", "", "foo\\", "c:foo", ""} + , {"c:\\foo\\", {"c:", "\\", "foo", ""}, "c:\\", "c:", "\\", "foo\\", "c:\\foo", ""} + , {"c:\\foo/", {"c:", "\\", "foo", ""}, "c:\\", "c:", "\\", "foo/", "c:\\foo", ""} + , {"c:/foo\\bar", {"c:", "/", "foo", "bar"}, "c:\\", "c:", "\\", "foo\\bar", "c:/foo", "bar"} +#else , {"c:\\", {"c:\\"}, "", "", "", "c:\\", "", "c:\\"} , {"c:\\foo", {"c:\\foo"}, "", "", "", "c:\\foo", "", "c:\\foo"} , {"c:foo\\", {"c:foo\\"}, "", "", "", "c:foo\\", "", "c:foo\\"} , {"c:\\foo\\", {"c:\\foo\\"}, "", "", "", "c:\\foo\\", "", "c:\\foo\\"} , {"c:\\foo/", {"c:\\foo", ""}, "", "", "", "c:\\foo/", "c:\\foo", ""} , {"c:/foo\\bar", {"c:", "foo\\bar"}, "", "", "", "c:/foo\\bar", "c:", "foo\\bar"} +#endif , {"//", {"/"}, "/", "", "/", "", "/", ""} }; @@ -127,7 +153,9 @@ void decompPathTest() assert(p.root_path() == TC.root_path); assert(p.has_root_path() != TC.root_path.empty()); +#ifndef _WIN32 assert(p.root_name().native().empty()); +#endif assert(p.root_name() == TC.root_name); assert(p.has_root_name() != TC.root_name.empty()); @@ -143,7 +171,28 @@ void decompPathTest() assert(p.filename() == TC.filename); assert(p.has_filename() != TC.filename.empty()); +#ifdef _WIN32 + if (!p.has_root_name()) { + assert(p.is_absolute() == false); + } else { + std::string root_name = p.root_name().string(); + assert(root_name.length() >= 2); + if (root_name[1] == ':') { + // Drive letter, absolute if has a root directory + assert(p.is_absolute() == p.has_root_directory()); + } else { + // Possibly a server path + // Convert to one separator style, for simplicity + std::replace(root_name.begin(), root_name.end(), '\\', '/'); + if (root_name[0] == '/' && root_name[1] == '/') + assert(p.is_absolute() == true); + else + assert(p.is_absolute() == false); + } + } +#else assert(p.is_absolute() == p.has_root_directory()); +#endif assert(p.is_relative() != p.is_absolute()); if (p.empty()) assert(p.is_relative());