Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(976)

Side by Side Diff: mojo/public/cpp/bindings/tests/union_unittest.cc

Issue 1535943002: Convert Pass()→std::move() in //mojo/public/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove self-move checks to avoid triggering clang warning. Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <utility>
5 #include <vector> 6 #include <vector>
6 7
7 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
8 #include "mojo/message_pump/message_pump_mojo.h" 9 #include "mojo/message_pump/message_pump_mojo.h"
9 #include "mojo/public/cpp/bindings/array.h" 10 #include "mojo/public/cpp/bindings/array.h"
10 #include "mojo/public/cpp/bindings/binding.h" 11 #include "mojo/public/cpp/bindings/binding.h"
11 #include "mojo/public/cpp/bindings/lib/array_internal.h" 12 #include "mojo/public/cpp/bindings/lib/array_internal.h"
12 #include "mojo/public/cpp/bindings/lib/array_serialization.h" 13 #include "mojo/public/cpp/bindings/lib/array_serialization.h"
13 #include "mojo/public/cpp/bindings/lib/bounds_checker.h" 14 #include "mojo/public/cpp/bindings/lib/bounds_checker.h"
14 #include "mojo/public/cpp/bindings/lib/fixed_buffer.h" 15 #include "mojo/public/cpp/bindings/lib/fixed_buffer.h"
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 117
117 TEST(UnionTest, PodSerialization) { 118 TEST(UnionTest, PodSerialization) {
118 PodUnionPtr pod1(PodUnion::New()); 119 PodUnionPtr pod1(PodUnion::New());
119 pod1->set_f_int8(10); 120 pod1->set_f_int8(10);
120 121
121 size_t size = GetSerializedSize_(pod1, false); 122 size_t size = GetSerializedSize_(pod1, false);
122 EXPECT_EQ(16U, size); 123 EXPECT_EQ(16U, size);
123 124
124 mojo::internal::FixedBufferForTesting buf(size); 125 mojo::internal::FixedBufferForTesting buf(size);
125 internal::PodUnion_Data* data = nullptr; 126 internal::PodUnion_Data* data = nullptr;
126 SerializeUnion_(pod1.Pass(), &buf, &data, false); 127 SerializeUnion_(std::move(pod1), &buf, &data, false);
127 128
128 PodUnionPtr pod2; 129 PodUnionPtr pod2;
129 Deserialize_(data, &pod2, nullptr); 130 Deserialize_(data, &pod2, nullptr);
130 131
131 EXPECT_EQ(10, pod2->get_f_int8()); 132 EXPECT_EQ(10, pod2->get_f_int8());
132 EXPECT_TRUE(pod2->is_f_int8()); 133 EXPECT_TRUE(pod2->is_f_int8());
133 EXPECT_EQ(pod2->which(), PodUnion::Tag::F_INT8); 134 EXPECT_EQ(pod2->which(), PodUnion::Tag::F_INT8);
134 } 135 }
135 136
136 TEST(UnionTest, EnumSerialization) { 137 TEST(UnionTest, EnumSerialization) {
137 PodUnionPtr pod1(PodUnion::New()); 138 PodUnionPtr pod1(PodUnion::New());
138 pod1->set_f_enum(AN_ENUM_SECOND); 139 pod1->set_f_enum(AN_ENUM_SECOND);
139 140
140 size_t size = GetSerializedSize_(pod1, false); 141 size_t size = GetSerializedSize_(pod1, false);
141 EXPECT_EQ(16U, size); 142 EXPECT_EQ(16U, size);
142 143
143 mojo::internal::FixedBufferForTesting buf(size); 144 mojo::internal::FixedBufferForTesting buf(size);
144 internal::PodUnion_Data* data = nullptr; 145 internal::PodUnion_Data* data = nullptr;
145 SerializeUnion_(pod1.Pass(), &buf, &data, false); 146 SerializeUnion_(std::move(pod1), &buf, &data, false);
146 147
147 PodUnionPtr pod2; 148 PodUnionPtr pod2;
148 Deserialize_(data, &pod2, nullptr); 149 Deserialize_(data, &pod2, nullptr);
149 150
150 EXPECT_EQ(AN_ENUM_SECOND, pod2->get_f_enum()); 151 EXPECT_EQ(AN_ENUM_SECOND, pod2->get_f_enum());
151 EXPECT_TRUE(pod2->is_f_enum()); 152 EXPECT_TRUE(pod2->is_f_enum());
152 EXPECT_EQ(pod2->which(), PodUnion::Tag::F_ENUM); 153 EXPECT_EQ(pod2->which(), PodUnion::Tag::F_ENUM);
153 } 154 }
154 155
155 TEST(UnionTest, PodValidation) { 156 TEST(UnionTest, PodValidation) {
156 PodUnionPtr pod(PodUnion::New()); 157 PodUnionPtr pod(PodUnion::New());
157 pod->set_f_int8(10); 158 pod->set_f_int8(10);
158 159
159 size_t size = GetSerializedSize_(pod, false); 160 size_t size = GetSerializedSize_(pod, false);
160 EXPECT_EQ(16U, size); 161 EXPECT_EQ(16U, size);
161 162
162 mojo::internal::FixedBufferForTesting buf(size); 163 mojo::internal::FixedBufferForTesting buf(size);
163 internal::PodUnion_Data* data = nullptr; 164 internal::PodUnion_Data* data = nullptr;
164 SerializeUnion_(pod.Pass(), &buf, &data, false); 165 SerializeUnion_(std::move(pod), &buf, &data, false);
165 std::vector<Handle> handles; 166 std::vector<Handle> handles;
166 data->EncodePointersAndHandles(&handles); 167 data->EncodePointersAndHandles(&handles);
167 EXPECT_TRUE(handles.empty()); 168 EXPECT_TRUE(handles.empty());
168 169
169 void* raw_buf = buf.Leak(); 170 void* raw_buf = buf.Leak();
170 mojo::internal::BoundsChecker bounds_checker(data, 171 mojo::internal::BoundsChecker bounds_checker(data,
171 static_cast<uint32_t>(size), 0); 172 static_cast<uint32_t>(size), 0);
172 EXPECT_TRUE( 173 EXPECT_TRUE(
173 internal::PodUnion_Data::Validate(raw_buf, &bounds_checker, false)); 174 internal::PodUnion_Data::Validate(raw_buf, &bounds_checker, false));
174 free(raw_buf); 175 free(raw_buf);
175 } 176 }
176 177
177 TEST(UnionTest, SerializeNotNull) { 178 TEST(UnionTest, SerializeNotNull) {
178 PodUnionPtr pod(PodUnion::New()); 179 PodUnionPtr pod(PodUnion::New());
179 pod->set_f_int8(0); 180 pod->set_f_int8(0);
180 size_t size = GetSerializedSize_(pod, false); 181 size_t size = GetSerializedSize_(pod, false);
181 mojo::internal::FixedBufferForTesting buf(size); 182 mojo::internal::FixedBufferForTesting buf(size);
182 internal::PodUnion_Data* data = nullptr; 183 internal::PodUnion_Data* data = nullptr;
183 SerializeUnion_(pod.Pass(), &buf, &data, false); 184 SerializeUnion_(std::move(pod), &buf, &data, false);
184 EXPECT_FALSE(data->is_null()); 185 EXPECT_FALSE(data->is_null());
185 } 186 }
186 187
187 TEST(UnionTest, SerializeIsNullInlined) { 188 TEST(UnionTest, SerializeIsNullInlined) {
188 PodUnionPtr pod; 189 PodUnionPtr pod;
189 size_t size = GetSerializedSize_(pod, false); 190 size_t size = GetSerializedSize_(pod, false);
190 EXPECT_EQ(16U, size); 191 EXPECT_EQ(16U, size);
191 mojo::internal::FixedBufferForTesting buf(size); 192 mojo::internal::FixedBufferForTesting buf(size);
192 internal::PodUnion_Data* data = internal::PodUnion_Data::New(&buf); 193 internal::PodUnion_Data* data = internal::PodUnion_Data::New(&buf);
193 194
194 // Check that dirty output buffers are handled correctly by serialization. 195 // Check that dirty output buffers are handled correctly by serialization.
195 data->size = 16U; 196 data->size = 16U;
196 data->tag = PodUnion::Tag::F_UINT16; 197 data->tag = PodUnion::Tag::F_UINT16;
197 data->data.f_f_int16 = 20; 198 data->data.f_f_int16 = 20;
198 199
199 SerializeUnion_(pod.Pass(), &buf, &data, true); 200 SerializeUnion_(std::move(pod), &buf, &data, true);
200 EXPECT_TRUE(data->is_null()); 201 EXPECT_TRUE(data->is_null());
201 202
202 PodUnionPtr pod2; 203 PodUnionPtr pod2;
203 Deserialize_(data, &pod2, nullptr); 204 Deserialize_(data, &pod2, nullptr);
204 EXPECT_TRUE(pod2.is_null()); 205 EXPECT_TRUE(pod2.is_null());
205 } 206 }
206 207
207 TEST(UnionTest, SerializeIsNullNotInlined) { 208 TEST(UnionTest, SerializeIsNullNotInlined) {
208 PodUnionPtr pod; 209 PodUnionPtr pod;
209 size_t size = GetSerializedSize_(pod, false); 210 size_t size = GetSerializedSize_(pod, false);
210 EXPECT_EQ(16U, size); 211 EXPECT_EQ(16U, size);
211 mojo::internal::FixedBufferForTesting buf(size); 212 mojo::internal::FixedBufferForTesting buf(size);
212 internal::PodUnion_Data* data = nullptr; 213 internal::PodUnion_Data* data = nullptr;
213 SerializeUnion_(pod.Pass(), &buf, &data, false); 214 SerializeUnion_(std::move(pod), &buf, &data, false);
214 EXPECT_EQ(nullptr, data); 215 EXPECT_EQ(nullptr, data);
215 } 216 }
216 217
217 TEST(UnionTest, NullValidation) { 218 TEST(UnionTest, NullValidation) {
218 void* buf = nullptr; 219 void* buf = nullptr;
219 mojo::internal::BoundsChecker bounds_checker(buf, 0, 0); 220 mojo::internal::BoundsChecker bounds_checker(buf, 0, 0);
220 EXPECT_TRUE(internal::PodUnion_Data::Validate(buf, &bounds_checker, false)); 221 EXPECT_TRUE(internal::PodUnion_Data::Validate(buf, &bounds_checker, false));
221 } 222 }
222 223
223 TEST(UnionTest, OutOfAlignmentValidation) { 224 TEST(UnionTest, OutOfAlignmentValidation) {
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 296
296 TEST(UnionTest, StringSerialization) { 297 TEST(UnionTest, StringSerialization) {
297 ObjectUnionPtr pod1(ObjectUnion::New()); 298 ObjectUnionPtr pod1(ObjectUnion::New());
298 299
299 String hello("hello world"); 300 String hello("hello world");
300 pod1->set_f_string(hello); 301 pod1->set_f_string(hello);
301 302
302 size_t size = GetSerializedSize_(pod1, false); 303 size_t size = GetSerializedSize_(pod1, false);
303 mojo::internal::FixedBufferForTesting buf(size); 304 mojo::internal::FixedBufferForTesting buf(size);
304 internal::ObjectUnion_Data* data = nullptr; 305 internal::ObjectUnion_Data* data = nullptr;
305 SerializeUnion_(pod1.Pass(), &buf, &data, false); 306 SerializeUnion_(std::move(pod1), &buf, &data, false);
306 307
307 std::vector<Handle> handles; 308 std::vector<Handle> handles;
308 data->EncodePointersAndHandles(&handles); 309 data->EncodePointersAndHandles(&handles);
309 data->DecodePointersAndHandles(&handles); 310 data->DecodePointersAndHandles(&handles);
310 311
311 ObjectUnionPtr pod2; 312 ObjectUnionPtr pod2;
312 Deserialize_(data, &pod2, nullptr); 313 Deserialize_(data, &pod2, nullptr);
313 EXPECT_EQ(hello, pod2->get_f_string()); 314 EXPECT_EQ(hello, pod2->get_f_string());
314 EXPECT_TRUE(pod2->is_f_string()); 315 EXPECT_TRUE(pod2->is_f_string());
315 EXPECT_EQ(pod2->which(), ObjectUnion::Tag::F_STRING); 316 EXPECT_EQ(pod2->which(), ObjectUnion::Tag::F_STRING);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 array[0]->set_f_int8(10); 386 array[0]->set_f_int8(10);
386 array[1]->set_f_int16(12); 387 array[1]->set_f_int16(12);
387 EXPECT_EQ(2U, array.size()); 388 EXPECT_EQ(2U, array.size());
388 389
389 size_t size = GetSerializedSize_(array); 390 size_t size = GetSerializedSize_(array);
390 EXPECT_EQ(40U, size); 391 EXPECT_EQ(40U, size);
391 392
392 mojo::internal::FixedBufferForTesting buf(size); 393 mojo::internal::FixedBufferForTesting buf(size);
393 mojo::internal::Array_Data<internal::PodUnion_Data>* data; 394 mojo::internal::Array_Data<internal::PodUnion_Data>* data;
394 mojo::internal::ArrayValidateParams validate_params(0, false, nullptr); 395 mojo::internal::ArrayValidateParams validate_params(0, false, nullptr);
395 SerializeArray_(array.Pass(), &buf, &data, &validate_params); 396 SerializeArray_(std::move(array), &buf, &data, &validate_params);
396 397
397 Array<PodUnionPtr> array2; 398 Array<PodUnionPtr> array2;
398 Deserialize_(data, &array2, nullptr); 399 Deserialize_(data, &array2, nullptr);
399 400
400 EXPECT_EQ(2U, array2.size()); 401 EXPECT_EQ(2U, array2.size());
401 402
402 EXPECT_EQ(10, array2[0]->get_f_int8()); 403 EXPECT_EQ(10, array2[0]->get_f_int8());
403 EXPECT_EQ(12, array2[1]->get_f_int16()); 404 EXPECT_EQ(12, array2[1]->get_f_int16());
404 } 405 }
405 406
406 TEST(UnionTest, PodUnionInArraySerializationWithNull) { 407 TEST(UnionTest, PodUnionInArraySerializationWithNull) {
407 Array<PodUnionPtr> array(2); 408 Array<PodUnionPtr> array(2);
408 array[0] = PodUnion::New(); 409 array[0] = PodUnion::New();
409 410
410 array[0]->set_f_int8(10); 411 array[0]->set_f_int8(10);
411 EXPECT_EQ(2U, array.size()); 412 EXPECT_EQ(2U, array.size());
412 413
413 size_t size = GetSerializedSize_(array); 414 size_t size = GetSerializedSize_(array);
414 EXPECT_EQ(40U, size); 415 EXPECT_EQ(40U, size);
415 416
416 mojo::internal::FixedBufferForTesting buf(size); 417 mojo::internal::FixedBufferForTesting buf(size);
417 mojo::internal::Array_Data<internal::PodUnion_Data>* data; 418 mojo::internal::Array_Data<internal::PodUnion_Data>* data;
418 mojo::internal::ArrayValidateParams validate_params(0, true, nullptr); 419 mojo::internal::ArrayValidateParams validate_params(0, true, nullptr);
419 SerializeArray_(array.Pass(), &buf, &data, &validate_params); 420 SerializeArray_(std::move(array), &buf, &data, &validate_params);
420 421
421 Array<PodUnionPtr> array2; 422 Array<PodUnionPtr> array2;
422 Deserialize_(data, &array2, nullptr); 423 Deserialize_(data, &array2, nullptr);
423 424
424 EXPECT_EQ(2U, array2.size()); 425 EXPECT_EQ(2U, array2.size());
425 426
426 EXPECT_EQ(10, array2[0]->get_f_int8()); 427 EXPECT_EQ(10, array2[0]->get_f_int8());
427 EXPECT_TRUE(array2[1].is_null()); 428 EXPECT_TRUE(array2[1].is_null());
428 } 429 }
429 430
(...skipping 11 matching lines...) Expand all
441 // Serialization test of a struct with a union of plain old data. 442 // Serialization test of a struct with a union of plain old data.
442 TEST(UnionTest, Serialization_UnionOfPods) { 443 TEST(UnionTest, Serialization_UnionOfPods) {
443 SmallStructPtr small_struct(SmallStruct::New()); 444 SmallStructPtr small_struct(SmallStruct::New());
444 small_struct->pod_union = PodUnion::New(); 445 small_struct->pod_union = PodUnion::New();
445 small_struct->pod_union->set_f_int32(10); 446 small_struct->pod_union->set_f_int32(10);
446 447
447 size_t size = GetSerializedSize_(small_struct); 448 size_t size = GetSerializedSize_(small_struct);
448 449
449 mojo::internal::FixedBufferForTesting buf(size); 450 mojo::internal::FixedBufferForTesting buf(size);
450 internal::SmallStruct_Data* data = nullptr; 451 internal::SmallStruct_Data* data = nullptr;
451 Serialize_(small_struct.Pass(), &buf, &data); 452 Serialize_(std::move(small_struct), &buf, &data);
452 453
453 SmallStructPtr deserialized; 454 SmallStructPtr deserialized;
454 Deserialize_(data, &deserialized, nullptr); 455 Deserialize_(data, &deserialized, nullptr);
455 456
456 EXPECT_EQ(10, deserialized->pod_union->get_f_int32()); 457 EXPECT_EQ(10, deserialized->pod_union->get_f_int32());
457 } 458 }
458 459
459 // Serialization test of a struct with a union of structs. 460 // Serialization test of a struct with a union of structs.
460 TEST(UnionTest, Serialization_UnionOfObjects) { 461 TEST(UnionTest, Serialization_UnionOfObjects) {
461 SmallObjStructPtr obj_struct(SmallObjStruct::New()); 462 SmallObjStructPtr obj_struct(SmallObjStruct::New());
462 obj_struct->obj_union = ObjectUnion::New(); 463 obj_struct->obj_union = ObjectUnion::New();
463 String hello("hello world"); 464 String hello("hello world");
464 obj_struct->obj_union->set_f_string(hello); 465 obj_struct->obj_union->set_f_string(hello);
465 466
466 size_t size = GetSerializedSize_(obj_struct); 467 size_t size = GetSerializedSize_(obj_struct);
467 468
468 mojo::internal::FixedBufferForTesting buf(size); 469 mojo::internal::FixedBufferForTesting buf(size);
469 internal::SmallObjStruct_Data* data = nullptr; 470 internal::SmallObjStruct_Data* data = nullptr;
470 Serialize_(obj_struct.Pass(), &buf, &data); 471 Serialize_(std::move(obj_struct), &buf, &data);
471 472
472 std::vector<Handle> handles; 473 std::vector<Handle> handles;
473 data->EncodePointersAndHandles(&handles); 474 data->EncodePointersAndHandles(&handles);
474 data->DecodePointersAndHandles(&handles); 475 data->DecodePointersAndHandles(&handles);
475 476
476 SmallObjStructPtr deserialized; 477 SmallObjStructPtr deserialized;
477 Deserialize_(data, &deserialized, nullptr); 478 Deserialize_(data, &deserialized, nullptr);
478 479
479 EXPECT_EQ(hello, deserialized->obj_union->get_f_string()); 480 EXPECT_EQ(hello, deserialized->obj_union->get_f_string());
480 } 481 }
481 482
482 // Validation test of a struct with a union. 483 // Validation test of a struct with a union.
483 TEST(UnionTest, Validation_UnionsInStruct) { 484 TEST(UnionTest, Validation_UnionsInStruct) {
484 SmallStructPtr small_struct(SmallStruct::New()); 485 SmallStructPtr small_struct(SmallStruct::New());
485 small_struct->pod_union = PodUnion::New(); 486 small_struct->pod_union = PodUnion::New();
486 small_struct->pod_union->set_f_int32(10); 487 small_struct->pod_union->set_f_int32(10);
487 488
488 size_t size = GetSerializedSize_(small_struct); 489 size_t size = GetSerializedSize_(small_struct);
489 490
490 mojo::internal::FixedBufferForTesting buf(size); 491 mojo::internal::FixedBufferForTesting buf(size);
491 internal::SmallStruct_Data* data = nullptr; 492 internal::SmallStruct_Data* data = nullptr;
492 Serialize_(small_struct.Pass(), &buf, &data); 493 Serialize_(std::move(small_struct), &buf, &data);
493 494
494 std::vector<Handle> handles; 495 std::vector<Handle> handles;
495 data->EncodePointersAndHandles(&handles); 496 data->EncodePointersAndHandles(&handles);
496 EXPECT_TRUE(handles.empty()); 497 EXPECT_TRUE(handles.empty());
497 498
498 void* raw_buf = buf.Leak(); 499 void* raw_buf = buf.Leak();
499 mojo::internal::BoundsChecker bounds_checker(data, 500 mojo::internal::BoundsChecker bounds_checker(data,
500 static_cast<uint32_t>(size), 0); 501 static_cast<uint32_t>(size), 0);
501 EXPECT_TRUE(internal::SmallStruct_Data::Validate(raw_buf, &bounds_checker)); 502 EXPECT_TRUE(internal::SmallStruct_Data::Validate(raw_buf, &bounds_checker));
502 free(raw_buf); 503 free(raw_buf);
503 } 504 }
504 505
505 // Validation test of a struct union fails due to unknown union tag. 506 // Validation test of a struct union fails due to unknown union tag.
506 TEST(UnionTest, Validation_PodUnionInStruct_Failure) { 507 TEST(UnionTest, Validation_PodUnionInStruct_Failure) {
507 SmallStructPtr small_struct(SmallStruct::New()); 508 SmallStructPtr small_struct(SmallStruct::New());
508 small_struct->pod_union = PodUnion::New(); 509 small_struct->pod_union = PodUnion::New();
509 small_struct->pod_union->set_f_int32(10); 510 small_struct->pod_union->set_f_int32(10);
510 511
511 size_t size = GetSerializedSize_(small_struct); 512 size_t size = GetSerializedSize_(small_struct);
512 513
513 mojo::internal::FixedBufferForTesting buf(size); 514 mojo::internal::FixedBufferForTesting buf(size);
514 internal::SmallStruct_Data* data = nullptr; 515 internal::SmallStruct_Data* data = nullptr;
515 Serialize_(small_struct.Pass(), &buf, &data); 516 Serialize_(std::move(small_struct), &buf, &data);
516 data->pod_union.tag = static_cast<internal::PodUnion_Data::PodUnion_Tag>(100); 517 data->pod_union.tag = static_cast<internal::PodUnion_Data::PodUnion_Tag>(100);
517 518
518 std::vector<Handle> handles; 519 std::vector<Handle> handles;
519 data->EncodePointersAndHandles(&handles); 520 data->EncodePointersAndHandles(&handles);
520 EXPECT_TRUE(handles.empty()); 521 EXPECT_TRUE(handles.empty());
521 522
522 void* raw_buf = buf.Leak(); 523 void* raw_buf = buf.Leak();
523 mojo::internal::BoundsChecker bounds_checker(data, 524 mojo::internal::BoundsChecker bounds_checker(data,
524 static_cast<uint32_t>(size), 0); 525 static_cast<uint32_t>(size), 0);
525 EXPECT_FALSE(internal::SmallStruct_Data::Validate(raw_buf, &bounds_checker)); 526 EXPECT_FALSE(internal::SmallStruct_Data::Validate(raw_buf, &bounds_checker));
(...skipping 20 matching lines...) Expand all
546 } 547 }
547 548
548 // Validation passes with nullable null union. 549 // Validation passes with nullable null union.
549 TEST(UnionTest, Validation_NullableUnion) { 550 TEST(UnionTest, Validation_NullableUnion) {
550 SmallStructPtr small_struct(SmallStruct::New()); 551 SmallStructPtr small_struct(SmallStruct::New());
551 552
552 size_t size = GetSerializedSize_(small_struct); 553 size_t size = GetSerializedSize_(small_struct);
553 554
554 mojo::internal::FixedBufferForTesting buf(size); 555 mojo::internal::FixedBufferForTesting buf(size);
555 internal::SmallStruct_Data* data = nullptr; 556 internal::SmallStruct_Data* data = nullptr;
556 Serialize_(small_struct.Pass(), &buf, &data); 557 Serialize_(std::move(small_struct), &buf, &data);
557 558
558 std::vector<Handle> handles; 559 std::vector<Handle> handles;
559 data->EncodePointersAndHandles(&handles); 560 data->EncodePointersAndHandles(&handles);
560 EXPECT_TRUE(handles.empty()); 561 EXPECT_TRUE(handles.empty());
561 562
562 void* raw_buf = buf.Leak(); 563 void* raw_buf = buf.Leak();
563 mojo::internal::BoundsChecker bounds_checker(data, 564 mojo::internal::BoundsChecker bounds_checker(data,
564 static_cast<uint32_t>(size), 0); 565 static_cast<uint32_t>(size), 0);
565 EXPECT_TRUE(internal::SmallStruct_Data::Validate(raw_buf, &bounds_checker)); 566 EXPECT_TRUE(internal::SmallStruct_Data::Validate(raw_buf, &bounds_checker));
566 free(raw_buf); 567 free(raw_buf);
(...skipping 22 matching lines...) Expand all
589 map["one"]->set_f_int8(8); 590 map["one"]->set_f_int8(8);
590 map["two"]->set_f_int16(16); 591 map["two"]->set_f_int16(16);
591 592
592 size_t size = GetSerializedSize_(map); 593 size_t size = GetSerializedSize_(map);
593 EXPECT_EQ(120U, size); 594 EXPECT_EQ(120U, size);
594 595
595 mojo::internal::FixedBufferForTesting buf(size); 596 mojo::internal::FixedBufferForTesting buf(size);
596 mojo::internal::Map_Data<mojo::internal::String_Data*, 597 mojo::internal::Map_Data<mojo::internal::String_Data*,
597 internal::PodUnion_Data>* data; 598 internal::PodUnion_Data>* data;
598 mojo::internal::ArrayValidateParams validate_params(0, false, nullptr); 599 mojo::internal::ArrayValidateParams validate_params(0, false, nullptr);
599 SerializeMap_(map.Pass(), &buf, &data, &validate_params); 600 SerializeMap_(std::move(map), &buf, &data, &validate_params);
600 601
601 Map<String, PodUnionPtr> map2; 602 Map<String, PodUnionPtr> map2;
602 Deserialize_(data, &map2, nullptr); 603 Deserialize_(data, &map2, nullptr);
603 604
604 EXPECT_EQ(8, map2["one"]->get_f_int8()); 605 EXPECT_EQ(8, map2["one"]->get_f_int8());
605 EXPECT_EQ(16, map2["two"]->get_f_int16()); 606 EXPECT_EQ(16, map2["two"]->get_f_int16());
606 } 607 }
607 608
608 TEST(UnionTest, PodUnionInMapSerializationWithNull) { 609 TEST(UnionTest, PodUnionInMapSerializationWithNull) {
609 Map<String, PodUnionPtr> map; 610 Map<String, PodUnionPtr> map;
610 map.insert("one", PodUnion::New()); 611 map.insert("one", PodUnion::New());
611 map.insert("two", nullptr); 612 map.insert("two", nullptr);
612 613
613 map["one"]->set_f_int8(8); 614 map["one"]->set_f_int8(8);
614 615
615 size_t size = GetSerializedSize_(map); 616 size_t size = GetSerializedSize_(map);
616 EXPECT_EQ(120U, size); 617 EXPECT_EQ(120U, size);
617 618
618 mojo::internal::FixedBufferForTesting buf(size); 619 mojo::internal::FixedBufferForTesting buf(size);
619 mojo::internal::Map_Data<mojo::internal::String_Data*, 620 mojo::internal::Map_Data<mojo::internal::String_Data*,
620 internal::PodUnion_Data>* data; 621 internal::PodUnion_Data>* data;
621 mojo::internal::ArrayValidateParams validate_params(0, true, nullptr); 622 mojo::internal::ArrayValidateParams validate_params(0, true, nullptr);
622 SerializeMap_(map.Pass(), &buf, &data, &validate_params); 623 SerializeMap_(std::move(map), &buf, &data, &validate_params);
623 624
624 Map<String, PodUnionPtr> map2; 625 Map<String, PodUnionPtr> map2;
625 Deserialize_(data, &map2, nullptr); 626 Deserialize_(data, &map2, nullptr);
626 627
627 EXPECT_EQ(8, map2["one"]->get_f_int8()); 628 EXPECT_EQ(8, map2["one"]->get_f_int8());
628 EXPECT_TRUE(map2["two"].is_null()); 629 EXPECT_TRUE(map2["two"].is_null());
629 } 630 }
630 631
631 TEST(UnionTest, StructInUnionGetterSetterPasser) { 632 TEST(UnionTest, StructInUnionGetterSetterPasser) {
632 DummyStructPtr dummy(DummyStruct::New()); 633 DummyStructPtr dummy(DummyStruct::New());
633 dummy->f_int8 = 8; 634 dummy->f_int8 = 8;
634 635
635 ObjectUnionPtr obj(ObjectUnion::New()); 636 ObjectUnionPtr obj(ObjectUnion::New());
636 obj->set_f_dummy(dummy.Pass()); 637 obj->set_f_dummy(std::move(dummy));
637 638
638 EXPECT_EQ(8, obj->get_f_dummy()->f_int8); 639 EXPECT_EQ(8, obj->get_f_dummy()->f_int8);
639 } 640 }
640 641
641 TEST(UnionTest, StructInUnionSerialization) { 642 TEST(UnionTest, StructInUnionSerialization) {
642 DummyStructPtr dummy(DummyStruct::New()); 643 DummyStructPtr dummy(DummyStruct::New());
643 dummy->f_int8 = 8; 644 dummy->f_int8 = 8;
644 645
645 ObjectUnionPtr obj(ObjectUnion::New()); 646 ObjectUnionPtr obj(ObjectUnion::New());
646 obj->set_f_dummy(dummy.Pass()); 647 obj->set_f_dummy(std::move(dummy));
647 648
648 size_t size = GetSerializedSize_(obj, false); 649 size_t size = GetSerializedSize_(obj, false);
649 EXPECT_EQ(32U, size); 650 EXPECT_EQ(32U, size);
650 651
651 mojo::internal::FixedBufferForTesting buf(size); 652 mojo::internal::FixedBufferForTesting buf(size);
652 internal::ObjectUnion_Data* data = nullptr; 653 internal::ObjectUnion_Data* data = nullptr;
653 SerializeUnion_(obj.Pass(), &buf, &data, false); 654 SerializeUnion_(std::move(obj), &buf, &data, false);
654 655
655 std::vector<Handle> handles; 656 std::vector<Handle> handles;
656 data->EncodePointersAndHandles(&handles); 657 data->EncodePointersAndHandles(&handles);
657 data->DecodePointersAndHandles(&handles); 658 data->DecodePointersAndHandles(&handles);
658 659
659 ObjectUnionPtr obj2; 660 ObjectUnionPtr obj2;
660 Deserialize_(data, &obj2, nullptr); 661 Deserialize_(data, &obj2, nullptr);
661 EXPECT_EQ(8, obj2->get_f_dummy()->f_int8); 662 EXPECT_EQ(8, obj2->get_f_dummy()->f_int8);
662 } 663 }
663 664
664 TEST(UnionTest, StructInUnionValidation) { 665 TEST(UnionTest, StructInUnionValidation) {
665 DummyStructPtr dummy(DummyStruct::New()); 666 DummyStructPtr dummy(DummyStruct::New());
666 dummy->f_int8 = 8; 667 dummy->f_int8 = 8;
667 668
668 ObjectUnionPtr obj(ObjectUnion::New()); 669 ObjectUnionPtr obj(ObjectUnion::New());
669 obj->set_f_dummy(dummy.Pass()); 670 obj->set_f_dummy(std::move(dummy));
670 671
671 size_t size = GetSerializedSize_(obj, false); 672 size_t size = GetSerializedSize_(obj, false);
672 673
673 mojo::internal::FixedBufferForTesting buf(size); 674 mojo::internal::FixedBufferForTesting buf(size);
674 internal::ObjectUnion_Data* data = nullptr; 675 internal::ObjectUnion_Data* data = nullptr;
675 SerializeUnion_(obj.Pass(), &buf, &data, false); 676 SerializeUnion_(std::move(obj), &buf, &data, false);
676 677
677 std::vector<Handle> handles; 678 std::vector<Handle> handles;
678 data->EncodePointersAndHandles(&handles); 679 data->EncodePointersAndHandles(&handles);
679 EXPECT_TRUE(handles.empty()); 680 EXPECT_TRUE(handles.empty());
680 681
681 void* raw_buf = buf.Leak(); 682 void* raw_buf = buf.Leak();
682 mojo::internal::BoundsChecker bounds_checker(data, 683 mojo::internal::BoundsChecker bounds_checker(data,
683 static_cast<uint32_t>(size), 0); 684 static_cast<uint32_t>(size), 0);
684 EXPECT_TRUE( 685 EXPECT_TRUE(
685 internal::ObjectUnion_Data::Validate(raw_buf, &bounds_checker, false)); 686 internal::ObjectUnion_Data::Validate(raw_buf, &bounds_checker, false));
686 free(raw_buf); 687 free(raw_buf);
687 } 688 }
688 689
689 TEST(UnionTest, StructInUnionValidationNonNullable) { 690 TEST(UnionTest, StructInUnionValidationNonNullable) {
690 DummyStructPtr dummy(nullptr); 691 DummyStructPtr dummy(nullptr);
691 692
692 ObjectUnionPtr obj(ObjectUnion::New()); 693 ObjectUnionPtr obj(ObjectUnion::New());
693 obj->set_f_dummy(dummy.Pass()); 694 obj->set_f_dummy(std::move(dummy));
694 695
695 size_t size = GetSerializedSize_(obj, false); 696 size_t size = GetSerializedSize_(obj, false);
696 697
697 mojo::internal::FixedBufferForTesting buf(size); 698 mojo::internal::FixedBufferForTesting buf(size);
698 internal::ObjectUnion_Data* data = nullptr; 699 internal::ObjectUnion_Data* data = nullptr;
699 SerializeUnion_(obj.Pass(), &buf, &data, false); 700 SerializeUnion_(std::move(obj), &buf, &data, false);
700 701
701 std::vector<Handle> handles; 702 std::vector<Handle> handles;
702 data->EncodePointersAndHandles(&handles); 703 data->EncodePointersAndHandles(&handles);
703 EXPECT_TRUE(handles.empty()); 704 EXPECT_TRUE(handles.empty());
704 705
705 void* raw_buf = buf.Leak(); 706 void* raw_buf = buf.Leak();
706 mojo::internal::BoundsChecker bounds_checker(data, 707 mojo::internal::BoundsChecker bounds_checker(data,
707 static_cast<uint32_t>(size), 0); 708 static_cast<uint32_t>(size), 0);
708 EXPECT_FALSE( 709 EXPECT_FALSE(
709 internal::ObjectUnion_Data::Validate(raw_buf, &bounds_checker, false)); 710 internal::ObjectUnion_Data::Validate(raw_buf, &bounds_checker, false));
710 free(raw_buf); 711 free(raw_buf);
711 } 712 }
712 713
713 TEST(UnionTest, StructInUnionValidationNullable) { 714 TEST(UnionTest, StructInUnionValidationNullable) {
714 DummyStructPtr dummy(nullptr); 715 DummyStructPtr dummy(nullptr);
715 716
716 ObjectUnionPtr obj(ObjectUnion::New()); 717 ObjectUnionPtr obj(ObjectUnion::New());
717 obj->set_f_nullable(dummy.Pass()); 718 obj->set_f_nullable(std::move(dummy));
718 719
719 size_t size = GetSerializedSize_(obj, false); 720 size_t size = GetSerializedSize_(obj, false);
720 721
721 mojo::internal::FixedBufferForTesting buf(size); 722 mojo::internal::FixedBufferForTesting buf(size);
722 internal::ObjectUnion_Data* data = nullptr; 723 internal::ObjectUnion_Data* data = nullptr;
723 SerializeUnion_(obj.Pass(), &buf, &data, false); 724 SerializeUnion_(std::move(obj), &buf, &data, false);
724 725
725 std::vector<Handle> handles; 726 std::vector<Handle> handles;
726 data->EncodePointersAndHandles(&handles); 727 data->EncodePointersAndHandles(&handles);
727 EXPECT_TRUE(handles.empty()); 728 EXPECT_TRUE(handles.empty());
728 729
729 void* raw_buf = buf.Leak(); 730 void* raw_buf = buf.Leak();
730 mojo::internal::BoundsChecker bounds_checker(data, 731 mojo::internal::BoundsChecker bounds_checker(data,
731 static_cast<uint32_t>(size), 0); 732 static_cast<uint32_t>(size), 0);
732 EXPECT_TRUE( 733 EXPECT_TRUE(
733 internal::ObjectUnion_Data::Validate(raw_buf, &bounds_checker, false)); 734 internal::ObjectUnion_Data::Validate(raw_buf, &bounds_checker, false));
734 free(raw_buf); 735 free(raw_buf);
735 } 736 }
736 737
737 TEST(UnionTest, ArrayInUnionGetterSetter) { 738 TEST(UnionTest, ArrayInUnionGetterSetter) {
738 Array<int8_t> array(2); 739 Array<int8_t> array(2);
739 array[0] = 8; 740 array[0] = 8;
740 array[1] = 9; 741 array[1] = 9;
741 742
742 ObjectUnionPtr obj(ObjectUnion::New()); 743 ObjectUnionPtr obj(ObjectUnion::New());
743 obj->set_f_array_int8(array.Pass()); 744 obj->set_f_array_int8(std::move(array));
744 745
745 EXPECT_EQ(8, obj->get_f_array_int8()[0]); 746 EXPECT_EQ(8, obj->get_f_array_int8()[0]);
746 EXPECT_EQ(9, obj->get_f_array_int8()[1]); 747 EXPECT_EQ(9, obj->get_f_array_int8()[1]);
747 } 748 }
748 749
749 TEST(UnionTest, ArrayInUnionSerialization) { 750 TEST(UnionTest, ArrayInUnionSerialization) {
750 Array<int8_t> array(2); 751 Array<int8_t> array(2);
751 array[0] = 8; 752 array[0] = 8;
752 array[1] = 9; 753 array[1] = 9;
753 754
754 ObjectUnionPtr obj(ObjectUnion::New()); 755 ObjectUnionPtr obj(ObjectUnion::New());
755 obj->set_f_array_int8(array.Pass()); 756 obj->set_f_array_int8(std::move(array));
756 757
757 size_t size = GetSerializedSize_(obj, false); 758 size_t size = GetSerializedSize_(obj, false);
758 EXPECT_EQ(32U, size); 759 EXPECT_EQ(32U, size);
759 760
760 mojo::internal::FixedBufferForTesting buf(size); 761 mojo::internal::FixedBufferForTesting buf(size);
761 internal::ObjectUnion_Data* data = nullptr; 762 internal::ObjectUnion_Data* data = nullptr;
762 SerializeUnion_(obj.Pass(), &buf, &data, false); 763 SerializeUnion_(std::move(obj), &buf, &data, false);
763 764
764 std::vector<Handle> handles; 765 std::vector<Handle> handles;
765 data->EncodePointersAndHandles(&handles); 766 data->EncodePointersAndHandles(&handles);
766 data->DecodePointersAndHandles(&handles); 767 data->DecodePointersAndHandles(&handles);
767 768
768 ObjectUnionPtr obj2; 769 ObjectUnionPtr obj2;
769 Deserialize_(data, &obj2, nullptr); 770 Deserialize_(data, &obj2, nullptr);
770 771
771 EXPECT_EQ(8, obj2->get_f_array_int8()[0]); 772 EXPECT_EQ(8, obj2->get_f_array_int8()[0]);
772 EXPECT_EQ(9, obj2->get_f_array_int8()[1]); 773 EXPECT_EQ(9, obj2->get_f_array_int8()[1]);
773 } 774 }
774 775
775 TEST(UnionTest, ArrayInUnionValidation) { 776 TEST(UnionTest, ArrayInUnionValidation) {
776 Array<int8_t> array(2); 777 Array<int8_t> array(2);
777 array[0] = 8; 778 array[0] = 8;
778 array[1] = 9; 779 array[1] = 9;
779 780
780 ObjectUnionPtr obj(ObjectUnion::New()); 781 ObjectUnionPtr obj(ObjectUnion::New());
781 obj->set_f_array_int8(array.Pass()); 782 obj->set_f_array_int8(std::move(array));
782 783
783 size_t size = GetSerializedSize_(obj, false); 784 size_t size = GetSerializedSize_(obj, false);
784 mojo::internal::FixedBufferForTesting buf(size); 785 mojo::internal::FixedBufferForTesting buf(size);
785 internal::ObjectUnion_Data* data = nullptr; 786 internal::ObjectUnion_Data* data = nullptr;
786 SerializeUnion_(obj.Pass(), &buf, &data, false); 787 SerializeUnion_(std::move(obj), &buf, &data, false);
787 788
788 std::vector<Handle> handles; 789 std::vector<Handle> handles;
789 data->EncodePointersAndHandles(&handles); 790 data->EncodePointersAndHandles(&handles);
790 791
791 void* raw_buf = buf.Leak(); 792 void* raw_buf = buf.Leak();
792 mojo::internal::BoundsChecker bounds_checker(data, 793 mojo::internal::BoundsChecker bounds_checker(data,
793 static_cast<uint32_t>(size), 0); 794 static_cast<uint32_t>(size), 0);
794 795
795 EXPECT_TRUE( 796 EXPECT_TRUE(
796 internal::ObjectUnion_Data::Validate(raw_buf, &bounds_checker, false)); 797 internal::ObjectUnion_Data::Validate(raw_buf, &bounds_checker, false));
797 free(raw_buf); 798 free(raw_buf);
798 } 799 }
799 800
800 TEST(UnionTest, MapInUnionGetterSetter) { 801 TEST(UnionTest, MapInUnionGetterSetter) {
801 Map<String, int8_t> map; 802 Map<String, int8_t> map;
802 map.insert("one", 1); 803 map.insert("one", 1);
803 map.insert("two", 2); 804 map.insert("two", 2);
804 805
805 ObjectUnionPtr obj(ObjectUnion::New()); 806 ObjectUnionPtr obj(ObjectUnion::New());
806 obj->set_f_map_int8(map.Pass()); 807 obj->set_f_map_int8(std::move(map));
807 808
808 EXPECT_EQ(1, obj->get_f_map_int8()["one"]); 809 EXPECT_EQ(1, obj->get_f_map_int8()["one"]);
809 EXPECT_EQ(2, obj->get_f_map_int8()["two"]); 810 EXPECT_EQ(2, obj->get_f_map_int8()["two"]);
810 } 811 }
811 812
812 TEST(UnionTest, MapInUnionSerialization) { 813 TEST(UnionTest, MapInUnionSerialization) {
813 Map<String, int8_t> map; 814 Map<String, int8_t> map;
814 map.insert("one", 1); 815 map.insert("one", 1);
815 map.insert("two", 2); 816 map.insert("two", 2);
816 817
817 ObjectUnionPtr obj(ObjectUnion::New()); 818 ObjectUnionPtr obj(ObjectUnion::New());
818 obj->set_f_map_int8(map.Pass()); 819 obj->set_f_map_int8(std::move(map));
819 820
820 size_t size = GetSerializedSize_(obj, false); 821 size_t size = GetSerializedSize_(obj, false);
821 EXPECT_EQ(112U, size); 822 EXPECT_EQ(112U, size);
822 823
823 mojo::internal::FixedBufferForTesting buf(size); 824 mojo::internal::FixedBufferForTesting buf(size);
824 internal::ObjectUnion_Data* data = nullptr; 825 internal::ObjectUnion_Data* data = nullptr;
825 SerializeUnion_(obj.Pass(), &buf, &data, false); 826 SerializeUnion_(std::move(obj), &buf, &data, false);
826 827
827 std::vector<Handle> handles; 828 std::vector<Handle> handles;
828 data->EncodePointersAndHandles(&handles); 829 data->EncodePointersAndHandles(&handles);
829 data->DecodePointersAndHandles(&handles); 830 data->DecodePointersAndHandles(&handles);
830 831
831 ObjectUnionPtr obj2; 832 ObjectUnionPtr obj2;
832 Deserialize_(data, &obj2, nullptr); 833 Deserialize_(data, &obj2, nullptr);
833 834
834 EXPECT_EQ(1, obj2->get_f_map_int8()["one"]); 835 EXPECT_EQ(1, obj2->get_f_map_int8()["one"]);
835 EXPECT_EQ(2, obj2->get_f_map_int8()["two"]); 836 EXPECT_EQ(2, obj2->get_f_map_int8()["two"]);
836 } 837 }
837 838
838 TEST(UnionTest, MapInUnionValidation) { 839 TEST(UnionTest, MapInUnionValidation) {
839 Map<String, int8_t> map; 840 Map<String, int8_t> map;
840 map.insert("one", 1); 841 map.insert("one", 1);
841 map.insert("two", 2); 842 map.insert("two", 2);
842 843
843 ObjectUnionPtr obj(ObjectUnion::New()); 844 ObjectUnionPtr obj(ObjectUnion::New());
844 obj->set_f_map_int8(map.Pass()); 845 obj->set_f_map_int8(std::move(map));
845 846
846 size_t size = GetSerializedSize_(obj, false); 847 size_t size = GetSerializedSize_(obj, false);
847 EXPECT_EQ(112U, size); 848 EXPECT_EQ(112U, size);
848 849
849 mojo::internal::FixedBufferForTesting buf(size); 850 mojo::internal::FixedBufferForTesting buf(size);
850 internal::ObjectUnion_Data* data = nullptr; 851 internal::ObjectUnion_Data* data = nullptr;
851 SerializeUnion_(obj.Pass(), &buf, &data, false); 852 SerializeUnion_(std::move(obj), &buf, &data, false);
852 853
853 std::vector<Handle> handles; 854 std::vector<Handle> handles;
854 data->EncodePointersAndHandles(&handles); 855 data->EncodePointersAndHandles(&handles);
855 EXPECT_TRUE(handles.empty()); 856 EXPECT_TRUE(handles.empty());
856 857
857 void* raw_buf = buf.Leak(); 858 void* raw_buf = buf.Leak();
858 mojo::internal::BoundsChecker bounds_checker(data, 859 mojo::internal::BoundsChecker bounds_checker(data,
859 static_cast<uint32_t>(size), 0); 860 static_cast<uint32_t>(size), 0);
860 861
861 EXPECT_TRUE( 862 EXPECT_TRUE(
862 internal::ObjectUnion_Data::Validate(raw_buf, &bounds_checker, false)); 863 internal::ObjectUnion_Data::Validate(raw_buf, &bounds_checker, false));
863 free(raw_buf); 864 free(raw_buf);
864 } 865 }
865 866
866 TEST(UnionTest, UnionInUnionGetterSetter) { 867 TEST(UnionTest, UnionInUnionGetterSetter) {
867 PodUnionPtr pod(PodUnion::New()); 868 PodUnionPtr pod(PodUnion::New());
868 pod->set_f_int8(10); 869 pod->set_f_int8(10);
869 870
870 ObjectUnionPtr obj(ObjectUnion::New()); 871 ObjectUnionPtr obj(ObjectUnion::New());
871 obj->set_f_pod_union(pod.Pass()); 872 obj->set_f_pod_union(std::move(pod));
872 873
873 EXPECT_EQ(10, obj->get_f_pod_union()->get_f_int8()); 874 EXPECT_EQ(10, obj->get_f_pod_union()->get_f_int8());
874 } 875 }
875 876
876 TEST(UnionTest, UnionInUnionSerialization) { 877 TEST(UnionTest, UnionInUnionSerialization) {
877 PodUnionPtr pod(PodUnion::New()); 878 PodUnionPtr pod(PodUnion::New());
878 pod->set_f_int8(10); 879 pod->set_f_int8(10);
879 880
880 ObjectUnionPtr obj(ObjectUnion::New()); 881 ObjectUnionPtr obj(ObjectUnion::New());
881 obj->set_f_pod_union(pod.Pass()); 882 obj->set_f_pod_union(std::move(pod));
882 883
883 size_t size = GetSerializedSize_(obj, false); 884 size_t size = GetSerializedSize_(obj, false);
884 EXPECT_EQ(32U, size); 885 EXPECT_EQ(32U, size);
885 886
886 mojo::internal::FixedBufferForTesting buf(size); 887 mojo::internal::FixedBufferForTesting buf(size);
887 internal::ObjectUnion_Data* data = nullptr; 888 internal::ObjectUnion_Data* data = nullptr;
888 SerializeUnion_(obj.Pass(), &buf, &data, false); 889 SerializeUnion_(std::move(obj), &buf, &data, false);
889 890
890 std::vector<Handle> handles; 891 std::vector<Handle> handles;
891 data->EncodePointersAndHandles(&handles); 892 data->EncodePointersAndHandles(&handles);
892 data->DecodePointersAndHandles(&handles); 893 data->DecodePointersAndHandles(&handles);
893 894
894 ObjectUnionPtr obj2; 895 ObjectUnionPtr obj2;
895 Deserialize_(data, &obj2, nullptr); 896 Deserialize_(data, &obj2, nullptr);
896 EXPECT_EQ(10, obj2->get_f_pod_union()->get_f_int8()); 897 EXPECT_EQ(10, obj2->get_f_pod_union()->get_f_int8());
897 } 898 }
898 899
899 TEST(UnionTest, UnionInUnionValidation) { 900 TEST(UnionTest, UnionInUnionValidation) {
900 PodUnionPtr pod(PodUnion::New()); 901 PodUnionPtr pod(PodUnion::New());
901 pod->set_f_int8(10); 902 pod->set_f_int8(10);
902 903
903 ObjectUnionPtr obj(ObjectUnion::New()); 904 ObjectUnionPtr obj(ObjectUnion::New());
904 obj->set_f_pod_union(pod.Pass()); 905 obj->set_f_pod_union(std::move(pod));
905 906
906 size_t size = GetSerializedSize_(obj, false); 907 size_t size = GetSerializedSize_(obj, false);
907 EXPECT_EQ(32U, size); 908 EXPECT_EQ(32U, size);
908 909
909 mojo::internal::FixedBufferForTesting buf(size); 910 mojo::internal::FixedBufferForTesting buf(size);
910 internal::ObjectUnion_Data* data = nullptr; 911 internal::ObjectUnion_Data* data = nullptr;
911 SerializeUnion_(obj.Pass(), &buf, &data, false); 912 SerializeUnion_(std::move(obj), &buf, &data, false);
912 913
913 std::vector<Handle> handles; 914 std::vector<Handle> handles;
914 data->EncodePointersAndHandles(&handles); 915 data->EncodePointersAndHandles(&handles);
915 EXPECT_TRUE(handles.empty()); 916 EXPECT_TRUE(handles.empty());
916 917
917 void* raw_buf = buf.Leak(); 918 void* raw_buf = buf.Leak();
918 mojo::internal::BoundsChecker bounds_checker(data, 919 mojo::internal::BoundsChecker bounds_checker(data,
919 static_cast<uint32_t>(size), 0); 920 static_cast<uint32_t>(size), 0);
920 EXPECT_TRUE( 921 EXPECT_TRUE(
921 internal::ObjectUnion_Data::Validate(raw_buf, &bounds_checker, false)); 922 internal::ObjectUnion_Data::Validate(raw_buf, &bounds_checker, false));
922 free(raw_buf); 923 free(raw_buf);
923 } 924 }
924 925
925 TEST(UnionTest, UnionInUnionValidationNonNullable) { 926 TEST(UnionTest, UnionInUnionValidationNonNullable) {
926 PodUnionPtr pod(nullptr); 927 PodUnionPtr pod(nullptr);
927 928
928 ObjectUnionPtr obj(ObjectUnion::New()); 929 ObjectUnionPtr obj(ObjectUnion::New());
929 obj->set_f_pod_union(pod.Pass()); 930 obj->set_f_pod_union(std::move(pod));
930 931
931 size_t size = GetSerializedSize_(obj, false); 932 size_t size = GetSerializedSize_(obj, false);
932 933
933 mojo::internal::FixedBufferForTesting buf(size); 934 mojo::internal::FixedBufferForTesting buf(size);
934 internal::ObjectUnion_Data* data = nullptr; 935 internal::ObjectUnion_Data* data = nullptr;
935 SerializeUnion_(obj.Pass(), &buf, &data, false); 936 SerializeUnion_(std::move(obj), &buf, &data, false);
936 std::vector<Handle> handles; 937 std::vector<Handle> handles;
937 data->EncodePointersAndHandles(&handles); 938 data->EncodePointersAndHandles(&handles);
938 939
939 void* raw_buf = buf.Leak(); 940 void* raw_buf = buf.Leak();
940 mojo::internal::BoundsChecker bounds_checker(data, 941 mojo::internal::BoundsChecker bounds_checker(data,
941 static_cast<uint32_t>(size), 0); 942 static_cast<uint32_t>(size), 0);
942 EXPECT_FALSE( 943 EXPECT_FALSE(
943 internal::ObjectUnion_Data::Validate(raw_buf, &bounds_checker, false)); 944 internal::ObjectUnion_Data::Validate(raw_buf, &bounds_checker, false));
944 free(raw_buf); 945 free(raw_buf);
945 } 946 }
946 947
947 TEST(UnionTest, HandleInUnionGetterSetter) { 948 TEST(UnionTest, HandleInUnionGetterSetter) {
948 ScopedMessagePipeHandle pipe0; 949 ScopedMessagePipeHandle pipe0;
949 ScopedMessagePipeHandle pipe1; 950 ScopedMessagePipeHandle pipe1;
950 951
951 CreateMessagePipe(nullptr, &pipe0, &pipe1); 952 CreateMessagePipe(nullptr, &pipe0, &pipe1);
952 953
953 HandleUnionPtr handle(HandleUnion::New()); 954 HandleUnionPtr handle(HandleUnion::New());
954 handle->set_f_message_pipe(pipe1.Pass()); 955 handle->set_f_message_pipe(std::move(pipe1));
955 956
956 std::string golden("hello world"); 957 std::string golden("hello world");
957 WriteTextMessage(pipe0.get(), golden); 958 WriteTextMessage(pipe0.get(), golden);
958 959
959 std::string actual; 960 std::string actual;
960 ReadTextMessage(handle->get_f_message_pipe().get(), &actual); 961 ReadTextMessage(handle->get_f_message_pipe().get(), &actual);
961 962
962 EXPECT_EQ(golden, actual); 963 EXPECT_EQ(golden, actual);
963 } 964 }
964 965
965 TEST(UnionTest, HandleInUnionSerialization) { 966 TEST(UnionTest, HandleInUnionSerialization) {
966 ScopedMessagePipeHandle pipe0; 967 ScopedMessagePipeHandle pipe0;
967 ScopedMessagePipeHandle pipe1; 968 ScopedMessagePipeHandle pipe1;
968 969
969 CreateMessagePipe(nullptr, &pipe0, &pipe1); 970 CreateMessagePipe(nullptr, &pipe0, &pipe1);
970 971
971 HandleUnionPtr handle(HandleUnion::New()); 972 HandleUnionPtr handle(HandleUnion::New());
972 handle->set_f_message_pipe(pipe1.Pass()); 973 handle->set_f_message_pipe(std::move(pipe1));
973 974
974 size_t size = GetSerializedSize_(handle, false); 975 size_t size = GetSerializedSize_(handle, false);
975 EXPECT_EQ(16U, size); 976 EXPECT_EQ(16U, size);
976 977
977 mojo::internal::FixedBufferForTesting buf(size); 978 mojo::internal::FixedBufferForTesting buf(size);
978 internal::HandleUnion_Data* data = nullptr; 979 internal::HandleUnion_Data* data = nullptr;
979 SerializeUnion_(handle.Pass(), &buf, &data, false); 980 SerializeUnion_(std::move(handle), &buf, &data, false);
980 981
981 std::vector<Handle> handles; 982 std::vector<Handle> handles;
982 data->EncodePointersAndHandles(&handles); 983 data->EncodePointersAndHandles(&handles);
983 EXPECT_EQ(1U, handles.size()); 984 EXPECT_EQ(1U, handles.size());
984 data->DecodePointersAndHandles(&handles); 985 data->DecodePointersAndHandles(&handles);
985 986
986 HandleUnionPtr handle2(HandleUnion::New()); 987 HandleUnionPtr handle2(HandleUnion::New());
987 Deserialize_(data, &handle2, nullptr); 988 Deserialize_(data, &handle2, nullptr);
988 989
989 std::string golden("hello world"); 990 std::string golden("hello world");
990 WriteTextMessage(pipe0.get(), golden); 991 WriteTextMessage(pipe0.get(), golden);
991 992
992 std::string actual; 993 std::string actual;
993 ReadTextMessage(handle2->get_f_message_pipe().get(), &actual); 994 ReadTextMessage(handle2->get_f_message_pipe().get(), &actual);
994 995
995 EXPECT_EQ(golden, actual); 996 EXPECT_EQ(golden, actual);
996 } 997 }
997 998
998 TEST(UnionTest, HandleInUnionValidation) { 999 TEST(UnionTest, HandleInUnionValidation) {
999 ScopedMessagePipeHandle pipe0; 1000 ScopedMessagePipeHandle pipe0;
1000 ScopedMessagePipeHandle pipe1; 1001 ScopedMessagePipeHandle pipe1;
1001 1002
1002 CreateMessagePipe(nullptr, &pipe0, &pipe1); 1003 CreateMessagePipe(nullptr, &pipe0, &pipe1);
1003 1004
1004 HandleUnionPtr handle(HandleUnion::New()); 1005 HandleUnionPtr handle(HandleUnion::New());
1005 handle->set_f_message_pipe(pipe1.Pass()); 1006 handle->set_f_message_pipe(std::move(pipe1));
1006 1007
1007 size_t size = GetSerializedSize_(handle, false); 1008 size_t size = GetSerializedSize_(handle, false);
1008 EXPECT_EQ(16U, size); 1009 EXPECT_EQ(16U, size);
1009 1010
1010 mojo::internal::FixedBufferForTesting buf(size); 1011 mojo::internal::FixedBufferForTesting buf(size);
1011 internal::HandleUnion_Data* data = nullptr; 1012 internal::HandleUnion_Data* data = nullptr;
1012 SerializeUnion_(handle.Pass(), &buf, &data, false); 1013 SerializeUnion_(std::move(handle), &buf, &data, false);
1013 1014
1014 std::vector<Handle> handles; 1015 std::vector<Handle> handles;
1015 data->EncodePointersAndHandles(&handles); 1016 data->EncodePointersAndHandles(&handles);
1016 1017
1017 void* raw_buf = buf.Leak(); 1018 void* raw_buf = buf.Leak();
1018 mojo::internal::BoundsChecker bounds_checker(data, 1019 mojo::internal::BoundsChecker bounds_checker(data,
1019 static_cast<uint32_t>(size), 1); 1020 static_cast<uint32_t>(size), 1);
1020 EXPECT_TRUE( 1021 EXPECT_TRUE(
1021 internal::HandleUnion_Data::Validate(raw_buf, &bounds_checker, false)); 1022 internal::HandleUnion_Data::Validate(raw_buf, &bounds_checker, false));
1022 free(raw_buf); 1023 free(raw_buf);
1023 } 1024 }
1024 1025
1025 TEST(UnionTest, HandleInUnionValidationNull) { 1026 TEST(UnionTest, HandleInUnionValidationNull) {
1026 ScopedMessagePipeHandle pipe; 1027 ScopedMessagePipeHandle pipe;
1027 HandleUnionPtr handle(HandleUnion::New()); 1028 HandleUnionPtr handle(HandleUnion::New());
1028 handle->set_f_message_pipe(pipe.Pass()); 1029 handle->set_f_message_pipe(std::move(pipe));
1029 1030
1030 size_t size = GetSerializedSize_(handle, false); 1031 size_t size = GetSerializedSize_(handle, false);
1031 EXPECT_EQ(16U, size); 1032 EXPECT_EQ(16U, size);
1032 1033
1033 mojo::internal::FixedBufferForTesting buf(size); 1034 mojo::internal::FixedBufferForTesting buf(size);
1034 internal::HandleUnion_Data* data = nullptr; 1035 internal::HandleUnion_Data* data = nullptr;
1035 SerializeUnion_(handle.Pass(), &buf, &data, false); 1036 SerializeUnion_(std::move(handle), &buf, &data, false);
1036 1037
1037 std::vector<Handle> handles; 1038 std::vector<Handle> handles;
1038 data->EncodePointersAndHandles(&handles); 1039 data->EncodePointersAndHandles(&handles);
1039 1040
1040 void* raw_buf = buf.Leak(); 1041 void* raw_buf = buf.Leak();
1041 mojo::internal::BoundsChecker bounds_checker(data, 1042 mojo::internal::BoundsChecker bounds_checker(data,
1042 static_cast<uint32_t>(size), 1); 1043 static_cast<uint32_t>(size), 1);
1043 EXPECT_FALSE( 1044 EXPECT_FALSE(
1044 internal::HandleUnion_Data::Validate(raw_buf, &bounds_checker, false)); 1045 internal::HandleUnion_Data::Validate(raw_buf, &bounds_checker, false));
1045 free(raw_buf); 1046 free(raw_buf);
(...skipping 14 matching lines...) Expand all
1060 int64_t int_value_; 1061 int64_t int_value_;
1061 }; 1062 };
1062 1063
1063 TEST(UnionTest, InterfaceInUnion) { 1064 TEST(UnionTest, InterfaceInUnion) {
1064 base::MessageLoop run_loop(common::MessagePumpMojo::Create()); 1065 base::MessageLoop run_loop(common::MessagePumpMojo::Create());
1065 SmallCacheImpl impl; 1066 SmallCacheImpl impl;
1066 SmallCachePtr ptr; 1067 SmallCachePtr ptr;
1067 Binding<SmallCache> bindings(&impl, GetProxy(&ptr)); 1068 Binding<SmallCache> bindings(&impl, GetProxy(&ptr));
1068 1069
1069 HandleUnionPtr handle(HandleUnion::New()); 1070 HandleUnionPtr handle(HandleUnion::New());
1070 handle->set_f_small_cache(ptr.Pass()); 1071 handle->set_f_small_cache(std::move(ptr));
1071 1072
1072 handle->get_f_small_cache()->SetIntValue(10); 1073 handle->get_f_small_cache()->SetIntValue(10);
1073 run_loop.RunUntilIdle(); 1074 run_loop.RunUntilIdle();
1074 EXPECT_EQ(10, impl.int_value()); 1075 EXPECT_EQ(10, impl.int_value());
1075 } 1076 }
1076 1077
1077 TEST(UnionTest, InterfaceInUnionSerialization) { 1078 TEST(UnionTest, InterfaceInUnionSerialization) {
1078 base::MessageLoop run_loop(common::MessagePumpMojo::Create()); 1079 base::MessageLoop run_loop(common::MessagePumpMojo::Create());
1079 SmallCacheImpl impl; 1080 SmallCacheImpl impl;
1080 SmallCachePtr ptr; 1081 SmallCachePtr ptr;
1081 Binding<SmallCache> bindings(&impl, GetProxy(&ptr)); 1082 Binding<SmallCache> bindings(&impl, GetProxy(&ptr));
1082 1083
1083 HandleUnionPtr handle(HandleUnion::New()); 1084 HandleUnionPtr handle(HandleUnion::New());
1084 handle->set_f_small_cache(ptr.Pass()); 1085 handle->set_f_small_cache(std::move(ptr));
1085 size_t size = GetSerializedSize_(handle, false); 1086 size_t size = GetSerializedSize_(handle, false);
1086 EXPECT_EQ(16U, size); 1087 EXPECT_EQ(16U, size);
1087 1088
1088 mojo::internal::FixedBufferForTesting buf(size); 1089 mojo::internal::FixedBufferForTesting buf(size);
1089 internal::HandleUnion_Data* data = nullptr; 1090 internal::HandleUnion_Data* data = nullptr;
1090 SerializeUnion_(handle.Pass(), &buf, &data, false); 1091 SerializeUnion_(std::move(handle), &buf, &data, false);
1091 1092
1092 std::vector<Handle> handles; 1093 std::vector<Handle> handles;
1093 data->EncodePointersAndHandles(&handles); 1094 data->EncodePointersAndHandles(&handles);
1094 EXPECT_EQ(1U, handles.size()); 1095 EXPECT_EQ(1U, handles.size());
1095 data->DecodePointersAndHandles(&handles); 1096 data->DecodePointersAndHandles(&handles);
1096 1097
1097 HandleUnionPtr handle2(HandleUnion::New()); 1098 HandleUnionPtr handle2(HandleUnion::New());
1098 Deserialize_(data, &handle2, nullptr); 1099 Deserialize_(data, &handle2, nullptr);
1099 1100
1100 handle2->get_f_small_cache()->SetIntValue(10); 1101 handle2->get_f_small_cache()->SetIntValue(10);
1101 run_loop.RunUntilIdle(); 1102 run_loop.RunUntilIdle();
1102 EXPECT_EQ(10, impl.int_value()); 1103 EXPECT_EQ(10, impl.int_value());
1103 } 1104 }
1104 1105
1105 class UnionInterfaceImpl : public UnionInterface { 1106 class UnionInterfaceImpl : public UnionInterface {
1106 public: 1107 public:
1107 UnionInterfaceImpl() {} 1108 UnionInterfaceImpl() {}
1108 ~UnionInterfaceImpl() override {} 1109 ~UnionInterfaceImpl() override {}
1109 1110
1110 private: 1111 private:
1111 void Echo(PodUnionPtr in, const EchoCallback& callback) override { 1112 void Echo(PodUnionPtr in, const EchoCallback& callback) override {
1112 callback.Run(in.Pass()); 1113 callback.Run(std::move(in));
1113 } 1114 }
1114 }; 1115 };
1115 1116
1116 TEST(UnionTest, UnionInInterface) { 1117 TEST(UnionTest, UnionInInterface) {
1117 base::MessageLoop run_loop(common::MessagePumpMojo::Create()); 1118 base::MessageLoop run_loop(common::MessagePumpMojo::Create());
1118 UnionInterfaceImpl impl; 1119 UnionInterfaceImpl impl;
1119 UnionInterfacePtr ptr; 1120 UnionInterfacePtr ptr;
1120 Binding<UnionInterface> bindings(&impl, GetProxy(&ptr)); 1121 Binding<UnionInterface> bindings(&impl, GetProxy(&ptr));
1121 1122
1122 PodUnionPtr pod(PodUnion::New()); 1123 PodUnionPtr pod(PodUnion::New());
1123 pod->set_f_int16(16); 1124 pod->set_f_int16(16);
1124 1125
1125 ptr->Echo(pod.Pass(), 1126 ptr->Echo(std::move(pod),
1126 [](PodUnionPtr out) { EXPECT_EQ(16, out->get_f_int16()); }); 1127 [](PodUnionPtr out) { EXPECT_EQ(16, out->get_f_int16()); });
1127 run_loop.RunUntilIdle(); 1128 run_loop.RunUntilIdle();
1128 } 1129 }
1129 1130
1130 } // namespace test 1131 } // namespace test
1131 } // namespace mojo 1132 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698