| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 | 53 |
| 54 // Checks that the stream reads in the expected contents and then returns an | 54 // Checks that the stream reads in the expected contents and then returns an |
| 55 // end of stream result. | 55 // end of stream result. |
| 56 void VerifyStreamRead(const char* expected_contents, | 56 void VerifyStreamRead(const char* expected_contents, |
| 57 const size_t expected_length, | 57 const size_t expected_length, |
| 58 const std::string& dir_path, | 58 const std::string& dir_path, |
| 59 const char* file_prefix) { | 59 const char* file_prefix) { |
| 60 scoped_ptr<FileRotatingStream> stream; | 60 scoped_ptr<FileRotatingStream> stream; |
| 61 stream.reset(new FileRotatingStream(dir_path, file_prefix)); | 61 stream.reset(new FileRotatingStream(dir_path, file_prefix)); |
| 62 ASSERT_TRUE(stream->Open()); | 62 ASSERT_TRUE(stream->Open()); |
| 63 size_t read = 0; |
| 64 size_t stream_size = 0; |
| 65 EXPECT_TRUE(stream->GetSize(&stream_size)); |
| 63 scoped_ptr<uint8_t[]> buffer(new uint8_t[expected_length]); | 66 scoped_ptr<uint8_t[]> buffer(new uint8_t[expected_length]); |
| 64 EXPECT_EQ(SR_SUCCESS, | 67 EXPECT_EQ(SR_SUCCESS, |
| 65 stream->ReadAll(buffer.get(), expected_length, nullptr, nullptr)); | 68 stream->ReadAll(buffer.get(), expected_length, &read, nullptr)); |
| 66 EXPECT_EQ(0, memcmp(expected_contents, buffer.get(), expected_length)); | 69 EXPECT_EQ(0, memcmp(expected_contents, buffer.get(), expected_length)); |
| 67 EXPECT_EQ(SR_EOS, stream->ReadAll(buffer.get(), 1, nullptr, nullptr)); | 70 EXPECT_EQ(SR_EOS, stream->ReadAll(buffer.get(), 1, nullptr, nullptr)); |
| 71 EXPECT_EQ(stream_size, read); |
| 68 } | 72 } |
| 69 | 73 |
| 70 void VerifyFileContents(const char* expected_contents, | 74 void VerifyFileContents(const char* expected_contents, |
| 71 const size_t expected_length, | 75 const size_t expected_length, |
| 72 const std::string& file_path) { | 76 const std::string& file_path) { |
| 73 scoped_ptr<uint8_t[]> buffer(new uint8_t[expected_length]); | 77 scoped_ptr<uint8_t[]> buffer(new uint8_t[expected_length]); |
| 74 scoped_ptr<FileStream> stream(Filesystem::OpenFile(file_path, "r")); | 78 scoped_ptr<FileStream> stream(Filesystem::OpenFile(file_path, "r")); |
| 75 EXPECT_TRUE(stream); | 79 EXPECT_TRUE(stream); |
| 76 if (!stream) { | 80 if (!stream) { |
| 77 return; | 81 return; |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 } | 211 } |
| 208 | 212 |
| 209 // Checks that the stream reads in the expected contents and then returns an | 213 // Checks that the stream reads in the expected contents and then returns an |
| 210 // end of stream result. | 214 // end of stream result. |
| 211 void VerifyStreamRead(const char* expected_contents, | 215 void VerifyStreamRead(const char* expected_contents, |
| 212 const size_t expected_length, | 216 const size_t expected_length, |
| 213 const std::string& dir_path) { | 217 const std::string& dir_path) { |
| 214 scoped_ptr<CallSessionFileRotatingStream> stream( | 218 scoped_ptr<CallSessionFileRotatingStream> stream( |
| 215 new CallSessionFileRotatingStream(dir_path)); | 219 new CallSessionFileRotatingStream(dir_path)); |
| 216 ASSERT_TRUE(stream->Open()); | 220 ASSERT_TRUE(stream->Open()); |
| 221 size_t read = 0; |
| 222 size_t stream_size = 0; |
| 223 EXPECT_TRUE(stream->GetSize(&stream_size)); |
| 217 scoped_ptr<uint8_t[]> buffer(new uint8_t[expected_length]); | 224 scoped_ptr<uint8_t[]> buffer(new uint8_t[expected_length]); |
| 218 EXPECT_EQ(SR_SUCCESS, | 225 EXPECT_EQ(SR_SUCCESS, |
| 219 stream->ReadAll(buffer.get(), expected_length, nullptr, nullptr)); | 226 stream->ReadAll(buffer.get(), expected_length, &read, nullptr)); |
| 220 EXPECT_EQ(0, memcmp(expected_contents, buffer.get(), expected_length)); | 227 EXPECT_EQ(0, memcmp(expected_contents, buffer.get(), expected_length)); |
| 221 EXPECT_EQ(SR_EOS, stream->ReadAll(buffer.get(), 1, nullptr, nullptr)); | 228 EXPECT_EQ(SR_EOS, stream->ReadAll(buffer.get(), 1, nullptr, nullptr)); |
| 229 EXPECT_EQ(stream_size, read); |
| 222 } | 230 } |
| 223 | 231 |
| 224 scoped_ptr<CallSessionFileRotatingStream> stream_; | 232 scoped_ptr<CallSessionFileRotatingStream> stream_; |
| 225 std::string dir_path_; | 233 std::string dir_path_; |
| 226 }; | 234 }; |
| 227 | 235 |
| 228 // Tests that writing and reading to a stream with the smallest possible | 236 // Tests that writing and reading to a stream with the smallest possible |
| 229 // capacity works. | 237 // capacity works. |
| 230 TEST_F(CallSessionFileRotatingStreamTest, WriteAndReadSmallest) { | 238 TEST_F(CallSessionFileRotatingStreamTest, WriteAndReadSmallest) { |
| 231 Init("CallSessionFileRotatingStreamTestWriteAndReadSmallest", 4); | 239 Init("CallSessionFileRotatingStreamTestWriteAndReadSmallest", 4); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 for (size_t i = 0; i < arraysize(expected_vals); ++i) { | 307 for (size_t i = 0; i < arraysize(expected_vals); ++i) { |
| 300 memset(expected_buffer.get(), expected_vals[i], buffer_size); | 308 memset(expected_buffer.get(), expected_vals[i], buffer_size); |
| 301 EXPECT_EQ(SR_SUCCESS, | 309 EXPECT_EQ(SR_SUCCESS, |
| 302 stream_->ReadAll(buffer.get(), buffer_size, nullptr, nullptr)); | 310 stream_->ReadAll(buffer.get(), buffer_size, nullptr, nullptr)); |
| 303 EXPECT_EQ(0, memcmp(buffer.get(), expected_buffer.get(), buffer_size)); | 311 EXPECT_EQ(0, memcmp(buffer.get(), expected_buffer.get(), buffer_size)); |
| 304 } | 312 } |
| 305 EXPECT_EQ(SR_EOS, stream_->ReadAll(buffer.get(), 1, nullptr, nullptr)); | 313 EXPECT_EQ(SR_EOS, stream_->ReadAll(buffer.get(), 1, nullptr, nullptr)); |
| 306 } | 314 } |
| 307 | 315 |
| 308 } // namespace rtc | 316 } // namespace rtc |
| OLD | NEW |