aboutsummaryrefslogtreecommitdiff
path: root/mojo/public/cpp/bindings/tests/struct_with_traits_impl_traits.h
diff options
context:
space:
mode:
authorHidehiko Abe <hidehiko@google.com>2018-04-17 16:34:13 +0900
committerHidehiko Abe <hidehiko@google.com>2018-04-17 16:56:42 +0900
commit1e4a1e50aed7593adac78af6f319adb67f03d7bb (patch)
tree1398145f7694eac739142d9bcbfcdf3d8cf4b9a8 /mojo/public/cpp/bindings/tests/struct_with_traits_impl_traits.h
parent0325b56b0518f5ca16701e5048fcf81cc96fd725 (diff)
downloadlibmojo-1e4a1e50aed7593adac78af6f319adb67f03d7bb.tar.gz
Reduce diffs from Chrome r456626.
Currently, mojo/ directory is more diverged than it should be. This CL fills the unnecessary gaps. Bug: 73606903 Test: Built locally. Treehugger. Made sure the diff on eyes. Change-Id: I65877b0ff853ecfd6661259f97b0078631a158a7
Diffstat (limited to 'mojo/public/cpp/bindings/tests/struct_with_traits_impl_traits.h')
-rw-r--r--mojo/public/cpp/bindings/tests/struct_with_traits_impl_traits.h99
1 files changed, 86 insertions, 13 deletions
diff --git a/mojo/public/cpp/bindings/tests/struct_with_traits_impl_traits.h b/mojo/public/cpp/bindings/tests/struct_with_traits_impl_traits.h
index 4550526..adcad8a 100644
--- a/mojo/public/cpp/bindings/tests/struct_with_traits_impl_traits.h
+++ b/mojo/public/cpp/bindings/tests/struct_with_traits_impl_traits.h
@@ -18,7 +18,7 @@
namespace mojo {
template <>
-struct StructTraits<test::NestedStructWithTraits,
+struct StructTraits<test::NestedStructWithTraitsDataView,
test::NestedStructWithTraitsImpl> {
static void* SetUpContext(const test::NestedStructWithTraitsImpl& input);
static void TearDownContext(const test::NestedStructWithTraitsImpl& input,
@@ -27,7 +27,7 @@ struct StructTraits<test::NestedStructWithTraits,
static int32_t value(const test::NestedStructWithTraitsImpl& input,
void* context);
- static bool Read(test::NestedStructWithTraits::DataView data,
+ static bool Read(test::NestedStructWithTraitsDataView data,
test::NestedStructWithTraitsImpl* output);
};
@@ -39,9 +39,10 @@ struct EnumTraits<test::EnumWithTraits, test::EnumWithTraitsImpl> {
};
template <>
-struct StructTraits<test::StructWithTraits, test::StructWithTraitsImpl> {
+struct StructTraits<test::StructWithTraitsDataView,
+ test::StructWithTraitsImpl> {
// Deserialization to test::StructTraitsImpl.
- static bool Read(test::StructWithTraits::DataView data,
+ static bool Read(test::StructWithTraitsDataView data,
test::StructWithTraitsImpl* out);
// Fields in test::StructWithTraits.
@@ -76,6 +77,11 @@ struct StructTraits<test::StructWithTraits, test::StructWithTraitsImpl> {
return value.get_string_array();
}
+ static const std::set<std::string>& f_string_set(
+ const test::StructWithTraitsImpl& value) {
+ return value.get_string_set();
+ }
+
static const test::NestedStructWithTraitsImpl& f_struct(
const test::StructWithTraitsImpl& value) {
return value.get_struct();
@@ -93,31 +99,98 @@ struct StructTraits<test::StructWithTraits, test::StructWithTraitsImpl> {
};
template <>
-struct StructTraits<test::PassByValueStructWithTraits,
- test::PassByValueStructWithTraitsImpl> {
- // Deserialization to test::PassByValueStructTraitsImpl.
- static bool Read(test::PassByValueStructWithTraits::DataView data,
- test::PassByValueStructWithTraitsImpl* out);
+struct StructTraits<test::TrivialStructWithTraitsDataView,
+ test::TrivialStructWithTraitsImpl> {
+ // Deserialization to test::TrivialStructTraitsImpl.
+ static bool Read(test::TrivialStructWithTraitsDataView data,
+ test::TrivialStructWithTraitsImpl* out) {
+ out->value = data.value();
+ return true;
+ }
+
+ // Fields in test::TrivialStructWithTraits.
+ // See src/mojo/public/interfaces/bindings/tests/struct_with_traits.mojom.
+ static int32_t value(test::TrivialStructWithTraitsImpl& input) {
+ return input.value;
+ }
+};
+
+template <>
+struct StructTraits<test::MoveOnlyStructWithTraitsDataView,
+ test::MoveOnlyStructWithTraitsImpl> {
+ // Deserialization to test::MoveOnlyStructTraitsImpl.
+ static bool Read(test::MoveOnlyStructWithTraitsDataView data,
+ test::MoveOnlyStructWithTraitsImpl* out);
- // Fields in test::PassByValueStructWithTraits.
+ // Fields in test::MoveOnlyStructWithTraits.
// See src/mojo/public/interfaces/bindings/tests/struct_with_traits.mojom.
- static ScopedHandle f_handle(test::PassByValueStructWithTraitsImpl& value) {
+ static ScopedHandle f_handle(test::MoveOnlyStructWithTraitsImpl& value) {
return std::move(value.get_mutable_handle());
}
};
template <>
-struct StructTraits<test::StructWithTraitsForUniquePtrTest,
+struct StructTraits<test::StructWithTraitsForUniquePtrDataView,
std::unique_ptr<int>> {
+ static bool IsNull(const std::unique_ptr<int>& data) { return !data; }
+ static void SetToNull(std::unique_ptr<int>* data) { data->reset(); }
+
static int f_int32(const std::unique_ptr<int>& data) { return *data; }
- static bool Read(test::StructWithTraitsForUniquePtrTest::DataView data,
+ static bool Read(test::StructWithTraitsForUniquePtrDataView data,
std::unique_ptr<int>* out) {
out->reset(new int(data.f_int32()));
return true;
}
};
+template <>
+struct UnionTraits<test::UnionWithTraitsDataView,
+ std::unique_ptr<test::UnionWithTraitsBase>> {
+ static bool IsNull(const std::unique_ptr<test::UnionWithTraitsBase>& data) {
+ return !data;
+ }
+ static void SetToNull(std::unique_ptr<test::UnionWithTraitsBase>* data) {
+ data->reset();
+ }
+
+ static test::UnionWithTraitsDataView::Tag GetTag(
+ const std::unique_ptr<test::UnionWithTraitsBase>& data) {
+ if (data->type() == test::UnionWithTraitsBase::Type::INT32)
+ return test::UnionWithTraitsDataView::Tag::F_INT32;
+
+ return test::UnionWithTraitsDataView::Tag::F_STRUCT;
+ }
+
+ static int32_t f_int32(
+ const std::unique_ptr<test::UnionWithTraitsBase>& data) {
+ return static_cast<test::UnionWithTraitsInt32*>(data.get())->value();
+ }
+
+ static const test::NestedStructWithTraitsImpl& f_struct(
+ const std::unique_ptr<test::UnionWithTraitsBase>& data) {
+ return static_cast<test::UnionWithTraitsStruct*>(data.get())->get_struct();
+ }
+
+ static bool Read(test::UnionWithTraitsDataView data,
+ std::unique_ptr<test::UnionWithTraitsBase>* out) {
+ switch (data.tag()) {
+ case test::UnionWithTraitsDataView::Tag::F_INT32: {
+ out->reset(new test::UnionWithTraitsInt32(data.f_int32()));
+ return true;
+ }
+ case test::UnionWithTraitsDataView::Tag::F_STRUCT: {
+ auto* struct_object = new test::UnionWithTraitsStruct();
+ out->reset(struct_object);
+ return data.ReadFStruct(&struct_object->get_mutable_struct());
+ }
+ }
+
+ NOTREACHED();
+ return false;
+ }
+};
+
} // namespace mojo
#endif // MOJO_PUBLIC_CPP_BINDINGS_TESTS_STRUCT_WITH_TRAITS_IMPL_TRAITS_H_