OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2015 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include <memory> | 11 #include <memory> |
12 | 12 |
13 #include "webrtc/base/arraysize.h" | 13 #include "webrtc/base/arraysize.h" |
14 #include "webrtc/base/checks.h" | 14 #include "webrtc/base/checks.h" |
15 #include "webrtc/base/filerotatingstream.h" | 15 #include "webrtc/base/filerotatingstream.h" |
16 #include "webrtc/base/fileutils.h" | 16 #include "webrtc/base/fileutils.h" |
17 #include "webrtc/base/gunit.h" | 17 #include "webrtc/base/gunit.h" |
18 #include "webrtc/base/pathutils.h" | 18 #include "webrtc/base/pathutils.h" |
| 19 #include "webrtc/test/testsupport/fileutils.h" |
19 | 20 |
20 namespace rtc { | 21 namespace rtc { |
21 | 22 |
| 23 namespace { |
| 24 |
| 25 void CleanupLogDirectory(const FileRotatingStream& stream) { |
| 26 for (size_t i = 0; i < stream.GetNumFiles(); ++i) { |
| 27 // Ignore return value, not all files are expected to exist. |
| 28 webrtc::test::RemoveFile(stream.GetFilePath(i)); |
| 29 } |
| 30 } |
| 31 |
| 32 } // namespace |
| 33 |
22 #if defined (WEBRTC_ANDROID) | 34 #if defined (WEBRTC_ANDROID) |
23 // Fails on Android: https://bugs.chromium.org/p/webrtc/issues/detail?id=4364. | 35 // Fails on Android: https://bugs.chromium.org/p/webrtc/issues/detail?id=4364. |
24 #define MAYBE_FileRotatingStreamTest DISABLED_FileRotatingStreamTest | 36 #define MAYBE_FileRotatingStreamTest DISABLED_FileRotatingStreamTest |
25 #else | 37 #else |
26 #define MAYBE_FileRotatingStreamTest FileRotatingStreamTest | 38 #define MAYBE_FileRotatingStreamTest FileRotatingStreamTest |
27 #endif | 39 #endif |
28 | 40 |
29 class MAYBE_FileRotatingStreamTest : public ::testing::Test { | 41 class MAYBE_FileRotatingStreamTest : public ::testing::Test { |
30 protected: | 42 protected: |
31 static const char* kFilePrefix; | 43 static const char* kFilePrefix; |
32 static const size_t kMaxFileSize; | 44 static const size_t kMaxFileSize; |
33 | 45 |
34 void Init(const std::string& dir_name, | 46 void Init(const std::string& dir_name, |
35 const std::string& file_prefix, | 47 const std::string& file_prefix, |
36 size_t max_file_size, | 48 size_t max_file_size, |
37 size_t num_log_files) { | 49 size_t num_log_files) { |
38 Pathname test_path; | 50 dir_path_ = webrtc::test::OutputPath(); |
39 ASSERT_TRUE(Filesystem::GetAppTempFolder(&test_path)); | 51 |
40 // Append per-test output path in order to run within gtest parallel. | 52 // Append per-test output path in order to run within gtest parallel. |
41 test_path.AppendFolder(dir_name); | 53 dir_path_.append(dir_name); |
42 ASSERT_TRUE(Filesystem::CreateFolder(test_path)); | 54 dir_path_.push_back(Pathname::DefaultFolderDelimiter()); |
43 dir_path_ = test_path.pathname(); | 55 ASSERT_TRUE(webrtc::test::CreateDir(dir_path_)); |
44 ASSERT_TRUE(dir_path_.size()); | |
45 stream_.reset(new FileRotatingStream(dir_path_, file_prefix, max_file_size, | 56 stream_.reset(new FileRotatingStream(dir_path_, file_prefix, max_file_size, |
46 num_log_files)); | 57 num_log_files)); |
47 } | 58 } |
48 | 59 |
49 void TearDown() override { | 60 void TearDown() override { |
| 61 // On windows, open files can't be removed. |
| 62 stream_->Close(); |
| 63 CleanupLogDirectory(*stream_); |
| 64 EXPECT_TRUE(webrtc::test::RemoveDir(dir_path_)); |
| 65 |
50 stream_.reset(); | 66 stream_.reset(); |
51 if (dir_path_.size() && Filesystem::IsFolder(dir_path_) && | |
52 Filesystem::IsTemporaryPath(dir_path_)) { | |
53 Filesystem::DeleteFolderAndContents(dir_path_); | |
54 } | |
55 } | 67 } |
56 | 68 |
57 // Writes the data to the stream and flushes it. | 69 // Writes the data to the stream and flushes it. |
58 void WriteAndFlush(const void* data, const size_t data_len) { | 70 void WriteAndFlush(const void* data, const size_t data_len) { |
59 EXPECT_EQ(SR_SUCCESS, stream_->WriteAll(data, data_len, nullptr, nullptr)); | 71 EXPECT_EQ(SR_SUCCESS, stream_->WriteAll(data, data_len, nullptr, nullptr)); |
60 EXPECT_TRUE(stream_->Flush()); | 72 EXPECT_TRUE(stream_->Flush()); |
61 } | 73 } |
62 | 74 |
63 // Checks that the stream reads in the expected contents and then returns an | 75 // Checks that the stream reads in the expected contents and then returns an |
64 // end of stream result. | 76 // end of stream result. |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 #define MAYBE_CallSessionFileRotatingStreamTest \ | 209 #define MAYBE_CallSessionFileRotatingStreamTest \ |
198 DISABLED_CallSessionFileRotatingStreamTest | 210 DISABLED_CallSessionFileRotatingStreamTest |
199 #else | 211 #else |
200 #define MAYBE_CallSessionFileRotatingStreamTest \ | 212 #define MAYBE_CallSessionFileRotatingStreamTest \ |
201 CallSessionFileRotatingStreamTest | 213 CallSessionFileRotatingStreamTest |
202 #endif | 214 #endif |
203 | 215 |
204 class MAYBE_CallSessionFileRotatingStreamTest : public ::testing::Test { | 216 class MAYBE_CallSessionFileRotatingStreamTest : public ::testing::Test { |
205 protected: | 217 protected: |
206 void Init(const std::string& dir_name, size_t max_total_log_size) { | 218 void Init(const std::string& dir_name, size_t max_total_log_size) { |
207 Pathname test_path; | 219 dir_path_ = webrtc::test::OutputPath(); |
208 ASSERT_TRUE(Filesystem::GetAppTempFolder(&test_path)); | 220 |
209 // Append per-test output path in order to run within gtest parallel. | 221 // Append per-test output path in order to run within gtest parallel. |
210 test_path.AppendFolder(dir_name); | 222 dir_path_.append(dir_name); |
211 ASSERT_TRUE(Filesystem::CreateFolder(test_path)); | 223 dir_path_.push_back(Pathname::DefaultFolderDelimiter()); |
212 dir_path_ = test_path.pathname(); | 224 ASSERT_TRUE(webrtc::test::CreateDir(dir_path_)); |
213 ASSERT_TRUE(dir_path_.size()); | |
214 stream_.reset( | 225 stream_.reset( |
215 new CallSessionFileRotatingStream(dir_path_, max_total_log_size)); | 226 new CallSessionFileRotatingStream(dir_path_, max_total_log_size)); |
216 } | 227 } |
217 | 228 |
218 virtual void TearDown() { | 229 virtual void TearDown() { |
| 230 // On windows, open files can't be removed. |
| 231 stream_->Close(); |
| 232 CleanupLogDirectory(*stream_); |
| 233 EXPECT_TRUE(webrtc::test::RemoveDir(dir_path_)); |
| 234 |
219 stream_.reset(); | 235 stream_.reset(); |
220 if (dir_path_.size() && Filesystem::IsFolder(dir_path_) && | |
221 Filesystem::IsTemporaryPath(dir_path_)) { | |
222 Filesystem::DeleteFolderAndContents(dir_path_); | |
223 } | |
224 } | 236 } |
225 | 237 |
226 // Writes the data to the stream and flushes it. | 238 // Writes the data to the stream and flushes it. |
227 void WriteAndFlush(const void* data, const size_t data_len) { | 239 void WriteAndFlush(const void* data, const size_t data_len) { |
228 EXPECT_EQ(SR_SUCCESS, stream_->WriteAll(data, data_len, nullptr, nullptr)); | 240 EXPECT_EQ(SR_SUCCESS, stream_->WriteAll(data, data_len, nullptr, nullptr)); |
229 EXPECT_TRUE(stream_->Flush()); | 241 EXPECT_TRUE(stream_->Flush()); |
230 } | 242 } |
231 | 243 |
232 // Checks that the stream reads in the expected contents and then returns an | 244 // Checks that the stream reads in the expected contents and then returns an |
233 // end of stream result. | 245 // end of stream result. |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 for (size_t i = 0; i < arraysize(expected_vals); ++i) { | 338 for (size_t i = 0; i < arraysize(expected_vals); ++i) { |
327 memset(expected_buffer.get(), expected_vals[i], buffer_size); | 339 memset(expected_buffer.get(), expected_vals[i], buffer_size); |
328 EXPECT_EQ(SR_SUCCESS, | 340 EXPECT_EQ(SR_SUCCESS, |
329 stream_->ReadAll(buffer.get(), buffer_size, nullptr, nullptr)); | 341 stream_->ReadAll(buffer.get(), buffer_size, nullptr, nullptr)); |
330 EXPECT_EQ(0, memcmp(buffer.get(), expected_buffer.get(), buffer_size)); | 342 EXPECT_EQ(0, memcmp(buffer.get(), expected_buffer.get(), buffer_size)); |
331 } | 343 } |
332 EXPECT_EQ(SR_EOS, stream_->ReadAll(buffer.get(), 1, nullptr, nullptr)); | 344 EXPECT_EQ(SR_EOS, stream_->ReadAll(buffer.get(), 1, nullptr, nullptr)); |
333 } | 345 } |
334 | 346 |
335 } // namespace rtc | 347 } // namespace rtc |
OLD | NEW |