Title: [277231] trunk
Revision
277231
Author
[email protected]
Date
2021-05-08 15:35:07 -0700 (Sat, 08 May 2021)

Log Message

Port Filesystem::pathByAppendingComponent() & Filesystem:: pathByAppendingComponents() to std::filesystem
https://bugs.webkit.org/show_bug.cgi?id=225550

Reviewed by Darin Adler.

Source/_javascript_Core:

Build fix.

* Configurations/_javascript_Core.xcconfig:

Source/WTF:

Port Filesystem::pathByAppendingComponent() & Filesystem:: pathByAppendingComponents() to std::filesystem
and get rid of platform-specific implementations.

* wtf/FileSystem.cpp:
(WTF::FileSystemImpl::pathByAppendingComponent):
(WTF::FileSystemImpl::pathByAppendingComponents):
* wtf/glib/FileSystemGlib.cpp:
* wtf/posix/FileSystemPOSIX.cpp:
* wtf/win/FileSystemWin.cpp:

Tools:

Add API test coverage.

* TestWebKitAPI/Tests/WTF/FileSystem.cpp:
(TestWebKitAPI::TEST_F):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (277230 => 277231)


--- trunk/Source/_javascript_Core/ChangeLog	2021-05-08 17:56:35 UTC (rev 277230)
+++ trunk/Source/_javascript_Core/ChangeLog	2021-05-08 22:35:07 UTC (rev 277231)
@@ -1,3 +1,14 @@
+2021-05-08  Chris Dumez  <[email protected]>
+
+        Port Filesystem::pathByAppendingComponent() & Filesystem:: pathByAppendingComponents() to std::filesystem
+        https://bugs.webkit.org/show_bug.cgi?id=225550
+
+        Reviewed by Darin Adler.
+
+        Build fix.
+
+        * Configurations/_javascript_Core.xcconfig:
+
 2021-05-08  Ross Kirsling  <[email protected]>
 
         Introduce JSObject::getIfPropertyExists helper

Modified: trunk/Source/_javascript_Core/Configurations/_javascript_Core.xcconfig (277230 => 277231)


--- trunk/Source/_javascript_Core/Configurations/_javascript_Core.xcconfig	2021-05-08 17:56:35 UTC (rev 277230)
+++ trunk/Source/_javascript_Core/Configurations/_javascript_Core.xcconfig	2021-05-08 22:35:07 UTC (rev 277231)
@@ -27,7 +27,7 @@
 MODULEMAP_FILE = $(SRCROOT)/_javascript_Core.modulemap;
 
 // Prevent C++ standard library operator new, delete and their related exception types from being exported as weak symbols.
-OTHER_LDFLAGS_HIDE_SYMBOLS = -Wl,-unexported_symbol,__ZTISt9bad_alloc -Wl,-unexported_symbol,__ZTISt9exception -Wl,-unexported_symbol,__ZTSSt9bad_alloc -Wl,-unexported_symbol,__ZTSSt9exception -Wl,-unexported_symbol,__ZdlPvS_ -Wl,-unexported_symbol,__ZnwmPv -Wl,-unexported_symbol,__ZNKSt3__18functionIFvvEEclEv -Wl,-unexported_symbol,__ZNSt3__18functionIFvvEEC1EOS2_ -Wl,-unexported_symbol,__ZNSt3__18functionIFvvEEC2EOS2_ -Wl,-unexported_symbol,__ZNKSt3__18functionIFvRN3JSC17BytecodeGeneratorEPNS1_10RegisterIDEEEclES3_S5_ -Wl,-unexported_symbol,__ZNSt3__18functionIFvRN3JSC17BytecodeGeneratorEPNS1_10RegisterIDEEED1Ev -Wl,-unexported_symbol,__ZNSt3__18functionIFvRN3JSC17BytecodeGeneratorEPNS1_10RegisterIDEEED2Ev -Wl,-unexported_symbol,__ZNSt3__18functionIFvvEED1Ev -Wl,-unexported_symbol,__ZNSt3__18functionIFvvEED2Ev -Wl,-unexported_symbol,__ZTVNSt3__117bad_function_callE -Wl,-unexported_symbol,__ZNSt3__14__fs10filesystem24__is_pathable_char_arrayIPKcS4_cLb1EE11__range_endES4
 _ -Wl,-unexported_symbol,__ZNSt3__14__fs10filesystem24__is_pathable_char_arrayIPKcS4_cLb1EE13__range_beginES4_ -Wl,-unexported_symbol,__ZNSt3__14__fs10filesystem8_PathCVTIcE14__append_rangeIPKcEENS_9enable_ifIXsr27__is_cpp17_forward_iteratorIT_EE5valueEvE4typeERNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEES8_S8_ -Wl,-unexported_symbol,__ZNSt3__14__fs10filesystem8_PathCVTIcE15__append_sourceIPKcEEvRNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEERKT_ -Wl,-unexported_symbol,__ZNSt3__14__fs10filesystem8_PathCVTIcE14__append_rangeIPKcEENS_9enable_ifIXsr21__is_forward_iteratorIT_EE5valueEvE4typeERNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEES8_S8_ -Wl,-unexported_symbol,__ZNKSt3__14__fs10filesystem18directory_iteratordeEv -Wl,-unexported_symbol,__ZNSt3__14__fs10filesystem18directory_iteratorppEv -Wl,-unexported_symbol,__ZNSt3__14__fs10filesystem24__is_pathable_char_arrayIA10_cPccLb1EE11__range_endEPKc -Wl,-unexported_symbol,__ZNSt3__14__fs10filesystem2
 4__is_pathable_char_arrayIA10_cPccLb1EE13__range_beginEPKc -Wl,-unexported_symbol,__ZNSt3__14__fs10filesystem4pathdVERKS2_ -Wl,-unexported_symbol,__ZNSt3__14__fs10filesystem8_PathCVTIcE15__append_sourceIA10_cEEvRNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEERKT_ -Wl,-unexported_symbol,__ZNSt3__14__fs10filesystem24__throw_filesystem_errorIJRPKcRKNS1_4pathERKNS_10error_codeEEEEvDpOT_;
+OTHER_LDFLAGS_HIDE_SYMBOLS = -Wl,-unexported_symbol,__ZTISt9bad_alloc -Wl,-unexported_symbol,__ZTISt9exception -Wl,-unexported_symbol,__ZTSSt9bad_alloc -Wl,-unexported_symbol,__ZTSSt9exception -Wl,-unexported_symbol,__ZdlPvS_ -Wl,-unexported_symbol,__ZnwmPv -Wl,-unexported_symbol,__ZNKSt3__18functionIFvvEEclEv -Wl,-unexported_symbol,__ZNSt3__18functionIFvvEEC1EOS2_ -Wl,-unexported_symbol,__ZNSt3__18functionIFvvEEC2EOS2_ -Wl,-unexported_symbol,__ZNKSt3__18functionIFvRN3JSC17BytecodeGeneratorEPNS1_10RegisterIDEEEclES3_S5_ -Wl,-unexported_symbol,__ZNSt3__18functionIFvRN3JSC17BytecodeGeneratorEPNS1_10RegisterIDEEED1Ev -Wl,-unexported_symbol,__ZNSt3__18functionIFvRN3JSC17BytecodeGeneratorEPNS1_10RegisterIDEEED2Ev -Wl,-unexported_symbol,__ZNSt3__18functionIFvvEED1Ev -Wl,-unexported_symbol,__ZNSt3__18functionIFvvEED2Ev -Wl,-unexported_symbol,__ZTVNSt3__117bad_function_callE -Wl,-unexported_symbol,__ZNSt3__14__fs10filesystem24__is_pathable_char_arrayIPKcS4_cLb1EE11__range_endES4_
  -Wl,-unexported_symbol,__ZNSt3__14__fs10filesystem24__is_pathable_char_arrayIPKcS4_cLb1EE13__range_beginES4_ -Wl,-unexported_symbol,__ZNSt3__14__fs10filesystem8_PathCVTIcE14__append_rangeIPKcEENS_9enable_ifIXsr27__is_cpp17_forward_iteratorIT_EE5valueEvE4typeERNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEES8_S8_ -Wl,-unexported_symbol,__ZNSt3__14__fs10filesystem8_PathCVTIcE15__append_sourceIPKcEEvRNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEERKT_ -Wl,-unexported_symbol,__ZNSt3__14__fs10filesystem8_PathCVTIcE14__append_rangeIPKcEENS_9enable_ifIXsr21__is_forward_iteratorIT_EE5valueEvE4typeERNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEES8_S8_ -Wl,-unexported_symbol,__ZNKSt3__14__fs10filesystem18directory_iteratordeEv -Wl,-unexported_symbol,__ZNSt3__14__fs10filesystem18directory_iteratorppEv -Wl,-unexported_symbol,__ZNSt3__14__fs10filesystem24__is_pathable_char_arrayIA10_cPccLb1EE11__range_endEPKc -Wl,-unexported_symbol,__ZNSt3__14__fs10filesystem24
 __is_pathable_char_arrayIA10_cPccLb1EE13__range_beginEPKc -Wl,-unexported_symbol,__ZNSt3__14__fs10filesystem4pathdVERKS2_ -Wl,-unexported_symbol,__ZNSt3__14__fs10filesystem8_PathCVTIcE15__append_sourceIA10_cEEvRNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEERKT_ -Wl,-unexported_symbol,__ZNSt3__14__fs10filesystem24__throw_filesystem_errorIJRPKcRKNS1_4pathERKNS_10error_codeEEEEvDpOT_ -Wl,-unexported_symbol,__ZNSt3__14__fs10filesystem14__is_separatorIcEENS_9enable_ifIXsr18__can_convert_charIT_EE5valueEbE4typeES4_ -Wl,-unexported_symbol,__ZNSt3__14__fs10filesystem24__is_pathable_char_arrayIPKcS4_cLb1EE15__first_or_nullES4_ -Wl,-unexported_symbol,__ZNSt3__14__fs10filesystem4path20__source_is_absoluteIcEEbT_ -Wl,-unexported_symbol,__ZNSt3__14__fs10filesystem4path6appendIPKcEENS_9enable_ifIXsr13__is_pathableIT_EE5valueERS2_E4typeERKS7_ -Wl,-unexported_symbol,__ZNSt3__14__fs10filesystem6u8pathIPKcEENS_9enable_ifIXsr13__is_pathableIT_EE5valueENS1_4pathEE4typeERKS6_;
 
 OTHER_LDFLAGS_BASE = $(OTHER_LDFLAGS_HIDE_SYMBOLS) -force_load "$(BUILT_PRODUCTS_DIR)/DerivedSources/_javascript_Core/libWTF.a";
 OTHER_LDFLAGS[sdk=embedded*] = $(inherited) $(OTHER_LDFLAGS_BASE);

Modified: trunk/Source/WTF/ChangeLog (277230 => 277231)


--- trunk/Source/WTF/ChangeLog	2021-05-08 17:56:35 UTC (rev 277230)
+++ trunk/Source/WTF/ChangeLog	2021-05-08 22:35:07 UTC (rev 277231)
@@ -1,3 +1,20 @@
+2021-05-08  Chris Dumez  <[email protected]>
+
+        Port Filesystem::pathByAppendingComponent() & Filesystem:: pathByAppendingComponents() to std::filesystem
+        https://bugs.webkit.org/show_bug.cgi?id=225550
+
+        Reviewed by Darin Adler.
+
+        Port Filesystem::pathByAppendingComponent() & Filesystem:: pathByAppendingComponents() to std::filesystem
+        and get rid of platform-specific implementations.
+
+        * wtf/FileSystem.cpp:
+        (WTF::FileSystemImpl::pathByAppendingComponent):
+        (WTF::FileSystemImpl::pathByAppendingComponents):
+        * wtf/glib/FileSystemGlib.cpp:
+        * wtf/posix/FileSystemPOSIX.cpp:
+        * wtf/win/FileSystemWin.cpp:
+
 2021-05-08  Diego Pino Garcia  <[email protected]>
 
         [GLIB] REGRESSION(r277158) imported/w3c/web-platform-tests/xhr/FormData-append.html is crashing

Modified: trunk/Source/WTF/wtf/FileSystem.cpp (277230 => 277231)


--- trunk/Source/WTF/wtf/FileSystem.cpp	2021-05-08 17:56:35 UTC (rev 277230)
+++ trunk/Source/WTF/wtf/FileSystem.cpp	2021-05-08 22:35:07 UTC (rev 277231)
@@ -50,6 +50,16 @@
 
 namespace FileSystemImpl {
 
+static std::filesystem::path toStdFileSystemPath(StringView path)
+{
+    return std::filesystem::u8path(path.utf8().data());
+}
+
+static String fromStdFileSystemPath(const std::filesystem::path& path)
+{
+    return String::fromUTF8(path.u8string().c_str());
+}
+
 // The following lower-ASCII characters need escaping to be used in a filename
 // across all systems, including Windows:
 //     - Unprintable ASCII (00-1F)
@@ -525,13 +535,13 @@
 {
     std::error_code ec;
     // exists() returns false on error so no need to check ec.
-    return std::filesystem::exists(fileSystemRepresentation(path).data(), ec);
+    return std::filesystem::exists(toStdFileSystemPath(path), ec);
 }
 
 bool deleteFile(const String& path)
 {
     std::error_code ec;
-    std::filesystem::path fsPath = fileSystemRepresentation(path).data();
+    auto fsPath = toStdFileSystemPath(path);
 
     auto fileStatus = std::filesystem::symlink_status(fsPath, ec);
     if (ec || fileStatus.type() == std::filesystem::file_type::directory)
@@ -544,7 +554,7 @@
 bool deleteEmptyDirectory(const String& path)
 {
     std::error_code ec;
-    std::filesystem::path fsPath = fileSystemRepresentation(path).data();
+    auto fsPath = toStdFileSystemPath(path);
 
     auto fileStatus = std::filesystem::symlink_status(fsPath, ec);
     if (ec || fileStatus.type() != std::filesystem::file_type::directory)
@@ -570,8 +580,8 @@
 
 bool moveFile(const String& oldPath, const String& newPath)
 {
-    std::filesystem::path fsOldPath = fileSystemRepresentation(oldPath).data();
-    std::filesystem::path fsNewPath = fileSystemRepresentation(newPath).data();
+    auto fsOldPath = toStdFileSystemPath(oldPath);
+    auto fsNewPath = toStdFileSystemPath(newPath);
 
     std::error_code ec;
     std::filesystem::rename(fsOldPath, fsNewPath, ec);
@@ -589,7 +599,7 @@
 bool getFileSize(const String& path, long long& result)
 {
     std::error_code ec;
-    auto size = std::filesystem::file_size(fileSystemRepresentation(path).data(), ec);
+    auto size = std::filesystem::file_size(toStdFileSystemPath(path), ec);
     if (ec)
         return false;
     result = size;
@@ -601,9 +611,9 @@
     std::error_code ec;
     std::filesystem::file_status fileStatus;
     if (shouldFollowSymbolicLinks == ShouldFollowSymbolicLinks::Yes)
-        fileStatus = std::filesystem::status(fileSystemRepresentation(path).data(), ec);
+        fileStatus = std::filesystem::status(toStdFileSystemPath(path), ec);
     else
-        fileStatus = std::filesystem::symlink_status(fileSystemRepresentation(path).data(), ec);
+        fileStatus = std::filesystem::symlink_status(toStdFileSystemPath(path), ec);
     return fileStatus.type() == std::filesystem::file_type::directory;
 }
 
@@ -610,7 +620,7 @@
 bool makeAllDirectories(const String& path)
 {
     std::error_code ec;
-    std::filesystem::create_directories(fileSystemRepresentation(path).data(), ec);
+    std::filesystem::create_directories(toStdFileSystemPath(path), ec);
     return !ec;
 }
 
@@ -617,7 +627,7 @@
 bool getVolumeFreeSpace(const String& path, uint64_t& freeSpace)
 {
     std::error_code ec;
-    auto spaceInfo = std::filesystem::space(fileSystemRepresentation(path).data(), ec);
+    auto spaceInfo = std::filesystem::space(toStdFileSystemPath(path), ec);
     if (ec)
         return false;
     freeSpace = spaceInfo.available;
@@ -627,7 +637,7 @@
 bool createSymbolicLink(const String& targetPath, const String& symbolicLinkPath)
 {
     std::error_code ec;
-    std::filesystem::create_symlink(fileSystemRepresentation(targetPath).data(), fileSystemRepresentation(symbolicLinkPath).data(), ec);
+    std::filesystem::create_symlink(toStdFileSystemPath(targetPath), toStdFileSystemPath(symbolicLinkPath), ec);
     return !ec;
 }
 
@@ -634,14 +644,14 @@
 bool hardLink(const String& targetPath, const String& linkPath)
 {
     std::error_code ec;
-    std::filesystem::create_hard_link(fileSystemRepresentation(targetPath).data(), fileSystemRepresentation(linkPath).data(), ec);
+    std::filesystem::create_hard_link(toStdFileSystemPath(targetPath), toStdFileSystemPath(linkPath), ec);
     return !ec;
 }
 
 bool hardLinkOrCopyFile(const String& targetPath, const String& linkPath)
 {
-    std::filesystem::path fsTargetPath = fileSystemRepresentation(targetPath).data();
-    std::filesystem::path fsLinkPath = fileSystemRepresentation(linkPath).data();
+    auto fsTargetPath = toStdFileSystemPath(targetPath);
+    auto fsLinkPath = toStdFileSystemPath(linkPath);
 
     std::error_code ec;
     std::filesystem::create_hard_link(fsTargetPath, fsLinkPath, ec);
@@ -655,7 +665,7 @@
 bool deleteNonEmptyDirectory(const String& path)
 {
     std::error_code ec;
-    std::filesystem::remove_all(fileSystemRepresentation(path).data(), ec);
+    std::filesystem::remove_all(toStdFileSystemPath(path), ec);
     return !ec;
 }
 
@@ -662,7 +672,7 @@
 Optional<WallTime> getFileModificationTime(const String& path)
 {
     std::error_code ec;
-    auto modificationTime = std::filesystem::last_write_time(fileSystemRepresentation(path).data(), ec);
+    auto modificationTime = std::filesystem::last_write_time(toStdFileSystemPath(path), ec);
     if (ec)
         return WTF::nullopt;
     return toWallTime(modificationTime);
@@ -673,7 +683,7 @@
     if (path.isEmpty())
         return WTF::nullopt;
 
-    std::filesystem::path fsPath = fileSystemRepresentation(path).data();
+    auto fsPath = toStdFileSystemPath(path);
 
     std::error_code ec;
     if (shouldFollowSymbolicLinks == ShouldFollowSymbolicLinks::Yes && std::filesystem::is_symlink(fsPath, ec)) {
@@ -721,15 +731,26 @@
 
 String pathGetFileName(const String& path)
 {
-    std::filesystem::path fsPath = fileSystemRepresentation(path).data();
-    return String::fromUTF8(fsPath.filename().u8string().c_str());
+    return fromStdFileSystemPath(toStdFileSystemPath(path).filename());
 }
 
 String directoryName(const String& path)
 {
-    std::filesystem::path fsPath = fileSystemRepresentation(path).data();
-    return String::fromUTF8(fsPath.parent_path().u8string().c_str());
+    return fromStdFileSystemPath(toStdFileSystemPath(path).parent_path());
 }
 
+String pathByAppendingComponent(const String& path, const String& component)
+{
+    return fromStdFileSystemPath(toStdFileSystemPath(path) / toStdFileSystemPath(component));
+}
+
+String pathByAppendingComponents(StringView path, const Vector<StringView>& components)
+{
+    auto fsPath = toStdFileSystemPath(path);
+    for (auto& component : components)
+        fsPath /= toStdFileSystemPath(component);
+    return fromStdFileSystemPath(fsPath);
+}
+
 } // namespace FileSystemImpl
 } // namespace WTF

Modified: trunk/Source/WTF/wtf/glib/FileSystemGlib.cpp (277230 => 277231)


--- trunk/Source/WTF/wtf/glib/FileSystemGlib.cpp	2021-05-08 17:56:35 UTC (rev 277230)
+++ trunk/Source/WTF/wtf/glib/FileSystemGlib.cpp	2021-05-08 22:35:07 UTC (rev 277231)
@@ -136,24 +136,6 @@
     return WTF::nullopt;
 }
 
-String pathByAppendingComponent(const String& path, const String& component)
-{
-    if (path.endsWith(G_DIR_SEPARATOR_S))
-        return path + component;
-    return path + G_DIR_SEPARATOR_S + component;
-}
-
-String pathByAppendingComponents(StringView path, const Vector<StringView>& components)
-{
-    StringBuilder builder;
-    builder.append(path);
-    for (auto& component : components) {
-        builder.append(G_DIR_SEPARATOR_S);
-        builder.append(component);
-    }
-    return builder.toString();
-}
-
 String homeDirectoryPath()
 {
     return stringFromFileSystemRepresentation(g_get_home_dir());

Modified: trunk/Source/WTF/wtf/posix/FileSystemPOSIX.cpp (277230 => 277231)


--- trunk/Source/WTF/wtf/posix/FileSystemPOSIX.cpp	2021-05-08 17:56:35 UTC (rev 277230)
+++ trunk/Source/WTF/wtf/posix/FileSystemPOSIX.cpp	2021-05-08 22:35:07 UTC (rev 277231)
@@ -186,22 +186,6 @@
 #endif
 }
 
-String pathByAppendingComponent(const String& path, const String& component)
-{
-    if (path.endsWith('/'))
-        return path + component;
-    return path + "/" + component;
-}
-
-String pathByAppendingComponents(StringView path, const Vector<StringView>& components)
-{
-    StringBuilder builder;
-    builder.append(path);
-    for (auto& component : components)
-        builder.append('/', component);
-    return builder.toString();
-}
-
 Vector<String> listDirectory(const String& path, const String& filter)
 {
     Vector<String> entries;

Modified: trunk/Source/WTF/wtf/win/FileSystemWin.cpp (277230 => 277231)


--- trunk/Source/WTF/wtf/win/FileSystemWin.cpp	2021-05-08 17:56:35 UTC (rev 277230)
+++ trunk/Source/WTF/wtf/win/FileSystemWin.cpp	2021-05-08 22:35:07 UTC (rev 277231)
@@ -143,30 +143,6 @@
     return String::adopt(WTFMove(buffer));
 }
 
-String pathByAppendingComponent(const String& path, const String& component)
-{
-    Vector<UChar> buffer(MAX_PATH);
-    if (path.length() + 1 > buffer.size())
-        return String();
-
-    StringView(path).getCharactersWithUpconvert(buffer.data());
-    buffer[path.length()] = '\0';
-
-    if (!PathAppendW(wcharFrom(buffer.data()), component.wideCharacters().data()))
-        return String();
-
-    buffer.shrink(wcslen(wcharFrom(buffer.data())));
-    return String::adopt(WTFMove(buffer));
-}
-
-String pathByAppendingComponents(StringView path, const Vector<StringView>& components)
-{
-    String result = path.toString();
-    for (auto& component : components)
-        result = pathByAppendingComponent(result, component.toString());
-    return result;
-}
-
 #if !USE(CF)
 
 CString fileSystemRepresentation(const String& path)

Modified: trunk/Tools/ChangeLog (277230 => 277231)


--- trunk/Tools/ChangeLog	2021-05-08 17:56:35 UTC (rev 277230)
+++ trunk/Tools/ChangeLog	2021-05-08 22:35:07 UTC (rev 277231)
@@ -1,3 +1,15 @@
+2021-05-08  Chris Dumez  <[email protected]>
+
+        Port Filesystem::pathByAppendingComponent() & Filesystem:: pathByAppendingComponents() to std::filesystem
+        https://bugs.webkit.org/show_bug.cgi?id=225550
+
+        Reviewed by Darin Adler.
+
+        Add API test coverage.
+
+        * TestWebKitAPI/Tests/WTF/FileSystem.cpp:
+        (TestWebKitAPI::TEST_F):
+
 2021-05-07  Chris Dumez  <[email protected]>
 
         Port FileSystem::pathGetFileName() & Filesystem::directoryName() to std::filesystem

Modified: trunk/Tools/TestWebKitAPI/Tests/WTF/FileSystem.cpp (277230 => 277231)


--- trunk/Tools/TestWebKitAPI/Tests/WTF/FileSystem.cpp	2021-05-08 17:56:35 UTC (rev 277230)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/FileSystem.cpp	2021-05-08 22:35:07 UTC (rev 277231)
@@ -744,4 +744,40 @@
 #endif
 }
 
+TEST_F(FileSystemTest, pathByAppendingComponent)
+{
+#if OS(UNIX)
+    EXPECT_STREQ("/var", FileSystem::pathByAppendingComponent("/", "var").utf8().data());
+    EXPECT_STREQ("/var/tmp", FileSystem::pathByAppendingComponent("/var/", "tmp").utf8().data());
+    EXPECT_STREQ("/var/tmp", FileSystem::pathByAppendingComponent("/var", "tmp").utf8().data());
+    EXPECT_STREQ("/var/tmp/file.txt", FileSystem::pathByAppendingComponent("/var/tmp", "file.txt").utf8().data());
+    EXPECT_STREQ("/var/", FileSystem::pathByAppendingComponent("/var", "").utf8().data());
+    EXPECT_STREQ("/var/", FileSystem::pathByAppendingComponent("/var/", "").utf8().data());
+#endif
+#if OS(WINDOWS)
+    EXPECT_STREQ("C:\\Foo", FileSystem::pathByAppendingComponent("C:\\", "Foo").utf8().data());
+    EXPECT_STREQ("C:\\Foo\\Bar", FileSystem::pathByAppendingComponent("C:\\Foo", "Bar").utf8().data());
+    EXPECT_STREQ("C:\\Foo\\Bar\\File.txt", FileSystem::pathByAppendingComponent("C:\\Foo\\Bar", "File.txt").utf8().data());
+#endif
+}
+
+TEST_F(FileSystemTest, pathByAppendingComponents)
+{
+    EXPECT_STREQ(tempEmptyFolderPath().utf8().data(), FileSystem::pathByAppendingComponents(tempEmptyFolderPath(), { }).utf8().data());
+    EXPECT_STREQ(FileSystem::pathByAppendingComponent(tempEmptyFolderPath(), "file.txt").utf8().data(), FileSystem::pathByAppendingComponents(tempEmptyFolderPath(), { "file.txt" }).utf8().data());
+#if OS(UNIX)
+    EXPECT_STREQ("/var/tmp/file.txt", FileSystem::pathByAppendingComponents("/", { "var", "tmp", "file.txt" }).utf8().data());
+    EXPECT_STREQ("/var/tmp/file.txt", FileSystem::pathByAppendingComponents("/var", { "tmp", "file.txt" }).utf8().data());
+    EXPECT_STREQ("/var/tmp/file.txt", FileSystem::pathByAppendingComponents("/var/", { "tmp", "file.txt" }).utf8().data());
+    EXPECT_STREQ("/var/tmp/file.txt", FileSystem::pathByAppendingComponents("/var/tmp", { "file.txt" }).utf8().data());
+#endif
+#if OS(WINDOWS)
+    EXPECT_STREQ("C:\\Foo\\Bar\\File.txt", FileSystem::pathByAppendingComponents("C:\\", { "Foo", "Bar", "File.txt" }).utf8().data());
+    EXPECT_STREQ("C:\\Foo\\Bar\\File.txt", FileSystem::pathByAppendingComponents("C:\\Foo", { "Bar", "File.txt" }).utf8().data());
+    EXPECT_STREQ("C:\\Foo\\Bar\\File.txt", FileSystem::pathByAppendingComponents("C:\\Foo\\", { "Bar", "File.txt" }).utf8().data());
+    EXPECT_STREQ("C:\\Foo\\Bar\\File.txt", FileSystem::pathByAppendingComponents("C:\\Foo\\Bar", { "File.txt" }).utf8().data());
+    EXPECT_STREQ("C:\\Foo\\Bar\\File.txt", FileSystem::pathByAppendingComponents("C:\\Foo\\Bar\\", { "File.txt" }).utf8().data());
+#endif
+}
+
 } // namespace TestWebKitAPI
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to