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

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

Issue 2146153002: Mojo typemap config: support "copyable_pass_by_value" attribute. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@69_change_move_only
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
« no previous file with comments | « no previous file | mojo/public/cpp/bindings/tests/struct_with_traits.typemap » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 } 127 }
128 128
129 private: 129 private:
130 // TraitsTestService: 130 // TraitsTestService:
131 void EchoStructWithTraits( 131 void EchoStructWithTraits(
132 const StructWithTraitsImpl& s, 132 const StructWithTraitsImpl& s,
133 const EchoStructWithTraitsCallback& callback) override { 133 const EchoStructWithTraitsCallback& callback) override {
134 callback.Run(s); 134 callback.Run(s);
135 } 135 }
136 136
137 void EchoPassByValueStructWithTraits( 137 void EchoTrivialStructWithTraits(
138 PassByValueStructWithTraitsImpl s, 138 TrivialStructWithTraitsImpl s,
139 const EchoPassByValueStructWithTraitsCallback& callback) override { 139 const EchoTrivialStructWithTraitsCallback& callback) override {
140 callback.Run(s);
141 }
142
143 void EchoMoveOnlyStructWithTraits(
144 MoveOnlyStructWithTraitsImpl s,
145 const EchoMoveOnlyStructWithTraitsCallback& callback) override {
140 callback.Run(std::move(s)); 146 callback.Run(std::move(s));
141 } 147 }
142 148
143 void EchoEnumWithTraits(EnumWithTraitsImpl e, 149 void EchoEnumWithTraits(EnumWithTraitsImpl e,
144 const EchoEnumWithTraitsCallback& callback) override { 150 const EchoEnumWithTraitsCallback& callback) override {
145 callback.Run(e); 151 callback.Run(e);
146 } 152 }
147 153
148 void EchoStructWithTraitsForUniquePtrTest( 154 void EchoStructWithTraitsForUniquePtrTest(
149 std::unique_ptr<int> e, 155 std::unique_ptr<int> e,
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 273
268 TEST_F(StructTraitsTest, CloneStructWithTraitsContainer) { 274 TEST_F(StructTraitsTest, CloneStructWithTraitsContainer) {
269 StructWithTraitsContainerPtr container = StructWithTraitsContainer::New(); 275 StructWithTraitsContainerPtr container = StructWithTraitsContainer::New();
270 container->f_struct.set_uint32(7); 276 container->f_struct.set_uint32(7);
271 container->f_struct.set_uint64(42); 277 container->f_struct.set_uint64(42);
272 StructWithTraitsContainerPtr cloned_container = container.Clone(); 278 StructWithTraitsContainerPtr cloned_container = container.Clone();
273 EXPECT_EQ(7u, cloned_container->f_struct.get_uint32()); 279 EXPECT_EQ(7u, cloned_container->f_struct.get_uint32());
274 EXPECT_EQ(42u, cloned_container->f_struct.get_uint64()); 280 EXPECT_EQ(42u, cloned_container->f_struct.get_uint64());
275 } 281 }
276 282
283 void ExpectTrivialStructWithTraits(TrivialStructWithTraitsImpl expected,
284 const base::Closure& closure,
285 TrivialStructWithTraitsImpl passed) {
286 EXPECT_EQ(expected.value, passed.value);
287 closure.Run();
288 }
289
290 TEST_F(StructTraitsTest, EchoTrivialStructWithTraits) {
291 TrivialStructWithTraitsImpl input;
292 input.value = 42;
293
294 base::RunLoop loop;
295 TraitsTestServicePtr proxy = GetTraitsTestProxy();
296
297 proxy->EchoTrivialStructWithTraits(
298 input,
299 base::Bind(&ExpectTrivialStructWithTraits, input, loop.QuitClosure()));
300 loop.Run();
301 }
302
277 void CaptureMessagePipe(ScopedMessagePipeHandle* storage, 303 void CaptureMessagePipe(ScopedMessagePipeHandle* storage,
278 const base::Closure& closure, 304 const base::Closure& closure,
279 PassByValueStructWithTraitsImpl passed) { 305 MoveOnlyStructWithTraitsImpl passed) {
280 storage->reset(MessagePipeHandle( 306 storage->reset(MessagePipeHandle(
281 passed.get_mutable_handle().release().value())); 307 passed.get_mutable_handle().release().value()));
282 closure.Run(); 308 closure.Run();
283 } 309 }
284 310
285 TEST_F(StructTraitsTest, EchoPassByValueStructWithTraits) { 311 TEST_F(StructTraitsTest, EchoMoveOnlyStructWithTraits) {
286 MessagePipe mp; 312 MessagePipe mp;
287 PassByValueStructWithTraitsImpl input; 313 MoveOnlyStructWithTraitsImpl input;
288 input.get_mutable_handle().reset(mp.handle0.release()); 314 input.get_mutable_handle().reset(mp.handle0.release());
289 315
290 base::RunLoop loop; 316 base::RunLoop loop;
291 TraitsTestServicePtr proxy = GetTraitsTestProxy(); 317 TraitsTestServicePtr proxy = GetTraitsTestProxy();
292 318
293 ScopedMessagePipeHandle received; 319 ScopedMessagePipeHandle received;
294 proxy->EchoPassByValueStructWithTraits( 320 proxy->EchoMoveOnlyStructWithTraits(
295 std::move(input), 321 std::move(input),
296 base::Bind(&CaptureMessagePipe, &received, loop.QuitClosure())); 322 base::Bind(&CaptureMessagePipe, &received, loop.QuitClosure()));
297 loop.Run(); 323 loop.Run();
298 324
299 ASSERT_TRUE(received.is_valid()); 325 ASSERT_TRUE(received.is_valid());
300 326
301 // Verify that the message pipe handle is correctly passed. 327 // Verify that the message pipe handle is correctly passed.
302 const char kHello[] = "hello"; 328 const char kHello[] = "hello";
303 const uint32_t kHelloSize = static_cast<uint32_t>(sizeof(kHello)); 329 const uint32_t kHelloSize = static_cast<uint32_t>(sizeof(kHello));
304 EXPECT_EQ(MOJO_RESULT_OK, 330 EXPECT_EQ(MOJO_RESULT_OK,
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 TraitsTestServicePtr proxy = GetTraitsTestProxy(); 403 TraitsTestServicePtr proxy = GetTraitsTestProxy();
378 404
379 proxy->EchoStructWithTraitsForUniquePtrTest( 405 proxy->EchoStructWithTraitsForUniquePtrTest(
380 base::MakeUnique<int>(12345), 406 base::MakeUnique<int>(12345),
381 base::Bind(&ExpectUniquePtr, 12345, loop.QuitClosure())); 407 base::Bind(&ExpectUniquePtr, 12345, loop.QuitClosure()));
382 loop.Run(); 408 loop.Run();
383 } 409 }
384 410
385 } // namespace test 411 } // namespace test
386 } // namespace mojo 412 } // namespace mojo
OLDNEW
« no previous file with comments | « no previous file | mojo/public/cpp/bindings/tests/struct_with_traits.typemap » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698