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}
This commit is contained in:
parent
79ce820a13
commit
392f8d0fa9
@ -14,15 +14,6 @@
|
|||||||
|
|
||||||
namespace rtc {
|
namespace rtc {
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
std::string NormalizePathname(Pathname&& path) {
|
|
||||||
path.Normalize();
|
|
||||||
return path.pathname();
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
File::File(PlatformFile file) : file_(file) {}
|
File::File(PlatformFile file) : file_(file) {}
|
||||||
|
|
||||||
File::File() : file_(kInvalidPlatformFileValue) {}
|
File::File() : file_(kInvalidPlatformFileValue) {}
|
||||||
@ -36,46 +27,16 @@ File File::Open(const std::string& path) {
|
|||||||
return File(OpenPlatformFile(path));
|
return File(OpenPlatformFile(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
|
||||||
File File::Open(Pathname&& path) {
|
|
||||||
return Open(NormalizePathname(std::move(path)));
|
|
||||||
}
|
|
||||||
|
|
||||||
// static
|
|
||||||
File File::Open(const Pathname& path) {
|
|
||||||
return Open(Pathname(path));
|
|
||||||
}
|
|
||||||
|
|
||||||
// static
|
// static
|
||||||
File File::Create(const std::string& path) {
|
File File::Create(const std::string& path) {
|
||||||
return File(CreatePlatformFile(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
|
// static
|
||||||
bool File::Remove(const std::string& path) {
|
bool File::Remove(const std::string& path) {
|
||||||
return RemoveFile(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_) {
|
File::File(File&& other) : file_(other.file_) {
|
||||||
other.file_ = kInvalidPlatformFileValue;
|
other.file_ = kInvalidPlatformFileValue;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,7 +16,6 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "rtc_base/constructormagic.h"
|
#include "rtc_base/constructormagic.h"
|
||||||
#include "rtc_base/pathutils.h"
|
|
||||||
#include "rtc_base/platform_file.h"
|
#include "rtc_base/platform_file.h"
|
||||||
|
|
||||||
namespace rtc {
|
namespace rtc {
|
||||||
@ -40,17 +39,11 @@ class File {
|
|||||||
|
|
||||||
// Open and Create give files with both reading and writing enabled.
|
// Open and Create give files with both reading and writing enabled.
|
||||||
static File Open(const std::string& path);
|
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.
|
// If the file already exists it will be overwritten.
|
||||||
static File Create(const std::string& path);
|
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.
|
// Remove a file in the file system.
|
||||||
static bool Remove(const std::string& path);
|
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 Write(const uint8_t* data, size_t length);
|
||||||
size_t Read(uint8_t* buffer, size_t length);
|
size_t Read(uint8_t* buffer, size_t length);
|
||||||
|
|||||||
@ -163,39 +163,13 @@ TEST_F(FileTest, RandomAccessReadWrite) {
|
|||||||
EXPECT_TRUE(VerifyBuffer(out, 2, 0));
|
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) {
|
TEST_F(FileTest, ShouldBeAbleToRemoveFile) {
|
||||||
{
|
{
|
||||||
File file = File::Open(Pathname(path_));
|
File file = File::Open(path_);
|
||||||
ASSERT_TRUE(file.IsOpen()) << "Error: " << LastError();
|
ASSERT_TRUE(file.IsOpen()) << "Error: " << LastError();
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSERT_TRUE(File::Remove(Pathname(path_))) << "Error: " << LastError();
|
ASSERT_TRUE(File::Remove(path_)) << "Error: " << LastError();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace rtc
|
} // namespace rtc
|
||||||
|
|||||||
@ -355,6 +355,11 @@ std::string ResourcePath(const std::string& name,
|
|||||||
#endif // defined (WEBRTC_IOS)
|
#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) {
|
size_t GetFileSize(const std::string& filename) {
|
||||||
FILE* f = fopen(filename.c_str(), "rb");
|
FILE* f = fopen(filename.c_str(), "rb");
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
|
|||||||
@ -67,8 +67,10 @@ std::string GenerateTempFilename(const std::string& dir,
|
|||||||
// If a directory path is prepended to the filename, a subdirectory
|
// If a directory path is prepended to the filename, a subdirectory
|
||||||
// hierarchy reflecting that path is assumed to be present.
|
// hierarchy reflecting that path is assumed to be present.
|
||||||
// extension - File extension, without the dot, i.e. "bmp" or "yuv".
|
// extension - File extension, without the dot, i.e. "bmp" or "yuv".
|
||||||
std::string ResourcePath(const std::string& name,
|
std::string ResourcePath(const std::string& name, const std::string& extension);
|
||||||
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.
|
// Gets the current working directory for the executing program.
|
||||||
// Returns "./" if for some reason it is not possible to find the working
|
// Returns "./" if for some reason it is not possible to find the working
|
||||||
|
|||||||
@ -15,7 +15,6 @@
|
|||||||
#include "rtc_base/file.h"
|
#include "rtc_base/file.h"
|
||||||
#include "rtc_base/flags.h"
|
#include "rtc_base/flags.h"
|
||||||
#include "rtc_base/logging.h"
|
#include "rtc_base/logging.h"
|
||||||
#include "rtc_base/pathutils.h"
|
|
||||||
#include "test/testsupport/fileutils.h"
|
#include "test/testsupport/fileutils.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
@ -55,7 +54,7 @@ bool WriteToTestArtifactsDir(const char* filename,
|
|||||||
}
|
}
|
||||||
|
|
||||||
rtc::File output =
|
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;
|
return output.IsOpen() && output.Write(buffer, length) == length;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,6 +19,7 @@
|
|||||||
#include "rtc_base/pathutils.h"
|
#include "rtc_base/pathutils.h"
|
||||||
#include "rtc_base/platform_file.h"
|
#include "rtc_base/platform_file.h"
|
||||||
#include "test/gtest.h"
|
#include "test/gtest.h"
|
||||||
|
#include "test/testsupport/fileutils.h"
|
||||||
|
|
||||||
DECLARE_string(test_artifacts_dir);
|
DECLARE_string(test_artifacts_dir);
|
||||||
|
|
||||||
@ -42,7 +43,7 @@ TEST(IsolatedOutputTest, ShouldBeAbleToWriteContent) {
|
|||||||
const char* filename = "a-file";
|
const char* filename = "a-file";
|
||||||
const char* content = "some-contents";
|
const char* content = "some-contents";
|
||||||
if (WriteToTestArtifactsDir(filename, content)) {
|
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);
|
rtc::File input = rtc::File::Open(out_file);
|
||||||
EXPECT_TRUE(input.IsOpen());
|
EXPECT_TRUE(input.IsOpen());
|
||||||
EXPECT_TRUE(input.Seek(0));
|
EXPECT_TRUE(input.Seek(0));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user