Add JoinFilename to testsupport code, replacing use of rtc::Pathname.
This is a partial revert of https://codereview.webrtc.org/2533213005,
deleting rtc::File methods accepting an rtc::Pathname argument.
Bug: webrtc:6424
Change-Id: Ib16bdc7294dbddfa12ba9ae206c024ff97e529a4
Reviewed-on: https://webrtc-review.googlesource.com/80180
Commit-Queue: Niels Moller <nisse@webrtc.org>
Reviewed-by: Patrik Höglund <phoglund@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23489}
diff --git a/rtc_base/file.cc b/rtc_base/file.cc
index a6ee2aa..6202411 100644
--- a/rtc_base/file.cc
+++ b/rtc_base/file.cc
@@ -14,15 +14,6 @@
namespace rtc {
-namespace {
-
-std::string NormalizePathname(Pathname&& path) {
- path.Normalize();
- return path.pathname();
-}
-
-} // namespace
-
File::File(PlatformFile file) : file_(file) {}
File::File() : file_(kInvalidPlatformFileValue) {}
@@ -37,45 +28,15 @@
}
// static
-File File::Open(Pathname&& path) {
- return Open(NormalizePathname(std::move(path)));
-}
-
-// static
-File File::Open(const Pathname& path) {
- return Open(Pathname(path));
-}
-
-// static
File File::Create(const std::string& path) {
return File(CreatePlatformFile(path));
}
// static
-File File::Create(Pathname&& path) {
- return Create(NormalizePathname(std::move(path)));
-}
-
-// static
-File File::Create(const Pathname& path) {
- return Create(Pathname(path));
-}
-
-// static
bool File::Remove(const std::string& path) {
return RemoveFile(path);
}
-// static
-bool File::Remove(Pathname&& path) {
- return Remove(NormalizePathname(std::move(path)));
-}
-
-// static
-bool File::Remove(const Pathname& path) {
- return Remove(Pathname(path));
-}
-
File::File(File&& other) : file_(other.file_) {
other.file_ = kInvalidPlatformFileValue;
}
diff --git a/rtc_base/file.h b/rtc_base/file.h
index f87d9ce..75fd93d 100644
--- a/rtc_base/file.h
+++ b/rtc_base/file.h
@@ -16,7 +16,6 @@
#include <string>
#include "rtc_base/constructormagic.h"
-#include "rtc_base/pathutils.h"
#include "rtc_base/platform_file.h"
namespace rtc {
@@ -40,17 +39,11 @@
// Open and Create give files with both reading and writing enabled.
static File Open(const std::string& path);
- static File Open(Pathname&& path);
- static File Open(const Pathname& path);
// If the file already exists it will be overwritten.
static File Create(const std::string& path);
- static File Create(Pathname&& path);
- static File Create(const Pathname& path);
// Remove a file in the file system.
static bool Remove(const std::string& path);
- static bool Remove(Pathname&& path);
- static bool Remove(const Pathname& path);
size_t Write(const uint8_t* data, size_t length);
size_t Read(uint8_t* buffer, size_t length);
diff --git a/rtc_base/file_unittest.cc b/rtc_base/file_unittest.cc
index a8e39dd..5a72e5d 100644
--- a/rtc_base/file_unittest.cc
+++ b/rtc_base/file_unittest.cc
@@ -163,39 +163,13 @@
EXPECT_TRUE(VerifyBuffer(out, 2, 0));
}
-TEST_F(FileTest, OpenFromPathname) {
- {
- File file = File::Open(Pathname(path_));
- ASSERT_TRUE(file.IsOpen()) << "Error: " << LastError();
- }
-
- {
- Pathname path(path_);
- File file = File::Open(path);
- ASSERT_TRUE(file.IsOpen()) << "Error: " << LastError();
- }
-}
-
-TEST_F(FileTest, CreateFromPathname) {
- {
- File file = File::Create(Pathname(path_));
- ASSERT_TRUE(file.IsOpen()) << "Error: " << LastError();
- }
-
- {
- Pathname path(path_);
- File file = File::Create(path);
- ASSERT_TRUE(file.IsOpen()) << "Error: " << LastError();
- }
-}
-
TEST_F(FileTest, ShouldBeAbleToRemoveFile) {
{
- File file = File::Open(Pathname(path_));
+ File file = File::Open(path_);
ASSERT_TRUE(file.IsOpen()) << "Error: " << LastError();
}
- ASSERT_TRUE(File::Remove(Pathname(path_))) << "Error: " << LastError();
+ ASSERT_TRUE(File::Remove(path_)) << "Error: " << LastError();
}
} // namespace rtc
diff --git a/test/testsupport/fileutils.cc b/test/testsupport/fileutils.cc
index 23508de..7ba24c1 100644
--- a/test/testsupport/fileutils.cc
+++ b/test/testsupport/fileutils.cc
@@ -355,6 +355,11 @@
#endif // defined (WEBRTC_IOS)
}
+std::string JoinFilename(const std::string& dir, const std::string& name) {
+ RTC_CHECK(!dir.empty()) << "Special cases not implemented.";
+ return dir + kPathDelimiter + name;
+}
+
size_t GetFileSize(const std::string& filename) {
FILE* f = fopen(filename.c_str(), "rb");
size_t size = 0;
diff --git a/test/testsupport/fileutils.h b/test/testsupport/fileutils.h
index 8bf1919..b1eec8b 100644
--- a/test/testsupport/fileutils.h
+++ b/test/testsupport/fileutils.h
@@ -67,8 +67,10 @@
// If a directory path is prepended to the filename, a subdirectory
// hierarchy reflecting that path is assumed to be present.
// extension - File extension, without the dot, i.e. "bmp" or "yuv".
-std::string ResourcePath(const std::string& name,
- const std::string& extension);
+std::string ResourcePath(const std::string& name, const std::string& extension);
+
+// Joins directory name and file name, separated by the path delimiter.
+std::string JoinFilename(const std::string& dir, const std::string& name);
// Gets the current working directory for the executing program.
// Returns "./" if for some reason it is not possible to find the working
diff --git a/test/testsupport/test_artifacts.cc b/test/testsupport/test_artifacts.cc
index 3d97a94..e9d31bb 100644
--- a/test/testsupport/test_artifacts.cc
+++ b/test/testsupport/test_artifacts.cc
@@ -15,7 +15,6 @@
#include "rtc_base/file.h"
#include "rtc_base/flags.h"
#include "rtc_base/logging.h"
-#include "rtc_base/pathutils.h"
#include "test/testsupport/fileutils.h"
namespace {
@@ -55,7 +54,7 @@
}
rtc::File output =
- rtc::File::Create(rtc::Pathname(FLAG_test_artifacts_dir, filename));
+ rtc::File::Create(JoinFilename(FLAG_test_artifacts_dir, filename));
return output.IsOpen() && output.Write(buffer, length) == length;
}
diff --git a/test/testsupport/test_artifacts_unittest.cc b/test/testsupport/test_artifacts_unittest.cc
index 251c5cd..c423cd9 100644
--- a/test/testsupport/test_artifacts_unittest.cc
+++ b/test/testsupport/test_artifacts_unittest.cc
@@ -19,6 +19,7 @@
#include "rtc_base/pathutils.h"
#include "rtc_base/platform_file.h"
#include "test/gtest.h"
+#include "test/testsupport/fileutils.h"
DECLARE_string(test_artifacts_dir);
@@ -42,7 +43,7 @@
const char* filename = "a-file";
const char* content = "some-contents";
if (WriteToTestArtifactsDir(filename, content)) {
- rtc::Pathname out_file(FLAG_test_artifacts_dir, filename);
+ std::string out_file = JoinFilename(FLAG_test_artifacts_dir, filename);
rtc::File input = rtc::File::Open(out_file);
EXPECT_TRUE(input.IsOpen());
EXPECT_TRUE(input.Seek(0));