[PATCH 2/2] libstdc++: Extend tests for UNC paths on MinGW
Johannes Grunenberg
johannes.grunenberg@stud.uni-hannover.de
Sat May 10 11:46:17 GMT 2025
Adds some additional tests to ensure that UNC paths are properly
handled (mainly decomposed) on MinGW.
libstdc++-v3/ChangeLog:
* testsuite/27_io/filesystem/path/decompose/extension.cc:
Test for UNC paths with dots in the root directory.
* testsuite/27_io/filesystem/path/decompose/relative_path.cc:
Test for UNC paths.
* testsuite/27_io/filesystem/path/decompose/root_directory.cc:
Test for UNC path.
* testsuite/27_io/filesystem/path/decompose/root_name.cc:
Test for Windows paths.
* testsuite/27_io/filesystem/path/decompose/root_path.cc:
Test for Windows paths.
* testsuite/27_io/filesystem/path/decompose/stem.cc:
Test for Windows paths.
* testsuite/27_io/filesystem/path/generation/relative.cc:
Test for Windows paths.
Signed-off-by: Johannes Grunenberg <johannes.grunenberg@stud.uni-hannover.de>
---
.../filesystem/path/decompose/extension.cc | 5 +++++
.../path/decompose/relative_path.cc | 9 +++++++++
.../path/decompose/root_directory.cc | 1 +
.../filesystem/path/decompose/root_name.cc | 20 +++++++++++++++++++
.../filesystem/path/decompose/root_path.cc | 13 ++++++++++++
.../27_io/filesystem/path/decompose/stem.cc | 5 +++++
.../filesystem/path/generation/relative.cc | 14 +++++++++++++
7 files changed, 67 insertions(+)
diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/extension.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/extension.cc
index 82887beea37..0965209d283 100644
--- a/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/extension.cc
+++ b/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/extension.cc
@@ -45,6 +45,11 @@ test01()
VERIFY( path(".").extension() == path("") );
VERIFY( path().extension() == path() );
+
+#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
+ VERIFY( path("\\\\wsl.local").extension() == path("") );
+ VERIFY( path("\\\\wsl.local\\foo.bar").extension() == path(".bar") );
+#endif
}
void
diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/relative_path.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/relative_path.cc
index 0c3eb4b333e..ebc56b99d56 100644
--- a/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/relative_path.cc
+++ b/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/relative_path.cc
@@ -34,6 +34,15 @@ test01()
VERIFY( p2.relative_path() == p2 );
path p3 = "/foo/bar";
VERIFY( p3.relative_path() == p2 );
+
+#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
+ path p4 = "\\\\baz/foo/bar";
+ VERIFY( p4.relative_path() == p2 );
+ path p5 = "foo\\bar";
+ VERIFY( p5.relative_path() == p5 );
+ path p6 = "\\\\baz\\foo\\bar";
+ VERIFY( p6.relative_path() == p5 );
+#endif
}
#include <iostream> // XXX
diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/root_directory.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/root_directory.cc
index a7c90f99752..ffdf18929be 100644
--- a/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/root_directory.cc
+++ b/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/root_directory.cc
@@ -35,6 +35,7 @@ test01()
path p3 = "//foo";
#if defined(__CYGWIN__) || defined(_GLIBCXX_FILESYSTEM_IS_WINDOWS)
VERIFY( p3.root_directory() == path() );
+ VERIFY( path("//").root_directory() == path("//") );
#else
VERIFY( p3.root_directory() == path("/") );
#endif
diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/root_name.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/root_name.cc
index c32242ff6fe..d5d1934ec15 100644
--- a/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/root_name.cc
+++ b/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/root_name.cc
@@ -34,8 +34,28 @@ test01()
VERIFY( path("..").extension().empty() );
}
+void
+test02()
+{
+#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
+ VERIFY( path("/foo/bar").root_name() == "" );
+ VERIFY( path("\\").root_name() == "" );
+ VERIFY( path("\\\\").root_name() == "" );
+ VERIFY( path("\\\\foo").root_name() == "\\\\foo" );
+ VERIFY( path("\\\\foo\\").root_name() == "\\\\foo" );
+ VERIFY( path("\\\\foo\\bar").root_name() == "\\\\foo" );
+ VERIFY( path("\\\\?\\c\\").root_name() == "\\\\?" );
+ VERIFY( path("c:/").root_name() == "c:" );
+ VERIFY( path("c:\\").root_name() == "c:" );
+ VERIFY( path("c:").root_name() == "c:" );
+ VERIFY( path("c:\\foo").root_name() == "c:" );
+#endif
+ VERIFY( path("").root_name() == "" );
+}
+
int
main()
{
test01();
+ test02();
}
diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/root_path.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/root_path.cc
index b01c75fa0b9..c393e5e4681 100644
--- a/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/root_path.cc
+++ b/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/root_path.cc
@@ -32,6 +32,19 @@ test01()
VERIFY( p1.root_path() == path() );
path p2 = "/foo/bar";
VERIFY( p2.root_path() == path("/") );
+
+#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
+ VERIFY( path("\\").root_path() == "\\" );
+ VERIFY( path("\\\\").root_path() == "\\\\" );
+ VERIFY( path("\\\\foo").root_path() == "\\\\foo" );
+ VERIFY( path("\\\\foo\\").root_path() == "\\\\foo\\" );
+ VERIFY( path("\\\\foo\\bar").root_path() == "\\\\foo\\" );
+ VERIFY( path("\\\\?\\c\\").root_path() == "\\\\?\\" );
+ VERIFY( path("c:/").root_path() == "c:/" );
+ VERIFY( path("c:\\").root_path() == "c:\\" );
+ VERIFY( path("c:").root_path() == "c:" );
+ VERIFY( path("c:\\foo").root_path() == "c:\\" );
+#endif
}
void
diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/stem.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/stem.cc
index bb5a8f3d2ae..b3b5957eea5 100644
--- a/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/stem.cc
+++ b/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/stem.cc
@@ -51,6 +51,11 @@ test01()
VERIFY( path(".").stem() == path(".") );
VERIFY( path().stem() == path() );
+
+#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
+ VERIFY( path("\\\\wsl.local").stem() == path("") );
+ VERIFY( path("\\\\wsl.local\\foo.bar").stem() == path("foo") );
+#endif
}
int
diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/generation/relative.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/generation/relative.cc
index de99fe848ba..121be5c0655 100644
--- a/libstdc++-v3/testsuite/27_io/filesystem/path/generation/relative.cc
+++ b/libstdc++-v3/testsuite/27_io/filesystem/path/generation/relative.cc
@@ -91,6 +91,19 @@ test04()
#endif
}
+void
+test05()
+{
+#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
+ compare_paths(path("f:/foo").lexically_relative("f:/foo/bar"), "..");
+ compare_paths(path("g:/foo").lexically_relative("f:/foo/bar"), "");
+ compare_paths(path("\\\\?\\f:/foo").lexically_relative("f:/foo/bar"), "");
+ compare_paths(path("\\\\a/b/c").lexically_relative("\\\\a/b"), "c");
+ compare_paths(path("\\\\a/b/c").lexically_relative("\\\\a/b/c/d"), "..");
+ compare_paths(path("\\\\b/b/c").lexically_relative("\\\\a/b/c/d"), "");
+#endif
+}
+
int
main()
{
@@ -98,4 +111,5 @@ main()
test02();
test03();
test04();
+ test05();
}
--
2.49.0.windows.1
More information about the Libstdc++
mailing list