OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/callback.h" | 6 #include "base/callback.h" |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "mojo/public/cpp/bindings/binding_set.h" | 10 #include "mojo/public/cpp/bindings/binding_set.h" |
11 #include "mojo/public/cpp/bindings/interface_request.h" | 11 #include "mojo/public/cpp/bindings/interface_request.h" |
12 #include "mojo/public/cpp/bindings/tests/rect_blink.h" | 12 #include "mojo/public/cpp/bindings/tests/rect_blink.h" |
13 #include "mojo/public/cpp/bindings/tests/rect_chromium.h" | 13 #include "mojo/public/cpp/bindings/tests/rect_chromium.h" |
14 #include "mojo/public/cpp/bindings/tests/struct_with_traits_impl.h" | 14 #include "mojo/public/cpp/bindings/tests/struct_with_traits_impl.h" |
| 15 #include "mojo/public/cpp/bindings/tests/struct_with_traits_impl_traits.h" |
15 #include "mojo/public/cpp/bindings/tests/variant_test_util.h" | 16 #include "mojo/public/cpp/bindings/tests/variant_test_util.h" |
16 #include "mojo/public/interfaces/bindings/tests/struct_with_traits.mojom.h" | 17 #include "mojo/public/interfaces/bindings/tests/struct_with_traits.mojom.h" |
17 #include "mojo/public/interfaces/bindings/tests/test_native_types.mojom-blink.h" | 18 #include "mojo/public/interfaces/bindings/tests/test_native_types.mojom-blink.h" |
18 #include "mojo/public/interfaces/bindings/tests/test_native_types.mojom.h" | 19 #include "mojo/public/interfaces/bindings/tests/test_native_types.mojom.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
20 | 21 |
21 namespace mojo { | 22 namespace mojo { |
22 namespace test { | 23 namespace test { |
23 namespace { | 24 namespace { |
24 | 25 |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 TraitsTestServicePtr proxy = GetTraitsTestProxy(); | 305 TraitsTestServicePtr proxy = GetTraitsTestProxy(); |
305 | 306 |
306 proxy->EchoEnumWithTraits( | 307 proxy->EchoEnumWithTraits( |
307 EnumWithTraitsImpl::CUSTOM_VALUE_1, [&](EnumWithTraitsImpl passed) { | 308 EnumWithTraitsImpl::CUSTOM_VALUE_1, [&](EnumWithTraitsImpl passed) { |
308 EXPECT_EQ(EnumWithTraitsImpl::CUSTOM_VALUE_1, passed); | 309 EXPECT_EQ(EnumWithTraitsImpl::CUSTOM_VALUE_1, passed); |
309 loop.Quit(); | 310 loop.Quit(); |
310 }); | 311 }); |
311 loop.Run(); | 312 loop.Run(); |
312 } | 313 } |
313 | 314 |
| 315 TEST_F(StructTraitsTest, SerializeStructWithTraits) { |
| 316 StructWithTraitsImpl input; |
| 317 input.set_enum(EnumWithTraitsImpl::CUSTOM_VALUE_1); |
| 318 input.set_bool(true); |
| 319 input.set_uint32(7); |
| 320 input.set_uint64(42); |
| 321 input.set_string("hello world!"); |
| 322 input.get_mutable_string_array().assign({"hello", "world!"}); |
| 323 input.get_mutable_struct().value = 42; |
| 324 input.get_mutable_struct_array().resize(2); |
| 325 input.get_mutable_struct_array()[0].value = 1; |
| 326 input.get_mutable_struct_array()[1].value = 2; |
| 327 input.get_mutable_struct_map()["hello"] = NestedStructWithTraitsImpl(1024); |
| 328 input.get_mutable_struct_map()["world"] = NestedStructWithTraitsImpl(2048); |
| 329 |
| 330 mojo::Array<uint8_t> data = StructWithTraits::Serialize(&input); |
| 331 StructWithTraitsImpl output; |
| 332 ASSERT_TRUE(StructWithTraits::Deserialize(std::move(data), &output)); |
| 333 |
| 334 EXPECT_EQ(input.get_enum(), output.get_enum()); |
| 335 EXPECT_EQ(input.get_bool(), output.get_bool()); |
| 336 EXPECT_EQ(input.get_uint32(), output.get_uint32()); |
| 337 EXPECT_EQ(input.get_uint64(), output.get_uint64()); |
| 338 EXPECT_EQ(input.get_string(), output.get_string()); |
| 339 EXPECT_EQ(input.get_string_array(), output.get_string_array()); |
| 340 EXPECT_EQ(input.get_struct(), output.get_struct()); |
| 341 EXPECT_EQ(input.get_struct_array(), output.get_struct_array()); |
| 342 EXPECT_EQ(input.get_struct_map(), output.get_struct_map()); |
| 343 } |
| 344 |
314 } // namespace test | 345 } // namespace test |
315 } // namespace mojo | 346 } // namespace mojo |
OLD | NEW |