Vitaly Buka | 4615e0d | 2015-10-14 15:35:12 -0700 | [diff] [blame] | 1 | // Copyright 2015 The Weave Authors. All rights reserved. |
Vitaly Buka | ff32458 | 2015-10-08 13:37:53 -0700 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "src/streams.h" |
| 6 | |
| 7 | #include <functional> |
| 8 | #include <gmock/gmock.h> |
| 9 | #include <gtest/gtest.h> |
| 10 | #include <weave/provider/test/fake_task_runner.h> |
| 11 | |
| 12 | #include <src/bind_lambda.h> |
| 13 | |
| 14 | namespace weave { |
| 15 | |
| 16 | TEST(Stream, CopyStreams) { |
| 17 | provider::test::FakeTaskRunner task_runner; |
| 18 | std::vector<uint8_t> test_data(1024 * 1024); |
| 19 | for (size_t i = 0; i < test_data.size(); ++i) |
| 20 | test_data[i] = static_cast<uint8_t>(std::hash<size_t>()(i)); |
| 21 | MemoryStream source{test_data, &task_runner}; |
| 22 | MemoryStream destination{{}, &task_runner}; |
| 23 | |
| 24 | bool done = false; |
| 25 | |
Vitaly Buka | 7476342 | 2015-10-11 00:39:52 -0700 | [diff] [blame] | 26 | auto callback = base::Bind( |
| 27 | [&test_data, &done, &destination](size_t size, ErrorPtr error) { |
| 28 | EXPECT_FALSE(error); |
| 29 | done = true; |
| 30 | EXPECT_EQ(test_data, destination.GetData()); |
| 31 | }); |
Vitaly Buka | ff32458 | 2015-10-08 13:37:53 -0700 | [diff] [blame] | 32 | StreamCopier copier{&source, &destination}; |
Vitaly Buka | 7476342 | 2015-10-11 00:39:52 -0700 | [diff] [blame] | 33 | copier.Copy(callback); |
Vitaly Buka | ff32458 | 2015-10-08 13:37:53 -0700 | [diff] [blame] | 34 | |
| 35 | task_runner.Run(test_data.size()); |
| 36 | EXPECT_TRUE(done); |
| 37 | } |
| 38 | |
| 39 | } // namespace weave |