| 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 <string.h> | 5 #include <string.h> |
| 6 | 6 |
| 7 #include "mojo/public/cpp/bindings/lib/fixed_buffer.h" | 7 #include "mojo/public/cpp/bindings/lib/fixed_buffer.h" |
| 8 #include "mojo/public/cpp/environment/environment.h" | 8 #include "mojo/public/cpp/environment/environment.h" |
| 9 #include "mojo/public/cpp/system/message_pipe.h" | 9 #include "mojo/public/cpp/system/message_pipe.h" |
| 10 #include "mojo/public/interfaces/bindings/tests/test_structs.mojom.h" | 10 #include "mojo/public/interfaces/bindings/tests/test_structs.mojom.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 EXPECT_EQ(2 * factor, rect.y); | 28 EXPECT_EQ(2 * factor, rect.y); |
| 29 EXPECT_EQ(10 * factor, rect.width); | 29 EXPECT_EQ(10 * factor, rect.width); |
| 30 EXPECT_EQ(20 * factor, rect.height); | 30 EXPECT_EQ(20 * factor, rect.height); |
| 31 } | 31 } |
| 32 | 32 |
| 33 MultiVersionStructPtr MakeMultiVersionStruct() { | 33 MultiVersionStructPtr MakeMultiVersionStruct() { |
| 34 MultiVersionStructPtr output(MultiVersionStruct::New()); | 34 MultiVersionStructPtr output(MultiVersionStruct::New()); |
| 35 output->f_int32 = 123; | 35 output->f_int32 = 123; |
| 36 output->f_rect = MakeRect(5); | 36 output->f_rect = MakeRect(5); |
| 37 output->f_string = "hello"; | 37 output->f_string = "hello"; |
| 38 output->f_array = Array<int8_t>(3); | 38 output->f_array = Array<int8_t>::New(3); |
| 39 output->f_array[0] = 10; | 39 output->f_array[0] = 10; |
| 40 output->f_array[1] = 9; | 40 output->f_array[1] = 9; |
| 41 output->f_array[2] = 8; | 41 output->f_array[2] = 8; |
| 42 MessagePipe pipe; | 42 MessagePipe pipe; |
| 43 output->f_message_pipe = pipe.handle0.Pass(); | 43 output->f_message_pipe = pipe.handle0.Pass(); |
| 44 output->f_int16 = 42; | 44 output->f_int16 = 42; |
| 45 | 45 |
| 46 return output.Pass(); | 46 return output.Pass(); |
| 47 } | 47 } |
| 48 | 48 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 | 115 |
| 116 region = NamedRegion::New(); | 116 region = NamedRegion::New(); |
| 117 clone_region = region.Clone(); | 117 clone_region = region.Clone(); |
| 118 EXPECT_TRUE(clone_region->name.is_null()); | 118 EXPECT_TRUE(clone_region->name.is_null()); |
| 119 EXPECT_TRUE(clone_region->rects.is_null()); | 119 EXPECT_TRUE(clone_region->rects.is_null()); |
| 120 | 120 |
| 121 region->name = "hello world"; | 121 region->name = "hello world"; |
| 122 clone_region = region.Clone(); | 122 clone_region = region.Clone(); |
| 123 EXPECT_EQ(region->name, clone_region->name); | 123 EXPECT_EQ(region->name, clone_region->name); |
| 124 | 124 |
| 125 region->rects = Array<RectPtr>(2); | 125 region->rects = Array<RectPtr>::New(2); |
| 126 region->rects[1] = MakeRect(); | 126 region->rects[1] = MakeRect(); |
| 127 clone_region = region.Clone(); | 127 clone_region = region.Clone(); |
| 128 EXPECT_EQ(2u, clone_region->rects.size()); | 128 EXPECT_EQ(2u, clone_region->rects.size()); |
| 129 EXPECT_TRUE(clone_region->rects[0].is_null()); | 129 EXPECT_TRUE(clone_region->rects[0].is_null()); |
| 130 CheckRect(*clone_region->rects[1]); | 130 CheckRect(*clone_region->rects[1]); |
| 131 | 131 |
| 132 // NoDefaultFieldValues contains handles, so Clone() is not available, but | 132 // NoDefaultFieldValues contains handles, so Clone() is not available, but |
| 133 // NoDefaultFieldValuesPtr should still compile. | 133 // NoDefaultFieldValuesPtr should still compile. |
| 134 NoDefaultFieldValuesPtr no_default_field_values(NoDefaultFieldValues::New()); | 134 NoDefaultFieldValuesPtr no_default_field_values(NoDefaultFieldValues::New()); |
| 135 EXPECT_FALSE(no_default_field_values->f13.is_valid()); | 135 EXPECT_FALSE(no_default_field_values->f13.is_valid()); |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 SerializeAndDeserialize<MultiVersionStructPtr>(input.Pass()); | 285 SerializeAndDeserialize<MultiVersionStructPtr>(input.Pass()); |
| 286 EXPECT_TRUE(output); | 286 EXPECT_TRUE(output); |
| 287 EXPECT_TRUE(output->Equals(*expected_output)); | 287 EXPECT_TRUE(output->Equals(*expected_output)); |
| 288 } | 288 } |
| 289 | 289 |
| 290 { | 290 { |
| 291 MultiVersionStructV5Ptr input(MultiVersionStructV5::New()); | 291 MultiVersionStructV5Ptr input(MultiVersionStructV5::New()); |
| 292 input->f_int32 = 123; | 292 input->f_int32 = 123; |
| 293 input->f_rect = MakeRect(5); | 293 input->f_rect = MakeRect(5); |
| 294 input->f_string = "hello"; | 294 input->f_string = "hello"; |
| 295 input->f_array = Array<int8_t>(3); | 295 input->f_array = Array<int8_t>::New(3); |
| 296 input->f_array[0] = 10; | 296 input->f_array[0] = 10; |
| 297 input->f_array[1] = 9; | 297 input->f_array[1] = 9; |
| 298 input->f_array[2] = 8; | 298 input->f_array[2] = 8; |
| 299 MultiVersionStructPtr expected_output(MultiVersionStruct::New()); | 299 MultiVersionStructPtr expected_output(MultiVersionStruct::New()); |
| 300 expected_output->f_int32 = 123; | 300 expected_output->f_int32 = 123; |
| 301 expected_output->f_rect = MakeRect(5); | 301 expected_output->f_rect = MakeRect(5); |
| 302 expected_output->f_string = "hello"; | 302 expected_output->f_string = "hello"; |
| 303 expected_output->f_array = Array<int8_t>(3); | 303 expected_output->f_array = Array<int8_t>::New(3); |
| 304 expected_output->f_array[0] = 10; | 304 expected_output->f_array[0] = 10; |
| 305 expected_output->f_array[1] = 9; | 305 expected_output->f_array[1] = 9; |
| 306 expected_output->f_array[2] = 8; | 306 expected_output->f_array[2] = 8; |
| 307 | 307 |
| 308 MultiVersionStructPtr output = | 308 MultiVersionStructPtr output = |
| 309 SerializeAndDeserialize<MultiVersionStructPtr>(input.Pass()); | 309 SerializeAndDeserialize<MultiVersionStructPtr>(input.Pass()); |
| 310 EXPECT_TRUE(output); | 310 EXPECT_TRUE(output); |
| 311 EXPECT_TRUE(output->Equals(*expected_output)); | 311 EXPECT_TRUE(output->Equals(*expected_output)); |
| 312 } | 312 } |
| 313 | 313 |
| 314 { | 314 { |
| 315 MultiVersionStructV7Ptr input(MultiVersionStructV7::New()); | 315 MultiVersionStructV7Ptr input(MultiVersionStructV7::New()); |
| 316 input->f_int32 = 123; | 316 input->f_int32 = 123; |
| 317 input->f_rect = MakeRect(5); | 317 input->f_rect = MakeRect(5); |
| 318 input->f_string = "hello"; | 318 input->f_string = "hello"; |
| 319 input->f_array = Array<int8_t>(3); | 319 input->f_array = Array<int8_t>::New(3); |
| 320 input->f_array[0] = 10; | 320 input->f_array[0] = 10; |
| 321 input->f_array[1] = 9; | 321 input->f_array[1] = 9; |
| 322 input->f_array[2] = 8; | 322 input->f_array[2] = 8; |
| 323 MessagePipe pipe; | 323 MessagePipe pipe; |
| 324 input->f_message_pipe = pipe.handle0.Pass(); | 324 input->f_message_pipe = pipe.handle0.Pass(); |
| 325 | 325 |
| 326 MultiVersionStructPtr expected_output(MultiVersionStruct::New()); | 326 MultiVersionStructPtr expected_output(MultiVersionStruct::New()); |
| 327 expected_output->f_int32 = 123; | 327 expected_output->f_int32 = 123; |
| 328 expected_output->f_rect = MakeRect(5); | 328 expected_output->f_rect = MakeRect(5); |
| 329 expected_output->f_string = "hello"; | 329 expected_output->f_string = "hello"; |
| 330 expected_output->f_array = Array<int8_t>(3); | 330 expected_output->f_array = Array<int8_t>::New(3); |
| 331 expected_output->f_array[0] = 10; | 331 expected_output->f_array[0] = 10; |
| 332 expected_output->f_array[1] = 9; | 332 expected_output->f_array[1] = 9; |
| 333 expected_output->f_array[2] = 8; | 333 expected_output->f_array[2] = 8; |
| 334 // Save the raw handle value separately so that we can compare later. | 334 // Save the raw handle value separately so that we can compare later. |
| 335 MojoHandle expected_handle = input->f_message_pipe.get().value(); | 335 MojoHandle expected_handle = input->f_message_pipe.get().value(); |
| 336 | 336 |
| 337 MultiVersionStructPtr output = | 337 MultiVersionStructPtr output = |
| 338 SerializeAndDeserialize<MultiVersionStructPtr>(input.Pass()); | 338 SerializeAndDeserialize<MultiVersionStructPtr>(input.Pass()); |
| 339 EXPECT_TRUE(output); | 339 EXPECT_TRUE(output); |
| 340 EXPECT_EQ(expected_handle, output->f_message_pipe.get().value()); | 340 EXPECT_EQ(expected_handle, output->f_message_pipe.get().value()); |
| 341 output->f_message_pipe.reset(); | 341 output->f_message_pipe.reset(); |
| 342 EXPECT_TRUE(output->Equals(*expected_output)); | 342 EXPECT_TRUE(output->Equals(*expected_output)); |
| 343 } | 343 } |
| 344 } | 344 } |
| 345 | 345 |
| 346 // Tests deserializing structs as an older version. | 346 // Tests deserializing structs as an older version. |
| 347 TEST_F(StructTest, Versioning_NewToOld) { | 347 TEST_F(StructTest, Versioning_NewToOld) { |
| 348 { | 348 { |
| 349 MultiVersionStructPtr input = MakeMultiVersionStruct(); | 349 MultiVersionStructPtr input = MakeMultiVersionStruct(); |
| 350 MultiVersionStructV7Ptr expected_output(MultiVersionStructV7::New()); | 350 MultiVersionStructV7Ptr expected_output(MultiVersionStructV7::New()); |
| 351 expected_output->f_int32 = 123; | 351 expected_output->f_int32 = 123; |
| 352 expected_output->f_rect = MakeRect(5); | 352 expected_output->f_rect = MakeRect(5); |
| 353 expected_output->f_string = "hello"; | 353 expected_output->f_string = "hello"; |
| 354 expected_output->f_array = Array<int8_t>(3); | 354 expected_output->f_array = Array<int8_t>::New(3); |
| 355 expected_output->f_array[0] = 10; | 355 expected_output->f_array[0] = 10; |
| 356 expected_output->f_array[1] = 9; | 356 expected_output->f_array[1] = 9; |
| 357 expected_output->f_array[2] = 8; | 357 expected_output->f_array[2] = 8; |
| 358 // Save the raw handle value separately so that we can compare later. | 358 // Save the raw handle value separately so that we can compare later. |
| 359 MojoHandle expected_handle = input->f_message_pipe.get().value(); | 359 MojoHandle expected_handle = input->f_message_pipe.get().value(); |
| 360 | 360 |
| 361 MultiVersionStructV7Ptr output = | 361 MultiVersionStructV7Ptr output = |
| 362 SerializeAndDeserialize<MultiVersionStructV7Ptr>(input.Pass()); | 362 SerializeAndDeserialize<MultiVersionStructV7Ptr>(input.Pass()); |
| 363 EXPECT_TRUE(output); | 363 EXPECT_TRUE(output); |
| 364 EXPECT_EQ(expected_handle, output->f_message_pipe.get().value()); | 364 EXPECT_EQ(expected_handle, output->f_message_pipe.get().value()); |
| 365 output->f_message_pipe.reset(); | 365 output->f_message_pipe.reset(); |
| 366 EXPECT_TRUE(output->Equals(*expected_output)); | 366 EXPECT_TRUE(output->Equals(*expected_output)); |
| 367 } | 367 } |
| 368 | 368 |
| 369 { | 369 { |
| 370 MultiVersionStructPtr input = MakeMultiVersionStruct(); | 370 MultiVersionStructPtr input = MakeMultiVersionStruct(); |
| 371 MultiVersionStructV5Ptr expected_output(MultiVersionStructV5::New()); | 371 MultiVersionStructV5Ptr expected_output(MultiVersionStructV5::New()); |
| 372 expected_output->f_int32 = 123; | 372 expected_output->f_int32 = 123; |
| 373 expected_output->f_rect = MakeRect(5); | 373 expected_output->f_rect = MakeRect(5); |
| 374 expected_output->f_string = "hello"; | 374 expected_output->f_string = "hello"; |
| 375 expected_output->f_array = Array<int8_t>(3); | 375 expected_output->f_array = Array<int8_t>::New(3); |
| 376 expected_output->f_array[0] = 10; | 376 expected_output->f_array[0] = 10; |
| 377 expected_output->f_array[1] = 9; | 377 expected_output->f_array[1] = 9; |
| 378 expected_output->f_array[2] = 8; | 378 expected_output->f_array[2] = 8; |
| 379 | 379 |
| 380 MultiVersionStructV5Ptr output = | 380 MultiVersionStructV5Ptr output = |
| 381 SerializeAndDeserialize<MultiVersionStructV5Ptr>(input.Pass()); | 381 SerializeAndDeserialize<MultiVersionStructV5Ptr>(input.Pass()); |
| 382 EXPECT_TRUE(output); | 382 EXPECT_TRUE(output); |
| 383 EXPECT_TRUE(output->Equals(*expected_output)); | 383 EXPECT_TRUE(output->Equals(*expected_output)); |
| 384 } | 384 } |
| 385 | 385 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 414 expected_output->f_int32 = 123; | 414 expected_output->f_int32 = 123; |
| 415 | 415 |
| 416 MultiVersionStructV0Ptr output = | 416 MultiVersionStructV0Ptr output = |
| 417 SerializeAndDeserialize<MultiVersionStructV0Ptr>(input.Pass()); | 417 SerializeAndDeserialize<MultiVersionStructV0Ptr>(input.Pass()); |
| 418 EXPECT_TRUE(output); | 418 EXPECT_TRUE(output); |
| 419 EXPECT_TRUE(output->Equals(*expected_output)); | 419 EXPECT_TRUE(output->Equals(*expected_output)); |
| 420 } | 420 } |
| 421 } | 421 } |
| 422 } // namespace test | 422 } // namespace test |
| 423 } // namespace mojo | 423 } // namespace mojo |
| OLD | NEW |