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