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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: mojo/public/cpp/bindings/tests/struct_traits_unittest.cc
diff --git a/mojo/public/cpp/bindings/tests/struct_traits_unittest.cc b/mojo/public/cpp/bindings/tests/struct_traits_unittest.cc
index c86366ecbf42c4c64cf00ad363fc91c6ab49b0ad..221dc9352555e178b5eebe99366360e579ee633a 100644
--- a/mojo/public/cpp/bindings/tests/struct_traits_unittest.cc
+++ b/mojo/public/cpp/bindings/tests/struct_traits_unittest.cc
@@ -170,6 +170,12 @@ class StructTraitsTest : public testing::Test,
callback.Run(std::move(e));
}
+ void EchoUnionWithTraits(
+ std::unique_ptr<test::UnionWithTraitsBase> u,
+ const EchoUnionWithTraitsCallback& callback) override {
+ callback.Run(std::move(u));
+ }
+
base::MessageLoop loop_;
ChromiumRectServiceImpl chromium_service_;
@@ -453,5 +459,51 @@ TEST_F(StructTraitsTest, TypemapUniquePtr) {
}
}
+TEST_F(StructTraitsTest, EchoUnionWithTraits) {
+ TraitsTestServicePtr proxy = GetTraitsTestProxy();
+
+ {
+ std::unique_ptr<test::UnionWithTraitsBase> input(
+ new test::UnionWithTraitsInt32(1234));
+ base::RunLoop loop;
+ proxy->EchoUnionWithTraits(
+ std::move(input),
+ base::Bind(
+ [](const base::Closure& quit_closure,
+ std::unique_ptr<test::UnionWithTraitsBase> passed) {
+ ASSERT_EQ(test::UnionWithTraitsBase::Type::INT32, passed->type());
+ EXPECT_EQ(1234,
+ static_cast<test::UnionWithTraitsInt32*>(passed.get())
+ ->value());
+ quit_closure.Run();
+
+ },
+ loop.QuitClosure()));
+ loop.Run();
+ }
+
+ {
+ std::unique_ptr<test::UnionWithTraitsBase> input(
+ new test::UnionWithTraitsStruct(4321));
+ base::RunLoop loop;
+ proxy->EchoUnionWithTraits(
+ std::move(input),
+ base::Bind(
+ [](const base::Closure& quit_closure,
+ std::unique_ptr<test::UnionWithTraitsBase> passed) {
+ ASSERT_EQ(test::UnionWithTraitsBase::Type::STRUCT,
+ passed->type());
+ EXPECT_EQ(4321,
+ static_cast<test::UnionWithTraitsStruct*>(passed.get())
+ ->get_struct()
+ .value);
+ quit_closure.Run();
+
+ },
+ loop.QuitClosure()));
+ loop.Run();
+ }
+}
+
} // namespace test
} // namespace mojo

Powered by Google App Engine
This is Rietveld 408576698