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

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

Issue 2014403002: Mojo C++ bindings: custom type mapping of map (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/callback.h" 6 #include "base/callback.h"
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "mojo/public/cpp/bindings/binding_set.h" 10 #include "mojo/public/cpp/bindings/binding_set.h"
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 StructWithTraitsImpl input; 218 StructWithTraitsImpl input;
219 input.set_bool(true); 219 input.set_bool(true);
220 input.set_uint32(7); 220 input.set_uint32(7);
221 input.set_uint64(42); 221 input.set_uint64(42);
222 input.set_string("hello world!"); 222 input.set_string("hello world!");
223 input.get_mutable_string_array().assign({"hello", "world!"}); 223 input.get_mutable_string_array().assign({"hello", "world!"});
224 input.get_mutable_struct().value = 42; 224 input.get_mutable_struct().value = 42;
225 input.get_mutable_struct_array().resize(2); 225 input.get_mutable_struct_array().resize(2);
226 input.get_mutable_struct_array()[0].value = 1; 226 input.get_mutable_struct_array()[0].value = 1;
227 input.get_mutable_struct_array()[1].value = 2; 227 input.get_mutable_struct_array()[1].value = 2;
228 input.get_mutable_struct_map()["hello"] = NestedStructWithTraitsImpl(1024);
229 input.get_mutable_struct_map()["world"] = NestedStructWithTraitsImpl(2048);
228 230
229 base::RunLoop loop; 231 base::RunLoop loop;
230 TraitsTestServicePtr proxy = GetTraitsTestProxy(); 232 TraitsTestServicePtr proxy = GetTraitsTestProxy();
231 233
232 proxy->EchoStructWithTraits(input, [&](const StructWithTraitsImpl& passed) { 234 proxy->EchoStructWithTraits(input, [&](const StructWithTraitsImpl& passed) {
233 EXPECT_EQ(input.get_bool(), passed.get_bool()); 235 EXPECT_EQ(input.get_bool(), passed.get_bool());
234 EXPECT_EQ(input.get_uint32(), passed.get_uint32()); 236 EXPECT_EQ(input.get_uint32(), passed.get_uint32());
235 EXPECT_EQ(input.get_uint64(), passed.get_uint64()); 237 EXPECT_EQ(input.get_uint64(), passed.get_uint64());
236 EXPECT_EQ(input.get_string(), passed.get_string()); 238 EXPECT_EQ(input.get_string(), passed.get_string());
237 EXPECT_EQ(input.get_string_array(), passed.get_string_array()); 239 EXPECT_EQ(input.get_string_array(), passed.get_string_array());
238 EXPECT_EQ(input.get_struct(), passed.get_struct()); 240 EXPECT_EQ(input.get_struct(), passed.get_struct());
239 EXPECT_EQ(input.get_struct_array(), passed.get_struct_array()); 241 EXPECT_EQ(input.get_struct_array(), passed.get_struct_array());
242 EXPECT_EQ(input.get_struct_map(), passed.get_struct_map());
240 loop.Quit(); 243 loop.Quit();
241 }); 244 });
242 loop.Run(); 245 loop.Run();
243 } 246 }
244 247
245 TEST_F(StructTraitsTest, EchoPassByValueStructWithTraits) { 248 TEST_F(StructTraitsTest, EchoPassByValueStructWithTraits) {
246 MessagePipe mp; 249 MessagePipe mp;
247 PassByValueStructWithTraitsImpl input; 250 PassByValueStructWithTraitsImpl input;
248 input.get_mutable_handle().reset(mp.handle0.release()); 251 input.get_mutable_handle().reset(mp.handle0.release());
249 252
(...skipping 25 matching lines...) Expand all
275 uint32_t buffer_size = static_cast<uint32_t>(sizeof(buffer)); 278 uint32_t buffer_size = static_cast<uint32_t>(sizeof(buffer));
276 EXPECT_EQ(MOJO_RESULT_OK, 279 EXPECT_EQ(MOJO_RESULT_OK,
277 ReadMessageRaw(received.get(), buffer, &buffer_size, nullptr, 280 ReadMessageRaw(received.get(), buffer, &buffer_size, nullptr,
278 nullptr, MOJO_READ_MESSAGE_FLAG_NONE)); 281 nullptr, MOJO_READ_MESSAGE_FLAG_NONE));
279 EXPECT_EQ(kHelloSize, buffer_size); 282 EXPECT_EQ(kHelloSize, buffer_size);
280 EXPECT_STREQ(kHello, buffer); 283 EXPECT_STREQ(kHello, buffer);
281 } 284 }
282 285
283 } // namespace test 286 } // namespace test
284 } // namespace mojo 287 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/struct_traits.h ('k') | mojo/public/cpp/bindings/tests/struct_with_traits_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698