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(FileRotatingStream* stream) { | |
26 // On windows, open files can't be removed. | |
27 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.
| |
28 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.
| |
29 // Ignore return value, not all files are expected to exist. | |
30 webrtc::test::RemoveFile(stream->GetFilePath(i)); | |
31 } | |
32 } | |
33 | |
34 } // namespace | |
35 | |
22 #if defined (WEBRTC_ANDROID) | 36 #if defined (WEBRTC_ANDROID) |
23 // Fails on Android: https://bugs.chromium.org/p/webrtc/issues/detail?id=4364. | 37 // Fails on Android: https://bugs.chromium.org/p/webrtc/issues/detail?id=4364. |
24 #define MAYBE_FileRotatingStreamTest DISABLED_FileRotatingStreamTest | 38 #define MAYBE_FileRotatingStreamTest DISABLED_FileRotatingStreamTest |
25 #else | 39 #else |
26 #define MAYBE_FileRotatingStreamTest FileRotatingStreamTest | 40 #define MAYBE_FileRotatingStreamTest FileRotatingStreamTest |
27 #endif | 41 #endif |
28 | 42 |
29 class MAYBE_FileRotatingStreamTest : public ::testing::Test { | 43 class MAYBE_FileRotatingStreamTest : public ::testing::Test { |
30 protected: | 44 protected: |
31 static const char* kFilePrefix; | 45 static const char* kFilePrefix; |
32 static const size_t kMaxFileSize; | 46 static const size_t kMaxFileSize; |
33 | 47 |
34 void Init(const std::string& dir_name, | 48 void Init(const std::string& dir_name, |
35 const std::string& file_prefix, | 49 const std::string& file_prefix, |
36 size_t max_file_size, | 50 size_t max_file_size, |
37 size_t num_log_files) { | 51 size_t num_log_files) { |
38 Pathname test_path; | 52 dir_path_ = webrtc::test::OutputPath(); |
39 ASSERT_TRUE(Filesystem::GetAppTempFolder(&test_path)); | 53 |
40 // Append per-test output path in order to run within gtest parallel. | 54 // Append per-test output path in order to run within gtest parallel. |
41 test_path.AppendFolder(dir_name); | 55 dir_path_.append(dir_name); |
42 ASSERT_TRUE(Filesystem::CreateFolder(test_path)); | 56 dir_path_.push_back(Pathname::DefaultFolderDelimiter()); |
43 dir_path_ = test_path.pathname(); | 57 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, | 58 stream_.reset(new FileRotatingStream(dir_path_, file_prefix, max_file_size, |
46 num_log_files)); | 59 num_log_files)); |
47 } | 60 } |
48 | 61 |
49 void TearDown() override { | 62 void TearDown() override { |
63 CleanupLogDirectory(stream_.get()); | |
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 CleanupLogDirectory(stream_.get()); | |
231 EXPECT_TRUE(webrtc::test::RemoveDir(dir_path_)); | |
232 | |
219 stream_.reset(); | 233 stream_.reset(); |
220 if (dir_path_.size() && Filesystem::IsFolder(dir_path_) && | |
221 Filesystem::IsTemporaryPath(dir_path_)) { | |
222 Filesystem::DeleteFolderAndContents(dir_path_); | |
223 } | |
224 } | 234 } |
225 | 235 |
226 // Writes the data to the stream and flushes it. | 236 // Writes the data to the stream and flushes it. |
227 void WriteAndFlush(const void* data, const size_t data_len) { | 237 void WriteAndFlush(const void* data, const size_t data_len) { |
228 EXPECT_EQ(SR_SUCCESS, stream_->WriteAll(data, data_len, nullptr, nullptr)); | 238 EXPECT_EQ(SR_SUCCESS, stream_->WriteAll(data, data_len, nullptr, nullptr)); |
229 EXPECT_TRUE(stream_->Flush()); | 239 EXPECT_TRUE(stream_->Flush()); |
230 } | 240 } |
231 | 241 |
232 // Checks that the stream reads in the expected contents and then returns an | 242 // Checks that the stream reads in the expected contents and then returns an |
233 // end of stream result. | 243 // 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) { | 336 for (size_t i = 0; i < arraysize(expected_vals); ++i) { |
327 memset(expected_buffer.get(), expected_vals[i], buffer_size); | 337 memset(expected_buffer.get(), expected_vals[i], buffer_size); |
328 EXPECT_EQ(SR_SUCCESS, | 338 EXPECT_EQ(SR_SUCCESS, |
329 stream_->ReadAll(buffer.get(), buffer_size, nullptr, nullptr)); | 339 stream_->ReadAll(buffer.get(), buffer_size, nullptr, nullptr)); |
330 EXPECT_EQ(0, memcmp(buffer.get(), expected_buffer.get(), buffer_size)); | 340 EXPECT_EQ(0, memcmp(buffer.get(), expected_buffer.get(), buffer_size)); |
331 } | 341 } |
332 EXPECT_EQ(SR_EOS, stream_->ReadAll(buffer.get(), 1, nullptr, nullptr)); | 342 EXPECT_EQ(SR_EOS, stream_->ReadAll(buffer.get(), 1, nullptr, nullptr)); |
333 } | 343 } |
334 | 344 |
335 } // namespace rtc | 345 } // namespace rtc |
OLD | NEW |