blob: fba6ca58dec09fb92b509cdce51bd2665350c462 [file] [log] [blame]
Vitaly Buka4615e0d2015-10-14 15:35:12 -07001// Copyright 2015 The Weave Authors. All rights reserved.
Vitaly Bukaff324582015-10-08 13:37:53 -07002// 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
14namespace weave {
15
16TEST(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 Buka74763422015-10-11 00:39:52 -070026 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 Bukaff324582015-10-08 13:37:53 -070032 StreamCopier copier{&source, &destination};
Vitaly Buka74763422015-10-11 00:39:52 -070033 copier.Copy(callback);
Vitaly Bukaff324582015-10-08 13:37:53 -070034
35 task_runner.Run(test_data.size());
36 EXPECT_TRUE(done);
37}
38
39} // namespace weave