| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "mojo/public/cpp/bindings/array.h" | 5 #include "mojo/public/cpp/bindings/array.h" |
| 6 #include "mojo/public/cpp/bindings/lib/array_internal.h" | 6 #include "mojo/public/cpp/bindings/lib/array_internal.h" |
| 7 #include "mojo/public/cpp/bindings/lib/array_serialization.h" | 7 #include "mojo/public/cpp/bindings/lib/array_serialization.h" |
| 8 #include "mojo/public/cpp/bindings/lib/fixed_buffer.h" | 8 #include "mojo/public/cpp/bindings/lib/fixed_buffer.h" |
| 9 #include "mojo/public/cpp/bindings/tests/container_test_util.h" | 9 #include "mojo/public/cpp/bindings/tests/container_test_util.h" |
| 10 #include "mojo/public/cpp/bindings/tests/iterator_test_util.h" | 10 #include "mojo/public/cpp/bindings/tests/iterator_test_util.h" |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 EXPECT_TRUE(array[3].is_valid()); | 388 EXPECT_TRUE(array[3].is_valid()); |
| 389 } | 389 } |
| 390 | 390 |
| 391 TEST_F(ArrayTest, Serialization_StructWithArraysOfHandles) { | 391 TEST_F(ArrayTest, Serialization_StructWithArraysOfHandles) { |
| 392 StructWithHandles handles_struct; | 392 StructWithHandles handles_struct; |
| 393 MessagePipe handle_pair_0; | 393 MessagePipe handle_pair_0; |
| 394 } | 394 } |
| 395 | 395 |
| 396 // Test serializing and deserializing an Array<InterfacePtr>. | 396 // Test serializing and deserializing an Array<InterfacePtr>. |
| 397 TEST_F(ArrayTest, Serialization_ArrayOfInterfacePtr) { | 397 TEST_F(ArrayTest, Serialization_ArrayOfInterfacePtr) { |
| 398 auto iface_array = Array<TestInterfacePtr>::New(1); | 398 auto iface_array = Array<mojo::InterfaceHandle<TestInterface>>::New(1); |
| 399 size_t size = GetSerializedSize_(iface_array); | 399 size_t size = GetSerializedSize_(iface_array); |
| 400 EXPECT_EQ(8U // array header | 400 EXPECT_EQ(8U // array header |
| 401 + (8U * 1), // Interface_Data * number of elements | 401 + (8U * 1), // Interface_Data * number of elements |
| 402 size); | 402 size); |
| 403 | 403 |
| 404 FixedBufferForTesting buf(size * 3); | 404 FixedBufferForTesting buf(size * 3); |
| 405 Array_Data<mojo::internal::Interface_Data>* output = nullptr; | 405 Array_Data<mojo::internal::Interface_Data>* output = nullptr; |
| 406 | 406 |
| 407 // 1. Invalid InterfacePtr should fail serialization. | 407 // 1. Invalid InterfacePtr should fail serialization. |
| 408 ArrayValidateParams validate_non_nullable(1, false, nullptr); | 408 ArrayValidateParams validate_non_nullable(1, false, nullptr); |
| 409 EXPECT_EQ( | 409 EXPECT_EQ( |
| 410 mojo::internal::ValidationError::UNEXPECTED_INVALID_HANDLE, | 410 mojo::internal::ValidationError::UNEXPECTED_INVALID_HANDLE, |
| 411 SerializeArray_(&iface_array, &buf, &output, &validate_non_nullable)); | 411 SerializeArray_(&iface_array, &buf, &output, &validate_non_nullable)); |
| 412 EXPECT_FALSE(iface_array[0].is_bound()); | 412 EXPECT_FALSE(iface_array[0].is_valid()); |
| 413 | 413 |
| 414 // 2. Invalid InterfacePtr should pass if array elements are nullable. | 414 // 2. Invalid InterfacePtr should pass if array elements are nullable. |
| 415 ArrayValidateParams validate_nullable(1, true, nullptr); | 415 ArrayValidateParams validate_nullable(1, true, nullptr); |
| 416 EXPECT_EQ(mojo::internal::ValidationError::NONE, | 416 EXPECT_EQ(mojo::internal::ValidationError::NONE, |
| 417 SerializeArray_(&iface_array, &buf, &output, &validate_nullable)); | 417 SerializeArray_(&iface_array, &buf, &output, &validate_nullable)); |
| 418 EXPECT_FALSE(iface_array[0].is_bound()); | 418 EXPECT_FALSE(iface_array[0].is_valid()); |
| 419 | 419 |
| 420 // 3. Should serialize successfully if InterfacePtr is valid. | 420 // 3. Should serialize successfully if InterfacePtr is valid. |
| 421 TestInterfacePtr iface_ptr; | 421 TestInterfacePtr iface_ptr; |
| 422 auto iface_req = GetProxy(&iface_ptr); | 422 auto iface_req = GetProxy(&iface_ptr); |
| 423 | 423 |
| 424 iface_array[0] = iface_ptr.Pass(); | 424 iface_array[0] = iface_ptr.Pass(); |
| 425 EXPECT_TRUE(iface_array[0].is_bound()); | 425 EXPECT_TRUE(iface_array[0].is_valid()); |
| 426 | 426 |
| 427 EXPECT_EQ( | 427 EXPECT_EQ( |
| 428 mojo::internal::ValidationError::NONE, | 428 mojo::internal::ValidationError::NONE, |
| 429 SerializeArray_(&iface_array, &buf, &output, &validate_non_nullable)); | 429 SerializeArray_(&iface_array, &buf, &output, &validate_non_nullable)); |
| 430 EXPECT_FALSE(iface_array[0].is_bound()); | 430 EXPECT_FALSE(iface_array[0].is_valid()); |
| 431 | 431 |
| 432 Deserialize_(output, &iface_array); | 432 Deserialize_(output, &iface_array); |
| 433 EXPECT_TRUE(iface_array[0].is_bound()); | 433 EXPECT_TRUE(iface_array[0].is_valid()); |
| 434 } | 434 } |
| 435 | 435 |
| 436 // Test serializing and deserializing a struct with an Array<> of another struct | 436 // Test serializing and deserializing a struct with an Array<> of another struct |
| 437 // which has an InterfacePtr. | 437 // which has an InterfacePtr. |
| 438 TEST_F(ArrayTest, Serialization_StructWithArrayOfInterfacePtr) { | 438 TEST_F(ArrayTest, Serialization_StructWithArrayOfInterfacePtr) { |
| 439 StructWithInterfaceArray struct_arr_iface; | 439 StructWithInterfaceArray struct_arr_iface; |
| 440 struct_arr_iface.structs_array = Array<StructWithInterfacePtr>::New(1); | 440 struct_arr_iface.structs_array = Array<StructWithInterfacePtr>::New(1); |
| 441 struct_arr_iface.nullable_structs_array = | 441 struct_arr_iface.nullable_structs_array = |
| 442 Array<StructWithInterfacePtr>::New(1); | 442 Array<StructWithInterfacePtr>::New(1); |
| 443 | 443 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 461 Serialize_(&struct_arr_iface, &buf, &struct_arr_iface_data)); | 461 Serialize_(&struct_arr_iface, &buf, &struct_arr_iface_data)); |
| 462 | 462 |
| 463 // 2. Adding in a struct with a valid InterfacePtr<> will let it serialize. | 463 // 2. Adding in a struct with a valid InterfacePtr<> will let it serialize. |
| 464 TestInterfacePtr iface_ptr; | 464 TestInterfacePtr iface_ptr; |
| 465 auto iface_req = GetProxy(&iface_ptr); | 465 auto iface_req = GetProxy(&iface_ptr); |
| 466 | 466 |
| 467 StructWithInterfacePtr iface_struct(StructWithInterface::New()); | 467 StructWithInterfacePtr iface_struct(StructWithInterface::New()); |
| 468 iface_struct->iptr = iface_ptr.Pass(); | 468 iface_struct->iptr = iface_ptr.Pass(); |
| 469 | 469 |
| 470 struct_arr_iface.structs_array[0] = iface_struct.Pass(); | 470 struct_arr_iface.structs_array[0] = iface_struct.Pass(); |
| 471 ASSERT_TRUE(struct_arr_iface.structs_array[0]->iptr.is_bound()); | 471 ASSERT_TRUE(struct_arr_iface.structs_array[0]->iptr.is_valid()); |
| 472 EXPECT_EQ(mojo::internal::ValidationError::NONE, | 472 EXPECT_EQ(mojo::internal::ValidationError::NONE, |
| 473 Serialize_(&struct_arr_iface, &buf, &struct_arr_iface_data)); | 473 Serialize_(&struct_arr_iface, &buf, &struct_arr_iface_data)); |
| 474 | 474 |
| 475 EXPECT_FALSE(struct_arr_iface.structs_array[0]->iptr.is_bound()); | 475 EXPECT_FALSE(struct_arr_iface.structs_array[0]->iptr.is_valid()); |
| 476 | 476 |
| 477 Deserialize_(struct_arr_iface_data, &struct_arr_iface); | 477 Deserialize_(struct_arr_iface_data, &struct_arr_iface); |
| 478 EXPECT_TRUE(struct_arr_iface.structs_array[0]->iptr.is_bound()); | 478 EXPECT_TRUE(struct_arr_iface.structs_array[0]->iptr.is_valid()); |
| 479 } | 479 } |
| 480 | 480 |
| 481 // Test serializing and deserializing a struct with an Array<> of interface | 481 // Test serializing and deserializing a struct with an Array<> of interface |
| 482 // requests. | 482 // requests. |
| 483 TEST_F(ArrayTest, Serialization_StructWithArrayOfIntefaceRequest) { | 483 TEST_F(ArrayTest, Serialization_StructWithArrayOfIntefaceRequest) { |
| 484 StructWithInterfaceRequests struct_arr_iface_req; | 484 StructWithInterfaceRequests struct_arr_iface_req; |
| 485 struct_arr_iface_req.req_array = | 485 struct_arr_iface_req.req_array = |
| 486 Array<InterfaceRequest<TestInterface>>::New(1); | 486 Array<InterfaceRequest<TestInterface>>::New(1); |
| 487 struct_arr_iface_req.nullable_req_array = | 487 struct_arr_iface_req.nullable_req_array = |
| 488 Array<InterfaceRequest<TestInterface>>::New(1); | 488 Array<InterfaceRequest<TestInterface>>::New(1); |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 824 EXPECT_EQ(1, array3[1]->x); | 824 EXPECT_EQ(1, array3[1]->x); |
| 825 EXPECT_EQ(2, array3[1]->y); | 825 EXPECT_EQ(2, array3[1]->y); |
| 826 EXPECT_EQ(3, array3[1]->width); | 826 EXPECT_EQ(3, array3[1]->width); |
| 827 EXPECT_EQ(4, array3[1]->height); | 827 EXPECT_EQ(4, array3[1]->height); |
| 828 } | 828 } |
| 829 } | 829 } |
| 830 | 830 |
| 831 } // namespace | 831 } // namespace |
| 832 } // namespace test | 832 } // namespace test |
| 833 } // namespace mojo | 833 } // namespace mojo |
| OLD | NEW |