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

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

Issue 2136733002: Mojo C++ bindings: add a new mode to generator to use native STL/WTF types (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@67_new
Patch Set: . Created 4 years, 5 months 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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 #include <string.h> 7 #include <string.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "mojo/public/cpp/bindings/lib/fixed_buffer.h" 10 #include "mojo/public/cpp/bindings/lib/fixed_buffer.h"
(...skipping 18 matching lines...) Expand all
29 EXPECT_EQ(1 * factor, rect.x); 29 EXPECT_EQ(1 * factor, rect.x);
30 EXPECT_EQ(2 * factor, rect.y); 30 EXPECT_EQ(2 * factor, rect.y);
31 EXPECT_EQ(10 * factor, rect.width); 31 EXPECT_EQ(10 * factor, rect.width);
32 EXPECT_EQ(20 * factor, rect.height); 32 EXPECT_EQ(20 * factor, rect.height);
33 } 33 }
34 34
35 MultiVersionStructPtr MakeMultiVersionStruct() { 35 MultiVersionStructPtr MakeMultiVersionStruct() {
36 MultiVersionStructPtr output(MultiVersionStruct::New()); 36 MultiVersionStructPtr output(MultiVersionStruct::New());
37 output->f_int32 = 123; 37 output->f_int32 = 123;
38 output->f_rect = MakeRect(5); 38 output->f_rect = MakeRect(5);
39 output->f_string = "hello"; 39 output->f_string.emplace("hello");
40 output->f_array = Array<int8_t>(3); 40 output->f_array.emplace(3);
41 output->f_array[0] = 10; 41 (*output->f_array)[0] = 10;
42 output->f_array[1] = 9; 42 (*output->f_array)[1] = 9;
43 output->f_array[2] = 8; 43 (*output->f_array)[2] = 8;
44 MessagePipe pipe; 44 MessagePipe pipe;
45 output->f_message_pipe = std::move(pipe.handle0); 45 output->f_message_pipe = std::move(pipe.handle0);
46 output->f_int16 = 42; 46 output->f_int16 = 42;
47 47
48 return output; 48 return output;
49 } 49 }
50 50
51 template <typename U, typename T> 51 template <typename U, typename T>
52 U SerializeAndDeserialize(T input) { 52 U SerializeAndDeserialize(T input) {
53 using InputDataType = typename mojo::internal::MojomTypeTraits<T>::Data*; 53 using InputDataType = typename mojo::internal::MojomTypeTraits<T>::Data*;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 } 100 }
101 101
102 TEST_F(StructTest, Clone) { 102 TEST_F(StructTest, Clone) {
103 NamedRegionPtr region; 103 NamedRegionPtr region;
104 104
105 NamedRegionPtr clone_region = region.Clone(); 105 NamedRegionPtr clone_region = region.Clone();
106 EXPECT_TRUE(clone_region.is_null()); 106 EXPECT_TRUE(clone_region.is_null());
107 107
108 region = NamedRegion::New(); 108 region = NamedRegion::New();
109 clone_region = region.Clone(); 109 clone_region = region.Clone();
110 EXPECT_TRUE(clone_region->name.is_null()); 110 EXPECT_FALSE(clone_region->name);
111 EXPECT_TRUE(clone_region->rects.is_null()); 111 EXPECT_FALSE(clone_region->rects);
112 112
113 region->name = "hello world"; 113 region->name.emplace("hello world");
114 clone_region = region.Clone(); 114 clone_region = region.Clone();
115 EXPECT_EQ(region->name, clone_region->name); 115 EXPECT_EQ(region->name, clone_region->name);
116 116
117 region->rects = Array<RectPtr>(2); 117 region->rects.emplace(2);
118 region->rects[1] = MakeRect(); 118 (*region->rects)[1] = MakeRect();
119 clone_region = region.Clone(); 119 clone_region = region.Clone();
120 EXPECT_EQ(2u, clone_region->rects.size()); 120 EXPECT_EQ(2u, clone_region->rects->size());
121 EXPECT_TRUE(clone_region->rects[0].is_null()); 121 EXPECT_TRUE((*clone_region->rects)[0].is_null());
122 CheckRect(*clone_region->rects[1]); 122 CheckRect(*(*clone_region->rects)[1]);
123 123
124 // NoDefaultFieldValues contains handles, so Clone() is not available, but 124 // NoDefaultFieldValues contains handles, so Clone() is not available, but
125 // NoDefaultFieldValuesPtr should still compile. 125 // NoDefaultFieldValuesPtr should still compile.
126 NoDefaultFieldValuesPtr no_default_field_values(NoDefaultFieldValues::New()); 126 NoDefaultFieldValuesPtr no_default_field_values(NoDefaultFieldValues::New());
127 EXPECT_FALSE(no_default_field_values->f13.is_valid()); 127 EXPECT_FALSE(no_default_field_values->f13.is_valid());
128 } 128 }
129 129
130 // Serialization test of a struct with no pointer or handle members. 130 // Serialization test of a struct with no pointer or handle members.
131 TEST_F(StructTest, Serialization_Basic) { 131 TEST_F(StructTest, Serialization_Basic) {
132 RectPtr rect(MakeRect()); 132 RectPtr rect(MakeRect());
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 RectPairPtr pair2; 174 RectPairPtr pair2;
175 mojo::internal::Deserialize<RectPairPtr>(data, &pair2, nullptr); 175 mojo::internal::Deserialize<RectPairPtr>(data, &pair2, nullptr);
176 176
177 CheckRect(*pair2->first); 177 CheckRect(*pair2->first);
178 CheckRect(*pair2->second); 178 CheckRect(*pair2->second);
179 } 179 }
180 180
181 // Serialization test of a struct with an array member. 181 // Serialization test of a struct with an array member.
182 TEST_F(StructTest, Serialization_ArrayPointers) { 182 TEST_F(StructTest, Serialization_ArrayPointers) {
183 NamedRegionPtr region(NamedRegion::New()); 183 NamedRegionPtr region(NamedRegion::New());
184 region->name = "region"; 184 region->name.emplace("region");
185 region->rects = Array<RectPtr>::New(4); 185 region->rects.emplace(4);
186 for (size_t i = 0; i < region->rects.size(); ++i) 186 for (size_t i = 0; i < region->rects->size(); ++i)
187 region->rects[i] = MakeRect(static_cast<int32_t>(i) + 1); 187 (*region->rects)[i] = MakeRect(static_cast<int32_t>(i) + 1);
188 188
189 size_t size = 189 size_t size =
190 mojo::internal::PrepareToSerialize<NamedRegionPtr>(region, nullptr); 190 mojo::internal::PrepareToSerialize<NamedRegionPtr>(region, nullptr);
191 EXPECT_EQ(8U + // header 191 EXPECT_EQ(8U + // header
192 8U + // name pointer 192 8U + // name pointer
193 8U + // rects pointer 193 8U + // rects pointer
194 8U + // name header 194 8U + // name header
195 8U + // name payload (rounded up) 195 8U + // name payload (rounded up)
196 8U + // rects header 196 8U + // rects header
197 4 * 8U + // rects payload (four pointers) 197 4 * 8U + // rects payload (four pointers)
198 4 * (8U + // rect header 198 4 * (8U + // rect header
199 16U), // rect payload (four ints) 199 16U), // rect payload (four ints)
200 size); 200 size);
201 201
202 mojo::internal::FixedBufferForTesting buf(size); 202 mojo::internal::FixedBufferForTesting buf(size);
203 internal::NamedRegion_Data* data; 203 internal::NamedRegion_Data* data;
204 mojo::internal::Serialize<NamedRegionPtr>(region, &buf, &data, nullptr); 204 mojo::internal::Serialize<NamedRegionPtr>(region, &buf, &data, nullptr);
205 205
206 NamedRegionPtr region2; 206 NamedRegionPtr region2;
207 mojo::internal::Deserialize<NamedRegionPtr>(data, &region2, nullptr); 207 mojo::internal::Deserialize<NamedRegionPtr>(data, &region2, nullptr);
208 208
209 EXPECT_EQ(String("region"), region2->name); 209 EXPECT_EQ("region", *region2->name);
210 210
211 EXPECT_EQ(4U, region2->rects.size()); 211 EXPECT_EQ(4U, region2->rects->size());
212 for (size_t i = 0; i < region2->rects.size(); ++i) 212 for (size_t i = 0; i < region2->rects->size(); ++i)
213 CheckRect(*region2->rects[i], static_cast<int32_t>(i) + 1); 213 CheckRect(*(*region2->rects)[i], static_cast<int32_t>(i) + 1);
214 } 214 }
215 215
216 // Serialization test of a struct with null array pointers. 216 // Serialization test of a struct with null array pointers.
217 TEST_F(StructTest, Serialization_NullArrayPointers) { 217 TEST_F(StructTest, Serialization_NullArrayPointers) {
218 NamedRegionPtr region(NamedRegion::New()); 218 NamedRegionPtr region(NamedRegion::New());
219 EXPECT_TRUE(region->name.is_null()); 219 EXPECT_FALSE(region->name);
220 EXPECT_TRUE(region->rects.is_null()); 220 EXPECT_FALSE(region->rects);
221 221
222 size_t size = 222 size_t size =
223 mojo::internal::PrepareToSerialize<NamedRegionPtr>(region, nullptr); 223 mojo::internal::PrepareToSerialize<NamedRegionPtr>(region, nullptr);
224 EXPECT_EQ(8U + // header 224 EXPECT_EQ(8U + // header
225 8U + // name pointer 225 8U + // name pointer
226 8U, // rects pointer 226 8U, // rects pointer
227 size); 227 size);
228 228
229 mojo::internal::FixedBufferForTesting buf(size); 229 mojo::internal::FixedBufferForTesting buf(size);
230 internal::NamedRegion_Data* data; 230 internal::NamedRegion_Data* data;
231 mojo::internal::Serialize<NamedRegionPtr>(region, &buf, &data, nullptr); 231 mojo::internal::Serialize<NamedRegionPtr>(region, &buf, &data, nullptr);
232 232
233 NamedRegionPtr region2; 233 NamedRegionPtr region2;
234 mojo::internal::Deserialize<NamedRegionPtr>(data, &region2, nullptr); 234 mojo::internal::Deserialize<NamedRegionPtr>(data, &region2, nullptr);
235 235
236 EXPECT_TRUE(region2->name.is_null()); 236 EXPECT_FALSE(region2->name);
237 EXPECT_TRUE(region2->rects.is_null()); 237 EXPECT_FALSE(region2->rects);
238 } 238 }
239 239
240 // Tests deserializing structs as a newer version. 240 // Tests deserializing structs as a newer version.
241 TEST_F(StructTest, Versioning_OldToNew) { 241 TEST_F(StructTest, Versioning_OldToNew) {
242 { 242 {
243 MultiVersionStructV0Ptr input(MultiVersionStructV0::New()); 243 MultiVersionStructV0Ptr input(MultiVersionStructV0::New());
244 input->f_int32 = 123; 244 input->f_int32 = 123;
245 MultiVersionStructPtr expected_output(MultiVersionStruct::New()); 245 MultiVersionStructPtr expected_output(MultiVersionStruct::New());
246 expected_output->f_int32 = 123; 246 expected_output->f_int32 = 123;
247 247
(...skipping 14 matching lines...) Expand all
262 MultiVersionStructPtr output = 262 MultiVersionStructPtr output =
263 SerializeAndDeserialize<MultiVersionStructPtr>(std::move(input)); 263 SerializeAndDeserialize<MultiVersionStructPtr>(std::move(input));
264 EXPECT_TRUE(output); 264 EXPECT_TRUE(output);
265 EXPECT_TRUE(output->Equals(*expected_output)); 265 EXPECT_TRUE(output->Equals(*expected_output));
266 } 266 }
267 267
268 { 268 {
269 MultiVersionStructV3Ptr input(MultiVersionStructV3::New()); 269 MultiVersionStructV3Ptr input(MultiVersionStructV3::New());
270 input->f_int32 = 123; 270 input->f_int32 = 123;
271 input->f_rect = MakeRect(5); 271 input->f_rect = MakeRect(5);
272 input->f_string = "hello"; 272 input->f_string.emplace("hello");
273 MultiVersionStructPtr expected_output(MultiVersionStruct::New()); 273 MultiVersionStructPtr expected_output(MultiVersionStruct::New());
274 expected_output->f_int32 = 123; 274 expected_output->f_int32 = 123;
275 expected_output->f_rect = MakeRect(5); 275 expected_output->f_rect = MakeRect(5);
276 expected_output->f_string = "hello"; 276 expected_output->f_string.emplace("hello");
277 277
278 MultiVersionStructPtr output = 278 MultiVersionStructPtr output =
279 SerializeAndDeserialize<MultiVersionStructPtr>(std::move(input)); 279 SerializeAndDeserialize<MultiVersionStructPtr>(std::move(input));
280 EXPECT_TRUE(output); 280 EXPECT_TRUE(output);
281 EXPECT_TRUE(output->Equals(*expected_output)); 281 EXPECT_TRUE(output->Equals(*expected_output));
282 } 282 }
283 283
284 { 284 {
285 MultiVersionStructV5Ptr input(MultiVersionStructV5::New()); 285 MultiVersionStructV5Ptr input(MultiVersionStructV5::New());
286 input->f_int32 = 123; 286 input->f_int32 = 123;
287 input->f_rect = MakeRect(5); 287 input->f_rect = MakeRect(5);
288 input->f_string = "hello"; 288 input->f_string.emplace("hello");
289 input->f_array = Array<int8_t>(3); 289 input->f_array.emplace(3);
290 input->f_array[0] = 10; 290 (*input->f_array)[0] = 10;
291 input->f_array[1] = 9; 291 (*input->f_array)[1] = 9;
292 input->f_array[2] = 8; 292 (*input->f_array)[2] = 8;
293 MultiVersionStructPtr expected_output(MultiVersionStruct::New()); 293 MultiVersionStructPtr expected_output(MultiVersionStruct::New());
294 expected_output->f_int32 = 123; 294 expected_output->f_int32 = 123;
295 expected_output->f_rect = MakeRect(5); 295 expected_output->f_rect = MakeRect(5);
296 expected_output->f_string = "hello"; 296 expected_output->f_string.emplace("hello");
297 expected_output->f_array = Array<int8_t>(3); 297 expected_output->f_array.emplace(3);
298 expected_output->f_array[0] = 10; 298 (*expected_output->f_array)[0] = 10;
299 expected_output->f_array[1] = 9; 299 (*expected_output->f_array)[1] = 9;
300 expected_output->f_array[2] = 8; 300 (*expected_output->f_array)[2] = 8;
301 301
302 MultiVersionStructPtr output = 302 MultiVersionStructPtr output =
303 SerializeAndDeserialize<MultiVersionStructPtr>(std::move(input)); 303 SerializeAndDeserialize<MultiVersionStructPtr>(std::move(input));
304 EXPECT_TRUE(output); 304 EXPECT_TRUE(output);
305 EXPECT_TRUE(output->Equals(*expected_output)); 305 EXPECT_TRUE(output->Equals(*expected_output));
306 } 306 }
307 307
308 { 308 {
309 MultiVersionStructV7Ptr input(MultiVersionStructV7::New()); 309 MultiVersionStructV7Ptr input(MultiVersionStructV7::New());
310 input->f_int32 = 123; 310 input->f_int32 = 123;
311 input->f_rect = MakeRect(5); 311 input->f_rect = MakeRect(5);
312 input->f_string = "hello"; 312 input->f_string.emplace("hello");
313 input->f_array = Array<int8_t>(3); 313 input->f_array.emplace(3);
314 input->f_array[0] = 10; 314 (*input->f_array)[0] = 10;
315 input->f_array[1] = 9; 315 (*input->f_array)[1] = 9;
316 input->f_array[2] = 8; 316 (*input->f_array)[2] = 8;
317 MessagePipe pipe; 317 MessagePipe pipe;
318 input->f_message_pipe = std::move(pipe.handle0); 318 input->f_message_pipe = std::move(pipe.handle0);
319 319
320 MultiVersionStructPtr expected_output(MultiVersionStruct::New()); 320 MultiVersionStructPtr expected_output(MultiVersionStruct::New());
321 expected_output->f_int32 = 123; 321 expected_output->f_int32 = 123;
322 expected_output->f_rect = MakeRect(5); 322 expected_output->f_rect = MakeRect(5);
323 expected_output->f_string = "hello"; 323 expected_output->f_string.emplace("hello");
324 expected_output->f_array = Array<int8_t>(3); 324 expected_output->f_array.emplace(3);
325 expected_output->f_array[0] = 10; 325 (*expected_output->f_array)[0] = 10;
326 expected_output->f_array[1] = 9; 326 (*expected_output->f_array)[1] = 9;
327 expected_output->f_array[2] = 8; 327 (*expected_output->f_array)[2] = 8;
328 // Save the raw handle value separately so that we can compare later. 328 // Save the raw handle value separately so that we can compare later.
329 MojoHandle expected_handle = input->f_message_pipe.get().value(); 329 MojoHandle expected_handle = input->f_message_pipe.get().value();
330 330
331 MultiVersionStructPtr output = 331 MultiVersionStructPtr output =
332 SerializeAndDeserialize<MultiVersionStructPtr>(std::move(input)); 332 SerializeAndDeserialize<MultiVersionStructPtr>(std::move(input));
333 EXPECT_TRUE(output); 333 EXPECT_TRUE(output);
334 EXPECT_EQ(expected_handle, output->f_message_pipe.get().value()); 334 EXPECT_EQ(expected_handle, output->f_message_pipe.get().value());
335 output->f_message_pipe.reset(); 335 output->f_message_pipe.reset();
336 EXPECT_TRUE(output->Equals(*expected_output)); 336 EXPECT_TRUE(output->Equals(*expected_output));
337 } 337 }
338 } 338 }
339 339
340 // Tests deserializing structs as an older version. 340 // Tests deserializing structs as an older version.
341 TEST_F(StructTest, Versioning_NewToOld) { 341 TEST_F(StructTest, Versioning_NewToOld) {
342 { 342 {
343 MultiVersionStructPtr input = MakeMultiVersionStruct(); 343 MultiVersionStructPtr input = MakeMultiVersionStruct();
344 MultiVersionStructV7Ptr expected_output(MultiVersionStructV7::New()); 344 MultiVersionStructV7Ptr expected_output(MultiVersionStructV7::New());
345 expected_output->f_int32 = 123; 345 expected_output->f_int32 = 123;
346 expected_output->f_rect = MakeRect(5); 346 expected_output->f_rect = MakeRect(5);
347 expected_output->f_string = "hello"; 347 expected_output->f_string.emplace("hello");
348 expected_output->f_array = Array<int8_t>(3); 348 expected_output->f_array.emplace(3);
349 expected_output->f_array[0] = 10; 349 (*expected_output->f_array)[0] = 10;
350 expected_output->f_array[1] = 9; 350 (*expected_output->f_array)[1] = 9;
351 expected_output->f_array[2] = 8; 351 (*expected_output->f_array)[2] = 8;
352 // Save the raw handle value separately so that we can compare later. 352 // Save the raw handle value separately so that we can compare later.
353 MojoHandle expected_handle = input->f_message_pipe.get().value(); 353 MojoHandle expected_handle = input->f_message_pipe.get().value();
354 354
355 MultiVersionStructV7Ptr output = 355 MultiVersionStructV7Ptr output =
356 SerializeAndDeserialize<MultiVersionStructV7Ptr>(std::move(input)); 356 SerializeAndDeserialize<MultiVersionStructV7Ptr>(std::move(input));
357 EXPECT_TRUE(output); 357 EXPECT_TRUE(output);
358 EXPECT_EQ(expected_handle, output->f_message_pipe.get().value()); 358 EXPECT_EQ(expected_handle, output->f_message_pipe.get().value());
359 output->f_message_pipe.reset(); 359 output->f_message_pipe.reset();
360 EXPECT_TRUE(output->Equals(*expected_output)); 360 EXPECT_TRUE(output->Equals(*expected_output));
361 } 361 }
362 362
363 { 363 {
364 MultiVersionStructPtr input = MakeMultiVersionStruct(); 364 MultiVersionStructPtr input = MakeMultiVersionStruct();
365 MultiVersionStructV5Ptr expected_output(MultiVersionStructV5::New()); 365 MultiVersionStructV5Ptr expected_output(MultiVersionStructV5::New());
366 expected_output->f_int32 = 123; 366 expected_output->f_int32 = 123;
367 expected_output->f_rect = MakeRect(5); 367 expected_output->f_rect = MakeRect(5);
368 expected_output->f_string = "hello"; 368 expected_output->f_string.emplace("hello");
369 expected_output->f_array = Array<int8_t>(3); 369 expected_output->f_array.emplace(3);
370 expected_output->f_array[0] = 10; 370 (*expected_output->f_array)[0] = 10;
371 expected_output->f_array[1] = 9; 371 (*expected_output->f_array)[1] = 9;
372 expected_output->f_array[2] = 8; 372 (*expected_output->f_array)[2] = 8;
373 373
374 MultiVersionStructV5Ptr output = 374 MultiVersionStructV5Ptr output =
375 SerializeAndDeserialize<MultiVersionStructV5Ptr>(std::move(input)); 375 SerializeAndDeserialize<MultiVersionStructV5Ptr>(std::move(input));
376 EXPECT_TRUE(output); 376 EXPECT_TRUE(output);
377 EXPECT_TRUE(output->Equals(*expected_output)); 377 EXPECT_TRUE(output->Equals(*expected_output));
378 } 378 }
379 379
380 { 380 {
381 MultiVersionStructPtr input = MakeMultiVersionStruct(); 381 MultiVersionStructPtr input = MakeMultiVersionStruct();
382 MultiVersionStructV3Ptr expected_output(MultiVersionStructV3::New()); 382 MultiVersionStructV3Ptr expected_output(MultiVersionStructV3::New());
383 expected_output->f_int32 = 123; 383 expected_output->f_int32 = 123;
384 expected_output->f_rect = MakeRect(5); 384 expected_output->f_rect = MakeRect(5);
385 expected_output->f_string = "hello"; 385 expected_output->f_string.emplace("hello");
386 386
387 MultiVersionStructV3Ptr output = 387 MultiVersionStructV3Ptr output =
388 SerializeAndDeserialize<MultiVersionStructV3Ptr>(std::move(input)); 388 SerializeAndDeserialize<MultiVersionStructV3Ptr>(std::move(input));
389 EXPECT_TRUE(output); 389 EXPECT_TRUE(output);
390 EXPECT_TRUE(output->Equals(*expected_output)); 390 EXPECT_TRUE(output->Equals(*expected_output));
391 } 391 }
392 392
393 { 393 {
394 MultiVersionStructPtr input = MakeMultiVersionStruct(); 394 MultiVersionStructPtr input = MakeMultiVersionStruct();
395 MultiVersionStructV1Ptr expected_output(MultiVersionStructV1::New()); 395 MultiVersionStructV1Ptr expected_output(MultiVersionStructV1::New());
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 mojo::Array<uint8_t> data = Rect::Serialize(&rect); 513 mojo::Array<uint8_t> data = Rect::Serialize(&rect);
514 514
515 RectPtr output; 515 RectPtr output;
516 ASSERT_TRUE(Rect::Deserialize(std::move(data), &output)); 516 ASSERT_TRUE(Rect::Deserialize(std::move(data), &output));
517 EXPECT_TRUE(output.Equals(cloned_rect)); 517 EXPECT_TRUE(output.Equals(cloned_rect));
518 } 518 }
519 519
520 { 520 {
521 // A struct containing other objects. 521 // A struct containing other objects.
522 NamedRegionPtr region(NamedRegion::New()); 522 NamedRegionPtr region(NamedRegion::New());
523 region->name = "region"; 523 region->name.emplace("region");
524 region->rects = Array<RectPtr>::New(4); 524 region->rects.emplace(3);
525 for (size_t i = 0; i < region->rects.size(); ++i) 525 for (size_t i = 0; i < region->rects->size(); ++i)
526 region->rects[i] = MakeRect(static_cast<int32_t>(i) + 1); 526 (*region->rects)[i] = MakeRect(static_cast<int32_t>(i) + 1);
527 527
528 NamedRegionPtr cloned_region = region.Clone(); 528 NamedRegionPtr cloned_region = region.Clone();
529 mojo::Array<uint8_t> data = NamedRegion::Serialize(&region); 529 mojo::Array<uint8_t> data = NamedRegion::Serialize(&region);
530 530
531 // Make sure that the serialized result gets pointers encoded properly. 531 // Make sure that the serialized result gets pointers encoded properly.
532 mojo::Array<uint8_t> cloned_data = data.Clone(); 532 mojo::Array<uint8_t> cloned_data = data.Clone();
533 NamedRegionPtr output; 533 NamedRegionPtr output;
534 ASSERT_TRUE(NamedRegion::Deserialize(std::move(cloned_data), &output)); 534 ASSERT_TRUE(NamedRegion::Deserialize(std::move(cloned_data), &output));
535 EXPECT_TRUE(output.Equals(cloned_region)); 535 EXPECT_TRUE(output.Equals(cloned_region));
536 } 536 }
537 537
538 { 538 {
539 // Deserialization failure. 539 // Deserialization failure.
540 RectPtr rect = MakeRect(); 540 RectPtr rect = MakeRect();
541 mojo::Array<uint8_t> data = Rect::Serialize(&rect); 541 mojo::Array<uint8_t> data = Rect::Serialize(&rect);
542 542
543 NamedRegionPtr output; 543 NamedRegionPtr output;
544 EXPECT_FALSE(NamedRegion::Deserialize(std::move(data), &output)); 544 EXPECT_FALSE(NamedRegion::Deserialize(std::move(data), &output));
545 } 545 }
546 } 546 }
547 547
548 } // namespace test 548 } // namespace test
549 } // namespace mojo 549 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/tests/stl_converters_unittest.cc ('k') | mojo/public/cpp/bindings/tests/type_conversion_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698