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

Unified Diff: mojo/public/cpp/bindings/tests/struct_with_traits_impl.h

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_with_traits_impl.h
diff --git a/mojo/public/cpp/bindings/tests/struct_with_traits_impl.h b/mojo/public/cpp/bindings/tests/struct_with_traits_impl.h
index bff0da24ffe58af18e9c973eb716e8293f2c0cf6..87d45918ff5a1c9ca1bdb45f67795de2adecd3c0 100644
--- a/mojo/public/cpp/bindings/tests/struct_with_traits_impl.h
+++ b/mojo/public/cpp/bindings/tests/struct_with_traits_impl.h
@@ -114,6 +114,47 @@ class MoveOnlyStructWithTraitsImpl {
DISALLOW_COPY_AND_ASSIGN(MoveOnlyStructWithTraitsImpl);
};
+class UnionWithTraitsBase {
+ public:
+ enum class Type { INT32, STRUCT };
+
+ virtual ~UnionWithTraitsBase() {}
+
+ Type type() const { return type_; }
+
+ protected:
+ Type type_ = Type::INT32;
+};
+
+class UnionWithTraitsInt32 : public UnionWithTraitsBase {
+ public:
+ UnionWithTraitsInt32() {}
+ explicit UnionWithTraitsInt32(int32_t value) : value_(value) {}
+
+ ~UnionWithTraitsInt32() override;
+
+ int32_t value() const { return value_; }
+ void set_value(int32_t value) { value_ = value; }
+
+ private:
+ int32_t value_ = 0;
+};
+
+class UnionWithTraitsStruct : public UnionWithTraitsBase {
+ public:
+ UnionWithTraitsStruct() { type_ = Type::STRUCT; }
+ explicit UnionWithTraitsStruct(int32_t value) : struct_(value) {
+ type_ = Type::STRUCT;
+ }
+ ~UnionWithTraitsStruct() override;
+
+ NestedStructWithTraitsImpl& get_mutable_struct() { return struct_; }
+ const NestedStructWithTraitsImpl& get_struct() const { return struct_; }
+
+ private:
+ NestedStructWithTraitsImpl struct_;
+};
+
} // namespace test
} // namespace mojo

Powered by Google App Engine
This is Rietveld 408576698