| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <memory> | 5 #include <memory> |
| 6 #include <string> | 6 #include <string> |
| 7 #include <unordered_map> | 7 #include <unordered_map> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 | 26 |
| 27 struct DataViewHolder { | 27 struct DataViewHolder { |
| 28 std::unique_ptr<TestStructDataView> data_view; | 28 std::unique_ptr<TestStructDataView> data_view; |
| 29 std::unique_ptr<mojo::internal::FixedBufferForTesting> buf; | 29 std::unique_ptr<mojo::internal::FixedBufferForTesting> buf; |
| 30 mojo::internal::SerializationContext context; | 30 mojo::internal::SerializationContext context; |
| 31 }; | 31 }; |
| 32 | 32 |
| 33 std::unique_ptr<DataViewHolder> SerializeTestStruct(TestStructPtr input) { | 33 std::unique_ptr<DataViewHolder> SerializeTestStruct(TestStructPtr input) { |
| 34 std::unique_ptr<DataViewHolder> result(new DataViewHolder); | 34 std::unique_ptr<DataViewHolder> result(new DataViewHolder); |
| 35 | 35 |
| 36 size_t size = mojo::internal::PrepareToSerialize<TestStructPtr>( | 36 size_t size = mojo::internal::PrepareToSerialize<TestStructDataView>( |
| 37 input, &result->context); | 37 input, &result->context); |
| 38 | 38 |
| 39 result->buf.reset(new mojo::internal::FixedBufferForTesting(size)); | 39 result->buf.reset(new mojo::internal::FixedBufferForTesting(size)); |
| 40 internal::TestStruct_Data* data = nullptr; | 40 internal::TestStruct_Data* data = nullptr; |
| 41 mojo::internal::Serialize<TestStructPtr>(input, result->buf.get(), &data, | 41 mojo::internal::Serialize<TestStructDataView>(input, result->buf.get(), &data, |
| 42 &result->context); | 42 &result->context); |
| 43 | 43 |
| 44 result->data_view.reset(new TestStructDataView(data, &result->context)); | 44 result->data_view.reset(new TestStructDataView(data, &result->context)); |
| 45 return result; | 45 return result; |
| 46 } | 46 } |
| 47 | 47 |
| 48 class TestInterfaceImpl : public TestInterface { | 48 class TestInterfaceImpl : public TestInterface { |
| 49 public: | 49 public: |
| 50 explicit TestInterfaceImpl(TestInterfaceRequest request) | 50 explicit TestInterfaceImpl(TestInterfaceRequest request) |
| 51 : binding_(this, std::move(request)) {} | 51 : binding_(this, std::move(request)) {} |
| 52 ~TestInterfaceImpl() override {} | 52 ~TestInterfaceImpl() override {} |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 TEST_F(DataViewTest, InterfaceArray) { | 168 TEST_F(DataViewTest, InterfaceArray) { |
| 169 TestInterfacePtr ptr; | 169 TestInterfacePtr ptr; |
| 170 TestInterfaceImpl impl(GetProxy(&ptr)); | 170 TestInterfaceImpl impl(GetProxy(&ptr)); |
| 171 | 171 |
| 172 TestStructPtr obj(TestStruct::New()); | 172 TestStructPtr obj(TestStruct::New()); |
| 173 obj->f_interface_array.push_back(std::move(ptr)); | 173 obj->f_interface_array.push_back(std::move(ptr)); |
| 174 | 174 |
| 175 auto data_view_holder = SerializeTestStruct(std::move(obj)); | 175 auto data_view_holder = SerializeTestStruct(std::move(obj)); |
| 176 auto& data_view = *data_view_holder->data_view; | 176 auto& data_view = *data_view_holder->data_view; |
| 177 | 177 |
| 178 ArrayDataView<TestInterfacePtr> array_data_view; | 178 ArrayDataView<TestInterfacePtrDataView> array_data_view; |
| 179 data_view.GetFInterfaceArrayDataView(&array_data_view); | 179 data_view.GetFInterfaceArrayDataView(&array_data_view); |
| 180 | 180 |
| 181 ASSERT_FALSE(array_data_view.is_null()); | 181 ASSERT_FALSE(array_data_view.is_null()); |
| 182 ASSERT_EQ(1u, array_data_view.size()); | 182 ASSERT_EQ(1u, array_data_view.size()); |
| 183 | 183 |
| 184 TestInterfacePtr ptr2 = array_data_view.Take(0); | 184 TestInterfacePtr ptr2 = array_data_view.Take<TestInterfacePtr>(0); |
| 185 ASSERT_TRUE(ptr2); | 185 ASSERT_TRUE(ptr2); |
| 186 int32_t result = 0; | 186 int32_t result = 0; |
| 187 ASSERT_TRUE(ptr2->Echo(42, &result)); | 187 ASSERT_TRUE(ptr2->Echo(42, &result)); |
| 188 EXPECT_EQ(42, result); | 188 EXPECT_EQ(42, result); |
| 189 } | 189 } |
| 190 | 190 |
| 191 TEST_F(DataViewTest, NestedArray) { | 191 TEST_F(DataViewTest, NestedArray) { |
| 192 TestStructPtr obj(TestStruct::New()); | 192 TestStructPtr obj(TestStruct::New()); |
| 193 obj->f_nested_array = {{3, 4}, {2}}; | 193 obj->f_nested_array = {{3, 4}, {2}}; |
| 194 | 194 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 | 294 |
| 295 TestUnionPtr union_ptr2; | 295 TestUnionPtr union_ptr2; |
| 296 ASSERT_TRUE(array_data_view.Read(0, &union_ptr2)); | 296 ASSERT_TRUE(array_data_view.Read(0, &union_ptr2)); |
| 297 ASSERT_TRUE(union_ptr2->is_f_int32()); | 297 ASSERT_TRUE(union_ptr2->is_f_int32()); |
| 298 EXPECT_EQ(1024, union_ptr2->get_f_int32()); | 298 EXPECT_EQ(1024, union_ptr2->get_f_int32()); |
| 299 } | 299 } |
| 300 | 300 |
| 301 } // namespace data_view | 301 } // namespace data_view |
| 302 } // namespace test | 302 } // namespace test |
| 303 } // namespace mojo | 303 } // namespace mojo |
| OLD | NEW |