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" | |
20 | 19 |
21 namespace rtc { | 20 namespace rtc { |
22 | 21 |
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 | |
34 #if defined (WEBRTC_ANDROID) | 22 #if defined (WEBRTC_ANDROID) |
35 // Fails on Android: https://bugs.chromium.org/p/webrtc/issues/detail?id=4364. | 23 // Fails on Android: https://bugs.chromium.org/p/webrtc/issues/detail?id=4364. |
36 #define MAYBE_FileRotatingStreamTest DISABLED_FileRotatingStreamTest | 24 #define MAYBE_FileRotatingStreamTest DISABLED_FileRotatingStreamTest |
37 #else | 25 #else |
38 #define MAYBE_FileRotatingStreamTest FileRotatingStreamTest | 26 #define MAYBE_FileRotatingStreamTest FileRotatingStreamTest |
39 #endif | 27 #endif |
40 | 28 |
41 class MAYBE_FileRotatingStreamTest : public ::testing::Test { | 29 class MAYBE_FileRotatingStreamTest : public ::testing::Test { |
42 protected: | 30 protected: |
43 static const char* kFilePrefix; | 31 static const char* kFilePrefix; |
44 static const size_t kMaxFileSize; | 32 static const size_t kMaxFileSize; |
45 | 33 |
46 void Init(const std::string& dir_name, | 34 void Init(const std::string& dir_name, |
47 const std::string& file_prefix, | 35 const std::string& file_prefix, |
48 size_t max_file_size, | 36 size_t max_file_size, |
49 size_t num_log_files) { | 37 size_t num_log_files) { |
50 dir_path_ = webrtc::test::OutputPath(); | 38 Pathname test_path; |
51 | 39 ASSERT_TRUE(Filesystem::GetAppTempFolder(&test_path)); |
52 // Append per-test output path in order to run within gtest parallel. | 40 // Append per-test output path in order to run within gtest parallel. |
53 dir_path_.append(dir_name); | 41 test_path.AppendFolder(dir_name); |
54 dir_path_.push_back(Pathname::DefaultFolderDelimiter()); | 42 ASSERT_TRUE(Filesystem::CreateFolder(test_path)); |
55 ASSERT_TRUE(webrtc::test::CreateDir(dir_path_)); | 43 dir_path_ = test_path.pathname(); |
| 44 ASSERT_TRUE(dir_path_.size()); |
56 stream_.reset(new FileRotatingStream(dir_path_, file_prefix, max_file_size, | 45 stream_.reset(new FileRotatingStream(dir_path_, file_prefix, max_file_size, |
57 num_log_files)); | 46 num_log_files)); |
58 } | 47 } |
59 | 48 |
60 void TearDown() override { | 49 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 | |
66 stream_.reset(); | 50 stream_.reset(); |
| 51 if (dir_path_.size() && Filesystem::IsFolder(dir_path_) && |
| 52 Filesystem::IsTemporaryPath(dir_path_)) { |
| 53 Filesystem::DeleteFolderAndContents(dir_path_); |
| 54 } |
67 } | 55 } |
68 | 56 |
69 // Writes the data to the stream and flushes it. | 57 // Writes the data to the stream and flushes it. |
70 void WriteAndFlush(const void* data, const size_t data_len) { | 58 void WriteAndFlush(const void* data, const size_t data_len) { |
71 EXPECT_EQ(SR_SUCCESS, stream_->WriteAll(data, data_len, nullptr, nullptr)); | 59 EXPECT_EQ(SR_SUCCESS, stream_->WriteAll(data, data_len, nullptr, nullptr)); |
72 EXPECT_TRUE(stream_->Flush()); | 60 EXPECT_TRUE(stream_->Flush()); |
73 } | 61 } |
74 | 62 |
75 // Checks that the stream reads in the expected contents and then returns an | 63 // Checks that the stream reads in the expected contents and then returns an |
76 // end of stream result. | 64 // end of stream result. |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 #define MAYBE_CallSessionFileRotatingStreamTest \ | 197 #define MAYBE_CallSessionFileRotatingStreamTest \ |
210 DISABLED_CallSessionFileRotatingStreamTest | 198 DISABLED_CallSessionFileRotatingStreamTest |
211 #else | 199 #else |
212 #define MAYBE_CallSessionFileRotatingStreamTest \ | 200 #define MAYBE_CallSessionFileRotatingStreamTest \ |
213 CallSessionFileRotatingStreamTest | 201 CallSessionFileRotatingStreamTest |
214 #endif | 202 #endif |
215 | 203 |
216 class MAYBE_CallSessionFileRotatingStreamTest : public ::testing::Test { | 204 class MAYBE_CallSessionFileRotatingStreamTest : public ::testing::Test { |
217 protected: | 205 protected: |
218 void Init(const std::string& dir_name, size_t max_total_log_size) { | 206 void Init(const std::string& dir_name, size_t max_total_log_size) { |
219 dir_path_ = webrtc::test::OutputPath(); | 207 Pathname test_path; |
220 | 208 ASSERT_TRUE(Filesystem::GetAppTempFolder(&test_path)); |
221 // Append per-test output path in order to run within gtest parallel. | 209 // Append per-test output path in order to run within gtest parallel. |
222 dir_path_.append(dir_name); | 210 test_path.AppendFolder(dir_name); |
223 dir_path_.push_back(Pathname::DefaultFolderDelimiter()); | 211 ASSERT_TRUE(Filesystem::CreateFolder(test_path)); |
224 ASSERT_TRUE(webrtc::test::CreateDir(dir_path_)); | 212 dir_path_ = test_path.pathname(); |
| 213 ASSERT_TRUE(dir_path_.size()); |
225 stream_.reset( | 214 stream_.reset( |
226 new CallSessionFileRotatingStream(dir_path_, max_total_log_size)); | 215 new CallSessionFileRotatingStream(dir_path_, max_total_log_size)); |
227 } | 216 } |
228 | 217 |
229 virtual void TearDown() { | 218 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 | |
235 stream_.reset(); | 219 stream_.reset(); |
| 220 if (dir_path_.size() && Filesystem::IsFolder(dir_path_) && |
| 221 Filesystem::IsTemporaryPath(dir_path_)) { |
| 222 Filesystem::DeleteFolderAndContents(dir_path_); |
| 223 } |
236 } | 224 } |
237 | 225 |
238 // Writes the data to the stream and flushes it. | 226 // Writes the data to the stream and flushes it. |
239 void WriteAndFlush(const void* data, const size_t data_len) { | 227 void WriteAndFlush(const void* data, const size_t data_len) { |
240 EXPECT_EQ(SR_SUCCESS, stream_->WriteAll(data, data_len, nullptr, nullptr)); | 228 EXPECT_EQ(SR_SUCCESS, stream_->WriteAll(data, data_len, nullptr, nullptr)); |
241 EXPECT_TRUE(stream_->Flush()); | 229 EXPECT_TRUE(stream_->Flush()); |
242 } | 230 } |
243 | 231 |
244 // Checks that the stream reads in the expected contents and then returns an | 232 // Checks that the stream reads in the expected contents and then returns an |
245 // end of stream result. | 233 // end of stream result. |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 for (size_t i = 0; i < arraysize(expected_vals); ++i) { | 326 for (size_t i = 0; i < arraysize(expected_vals); ++i) { |
339 memset(expected_buffer.get(), expected_vals[i], buffer_size); | 327 memset(expected_buffer.get(), expected_vals[i], buffer_size); |
340 EXPECT_EQ(SR_SUCCESS, | 328 EXPECT_EQ(SR_SUCCESS, |
341 stream_->ReadAll(buffer.get(), buffer_size, nullptr, nullptr)); | 329 stream_->ReadAll(buffer.get(), buffer_size, nullptr, nullptr)); |
342 EXPECT_EQ(0, memcmp(buffer.get(), expected_buffer.get(), buffer_size)); | 330 EXPECT_EQ(0, memcmp(buffer.get(), expected_buffer.get(), buffer_size)); |
343 } | 331 } |
344 EXPECT_EQ(SR_EOS, stream_->ReadAll(buffer.get(), 1, nullptr, nullptr)); | 332 EXPECT_EQ(SR_EOS, stream_->ReadAll(buffer.get(), 1, nullptr, nullptr)); |
345 } | 333 } |
346 | 334 |
347 } // namespace rtc | 335 } // namespace rtc |
OLD | NEW |