Chromium Code Reviews| Index: webrtc/base/filerotatingstream_unittest.cc |
| diff --git a/webrtc/base/filerotatingstream_unittest.cc b/webrtc/base/filerotatingstream_unittest.cc |
| index 2a0e8589f460b62c58d52b6d361fe169a0d8af7b..45ac6fe45f78df892df8c11682ae96b66a30d30d 100644 |
| --- a/webrtc/base/filerotatingstream_unittest.cc |
| +++ b/webrtc/base/filerotatingstream_unittest.cc |
| @@ -16,9 +16,23 @@ |
| #include "webrtc/base/fileutils.h" |
| #include "webrtc/base/gunit.h" |
| #include "webrtc/base/pathutils.h" |
| +#include "webrtc/test/testsupport/fileutils.h" |
| namespace rtc { |
| +namespace { |
| + |
| +void CleanupLogDirectory(FileRotatingStream* stream) { |
| + // On windows, open files can't be removed. |
| + stream->Close(); |
|
tommi
2017/05/16 14:34:21
nit: it feels kinda strange to do this inside here
nisse-webrtc
2017/05/17 07:38:31
Done.
|
| + for (size_t i = 0; i < stream->GetNumFiles(); i++) { |
|
tommi
2017/05/16 14:34:21
++i
nisse-webrtc
2017/05/17 07:38:32
Done.
|
| + // Ignore return value, not all files are expected to exist. |
| + webrtc::test::RemoveFile(stream->GetFilePath(i)); |
| + } |
| +} |
| + |
| +} // namespace |
| + |
| #if defined (WEBRTC_ANDROID) |
| // Fails on Android: https://bugs.chromium.org/p/webrtc/issues/detail?id=4364. |
| #define MAYBE_FileRotatingStreamTest DISABLED_FileRotatingStreamTest |
| @@ -35,23 +49,21 @@ class MAYBE_FileRotatingStreamTest : public ::testing::Test { |
| const std::string& file_prefix, |
| size_t max_file_size, |
| size_t num_log_files) { |
| - Pathname test_path; |
| - ASSERT_TRUE(Filesystem::GetAppTempFolder(&test_path)); |
| + dir_path_ = webrtc::test::OutputPath(); |
| + |
| // Append per-test output path in order to run within gtest parallel. |
| - test_path.AppendFolder(dir_name); |
| - ASSERT_TRUE(Filesystem::CreateFolder(test_path)); |
| - dir_path_ = test_path.pathname(); |
| - ASSERT_TRUE(dir_path_.size()); |
| + dir_path_.append(dir_name); |
| + dir_path_.push_back(Pathname::DefaultFolderDelimiter()); |
| + ASSERT_TRUE(webrtc::test::CreateDir(dir_path_)); |
| stream_.reset(new FileRotatingStream(dir_path_, file_prefix, max_file_size, |
| num_log_files)); |
| } |
| void TearDown() override { |
| + CleanupLogDirectory(stream_.get()); |
| + EXPECT_TRUE(webrtc::test::RemoveDir(dir_path_)); |
| + |
| stream_.reset(); |
| - if (dir_path_.size() && Filesystem::IsFolder(dir_path_) && |
| - Filesystem::IsTemporaryPath(dir_path_)) { |
| - Filesystem::DeleteFolderAndContents(dir_path_); |
| - } |
| } |
| // Writes the data to the stream and flushes it. |
| @@ -204,23 +216,21 @@ TEST_F(MAYBE_FileRotatingStreamTest, GetFilePath) { |
| class MAYBE_CallSessionFileRotatingStreamTest : public ::testing::Test { |
| protected: |
| void Init(const std::string& dir_name, size_t max_total_log_size) { |
| - Pathname test_path; |
| - ASSERT_TRUE(Filesystem::GetAppTempFolder(&test_path)); |
| + dir_path_ = webrtc::test::OutputPath(); |
| + |
| // Append per-test output path in order to run within gtest parallel. |
| - test_path.AppendFolder(dir_name); |
| - ASSERT_TRUE(Filesystem::CreateFolder(test_path)); |
| - dir_path_ = test_path.pathname(); |
| - ASSERT_TRUE(dir_path_.size()); |
| + dir_path_.append(dir_name); |
| + dir_path_.push_back(Pathname::DefaultFolderDelimiter()); |
| + ASSERT_TRUE(webrtc::test::CreateDir(dir_path_)); |
| stream_.reset( |
| new CallSessionFileRotatingStream(dir_path_, max_total_log_size)); |
| } |
| virtual void TearDown() { |
| + CleanupLogDirectory(stream_.get()); |
| + EXPECT_TRUE(webrtc::test::RemoveDir(dir_path_)); |
| + |
| stream_.reset(); |
| - if (dir_path_.size() && Filesystem::IsFolder(dir_path_) && |
| - Filesystem::IsTemporaryPath(dir_path_)) { |
| - Filesystem::DeleteFolderAndContents(dir_path_); |
| - } |
| } |
| // Writes the data to the stream and flushes it. |