blob: 07a3e1ab25c783c4e368004fa652d0ed572ac877 [file] [log] [blame]
tkchin93411912015-07-22 12:12:17 -07001/*
2 * Copyright 2015 The WebRTC Project Authors. All rights reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Yves Gerey3e707812018-11-28 16:47:49 +010011#include <string.h>
12#include <cstdint>
jbauch555604a2016-04-26 03:13:22 -070013#include <memory>
14
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020015#include "rtc_base/arraysize.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#include "rtc_base/filerotatingstream.h"
Yves Gerey3e707812018-11-28 16:47:49 +010017#include "test/gtest.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "test/testsupport/fileutils.h"
tkchin93411912015-07-22 12:12:17 -070019
20namespace rtc {
21
nisse57efb032017-05-18 03:55:59 -070022namespace {
23
24void CleanupLogDirectory(const FileRotatingStream& stream) {
25 for (size_t i = 0; i < stream.GetNumFiles(); ++i) {
26 // Ignore return value, not all files are expected to exist.
27 webrtc::test::RemoveFile(stream.GetFilePath(i));
28 }
29}
30
31} // namespace
32
Yves Gerey665174f2018-06-19 15:03:05 +020033#if defined(WEBRTC_ANDROID)
phoglundbb738732016-07-15 03:57:12 -070034// Fails on Android: https://bugs.chromium.org/p/webrtc/issues/detail?id=4364.
35#define MAYBE_FileRotatingStreamTest DISABLED_FileRotatingStreamTest
36#else
37#define MAYBE_FileRotatingStreamTest FileRotatingStreamTest
38#endif
39
40class MAYBE_FileRotatingStreamTest : public ::testing::Test {
tkchin93411912015-07-22 12:12:17 -070041 protected:
42 static const char* kFilePrefix;
43 static const size_t kMaxFileSize;
44
45 void Init(const std::string& dir_name,
46 const std::string& file_prefix,
47 size_t max_file_size,
Niels Möller7b3c76b2018-11-07 09:54:28 +010048 size_t num_log_files,
49 bool ensure_trailing_delimiter = true) {
nisse57efb032017-05-18 03:55:59 -070050 dir_path_ = webrtc::test::OutputPath();
51
tkchin93411912015-07-22 12:12:17 -070052 // Append per-test output path in order to run within gtest parallel.
nisse57efb032017-05-18 03:55:59 -070053 dir_path_.append(dir_name);
Niels Möller7b3c76b2018-11-07 09:54:28 +010054 if (ensure_trailing_delimiter) {
55 dir_path_.append(webrtc::test::kPathDelimiter);
56 }
nisse57efb032017-05-18 03:55:59 -070057 ASSERT_TRUE(webrtc::test::CreateDir(dir_path_));
tkchin93411912015-07-22 12:12:17 -070058 stream_.reset(new FileRotatingStream(dir_path_, file_prefix, max_file_size,
59 num_log_files));
60 }
61
62 void TearDown() override {
nisse57efb032017-05-18 03:55:59 -070063 // On windows, open files can't be removed.
64 stream_->Close();
65 CleanupLogDirectory(*stream_);
66 EXPECT_TRUE(webrtc::test::RemoveDir(dir_path_));
67
tkchin93411912015-07-22 12:12:17 -070068 stream_.reset();
tkchin93411912015-07-22 12:12:17 -070069 }
70
71 // Writes the data to the stream and flushes it.
72 void WriteAndFlush(const void* data, const size_t data_len) {
73 EXPECT_EQ(SR_SUCCESS, stream_->WriteAll(data, data_len, nullptr, nullptr));
74 EXPECT_TRUE(stream_->Flush());
75 }
76
77 // Checks that the stream reads in the expected contents and then returns an
78 // end of stream result.
79 void VerifyStreamRead(const char* expected_contents,
80 const size_t expected_length,
81 const std::string& dir_path,
82 const char* file_prefix) {
Niels Möllerd9ac0582019-01-03 14:21:38 +010083 // TODO(nisse): Delete the part of this method using read-mode
84 // FileRotatingStream, together with support for read-mode.
jbauch555604a2016-04-26 03:13:22 -070085 std::unique_ptr<FileRotatingStream> stream;
tkchin93411912015-07-22 12:12:17 -070086 stream.reset(new FileRotatingStream(dir_path, file_prefix));
87 ASSERT_TRUE(stream->Open());
tkchin28bae022015-07-23 12:27:02 -070088 size_t read = 0;
89 size_t stream_size = 0;
90 EXPECT_TRUE(stream->GetSize(&stream_size));
jbauch555604a2016-04-26 03:13:22 -070091 std::unique_ptr<uint8_t[]> buffer(new uint8_t[expected_length]);
tkchin93411912015-07-22 12:12:17 -070092 EXPECT_EQ(SR_SUCCESS,
tkchin28bae022015-07-23 12:27:02 -070093 stream->ReadAll(buffer.get(), expected_length, &read, nullptr));
tkchin93411912015-07-22 12:12:17 -070094 EXPECT_EQ(0, memcmp(expected_contents, buffer.get(), expected_length));
95 EXPECT_EQ(SR_EOS, stream->ReadAll(buffer.get(), 1, nullptr, nullptr));
tkchin28bae022015-07-23 12:27:02 -070096 EXPECT_EQ(stream_size, read);
Niels Möllerd9ac0582019-01-03 14:21:38 +010097
98 // Test also with the FileRotatingStreamReader class.
99 FileRotatingStreamReader reader(dir_path, file_prefix);
100 EXPECT_EQ(reader.GetSize(), expected_length);
101 memset(buffer.get(), 0, expected_length);
102 EXPECT_EQ(expected_length, reader.ReadAll(buffer.get(), expected_length));
103 EXPECT_EQ(0, memcmp(expected_contents, buffer.get(), expected_length));
tkchin93411912015-07-22 12:12:17 -0700104 }
105
106 void VerifyFileContents(const char* expected_contents,
107 const size_t expected_length,
108 const std::string& file_path) {
jbauch555604a2016-04-26 03:13:22 -0700109 std::unique_ptr<uint8_t[]> buffer(new uint8_t[expected_length]);
nisse21083262017-05-31 02:07:21 -0700110 FileStream stream;
111 ASSERT_TRUE(stream.Open(file_path, "r", nullptr));
tkchin93411912015-07-22 12:12:17 -0700112 EXPECT_EQ(rtc::SR_SUCCESS,
nisse21083262017-05-31 02:07:21 -0700113 stream.ReadAll(buffer.get(), expected_length, nullptr, nullptr));
tkchin93411912015-07-22 12:12:17 -0700114 EXPECT_EQ(0, memcmp(expected_contents, buffer.get(), expected_length));
115 size_t file_size = 0;
nisse21083262017-05-31 02:07:21 -0700116 EXPECT_TRUE(stream.GetSize(&file_size));
tkchin93411912015-07-22 12:12:17 -0700117 EXPECT_EQ(file_size, expected_length);
118 }
119
jbauch555604a2016-04-26 03:13:22 -0700120 std::unique_ptr<FileRotatingStream> stream_;
tkchin93411912015-07-22 12:12:17 -0700121 std::string dir_path_;
122};
123
phoglundbb738732016-07-15 03:57:12 -0700124const char* MAYBE_FileRotatingStreamTest::kFilePrefix =
125 "FileRotatingStreamTest";
126const size_t MAYBE_FileRotatingStreamTest::kMaxFileSize = 2;
tkchin93411912015-07-22 12:12:17 -0700127
128// Tests that stream state is correct before and after Open / Close.
phoglundbb738732016-07-15 03:57:12 -0700129TEST_F(MAYBE_FileRotatingStreamTest, State) {
tkchin93411912015-07-22 12:12:17 -0700130 Init("FileRotatingStreamTestState", kFilePrefix, kMaxFileSize, 3);
131
132 EXPECT_EQ(SS_CLOSED, stream_->GetState());
133 ASSERT_TRUE(stream_->Open());
134 EXPECT_EQ(SS_OPEN, stream_->GetState());
135 stream_->Close();
136 EXPECT_EQ(SS_CLOSED, stream_->GetState());
137}
138
139// Tests that nothing is written to file when data of length zero is written.
phoglundbb738732016-07-15 03:57:12 -0700140TEST_F(MAYBE_FileRotatingStreamTest, EmptyWrite) {
tkchin93411912015-07-22 12:12:17 -0700141 Init("FileRotatingStreamTestEmptyWrite", kFilePrefix, kMaxFileSize, 3);
142
143 ASSERT_TRUE(stream_->Open());
144 WriteAndFlush("a", 0);
145
146 std::string logfile_path = stream_->GetFilePath(0);
nisse21083262017-05-31 02:07:21 -0700147 FileStream stream;
148 ASSERT_TRUE(stream.Open(logfile_path, "r", nullptr));
tkchin93411912015-07-22 12:12:17 -0700149 size_t file_size = 0;
nisse21083262017-05-31 02:07:21 -0700150 EXPECT_TRUE(stream.GetSize(&file_size));
tkchin93411912015-07-22 12:12:17 -0700151 EXPECT_EQ(0u, file_size);
152}
153
154// Tests that a write operation followed by a read returns the expected data
155// and writes to the expected files.
phoglundbb738732016-07-15 03:57:12 -0700156TEST_F(MAYBE_FileRotatingStreamTest, WriteAndRead) {
tkchin93411912015-07-22 12:12:17 -0700157 Init("FileRotatingStreamTestWriteAndRead", kFilePrefix, kMaxFileSize, 3);
158
159 ASSERT_TRUE(stream_->Open());
160 // The test is set up to create three log files of length 2. Write and check
161 // contents.
162 std::string messages[3] = {"aa", "bb", "cc"};
163 for (size_t i = 0; i < arraysize(messages); ++i) {
164 const std::string& message = messages[i];
165 WriteAndFlush(message.c_str(), message.size());
166 // Since the max log size is 2, we will be causing rotation. Read from the
167 // next file.
168 VerifyFileContents(message.c_str(), message.size(),
169 stream_->GetFilePath(1));
170 }
171 // Check that exactly three files exist.
172 for (size_t i = 0; i < arraysize(messages); ++i) {
Niels Möller260770c2018-11-07 15:08:18 +0100173 EXPECT_TRUE(webrtc::test::FileExists(stream_->GetFilePath(i)));
tkchin93411912015-07-22 12:12:17 -0700174 }
175 std::string message("d");
176 WriteAndFlush(message.c_str(), message.size());
177 for (size_t i = 0; i < arraysize(messages); ++i) {
Niels Möller260770c2018-11-07 15:08:18 +0100178 EXPECT_TRUE(webrtc::test::FileExists(stream_->GetFilePath(i)));
tkchin93411912015-07-22 12:12:17 -0700179 }
180 // TODO(tkchin): Maybe check all the files in the dir.
181
182 // Reopen for read.
183 std::string expected_contents("bbccd");
184 VerifyStreamRead(expected_contents.c_str(), expected_contents.size(),
185 dir_path_, kFilePrefix);
186}
187
Niels Möller7b3c76b2018-11-07 09:54:28 +0100188// Tests that a write operation (with dir name without delimiter) followed by a
189// read returns the expected data and writes to the expected files.
190TEST_F(MAYBE_FileRotatingStreamTest, WriteWithoutDelimiterAndRead) {
191 Init("FileRotatingStreamTestWriteWithoutDelimiterAndRead", kFilePrefix,
192 kMaxFileSize, 3,
193 /* ensure_trailing_delimiter*/ false);
194
195 ASSERT_TRUE(stream_->Open());
196 // The test is set up to create three log files of length 2. Write and check
197 // contents.
198 std::string messages[3] = {"aa", "bb", "cc"};
199 for (size_t i = 0; i < arraysize(messages); ++i) {
200 const std::string& message = messages[i];
201 WriteAndFlush(message.c_str(), message.size());
202 }
203 std::string message("d");
204 WriteAndFlush(message.c_str(), message.size());
205
206 // Reopen for read.
207 std::string expected_contents("bbccd");
208 VerifyStreamRead(expected_contents.c_str(), expected_contents.size(),
209 dir_path_ + webrtc::test::kPathDelimiter, kFilePrefix);
210}
211
212// Tests that a write operation followed by a read (without trailing delimiter)
213// returns the expected data and writes to the expected files.
214TEST_F(MAYBE_FileRotatingStreamTest, WriteAndReadWithoutDelimiter) {
215 Init("FileRotatingStreamTestWriteAndReadWithoutDelimiter", kFilePrefix,
216 kMaxFileSize, 3);
217
218 ASSERT_TRUE(stream_->Open());
219 // The test is set up to create three log files of length 2. Write and check
220 // contents.
221 std::string messages[3] = {"aa", "bb", "cc"};
222 for (size_t i = 0; i < arraysize(messages); ++i) {
223 const std::string& message = messages[i];
224 WriteAndFlush(message.c_str(), message.size());
225 }
226 std::string message("d");
227 WriteAndFlush(message.c_str(), message.size());
228
229 // Reopen for read.
230 std::string expected_contents("bbccd");
231 VerifyStreamRead(expected_contents.c_str(), expected_contents.size(),
232 dir_path_.substr(0, dir_path_.size() - 1), kFilePrefix);
233}
234
tkchin93411912015-07-22 12:12:17 -0700235// Tests that writing data greater than the total capacity of the files
236// overwrites the files correctly and is read correctly after.
phoglundbb738732016-07-15 03:57:12 -0700237TEST_F(MAYBE_FileRotatingStreamTest, WriteOverflowAndRead) {
tkchin93411912015-07-22 12:12:17 -0700238 Init("FileRotatingStreamTestWriteOverflowAndRead", kFilePrefix, kMaxFileSize,
239 3);
240 ASSERT_TRUE(stream_->Open());
241 // This should cause overflow across all three files, such that the first file
242 // we wrote to also gets overwritten.
243 std::string message("foobarbaz");
244 WriteAndFlush(message.c_str(), message.size());
245 std::string expected_file_contents("z");
246 VerifyFileContents(expected_file_contents.c_str(),
247 expected_file_contents.size(), stream_->GetFilePath(0));
248 std::string expected_stream_contents("arbaz");
249 VerifyStreamRead(expected_stream_contents.c_str(),
250 expected_stream_contents.size(), dir_path_, kFilePrefix);
251}
252
253// Tests that the returned file paths have the right folder and prefix.
phoglundbb738732016-07-15 03:57:12 -0700254TEST_F(MAYBE_FileRotatingStreamTest, GetFilePath) {
tkchin93411912015-07-22 12:12:17 -0700255 Init("FileRotatingStreamTestGetFilePath", kFilePrefix, kMaxFileSize, 20);
Niels Möller394b4eb2018-06-01 14:08:25 +0200256 // dir_path_ includes a trailing delimiter.
257 const std::string prefix = dir_path_ + kFilePrefix;
tkchin93411912015-07-22 12:12:17 -0700258 for (auto i = 0; i < 20; ++i) {
Niels Möller394b4eb2018-06-01 14:08:25 +0200259 EXPECT_EQ(0, stream_->GetFilePath(i).compare(0, prefix.size(), prefix));
tkchin93411912015-07-22 12:12:17 -0700260 }
261}
262
Yves Gerey665174f2018-06-19 15:03:05 +0200263#if defined(WEBRTC_ANDROID)
phoglundbb738732016-07-15 03:57:12 -0700264// Fails on Android: https://bugs.chromium.org/p/webrtc/issues/detail?id=4364.
265#define MAYBE_CallSessionFileRotatingStreamTest \
Yves Gerey665174f2018-06-19 15:03:05 +0200266 DISABLED_CallSessionFileRotatingStreamTest
phoglundbb738732016-07-15 03:57:12 -0700267#else
268#define MAYBE_CallSessionFileRotatingStreamTest \
Yves Gerey665174f2018-06-19 15:03:05 +0200269 CallSessionFileRotatingStreamTest
phoglundbb738732016-07-15 03:57:12 -0700270#endif
271
272class MAYBE_CallSessionFileRotatingStreamTest : public ::testing::Test {
tkchin93411912015-07-22 12:12:17 -0700273 protected:
274 void Init(const std::string& dir_name, size_t max_total_log_size) {
nisse57efb032017-05-18 03:55:59 -0700275 dir_path_ = webrtc::test::OutputPath();
276
tkchin93411912015-07-22 12:12:17 -0700277 // Append per-test output path in order to run within gtest parallel.
nisse57efb032017-05-18 03:55:59 -0700278 dir_path_.append(dir_name);
Niels Möller7b3c76b2018-11-07 09:54:28 +0100279 dir_path_.append(webrtc::test::kPathDelimiter);
nisse57efb032017-05-18 03:55:59 -0700280 ASSERT_TRUE(webrtc::test::CreateDir(dir_path_));
tkchin93411912015-07-22 12:12:17 -0700281 stream_.reset(
282 new CallSessionFileRotatingStream(dir_path_, max_total_log_size));
283 }
284
Steve Anton9de3aac2017-10-24 10:08:26 -0700285 void TearDown() override {
nisse57efb032017-05-18 03:55:59 -0700286 // On windows, open files can't be removed.
287 stream_->Close();
288 CleanupLogDirectory(*stream_);
289 EXPECT_TRUE(webrtc::test::RemoveDir(dir_path_));
290
tkchin93411912015-07-22 12:12:17 -0700291 stream_.reset();
tkchin93411912015-07-22 12:12:17 -0700292 }
293
294 // Writes the data to the stream and flushes it.
295 void WriteAndFlush(const void* data, const size_t data_len) {
296 EXPECT_EQ(SR_SUCCESS, stream_->WriteAll(data, data_len, nullptr, nullptr));
297 EXPECT_TRUE(stream_->Flush());
298 }
299
300 // Checks that the stream reads in the expected contents and then returns an
301 // end of stream result.
302 void VerifyStreamRead(const char* expected_contents,
303 const size_t expected_length,
304 const std::string& dir_path) {
Niels Möllerd9ac0582019-01-03 14:21:38 +0100305 // TODO(nisse): Delete the part of this method using read-mode
306 // CallSessionFileRotatingStream, together with support for read-mode.
jbauch555604a2016-04-26 03:13:22 -0700307 std::unique_ptr<CallSessionFileRotatingStream> stream(
tkchin93411912015-07-22 12:12:17 -0700308 new CallSessionFileRotatingStream(dir_path));
309 ASSERT_TRUE(stream->Open());
tkchin28bae022015-07-23 12:27:02 -0700310 size_t read = 0;
311 size_t stream_size = 0;
312 EXPECT_TRUE(stream->GetSize(&stream_size));
jbauch555604a2016-04-26 03:13:22 -0700313 std::unique_ptr<uint8_t[]> buffer(new uint8_t[expected_length]);
tkchin93411912015-07-22 12:12:17 -0700314 EXPECT_EQ(SR_SUCCESS,
tkchin28bae022015-07-23 12:27:02 -0700315 stream->ReadAll(buffer.get(), expected_length, &read, nullptr));
tkchin93411912015-07-22 12:12:17 -0700316 EXPECT_EQ(0, memcmp(expected_contents, buffer.get(), expected_length));
317 EXPECT_EQ(SR_EOS, stream->ReadAll(buffer.get(), 1, nullptr, nullptr));
tkchin28bae022015-07-23 12:27:02 -0700318 EXPECT_EQ(stream_size, read);
Niels Möllerd9ac0582019-01-03 14:21:38 +0100319
320 // Test also with the CallSessionFileRotatingStreamReader class.
321 CallSessionFileRotatingStreamReader reader(dir_path);
322 EXPECT_EQ(reader.GetSize(), expected_length);
323 memset(buffer.get(), 0, expected_length);
324 EXPECT_EQ(expected_length, reader.ReadAll(buffer.get(), expected_length));
325 EXPECT_EQ(0, memcmp(expected_contents, buffer.get(), expected_length));
tkchin93411912015-07-22 12:12:17 -0700326 }
327
jbauch555604a2016-04-26 03:13:22 -0700328 std::unique_ptr<CallSessionFileRotatingStream> stream_;
tkchin93411912015-07-22 12:12:17 -0700329 std::string dir_path_;
330};
331
332// Tests that writing and reading to a stream with the smallest possible
333// capacity works.
phoglundbb738732016-07-15 03:57:12 -0700334TEST_F(MAYBE_CallSessionFileRotatingStreamTest, WriteAndReadSmallest) {
tkchin93411912015-07-22 12:12:17 -0700335 Init("CallSessionFileRotatingStreamTestWriteAndReadSmallest", 4);
336
337 ASSERT_TRUE(stream_->Open());
338 std::string message("abcde");
339 WriteAndFlush(message.c_str(), message.size());
340 std::string expected_contents("abe");
341 VerifyStreamRead(expected_contents.c_str(), expected_contents.size(),
342 dir_path_);
343}
344
345// Tests that writing and reading to a stream with capacity lesser than 4MB
346// behaves correctly.
phoglundbb738732016-07-15 03:57:12 -0700347TEST_F(MAYBE_CallSessionFileRotatingStreamTest, WriteAndReadSmall) {
tkchin93411912015-07-22 12:12:17 -0700348 Init("CallSessionFileRotatingStreamTestWriteAndReadSmall", 8);
349
350 ASSERT_TRUE(stream_->Open());
351 std::string message("123456789");
352 WriteAndFlush(message.c_str(), message.size());
353 std::string expected_contents("1234789");
354 VerifyStreamRead(expected_contents.c_str(), expected_contents.size(),
355 dir_path_);
356}
357
358// Tests that writing and reading to a stream with capacity greater than 4MB
359// behaves correctly.
phoglundbb738732016-07-15 03:57:12 -0700360TEST_F(MAYBE_CallSessionFileRotatingStreamTest, WriteAndReadLarge) {
tkchin93411912015-07-22 12:12:17 -0700361 Init("CallSessionFileRotatingStreamTestWriteAndReadLarge", 6 * 1024 * 1024);
362
363 ASSERT_TRUE(stream_->Open());
364 const size_t buffer_size = 1024 * 1024;
jbauch555604a2016-04-26 03:13:22 -0700365 std::unique_ptr<uint8_t[]> buffer(new uint8_t[buffer_size]);
tkchin93411912015-07-22 12:12:17 -0700366 for (int i = 0; i < 8; i++) {
367 memset(buffer.get(), i, buffer_size);
368 EXPECT_EQ(SR_SUCCESS,
369 stream_->WriteAll(buffer.get(), buffer_size, nullptr, nullptr));
370 }
371
372 stream_.reset(new CallSessionFileRotatingStream(dir_path_));
373 ASSERT_TRUE(stream_->Open());
jbauch555604a2016-04-26 03:13:22 -0700374 std::unique_ptr<uint8_t[]> expected_buffer(new uint8_t[buffer_size]);
tkchin93411912015-07-22 12:12:17 -0700375 int expected_vals[] = {0, 1, 2, 6, 7};
376 for (size_t i = 0; i < arraysize(expected_vals); ++i) {
377 memset(expected_buffer.get(), expected_vals[i], buffer_size);
378 EXPECT_EQ(SR_SUCCESS,
379 stream_->ReadAll(buffer.get(), buffer_size, nullptr, nullptr));
380 EXPECT_EQ(0, memcmp(buffer.get(), expected_buffer.get(), buffer_size));
381 }
382 EXPECT_EQ(SR_EOS, stream_->ReadAll(buffer.get(), 1, nullptr, nullptr));
383}
384
385// Tests that writing and reading to a stream where only the first file is
386// written to behaves correctly.
phoglundbb738732016-07-15 03:57:12 -0700387TEST_F(MAYBE_CallSessionFileRotatingStreamTest, WriteAndReadFirstHalf) {
tkchin93411912015-07-22 12:12:17 -0700388 Init("CallSessionFileRotatingStreamTestWriteAndReadFirstHalf",
389 6 * 1024 * 1024);
390 ASSERT_TRUE(stream_->Open());
391 const size_t buffer_size = 1024 * 1024;
jbauch555604a2016-04-26 03:13:22 -0700392 std::unique_ptr<uint8_t[]> buffer(new uint8_t[buffer_size]);
tkchin93411912015-07-22 12:12:17 -0700393 for (int i = 0; i < 2; i++) {
394 memset(buffer.get(), i, buffer_size);
395 EXPECT_EQ(SR_SUCCESS,
396 stream_->WriteAll(buffer.get(), buffer_size, nullptr, nullptr));
397 }
398
399 stream_.reset(new CallSessionFileRotatingStream(dir_path_));
400 ASSERT_TRUE(stream_->Open());
jbauch555604a2016-04-26 03:13:22 -0700401 std::unique_ptr<uint8_t[]> expected_buffer(new uint8_t[buffer_size]);
tkchin93411912015-07-22 12:12:17 -0700402 int expected_vals[] = {0, 1};
403 for (size_t i = 0; i < arraysize(expected_vals); ++i) {
404 memset(expected_buffer.get(), expected_vals[i], buffer_size);
405 EXPECT_EQ(SR_SUCCESS,
406 stream_->ReadAll(buffer.get(), buffer_size, nullptr, nullptr));
407 EXPECT_EQ(0, memcmp(buffer.get(), expected_buffer.get(), buffer_size));
408 }
409 EXPECT_EQ(SR_EOS, stream_->ReadAll(buffer.get(), 1, nullptr, nullptr));
410}
411
412} // namespace rtc