1 // Copyright 2015 The Weave Authors. All rights reserved. 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 9 #include <gmock/gmock.h> 10 #include <gtest/gtest.h> 11 #include <weave/provider/test/fake_task_runner.h> 12 13 #include <src/bind_lambda.h> 14 15 namespace weave { 16 17 TEST(Stream, CopyStreams) { 18 provider::test::FakeTaskRunner task_runner; 19 std::vector<uint8_t> test_data(1024 * 1024); 20 for (size_t i = 0; i < test_data.size(); ++i) 21 test_data[i] = static_cast<uint8_t>(std::hash<size_t>()(i)); 22 MemoryStream source{test_data, &task_runner}; 23 MemoryStream destination{{}, &task_runner}; 24 25 bool done = false; 26 27 auto callback = base::Bind( 28 [&test_data, &done, &destination](size_t size, ErrorPtr error) { 29 EXPECT_FALSE(error); 30 done = true; 31 EXPECT_EQ(test_data, destination.GetData()); 32 }); 33 StreamCopier copier{&source, &destination}; 34 copier.Copy(callback); 35 36 task_runner.Run(test_data.size()); 37 EXPECT_TRUE(done); 38 } 39 40 } // namespace weave 41