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 <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 #include <utility> | 7 #include <utility> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 pod->set_f_uint16(13); | 46 pod->set_f_uint16(13); |
47 EXPECT_EQ(13, pod->get_f_uint16()); | 47 EXPECT_EQ(13, pod->get_f_uint16()); |
48 EXPECT_TRUE(pod->is_f_uint16()); | 48 EXPECT_TRUE(pod->is_f_uint16()); |
49 EXPECT_EQ(pod->which(), PodUnion::Tag::F_UINT16); | 49 EXPECT_EQ(pod->which(), PodUnion::Tag::F_UINT16); |
50 | 50 |
51 pod->set_f_int32(14); | 51 pod->set_f_int32(14); |
52 EXPECT_EQ(14, pod->get_f_int32()); | 52 EXPECT_EQ(14, pod->get_f_int32()); |
53 EXPECT_TRUE(pod->is_f_int32()); | 53 EXPECT_TRUE(pod->is_f_int32()); |
54 EXPECT_EQ(pod->which(), PodUnion::Tag::F_INT32); | 54 EXPECT_EQ(pod->which(), PodUnion::Tag::F_INT32); |
55 | 55 |
56 pod->set_f_uint32(static_cast<uint32_t>(15)); | 56 pod->set_f_uint32(uint32_t{15}); |
57 EXPECT_EQ(static_cast<uint32_t>(15), pod->get_f_uint32()); | 57 EXPECT_EQ(uint32_t{15}, pod->get_f_uint32()); |
58 EXPECT_TRUE(pod->is_f_uint32()); | 58 EXPECT_TRUE(pod->is_f_uint32()); |
59 EXPECT_EQ(pod->which(), PodUnion::Tag::F_UINT32); | 59 EXPECT_EQ(pod->which(), PodUnion::Tag::F_UINT32); |
60 | 60 |
61 pod->set_f_int64(16); | 61 pod->set_f_int64(16); |
62 EXPECT_EQ(16, pod->get_f_int64()); | 62 EXPECT_EQ(16, pod->get_f_int64()); |
63 EXPECT_TRUE(pod->is_f_int64()); | 63 EXPECT_TRUE(pod->is_f_int64()); |
64 EXPECT_EQ(pod->which(), PodUnion::Tag::F_INT64); | 64 EXPECT_EQ(pod->which(), PodUnion::Tag::F_INT64); |
65 | 65 |
66 pod->set_f_uint64(static_cast<uint64_t>(17)); | 66 pod->set_f_uint64(uint64_t{17}); |
67 EXPECT_EQ(static_cast<uint64_t>(17), pod->get_f_uint64()); | 67 EXPECT_EQ(uint64_t{17}, pod->get_f_uint64()); |
68 EXPECT_TRUE(pod->is_f_uint64()); | 68 EXPECT_TRUE(pod->is_f_uint64()); |
69 EXPECT_EQ(pod->which(), PodUnion::Tag::F_UINT64); | 69 EXPECT_EQ(pod->which(), PodUnion::Tag::F_UINT64); |
70 | 70 |
71 pod->set_f_float(1.5); | 71 pod->set_f_float(1.5); |
72 EXPECT_EQ(1.5, pod->get_f_float()); | 72 EXPECT_EQ(1.5, pod->get_f_float()); |
73 EXPECT_TRUE(pod->is_f_float()); | 73 EXPECT_TRUE(pod->is_f_float()); |
74 EXPECT_EQ(pod->which(), PodUnion::Tag::F_FLOAT); | 74 EXPECT_EQ(pod->which(), PodUnion::Tag::F_FLOAT); |
75 | 75 |
76 pod->set_f_double(1.9); | 76 pod->set_f_double(1.9); |
77 EXPECT_EQ(1.9, pod->get_f_double()); | 77 EXPECT_EQ(1.9, pod->get_f_double()); |
78 EXPECT_TRUE(pod->is_f_double()); | 78 EXPECT_TRUE(pod->is_f_double()); |
79 EXPECT_EQ(pod->which(), PodUnion::Tag::F_DOUBLE); | 79 EXPECT_EQ(pod->which(), PodUnion::Tag::F_DOUBLE); |
80 | 80 |
81 pod->set_f_bool(true); | 81 pod->set_f_bool(true); |
82 EXPECT_TRUE(pod->get_f_bool()); | 82 EXPECT_TRUE(pod->get_f_bool()); |
83 pod->set_f_bool(false); | 83 pod->set_f_bool(false); |
84 EXPECT_FALSE(pod->get_f_bool()); | 84 EXPECT_FALSE(pod->get_f_bool()); |
85 EXPECT_TRUE(pod->is_f_bool()); | 85 EXPECT_TRUE(pod->is_f_bool()); |
86 EXPECT_EQ(pod->which(), PodUnion::Tag::F_BOOL); | 86 EXPECT_EQ(pod->which(), PodUnion::Tag::F_BOOL); |
87 | 87 |
88 pod->set_f_enum(AnEnum::SECOND); | 88 pod->set_f_enum(AnEnum::SECOND); |
89 EXPECT_EQ(AnEnum::SECOND, pod->get_f_enum()); | 89 EXPECT_EQ(AnEnum::SECOND, pod->get_f_enum()); |
90 EXPECT_TRUE(pod->is_f_enum()); | 90 EXPECT_TRUE(pod->is_f_enum()); |
91 EXPECT_EQ(pod->which(), PodUnion::Tag::F_ENUM); | 91 EXPECT_EQ(pod->which(), PodUnion::Tag::F_ENUM); |
92 } | 92 } |
93 | 93 |
| 94 TEST(UnionTest, PlainOldDataFactoryFunction) { |
| 95 PodUnionPtr pod = PodUnion::NewFInt8(11); |
| 96 EXPECT_EQ(11, pod->get_f_int8()); |
| 97 EXPECT_TRUE(pod->is_f_int8()); |
| 98 EXPECT_EQ(pod->which(), PodUnion::Tag::F_INT8); |
| 99 |
| 100 pod = PodUnion::NewFInt16(12); |
| 101 EXPECT_EQ(12, pod->get_f_int16()); |
| 102 EXPECT_TRUE(pod->is_f_int16()); |
| 103 EXPECT_EQ(pod->which(), PodUnion::Tag::F_INT16); |
| 104 |
| 105 pod = PodUnion::NewFUint16(13); |
| 106 EXPECT_EQ(13, pod->get_f_uint16()); |
| 107 EXPECT_TRUE(pod->is_f_uint16()); |
| 108 EXPECT_EQ(pod->which(), PodUnion::Tag::F_UINT16); |
| 109 |
| 110 pod = PodUnion::NewFInt32(14); |
| 111 EXPECT_EQ(14, pod->get_f_int32()); |
| 112 EXPECT_TRUE(pod->is_f_int32()); |
| 113 EXPECT_EQ(pod->which(), PodUnion::Tag::F_INT32); |
| 114 |
| 115 pod = PodUnion::NewFUint32(15); |
| 116 EXPECT_EQ(uint32_t{15}, pod->get_f_uint32()); |
| 117 EXPECT_TRUE(pod->is_f_uint32()); |
| 118 EXPECT_EQ(pod->which(), PodUnion::Tag::F_UINT32); |
| 119 |
| 120 pod = PodUnion::NewFInt64(16); |
| 121 EXPECT_EQ(16, pod->get_f_int64()); |
| 122 EXPECT_TRUE(pod->is_f_int64()); |
| 123 EXPECT_EQ(pod->which(), PodUnion::Tag::F_INT64); |
| 124 |
| 125 pod = PodUnion::NewFUint64(17); |
| 126 EXPECT_EQ(uint64_t{17}, pod->get_f_uint64()); |
| 127 EXPECT_TRUE(pod->is_f_uint64()); |
| 128 EXPECT_EQ(pod->which(), PodUnion::Tag::F_UINT64); |
| 129 |
| 130 pod = PodUnion::NewFFloat(1.5); |
| 131 EXPECT_EQ(1.5, pod->get_f_float()); |
| 132 EXPECT_TRUE(pod->is_f_float()); |
| 133 EXPECT_EQ(pod->which(), PodUnion::Tag::F_FLOAT); |
| 134 |
| 135 pod = PodUnion::NewFDouble(1.9); |
| 136 EXPECT_EQ(1.9, pod->get_f_double()); |
| 137 EXPECT_TRUE(pod->is_f_double()); |
| 138 EXPECT_EQ(pod->which(), PodUnion::Tag::F_DOUBLE); |
| 139 |
| 140 pod = PodUnion::NewFBool(true); |
| 141 EXPECT_TRUE(pod->get_f_bool()); |
| 142 pod = PodUnion::NewFBool(false); |
| 143 EXPECT_FALSE(pod->get_f_bool()); |
| 144 EXPECT_TRUE(pod->is_f_bool()); |
| 145 EXPECT_EQ(pod->which(), PodUnion::Tag::F_BOOL); |
| 146 |
| 147 pod = PodUnion::NewFEnum(AnEnum::SECOND); |
| 148 EXPECT_EQ(AnEnum::SECOND, pod->get_f_enum()); |
| 149 EXPECT_TRUE(pod->is_f_enum()); |
| 150 EXPECT_EQ(pod->which(), PodUnion::Tag::F_ENUM); |
| 151 |
| 152 pod = PodUnion::NewFEnum(AnEnum::FIRST); |
| 153 EXPECT_EQ(AnEnum::FIRST, pod->get_f_enum()); |
| 154 EXPECT_TRUE(pod->is_f_enum()); |
| 155 EXPECT_EQ(pod->which(), PodUnion::Tag::F_ENUM); |
| 156 } |
| 157 |
94 TEST(UnionTest, PodEquals) { | 158 TEST(UnionTest, PodEquals) { |
95 PodUnionPtr pod1(PodUnion::New()); | 159 PodUnionPtr pod1(PodUnion::New()); |
96 PodUnionPtr pod2(PodUnion::New()); | 160 PodUnionPtr pod2(PodUnion::New()); |
97 | 161 |
98 pod1->set_f_int8(10); | 162 pod1->set_f_int8(10); |
99 pod2->set_f_int8(10); | 163 pod2->set_f_int8(10); |
100 EXPECT_TRUE(pod1.Equals(pod2)); | 164 EXPECT_TRUE(pod1.Equals(pod2)); |
101 | 165 |
102 pod2->set_f_int8(11); | 166 pod2->set_f_int8(11); |
103 EXPECT_FALSE(pod1.Equals(pod2)); | 167 EXPECT_FALSE(pod1.Equals(pod2)); |
(...skipping 28 matching lines...) Expand all Loading... |
132 | 196 |
133 PodUnionPtr pod2; | 197 PodUnionPtr pod2; |
134 mojo::internal::Deserialize<PodUnionDataView>(data, &pod2, &context); | 198 mojo::internal::Deserialize<PodUnionDataView>(data, &pod2, &context); |
135 | 199 |
136 EXPECT_EQ(10, pod2->get_f_int8()); | 200 EXPECT_EQ(10, pod2->get_f_int8()); |
137 EXPECT_TRUE(pod2->is_f_int8()); | 201 EXPECT_TRUE(pod2->is_f_int8()); |
138 EXPECT_EQ(pod2->which(), PodUnion::Tag::F_INT8); | 202 EXPECT_EQ(pod2->which(), PodUnion::Tag::F_INT8); |
139 } | 203 } |
140 | 204 |
141 TEST(UnionTest, EnumSerialization) { | 205 TEST(UnionTest, EnumSerialization) { |
142 PodUnionPtr pod1(PodUnion::New()); | 206 PodUnionPtr pod1(PodUnion::NewFEnum(AnEnum::SECOND)); |
143 pod1->set_f_enum(AnEnum::SECOND); | |
144 | 207 |
145 size_t size = mojo::internal::PrepareToSerialize<PodUnionDataView>( | 208 size_t size = mojo::internal::PrepareToSerialize<PodUnionDataView>( |
146 pod1, false, nullptr); | 209 pod1, false, nullptr); |
147 EXPECT_EQ(16U, size); | 210 EXPECT_EQ(16U, size); |
148 | 211 |
149 mojo::internal::FixedBufferForTesting buf(size); | 212 mojo::internal::FixedBufferForTesting buf(size); |
150 internal::PodUnion_Data* data = nullptr; | 213 internal::PodUnion_Data* data = nullptr; |
151 mojo::internal::Serialize<PodUnionDataView>(pod1, &buf, &data, false, | 214 mojo::internal::Serialize<PodUnionDataView>(pod1, &buf, &data, false, |
152 nullptr); | 215 nullptr); |
153 | 216 |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 data->tag = static_cast<internal::PodUnion_Data::PodUnion_Tag>(0xFFFFFF); | 327 data->tag = static_cast<internal::PodUnion_Data::PodUnion_Tag>(0xFFFFFF); |
265 mojo::internal::ValidationContext validation_context( | 328 mojo::internal::ValidationContext validation_context( |
266 data, static_cast<uint32_t>(size), 0, 0); | 329 data, static_cast<uint32_t>(size), 0, 0); |
267 void* raw_buf = buf.Leak(); | 330 void* raw_buf = buf.Leak(); |
268 EXPECT_FALSE( | 331 EXPECT_FALSE( |
269 internal::PodUnion_Data::Validate(raw_buf, &validation_context, false)); | 332 internal::PodUnion_Data::Validate(raw_buf, &validation_context, false)); |
270 free(raw_buf); | 333 free(raw_buf); |
271 } | 334 } |
272 | 335 |
273 TEST(UnionTest, UnknownEnumValueValidation) { | 336 TEST(UnionTest, UnknownEnumValueValidation) { |
274 PodUnionPtr pod(PodUnion::New()); | 337 PodUnionPtr pod(PodUnion::NewFEnum(static_cast<AnEnum>(0xFFFF))); |
275 pod->set_f_enum(static_cast<AnEnum>(0xFFFF)); | |
276 | 338 |
277 size_t size = | 339 size_t size = |
278 mojo::internal::PrepareToSerialize<PodUnionDataView>(pod, false, nullptr); | 340 mojo::internal::PrepareToSerialize<PodUnionDataView>(pod, false, nullptr); |
279 EXPECT_EQ(16U, size); | 341 EXPECT_EQ(16U, size); |
280 | 342 |
281 mojo::internal::FixedBufferForTesting buf(size); | 343 mojo::internal::FixedBufferForTesting buf(size); |
282 internal::PodUnion_Data* data = nullptr; | 344 internal::PodUnion_Data* data = nullptr; |
283 mojo::internal::Serialize<PodUnionDataView>(pod, &buf, &data, false, nullptr); | 345 mojo::internal::Serialize<PodUnionDataView>(pod, &buf, &data, false, nullptr); |
284 | 346 |
285 void* raw_buf = buf.Leak(); | 347 void* raw_buf = buf.Leak(); |
286 mojo::internal::ValidationContext validation_context( | 348 mojo::internal::ValidationContext validation_context( |
287 data, static_cast<uint32_t>(size), 0, 0); | 349 data, static_cast<uint32_t>(size), 0, 0); |
288 EXPECT_FALSE( | 350 EXPECT_FALSE( |
289 internal::PodUnion_Data::Validate(raw_buf, &validation_context, false)); | 351 internal::PodUnion_Data::Validate(raw_buf, &validation_context, false)); |
290 free(raw_buf); | 352 free(raw_buf); |
291 } | 353 } |
292 | 354 |
293 TEST(UnionTest, UnknownExtensibleEnumValueValidation) { | 355 TEST(UnionTest, UnknownExtensibleEnumValueValidation) { |
294 PodUnionPtr pod(PodUnion::New()); | 356 PodUnionPtr pod( |
295 pod->set_f_extensible_enum(static_cast<AnExtensibleEnum>(0xFFFF)); | 357 PodUnion::NewFExtensibleEnum(static_cast<AnExtensibleEnum>(0xFFFF))); |
296 | 358 |
297 size_t size = | 359 size_t size = |
298 mojo::internal::PrepareToSerialize<PodUnionDataView>(pod, false, nullptr); | 360 mojo::internal::PrepareToSerialize<PodUnionDataView>(pod, false, nullptr); |
299 EXPECT_EQ(16U, size); | 361 EXPECT_EQ(16U, size); |
300 | 362 |
301 mojo::internal::FixedBufferForTesting buf(size); | 363 mojo::internal::FixedBufferForTesting buf(size); |
302 internal::PodUnion_Data* data = nullptr; | 364 internal::PodUnion_Data* data = nullptr; |
303 mojo::internal::Serialize<PodUnionDataView>(pod, &buf, &data, false, nullptr); | 365 mojo::internal::Serialize<PodUnionDataView>(pod, &buf, &data, false, nullptr); |
304 | 366 |
305 void* raw_buf = buf.Leak(); | 367 void* raw_buf = buf.Leak(); |
306 mojo::internal::ValidationContext validation_context( | 368 mojo::internal::ValidationContext validation_context( |
307 data, static_cast<uint32_t>(size), 0, 0); | 369 data, static_cast<uint32_t>(size), 0, 0); |
308 EXPECT_TRUE( | 370 EXPECT_TRUE( |
309 internal::PodUnion_Data::Validate(raw_buf, &validation_context, false)); | 371 internal::PodUnion_Data::Validate(raw_buf, &validation_context, false)); |
310 free(raw_buf); | 372 free(raw_buf); |
311 } | 373 } |
312 | 374 |
313 TEST(UnionTest, StringGetterSetter) { | 375 TEST(UnionTest, StringGetterSetter) { |
314 ObjectUnionPtr pod(ObjectUnion::New()); | 376 ObjectUnionPtr pod(ObjectUnion::New()); |
315 | 377 |
316 std::string hello("hello world"); | 378 std::string hello("hello world"); |
317 pod->set_f_string(hello); | 379 pod->set_f_string(hello); |
318 EXPECT_EQ(hello, pod->get_f_string()); | 380 EXPECT_EQ(hello, pod->get_f_string()); |
319 EXPECT_TRUE(pod->is_f_string()); | 381 EXPECT_TRUE(pod->is_f_string()); |
320 EXPECT_EQ(pod->which(), ObjectUnion::Tag::F_STRING); | 382 EXPECT_EQ(pod->which(), ObjectUnion::Tag::F_STRING); |
321 } | 383 } |
322 | 384 |
| 385 TEST(UnionTest, StringFactoryFunction) { |
| 386 std::string hello("hello world"); |
| 387 ObjectUnionPtr pod(ObjectUnion::NewFString(hello)); |
| 388 |
| 389 EXPECT_EQ(hello, pod->get_f_string()); |
| 390 EXPECT_TRUE(pod->is_f_string()); |
| 391 EXPECT_EQ(pod->which(), ObjectUnion::Tag::F_STRING); |
| 392 } |
| 393 |
323 TEST(UnionTest, StringEquals) { | 394 TEST(UnionTest, StringEquals) { |
324 ObjectUnionPtr pod1(ObjectUnion::New()); | 395 ObjectUnionPtr pod1(ObjectUnion::NewFString("hello world")); |
325 ObjectUnionPtr pod2(ObjectUnion::New()); | 396 ObjectUnionPtr pod2(ObjectUnion::NewFString("hello world")); |
326 | 397 |
327 pod1->set_f_string("hello world"); | |
328 pod2->set_f_string("hello world"); | |
329 EXPECT_TRUE(pod1.Equals(pod2)); | 398 EXPECT_TRUE(pod1.Equals(pod2)); |
330 | 399 |
331 pod2->set_f_string("hello universe"); | 400 pod2->set_f_string("hello universe"); |
332 EXPECT_FALSE(pod1.Equals(pod2)); | 401 EXPECT_FALSE(pod1.Equals(pod2)); |
333 } | 402 } |
334 | 403 |
335 TEST(UnionTest, StringClone) { | 404 TEST(UnionTest, StringClone) { |
336 ObjectUnionPtr pod(ObjectUnion::New()); | 405 std::string hello("hello world"); |
| 406 ObjectUnionPtr pod(ObjectUnion::NewFString(hello)); |
337 | 407 |
338 std::string hello("hello world"); | |
339 pod->set_f_string(hello); | |
340 ObjectUnionPtr pod_clone = pod.Clone(); | 408 ObjectUnionPtr pod_clone = pod.Clone(); |
341 EXPECT_EQ(hello, pod_clone->get_f_string()); | 409 EXPECT_EQ(hello, pod_clone->get_f_string()); |
342 EXPECT_TRUE(pod_clone->is_f_string()); | 410 EXPECT_TRUE(pod_clone->is_f_string()); |
343 EXPECT_EQ(pod_clone->which(), ObjectUnion::Tag::F_STRING); | 411 EXPECT_EQ(pod_clone->which(), ObjectUnion::Tag::F_STRING); |
344 } | 412 } |
345 | 413 |
346 TEST(UnionTest, StringSerialization) { | 414 TEST(UnionTest, StringSerialization) { |
347 ObjectUnionPtr pod1(ObjectUnion::New()); | |
348 | |
349 std::string hello("hello world"); | 415 std::string hello("hello world"); |
350 pod1->set_f_string(hello); | 416 ObjectUnionPtr pod1(ObjectUnion::NewFString(hello)); |
351 | 417 |
352 size_t size = mojo::internal::PrepareToSerialize<ObjectUnionDataView>( | 418 size_t size = mojo::internal::PrepareToSerialize<ObjectUnionDataView>( |
353 pod1, false, nullptr); | 419 pod1, false, nullptr); |
354 mojo::internal::FixedBufferForTesting buf(size); | 420 mojo::internal::FixedBufferForTesting buf(size); |
355 internal::ObjectUnion_Data* data = nullptr; | 421 internal::ObjectUnion_Data* data = nullptr; |
356 mojo::internal::Serialize<ObjectUnionDataView>(pod1, &buf, &data, false, | 422 mojo::internal::Serialize<ObjectUnionDataView>(pod1, &buf, &data, false, |
357 nullptr); | 423 nullptr); |
358 | 424 |
359 ObjectUnionPtr pod2; | 425 ObjectUnionPtr pod2; |
360 mojo::internal::Deserialize<ObjectUnionDataView>(data, &pod2, nullptr); | 426 mojo::internal::Deserialize<ObjectUnionDataView>(data, &pod2, nullptr); |
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
973 TEST(UnionTest, UnionInUnionGetterSetter) { | 1039 TEST(UnionTest, UnionInUnionGetterSetter) { |
974 PodUnionPtr pod(PodUnion::New()); | 1040 PodUnionPtr pod(PodUnion::New()); |
975 pod->set_f_int8(10); | 1041 pod->set_f_int8(10); |
976 | 1042 |
977 ObjectUnionPtr obj(ObjectUnion::New()); | 1043 ObjectUnionPtr obj(ObjectUnion::New()); |
978 obj->set_f_pod_union(std::move(pod)); | 1044 obj->set_f_pod_union(std::move(pod)); |
979 | 1045 |
980 EXPECT_EQ(10, obj->get_f_pod_union()->get_f_int8()); | 1046 EXPECT_EQ(10, obj->get_f_pod_union()->get_f_int8()); |
981 } | 1047 } |
982 | 1048 |
| 1049 TEST(UnionTest, UnionInUnionFactoryFunction) { |
| 1050 PodUnionPtr pod(PodUnion::New()); |
| 1051 pod->set_f_int8(10); |
| 1052 |
| 1053 ObjectUnionPtr obj(ObjectUnion::NewFPodUnion(std::move(pod))); |
| 1054 |
| 1055 EXPECT_EQ(10, obj->get_f_pod_union()->get_f_int8()); |
| 1056 } |
| 1057 |
983 TEST(UnionTest, UnionInUnionSerialization) { | 1058 TEST(UnionTest, UnionInUnionSerialization) { |
984 PodUnionPtr pod(PodUnion::New()); | 1059 PodUnionPtr pod(PodUnion::New()); |
985 pod->set_f_int8(10); | 1060 pod->set_f_int8(10); |
986 | 1061 |
987 ObjectUnionPtr obj(ObjectUnion::New()); | 1062 ObjectUnionPtr obj(ObjectUnion::New()); |
988 obj->set_f_pod_union(std::move(pod)); | 1063 obj->set_f_pod_union(std::move(pod)); |
989 | 1064 |
990 size_t size = mojo::internal::PrepareToSerialize<ObjectUnionDataView>( | 1065 size_t size = mojo::internal::PrepareToSerialize<ObjectUnionDataView>( |
991 obj, false, nullptr); | 1066 obj, false, nullptr); |
992 EXPECT_EQ(32U, size); | 1067 EXPECT_EQ(32U, size); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1060 | 1135 |
1061 std::string golden("hello world"); | 1136 std::string golden("hello world"); |
1062 WriteTextMessage(pipe0.get(), golden); | 1137 WriteTextMessage(pipe0.get(), golden); |
1063 | 1138 |
1064 std::string actual; | 1139 std::string actual; |
1065 ReadTextMessage(handle->get_f_message_pipe().get(), &actual); | 1140 ReadTextMessage(handle->get_f_message_pipe().get(), &actual); |
1066 | 1141 |
1067 EXPECT_EQ(golden, actual); | 1142 EXPECT_EQ(golden, actual); |
1068 } | 1143 } |
1069 | 1144 |
| 1145 TEST(UnionTest, HandleInUnionGetterFactoryFunction) { |
| 1146 ScopedMessagePipeHandle pipe0; |
| 1147 ScopedMessagePipeHandle pipe1; |
| 1148 |
| 1149 CreateMessagePipe(nullptr, &pipe0, &pipe1); |
| 1150 |
| 1151 HandleUnionPtr handle(HandleUnion::NewFMessagePipe(std::move(pipe1))); |
| 1152 |
| 1153 std::string golden("hello world"); |
| 1154 WriteTextMessage(pipe0.get(), golden); |
| 1155 |
| 1156 std::string actual; |
| 1157 ReadTextMessage(handle->get_f_message_pipe().get(), &actual); |
| 1158 |
| 1159 EXPECT_EQ(golden, actual); |
| 1160 } |
| 1161 |
1070 TEST(UnionTest, HandleInUnionSerialization) { | 1162 TEST(UnionTest, HandleInUnionSerialization) { |
1071 ScopedMessagePipeHandle pipe0; | 1163 ScopedMessagePipeHandle pipe0; |
1072 ScopedMessagePipeHandle pipe1; | 1164 ScopedMessagePipeHandle pipe1; |
1073 | 1165 |
1074 CreateMessagePipe(nullptr, &pipe0, &pipe1); | 1166 CreateMessagePipe(nullptr, &pipe0, &pipe1); |
1075 | 1167 |
1076 HandleUnionPtr handle(HandleUnion::New()); | 1168 HandleUnionPtr handle(HandleUnion::New()); |
1077 handle->set_f_message_pipe(std::move(pipe1)); | 1169 handle->set_f_message_pipe(std::move(pipe1)); |
1078 | 1170 |
1079 mojo::internal::SerializationContext context; | 1171 mojo::internal::SerializationContext context; |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1179 Binding<SmallCache> bindings(&impl, MakeRequest(&ptr)); | 1271 Binding<SmallCache> bindings(&impl, MakeRequest(&ptr)); |
1180 | 1272 |
1181 HandleUnionPtr handle(HandleUnion::New()); | 1273 HandleUnionPtr handle(HandleUnion::New()); |
1182 handle->set_f_small_cache(std::move(ptr)); | 1274 handle->set_f_small_cache(std::move(ptr)); |
1183 | 1275 |
1184 handle->get_f_small_cache()->SetIntValue(10); | 1276 handle->get_f_small_cache()->SetIntValue(10); |
1185 run_loop.Run(); | 1277 run_loop.Run(); |
1186 EXPECT_EQ(10, impl.int_value()); | 1278 EXPECT_EQ(10, impl.int_value()); |
1187 } | 1279 } |
1188 | 1280 |
| 1281 TEST(UnionTest, InterfaceInUnionFactoryFunction) { |
| 1282 base::MessageLoop message_loop; |
| 1283 base::RunLoop run_loop; |
| 1284 SmallCacheImpl impl(run_loop.QuitClosure()); |
| 1285 SmallCachePtr ptr; |
| 1286 Binding<SmallCache> bindings(&impl, MakeRequest(&ptr)); |
| 1287 |
| 1288 HandleUnionPtr handle(HandleUnion::NewFSmallCache(std::move(ptr))); |
| 1289 |
| 1290 handle->get_f_small_cache()->SetIntValue(10); |
| 1291 run_loop.Run(); |
| 1292 EXPECT_EQ(10, impl.int_value()); |
| 1293 } |
| 1294 |
1189 TEST(UnionTest, InterfaceInUnionSerialization) { | 1295 TEST(UnionTest, InterfaceInUnionSerialization) { |
1190 base::MessageLoop message_loop; | 1296 base::MessageLoop message_loop; |
1191 base::RunLoop run_loop; | 1297 base::RunLoop run_loop; |
1192 SmallCacheImpl impl(run_loop.QuitClosure()); | 1298 SmallCacheImpl impl(run_loop.QuitClosure()); |
1193 SmallCachePtr ptr; | 1299 SmallCachePtr ptr; |
1194 Binding<SmallCache> bindings(&impl, MakeRequest(&ptr)); | 1300 Binding<SmallCache> bindings(&impl, MakeRequest(&ptr)); |
1195 | 1301 |
1196 mojo::internal::SerializationContext context; | 1302 mojo::internal::SerializationContext context; |
1197 HandleUnionPtr handle(HandleUnion::New()); | 1303 HandleUnionPtr handle(HandleUnion::New()); |
1198 handle->set_f_small_cache(std::move(ptr)); | 1304 handle->set_f_small_cache(std::move(ptr)); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1237 | 1343 |
1238 PodUnionPtr pod(PodUnion::New()); | 1344 PodUnionPtr pod(PodUnion::New()); |
1239 pod->set_f_int16(16); | 1345 pod->set_f_int16(16); |
1240 | 1346 |
1241 ptr->Echo(std::move(pod), base::Bind(&ExpectInt16, 16)); | 1347 ptr->Echo(std::move(pod), base::Bind(&ExpectInt16, 16)); |
1242 base::RunLoop().RunUntilIdle(); | 1348 base::RunLoop().RunUntilIdle(); |
1243 } | 1349 } |
1244 | 1350 |
1245 } // namespace test | 1351 } // namespace test |
1246 } // namespace mojo | 1352 } // namespace mojo |
OLD | NEW |