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

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

Issue 2228733002: Mojo C++ bindings: add test cases for union custom typemapping. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@86_union_traits
Patch Set: Created 4 years, 4 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 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 callback.Run(std::move(e)); 163 callback.Run(std::move(e));
164 } 164 }
165 165
166 void EchoNullableStructWithTraitsForUniquePtr( 166 void EchoNullableStructWithTraitsForUniquePtr(
167 std::unique_ptr<int> e, 167 std::unique_ptr<int> e,
168 const EchoNullableStructWithTraitsForUniquePtrCallback& callback) 168 const EchoNullableStructWithTraitsForUniquePtrCallback& callback)
169 override { 169 override {
170 callback.Run(std::move(e)); 170 callback.Run(std::move(e));
171 } 171 }
172 172
173 void EchoUnionWithTraits(
174 std::unique_ptr<test::UnionWithTraitsBase> u,
175 const EchoUnionWithTraitsCallback& callback) override {
176 callback.Run(std::move(u));
177 }
178
173 base::MessageLoop loop_; 179 base::MessageLoop loop_;
174 180
175 ChromiumRectServiceImpl chromium_service_; 181 ChromiumRectServiceImpl chromium_service_;
176 BindingSet<RectService> chromium_bindings_; 182 BindingSet<RectService> chromium_bindings_;
177 183
178 BlinkRectServiceImpl blink_service_; 184 BlinkRectServiceImpl blink_service_;
179 BindingSet<blink::RectService> blink_bindings_; 185 BindingSet<blink::RectService> blink_bindings_;
180 186
181 BindingSet<TraitsTestService> traits_test_bindings_; 187 BindingSet<TraitsTestService> traits_test_bindings_;
182 }; 188 };
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 loop.Run(); 452 loop.Run();
447 } 453 }
448 { 454 {
449 base::RunLoop loop; 455 base::RunLoop loop;
450 proxy->EchoNullableStructWithTraitsForUniquePtr( 456 proxy->EchoNullableStructWithTraitsForUniquePtr(
451 nullptr, base::Bind(&ExpectUniquePtr, nullptr, loop.QuitClosure())); 457 nullptr, base::Bind(&ExpectUniquePtr, nullptr, loop.QuitClosure()));
452 loop.Run(); 458 loop.Run();
453 } 459 }
454 } 460 }
455 461
462 TEST_F(StructTraitsTest, EchoUnionWithTraits) {
463 TraitsTestServicePtr proxy = GetTraitsTestProxy();
464
465 {
466 std::unique_ptr<test::UnionWithTraitsBase> input(
467 new test::UnionWithTraitsInt32(1234));
468 base::RunLoop loop;
469 proxy->EchoUnionWithTraits(
470 std::move(input),
471 base::Bind(
472 [](const base::Closure& quit_closure,
473 std::unique_ptr<test::UnionWithTraitsBase> passed) {
474 ASSERT_EQ(test::UnionWithTraitsBase::Type::INT32, passed->type());
475 EXPECT_EQ(1234,
476 static_cast<test::UnionWithTraitsInt32*>(passed.get())
477 ->value());
478 quit_closure.Run();
479
480 },
481 loop.QuitClosure()));
482 loop.Run();
483 }
484
485 {
486 std::unique_ptr<test::UnionWithTraitsBase> input(
487 new test::UnionWithTraitsStruct(4321));
488 base::RunLoop loop;
489 proxy->EchoUnionWithTraits(
490 std::move(input),
491 base::Bind(
492 [](const base::Closure& quit_closure,
493 std::unique_ptr<test::UnionWithTraitsBase> passed) {
494 ASSERT_EQ(test::UnionWithTraitsBase::Type::STRUCT,
495 passed->type());
496 EXPECT_EQ(4321,
497 static_cast<test::UnionWithTraitsStruct*>(passed.get())
498 ->get_struct()
499 .value);
500 quit_closure.Run();
501
502 },
503 loop.QuitClosure()));
504 loop.Run();
505 }
506 }
507
456 } // namespace test 508 } // namespace test
457 } // namespace mojo 509 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698