| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "mojo/public/cpp/bindings/tests/struct_with_traits_impl_traits.h" | 5 #include "mojo/public/cpp/bindings/tests/struct_with_traits_impl_traits.h" |
| 6 | 6 |
| 7 namespace mojo { | 7 namespace mojo { |
| 8 namespace { | 8 namespace { |
| 9 | 9 |
| 10 struct Context { | 10 struct Context { |
| 11 int32_t value; | 11 int32_t value; |
| 12 }; | 12 }; |
| 13 | 13 |
| 14 } // namespace | 14 } // namespace |
| 15 | 15 |
| 16 // static | 16 // static |
| 17 void* StructTraits<test::NestedStructWithTraits, | 17 void* StructTraits<test::NestedStructWithTraitsDataView, |
| 18 test::NestedStructWithTraitsImpl>:: | 18 test::NestedStructWithTraitsImpl>:: |
| 19 SetUpContext(const test::NestedStructWithTraitsImpl& input) { | 19 SetUpContext(const test::NestedStructWithTraitsImpl& input) { |
| 20 Context* context = new Context; | 20 Context* context = new Context; |
| 21 context->value = input.value; | 21 context->value = input.value; |
| 22 return context; | 22 return context; |
| 23 } | 23 } |
| 24 | 24 |
| 25 // static | 25 // static |
| 26 void StructTraits<test::NestedStructWithTraits, | 26 void StructTraits<test::NestedStructWithTraitsDataView, |
| 27 test::NestedStructWithTraitsImpl>:: | 27 test::NestedStructWithTraitsImpl>:: |
| 28 TearDownContext(const test::NestedStructWithTraitsImpl& input, | 28 TearDownContext(const test::NestedStructWithTraitsImpl& input, |
| 29 void* context) { | 29 void* context) { |
| 30 Context* context_obj = static_cast<Context*>(context); | 30 Context* context_obj = static_cast<Context*>(context); |
| 31 CHECK_EQ(context_obj->value, input.value); | 31 CHECK_EQ(context_obj->value, input.value); |
| 32 delete context_obj; | 32 delete context_obj; |
| 33 } | 33 } |
| 34 | 34 |
| 35 // static | 35 // static |
| 36 int32_t StructTraits<test::NestedStructWithTraits, | 36 int32_t StructTraits<test::NestedStructWithTraitsDataView, |
| 37 test::NestedStructWithTraitsImpl>:: | 37 test::NestedStructWithTraitsImpl>:: |
| 38 value(const test::NestedStructWithTraitsImpl& input, void* context) { | 38 value(const test::NestedStructWithTraitsImpl& input, void* context) { |
| 39 Context* context_obj = static_cast<Context*>(context); | 39 Context* context_obj = static_cast<Context*>(context); |
| 40 CHECK_EQ(context_obj->value, input.value); | 40 CHECK_EQ(context_obj->value, input.value); |
| 41 return input.value; | 41 return input.value; |
| 42 } | 42 } |
| 43 | 43 |
| 44 // static | 44 // static |
| 45 bool StructTraits<test::NestedStructWithTraits, | 45 bool StructTraits<test::NestedStructWithTraitsDataView, |
| 46 test::NestedStructWithTraitsImpl>:: | 46 test::NestedStructWithTraitsImpl>:: |
| 47 Read(test::NestedStructWithTraits::DataView data, | 47 Read(test::NestedStructWithTraits::DataView data, |
| 48 test::NestedStructWithTraitsImpl* output) { | 48 test::NestedStructWithTraitsImpl* output) { |
| 49 output->value = data.value(); | 49 output->value = data.value(); |
| 50 return true; | 50 return true; |
| 51 } | 51 } |
| 52 | 52 |
| 53 test::EnumWithTraits | 53 test::EnumWithTraits |
| 54 EnumTraits<test::EnumWithTraits, test::EnumWithTraitsImpl>::ToMojom( | 54 EnumTraits<test::EnumWithTraits, test::EnumWithTraitsImpl>::ToMojom( |
| 55 test::EnumWithTraitsImpl input) { | 55 test::EnumWithTraitsImpl input) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 73 return true; | 73 return true; |
| 74 case test::EnumWithTraits::VALUE_1: | 74 case test::EnumWithTraits::VALUE_1: |
| 75 *output = test::EnumWithTraitsImpl::CUSTOM_VALUE_1; | 75 *output = test::EnumWithTraitsImpl::CUSTOM_VALUE_1; |
| 76 return true; | 76 return true; |
| 77 }; | 77 }; |
| 78 | 78 |
| 79 return false; | 79 return false; |
| 80 } | 80 } |
| 81 | 81 |
| 82 // static | 82 // static |
| 83 bool StructTraits<test::StructWithTraits, test::StructWithTraitsImpl>::Read( | 83 bool StructTraits<test::StructWithTraitsDataView, test::StructWithTraitsImpl>:: |
| 84 test::StructWithTraits::DataView data, | 84 Read(test::StructWithTraits::DataView data, |
| 85 test::StructWithTraitsImpl* out) { | 85 test::StructWithTraitsImpl* out) { |
| 86 test::EnumWithTraitsImpl f_enum; | 86 test::EnumWithTraitsImpl f_enum; |
| 87 if (!data.ReadFEnum(&f_enum)) | 87 if (!data.ReadFEnum(&f_enum)) |
| 88 return false; | 88 return false; |
| 89 out->set_enum(f_enum); | 89 out->set_enum(f_enum); |
| 90 | 90 |
| 91 out->set_bool(data.f_bool()); | 91 out->set_bool(data.f_bool()); |
| 92 out->set_uint32(data.f_uint32()); | 92 out->set_uint32(data.f_uint32()); |
| 93 out->set_uint64(data.f_uint64()); | 93 out->set_uint64(data.f_uint64()); |
| 94 | 94 |
| 95 base::StringPiece f_string; | 95 base::StringPiece f_string; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 119 if (!data.ReadFStructArray(&out->get_mutable_struct_array())) | 119 if (!data.ReadFStructArray(&out->get_mutable_struct_array())) |
| 120 return false; | 120 return false; |
| 121 | 121 |
| 122 if (!data.ReadFStructMap(&out->get_mutable_struct_map())) | 122 if (!data.ReadFStructMap(&out->get_mutable_struct_map())) |
| 123 return false; | 123 return false; |
| 124 | 124 |
| 125 return true; | 125 return true; |
| 126 } | 126 } |
| 127 | 127 |
| 128 // static | 128 // static |
| 129 bool StructTraits<test::MoveOnlyStructWithTraits, | 129 bool StructTraits<test::MoveOnlyStructWithTraitsDataView, |
| 130 test::MoveOnlyStructWithTraitsImpl>:: | 130 test::MoveOnlyStructWithTraitsImpl>:: |
| 131 Read(test::MoveOnlyStructWithTraits::DataView data, | 131 Read(test::MoveOnlyStructWithTraits::DataView data, |
| 132 test::MoveOnlyStructWithTraitsImpl* out) { | 132 test::MoveOnlyStructWithTraitsImpl* out) { |
| 133 out->get_mutable_handle() = data.TakeFHandle(); | 133 out->get_mutable_handle() = data.TakeFHandle(); |
| 134 return true; | 134 return true; |
| 135 } | 135 } |
| 136 | 136 |
| 137 } // namespace mojo | 137 } // namespace mojo |
| OLD | NEW |