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 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 stream->ReadAll(buffer.get(), expected_length, &read, nullptr)); | 89 stream->ReadAll(buffer.get(), expected_length, &read, nullptr)); |
90 EXPECT_EQ(0, memcmp(expected_contents, buffer.get(), expected_length)); | 90 EXPECT_EQ(0, memcmp(expected_contents, buffer.get(), expected_length)); |
91 EXPECT_EQ(SR_EOS, stream->ReadAll(buffer.get(), 1, nullptr, nullptr)); | 91 EXPECT_EQ(SR_EOS, stream->ReadAll(buffer.get(), 1, nullptr, nullptr)); |
92 EXPECT_EQ(stream_size, read); | 92 EXPECT_EQ(stream_size, read); |
93 } | 93 } |
94 | 94 |
95 void VerifyFileContents(const char* expected_contents, | 95 void VerifyFileContents(const char* expected_contents, |
96 const size_t expected_length, | 96 const size_t expected_length, |
97 const std::string& file_path) { | 97 const std::string& file_path) { |
98 std::unique_ptr<uint8_t[]> buffer(new uint8_t[expected_length]); | 98 std::unique_ptr<uint8_t[]> buffer(new uint8_t[expected_length]); |
99 std::unique_ptr<FileStream> stream(Filesystem::OpenFile(file_path, "r")); | 99 FileStream stream; |
100 EXPECT_TRUE(stream); | 100 ASSERT_TRUE(stream.Open(file_path, "r", nullptr)); |
101 if (!stream) { | |
102 return; | |
103 } | |
104 EXPECT_EQ(rtc::SR_SUCCESS, | 101 EXPECT_EQ(rtc::SR_SUCCESS, |
105 stream->ReadAll(buffer.get(), expected_length, nullptr, nullptr)); | 102 stream.ReadAll(buffer.get(), expected_length, nullptr, nullptr)); |
106 EXPECT_EQ(0, memcmp(expected_contents, buffer.get(), expected_length)); | 103 EXPECT_EQ(0, memcmp(expected_contents, buffer.get(), expected_length)); |
107 size_t file_size = 0; | 104 size_t file_size = 0; |
108 EXPECT_TRUE(stream->GetSize(&file_size)); | 105 EXPECT_TRUE(stream.GetSize(&file_size)); |
109 EXPECT_EQ(file_size, expected_length); | 106 EXPECT_EQ(file_size, expected_length); |
110 } | 107 } |
111 | 108 |
112 std::unique_ptr<FileRotatingStream> stream_; | 109 std::unique_ptr<FileRotatingStream> stream_; |
113 std::string dir_path_; | 110 std::string dir_path_; |
114 }; | 111 }; |
115 | 112 |
116 const char* MAYBE_FileRotatingStreamTest::kFilePrefix = | 113 const char* MAYBE_FileRotatingStreamTest::kFilePrefix = |
117 "FileRotatingStreamTest"; | 114 "FileRotatingStreamTest"; |
118 const size_t MAYBE_FileRotatingStreamTest::kMaxFileSize = 2; | 115 const size_t MAYBE_FileRotatingStreamTest::kMaxFileSize = 2; |
(...skipping 10 matching lines...) Expand all Loading... |
129 } | 126 } |
130 | 127 |
131 // Tests that nothing is written to file when data of length zero is written. | 128 // Tests that nothing is written to file when data of length zero is written. |
132 TEST_F(MAYBE_FileRotatingStreamTest, EmptyWrite) { | 129 TEST_F(MAYBE_FileRotatingStreamTest, EmptyWrite) { |
133 Init("FileRotatingStreamTestEmptyWrite", kFilePrefix, kMaxFileSize, 3); | 130 Init("FileRotatingStreamTestEmptyWrite", kFilePrefix, kMaxFileSize, 3); |
134 | 131 |
135 ASSERT_TRUE(stream_->Open()); | 132 ASSERT_TRUE(stream_->Open()); |
136 WriteAndFlush("a", 0); | 133 WriteAndFlush("a", 0); |
137 | 134 |
138 std::string logfile_path = stream_->GetFilePath(0); | 135 std::string logfile_path = stream_->GetFilePath(0); |
139 std::unique_ptr<FileStream> stream(Filesystem::OpenFile(logfile_path, "r")); | 136 FileStream stream; |
| 137 ASSERT_TRUE(stream.Open(logfile_path, "r", nullptr)); |
140 size_t file_size = 0; | 138 size_t file_size = 0; |
141 EXPECT_TRUE(stream->GetSize(&file_size)); | 139 EXPECT_TRUE(stream.GetSize(&file_size)); |
142 EXPECT_EQ(0u, file_size); | 140 EXPECT_EQ(0u, file_size); |
143 } | 141 } |
144 | 142 |
145 // Tests that a write operation followed by a read returns the expected data | 143 // Tests that a write operation followed by a read returns the expected data |
146 // and writes to the expected files. | 144 // and writes to the expected files. |
147 TEST_F(MAYBE_FileRotatingStreamTest, WriteAndRead) { | 145 TEST_F(MAYBE_FileRotatingStreamTest, WriteAndRead) { |
148 Init("FileRotatingStreamTestWriteAndRead", kFilePrefix, kMaxFileSize, 3); | 146 Init("FileRotatingStreamTestWriteAndRead", kFilePrefix, kMaxFileSize, 3); |
149 | 147 |
150 ASSERT_TRUE(stream_->Open()); | 148 ASSERT_TRUE(stream_->Open()); |
151 // The test is set up to create three log files of length 2. Write and check | 149 // The test is set up to create three log files of length 2. Write and check |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 for (size_t i = 0; i < arraysize(expected_vals); ++i) { | 336 for (size_t i = 0; i < arraysize(expected_vals); ++i) { |
339 memset(expected_buffer.get(), expected_vals[i], buffer_size); | 337 memset(expected_buffer.get(), expected_vals[i], buffer_size); |
340 EXPECT_EQ(SR_SUCCESS, | 338 EXPECT_EQ(SR_SUCCESS, |
341 stream_->ReadAll(buffer.get(), buffer_size, nullptr, nullptr)); | 339 stream_->ReadAll(buffer.get(), buffer_size, nullptr, nullptr)); |
342 EXPECT_EQ(0, memcmp(buffer.get(), expected_buffer.get(), buffer_size)); | 340 EXPECT_EQ(0, memcmp(buffer.get(), expected_buffer.get(), buffer_size)); |
343 } | 341 } |
344 EXPECT_EQ(SR_EOS, stream_->ReadAll(buffer.get(), 1, nullptr, nullptr)); | 342 EXPECT_EQ(SR_EOS, stream_->ReadAll(buffer.get(), 1, nullptr, nullptr)); |
345 } | 343 } |
346 | 344 |
347 } // namespace rtc | 345 } // namespace rtc |
OLD | NEW |