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

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

Issue 2112093002: Mojo C++ bindings: Merge EncodePointers/DecodePointers into Serialize/Deserialize, respectively. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@61_array_fix
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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
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*;
54 using OutputDataType = typename mojo::internal::MojomTypeTraits<U>::Data*; 54 using OutputDataType = typename mojo::internal::MojomTypeTraits<U>::Data*;
55 55
56 mojo::internal::SerializationContext context; 56 mojo::internal::SerializationContext context;
57 size_t size = mojo::internal::PrepareToSerialize<T>(input, &context); 57 size_t size = mojo::internal::PrepareToSerialize<T>(input, &context);
58 mojo::internal::FixedBufferForTesting buf(size + 32); 58 mojo::internal::FixedBufferForTesting buf(size + 32);
59 InputDataType data; 59 InputDataType data;
60 mojo::internal::Serialize<T>(input, &buf, &data, &context); 60 mojo::internal::Serialize<T>(input, &buf, &data, &context);
61 61
62 data->EncodePointers();
63
64 // Set the subsequent area to a special value, so that we can find out if we 62 // Set the subsequent area to a special value, so that we can find out if we
65 // mistakenly access the area. 63 // mistakenly access the area.
66 void* subsequent_area = buf.Allocate(32); 64 void* subsequent_area = buf.Allocate(32);
67 memset(subsequent_area, 0xAA, 32); 65 memset(subsequent_area, 0xAA, 32);
68 66
69 OutputDataType output_data = reinterpret_cast<OutputDataType>(data); 67 OutputDataType output_data = reinterpret_cast<OutputDataType>(data);
70 output_data->DecodePointers();
71 68
72 U output; 69 U output;
73 mojo::internal::Deserialize<U>(output_data, &output, &context); 70 mojo::internal::Deserialize<U>(output_data, &output, &context);
74 return std::move(output); 71 return std::move(output);
75 } 72 }
76 73
77 using StructTest = testing::Test; 74 using StructTest = testing::Test;
78 75
79 } // namespace 76 } // namespace
80 77
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 mojo::internal::PrepareToSerialize<NativeStructPtr>(native, nullptr); 465 mojo::internal::PrepareToSerialize<NativeStructPtr>(native, nullptr);
469 EXPECT_EQ(16u, size); 466 EXPECT_EQ(16u, size);
470 mojo::internal::FixedBufferForTesting buf(size); 467 mojo::internal::FixedBufferForTesting buf(size);
471 468
472 Data* data = nullptr; 469 Data* data = nullptr;
473 mojo::internal::Serialize<NativeStructPtr>(std::move(native), &buf, &data, 470 mojo::internal::Serialize<NativeStructPtr>(std::move(native), &buf, &data,
474 nullptr); 471 nullptr);
475 472
476 EXPECT_NE(nullptr, data); 473 EXPECT_NE(nullptr, data);
477 474
478 data->EncodePointers();
479 data->DecodePointers();
480
481 NativeStructPtr output_native; 475 NativeStructPtr output_native;
482 mojo::internal::Deserialize<NativeStructPtr>(data, &output_native, nullptr); 476 mojo::internal::Deserialize<NativeStructPtr>(data, &output_native, nullptr);
483 EXPECT_FALSE(output_native.is_null()); 477 EXPECT_FALSE(output_native.is_null());
484 EXPECT_FALSE(output_native->data.is_null()); 478 EXPECT_FALSE(output_native->data.is_null());
485 EXPECT_EQ(2u, output_native->data.size()); 479 EXPECT_EQ(2u, output_native->data.size());
486 EXPECT_EQ('X', output_native->data[0]); 480 EXPECT_EQ('X', output_native->data[0]);
487 EXPECT_EQ('Y', output_native->data[1]); 481 EXPECT_EQ('Y', output_native->data[1]);
488 } 482 }
489 } 483 }
490 484
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 RectPtr rect = MakeRect(); 540 RectPtr rect = MakeRect();
547 mojo::Array<uint8_t> data = Rect::Serialize(&rect); 541 mojo::Array<uint8_t> data = Rect::Serialize(&rect);
548 542
549 NamedRegionPtr output; 543 NamedRegionPtr output;
550 EXPECT_FALSE(NamedRegion::Deserialize(std::move(data), &output)); 544 EXPECT_FALSE(NamedRegion::Deserialize(std::move(data), &output));
551 } 545 }
552 } 546 }
553 547
554 } // namespace test 548 } // namespace test
555 } // namespace mojo 549 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/tests/array_common_test.h ('k') | mojo/public/cpp/bindings/tests/union_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698