Reland "Delete rtc::Pathname"
This is a reland of 6b9dec0d16f2df59fa2820c5ec1341be52fb9f32
Original change's description:
> Delete rtc::Pathname
>
> Bug: webrtc:6424
> Change-Id: Iec01dc5dd1426d4558983b828b67af872107d723
> Reviewed-on: https://webrtc-review.googlesource.com/c/108400
> Commit-Queue: Niels Moller <nisse@webrtc.org>
> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#25479}
Bug: webrtc:6424
Change-Id: Ic7b42d435ffd8b93f603acebe68e8a92366bb197
Reviewed-on: https://webrtc-review.googlesource.com/c/109561
Commit-Queue: Niels Moller <nisse@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#25537}
diff --git a/rtc_base/filerotatingstream_unittest.cc b/rtc_base/filerotatingstream_unittest.cc
index 1905516..7ca7e3e 100644
--- a/rtc_base/filerotatingstream_unittest.cc
+++ b/rtc_base/filerotatingstream_unittest.cc
@@ -15,7 +15,6 @@
#include "rtc_base/filerotatingstream.h"
#include "rtc_base/fileutils.h"
#include "rtc_base/gunit.h"
-#include "rtc_base/pathutils.h"
#include "test/testsupport/fileutils.h"
namespace rtc {
@@ -46,12 +45,15 @@
void Init(const std::string& dir_name,
const std::string& file_prefix,
size_t max_file_size,
- size_t num_log_files) {
+ size_t num_log_files,
+ bool ensure_trailing_delimiter = true) {
dir_path_ = webrtc::test::OutputPath();
// Append per-test output path in order to run within gtest parallel.
dir_path_.append(dir_name);
- dir_path_.push_back(Pathname::DefaultFolderDelimiter());
+ if (ensure_trailing_delimiter) {
+ dir_path_.append(webrtc::test::kPathDelimiter);
+ }
ASSERT_TRUE(webrtc::test::CreateDir(dir_path_));
stream_.reset(new FileRotatingStream(dir_path_, file_prefix, max_file_size,
num_log_files));
@@ -174,6 +176,53 @@
dir_path_, kFilePrefix);
}
+// Tests that a write operation (with dir name without delimiter) followed by a
+// read returns the expected data and writes to the expected files.
+TEST_F(MAYBE_FileRotatingStreamTest, WriteWithoutDelimiterAndRead) {
+ Init("FileRotatingStreamTestWriteWithoutDelimiterAndRead", kFilePrefix,
+ kMaxFileSize, 3,
+ /* ensure_trailing_delimiter*/ false);
+
+ ASSERT_TRUE(stream_->Open());
+ // The test is set up to create three log files of length 2. Write and check
+ // contents.
+ std::string messages[3] = {"aa", "bb", "cc"};
+ for (size_t i = 0; i < arraysize(messages); ++i) {
+ const std::string& message = messages[i];
+ WriteAndFlush(message.c_str(), message.size());
+ }
+ std::string message("d");
+ WriteAndFlush(message.c_str(), message.size());
+
+ // Reopen for read.
+ std::string expected_contents("bbccd");
+ VerifyStreamRead(expected_contents.c_str(), expected_contents.size(),
+ dir_path_ + webrtc::test::kPathDelimiter, kFilePrefix);
+}
+
+// Tests that a write operation followed by a read (without trailing delimiter)
+// returns the expected data and writes to the expected files.
+TEST_F(MAYBE_FileRotatingStreamTest, WriteAndReadWithoutDelimiter) {
+ Init("FileRotatingStreamTestWriteAndReadWithoutDelimiter", kFilePrefix,
+ kMaxFileSize, 3);
+
+ ASSERT_TRUE(stream_->Open());
+ // The test is set up to create three log files of length 2. Write and check
+ // contents.
+ std::string messages[3] = {"aa", "bb", "cc"};
+ for (size_t i = 0; i < arraysize(messages); ++i) {
+ const std::string& message = messages[i];
+ WriteAndFlush(message.c_str(), message.size());
+ }
+ std::string message("d");
+ WriteAndFlush(message.c_str(), message.size());
+
+ // Reopen for read.
+ std::string expected_contents("bbccd");
+ VerifyStreamRead(expected_contents.c_str(), expected_contents.size(),
+ dir_path_.substr(0, dir_path_.size() - 1), kFilePrefix);
+}
+
// Tests that writing data greater than the total capacity of the files
// overwrites the files correctly and is read correctly after.
TEST_F(MAYBE_FileRotatingStreamTest, WriteOverflowAndRead) {
@@ -218,7 +267,7 @@
// Append per-test output path in order to run within gtest parallel.
dir_path_.append(dir_name);
- dir_path_.push_back(Pathname::DefaultFolderDelimiter());
+ dir_path_.append(webrtc::test::kPathDelimiter);
ASSERT_TRUE(webrtc::test::CreateDir(dir_path_));
stream_.reset(
new CallSessionFileRotatingStream(dir_path_, max_total_log_size));