OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 // Serialization warnings are only recorded when DLOG is enabled. | 5 // Serialization warnings are only recorded when DLOG is enabled. |
6 #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON) | 6 #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON) |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "mojo/public/cpp/bindings/array.h" | |
12 #include "mojo/public/cpp/bindings/lib/array_internal.h" | 11 #include "mojo/public/cpp/bindings/lib/array_internal.h" |
13 #include "mojo/public/cpp/bindings/lib/fixed_buffer.h" | 12 #include "mojo/public/cpp/bindings/lib/fixed_buffer.h" |
14 #include "mojo/public/cpp/bindings/lib/serialization.h" | 13 #include "mojo/public/cpp/bindings/lib/serialization.h" |
15 #include "mojo/public/cpp/bindings/lib/validation_errors.h" | 14 #include "mojo/public/cpp/bindings/lib/validation_errors.h" |
16 #include "mojo/public/cpp/system/message_pipe.h" | 15 #include "mojo/public/cpp/system/message_pipe.h" |
17 #include "mojo/public/interfaces/bindings/tests/serialization_test_structs.mojom
.h" | 16 #include "mojo/public/interfaces/bindings/tests/serialization_test_structs.mojom
.h" |
18 #include "mojo/public/interfaces/bindings/tests/test_unions.mojom.h" | 17 #include "mojo/public/interfaces/bindings/tests/test_unions.mojom.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
20 | 19 |
21 namespace mojo { | 20 namespace mojo { |
22 namespace test { | 21 namespace test { |
23 namespace { | 22 namespace { |
24 | 23 |
25 using mojo::internal::ContainerValidateParams; | 24 using mojo::internal::ContainerValidateParams; |
26 | 25 |
27 // Creates an array of arrays of handles (2 X 3) for testing. | 26 // Creates an array of arrays of handles (2 X 3) for testing. |
28 Array<Array<ScopedHandle>> CreateTestNestedHandleArray() { | 27 std::vector<base::Optional<std::vector<ScopedHandle>>> |
29 Array<Array<ScopedHandle>> array(2); | 28 CreateTestNestedHandleArray() { |
| 29 std::vector<base::Optional<std::vector<ScopedHandle>>> array(2); |
30 for (size_t i = 0; i < array.size(); ++i) { | 30 for (size_t i = 0; i < array.size(); ++i) { |
31 Array<ScopedHandle> nested_array(3); | 31 std::vector<ScopedHandle> nested_array(3); |
32 for (size_t j = 0; j < nested_array.size(); ++j) { | 32 for (size_t j = 0; j < nested_array.size(); ++j) { |
33 MessagePipe pipe; | 33 MessagePipe pipe; |
34 nested_array[j] = ScopedHandle::From(std::move(pipe.handle1)); | 34 nested_array[j] = ScopedHandle::From(std::move(pipe.handle1)); |
35 } | 35 } |
36 array[i] = std::move(nested_array); | 36 array[i].emplace(std::move(nested_array)); |
37 } | 37 } |
38 | 38 |
39 return array; | 39 return array; |
40 } | 40 } |
41 | 41 |
42 class SerializationWarningTest : public testing::Test { | 42 class SerializationWarningTest : public testing::Test { |
43 public: | 43 public: |
44 ~SerializationWarningTest() override {} | 44 ~SerializationWarningTest() override {} |
45 | 45 |
46 protected: | 46 protected: |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 test_struct = Struct5::New(); | 151 test_struct = Struct5::New(); |
152 test_struct->pair.resize(2); | 152 test_struct->pair.resize(2); |
153 test_struct->pair[0] = Struct1::New(); | 153 test_struct->pair[0] = Struct1::New(); |
154 test_struct->pair[1] = Struct1::New(); | 154 test_struct->pair[1] = Struct1::New(); |
155 | 155 |
156 TestWarning(std::move(test_struct), mojo::internal::VALIDATION_ERROR_NONE); | 156 TestWarning(std::move(test_struct), mojo::internal::VALIDATION_ERROR_NONE); |
157 } | 157 } |
158 | 158 |
159 TEST_F(SerializationWarningTest, ArrayOfArraysOfHandles) { | 159 TEST_F(SerializationWarningTest, ArrayOfArraysOfHandles) { |
160 using MojomType = ArrayDataView<ArrayDataView<ScopedHandle>>; | 160 using MojomType = ArrayDataView<ArrayDataView<ScopedHandle>>; |
161 Array<Array<ScopedHandle>> test_array = CreateTestNestedHandleArray(); | 161 auto test_array = CreateTestNestedHandleArray(); |
162 test_array[0] = nullptr; | 162 test_array[0] = base::nullopt; |
163 test_array[1][0] = ScopedHandle(); | 163 (*test_array[1])[0] = ScopedHandle(); |
164 | 164 |
165 ContainerValidateParams validate_params_0( | 165 ContainerValidateParams validate_params_0( |
166 0, true, new ContainerValidateParams(0, true, nullptr)); | 166 0, true, new ContainerValidateParams(0, true, nullptr)); |
167 TestArrayWarning<MojomType>(std::move(test_array), | 167 TestArrayWarning<MojomType>(std::move(test_array), |
168 mojo::internal::VALIDATION_ERROR_NONE, | 168 mojo::internal::VALIDATION_ERROR_NONE, |
169 &validate_params_0); | 169 &validate_params_0); |
170 | 170 |
171 test_array = CreateTestNestedHandleArray(); | 171 test_array = CreateTestNestedHandleArray(); |
172 test_array[0] = nullptr; | 172 test_array[0] = base::nullopt; |
173 ContainerValidateParams validate_params_1( | 173 ContainerValidateParams validate_params_1( |
174 0, false, new ContainerValidateParams(0, true, nullptr)); | 174 0, false, new ContainerValidateParams(0, true, nullptr)); |
175 TestArrayWarning<MojomType>( | 175 TestArrayWarning<MojomType>( |
176 std::move(test_array), | 176 std::move(test_array), |
177 mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER, | 177 mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER, |
178 &validate_params_1); | 178 &validate_params_1); |
179 | 179 |
180 test_array = CreateTestNestedHandleArray(); | 180 test_array = CreateTestNestedHandleArray(); |
181 test_array[1][0] = ScopedHandle(); | 181 (*test_array[1])[0] = ScopedHandle(); |
182 ContainerValidateParams validate_params_2( | 182 ContainerValidateParams validate_params_2( |
183 0, true, new ContainerValidateParams(0, false, nullptr)); | 183 0, true, new ContainerValidateParams(0, false, nullptr)); |
184 TestArrayWarning<MojomType>( | 184 TestArrayWarning<MojomType>( |
185 std::move(test_array), | 185 std::move(test_array), |
186 mojo::internal::VALIDATION_ERROR_UNEXPECTED_INVALID_HANDLE, | 186 mojo::internal::VALIDATION_ERROR_UNEXPECTED_INVALID_HANDLE, |
187 &validate_params_2); | 187 &validate_params_2); |
188 } | 188 } |
189 | 189 |
190 TEST_F(SerializationWarningTest, ArrayOfStrings) { | 190 TEST_F(SerializationWarningTest, ArrayOfStrings) { |
191 using MojomType = ArrayDataView<StringDataView>; | 191 using MojomType = ArrayDataView<StringDataView>; |
192 | 192 |
193 Array<std::string> test_array(3); | 193 std::vector<std::string> test_array(3); |
194 for (size_t i = 0; i < test_array.size(); ++i) | 194 for (size_t i = 0; i < test_array.size(); ++i) |
195 test_array[i] = "hello"; | 195 test_array[i] = "hello"; |
196 | 196 |
197 ContainerValidateParams validate_params_0( | 197 ContainerValidateParams validate_params_0( |
198 0, true, new ContainerValidateParams(0, false, nullptr)); | 198 0, true, new ContainerValidateParams(0, false, nullptr)); |
199 TestArrayWarning<MojomType>(std::move(test_array), | 199 TestArrayWarning<MojomType>(std::move(test_array), |
200 mojo::internal::VALIDATION_ERROR_NONE, | 200 mojo::internal::VALIDATION_ERROR_NONE, |
201 &validate_params_0); | 201 &validate_params_0); |
202 | 202 |
203 Array<base::Optional<std::string>> optional_test_array(3); | 203 std::vector<base::Optional<std::string>> optional_test_array(3); |
204 ContainerValidateParams validate_params_1( | 204 ContainerValidateParams validate_params_1( |
205 0, false, new ContainerValidateParams(0, false, nullptr)); | 205 0, false, new ContainerValidateParams(0, false, nullptr)); |
206 TestArrayWarning<MojomType>( | 206 TestArrayWarning<MojomType>( |
207 std::move(optional_test_array), | 207 std::move(optional_test_array), |
208 mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER, | 208 mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER, |
209 &validate_params_1); | 209 &validate_params_1); |
210 | 210 |
211 test_array = Array<std::string>(2); | 211 test_array = std::vector<std::string>(2); |
212 ContainerValidateParams validate_params_2( | 212 ContainerValidateParams validate_params_2( |
213 3, true, new ContainerValidateParams(0, false, nullptr)); | 213 3, true, new ContainerValidateParams(0, false, nullptr)); |
214 TestArrayWarning<MojomType>( | 214 TestArrayWarning<MojomType>( |
215 std::move(test_array), | 215 std::move(test_array), |
216 mojo::internal::VALIDATION_ERROR_UNEXPECTED_ARRAY_HEADER, | 216 mojo::internal::VALIDATION_ERROR_UNEXPECTED_ARRAY_HEADER, |
217 &validate_params_2); | 217 &validate_params_2); |
218 } | 218 } |
219 | 219 |
220 TEST_F(SerializationWarningTest, StructInUnion) { | 220 TEST_F(SerializationWarningTest, StructInUnion) { |
221 DummyStructPtr dummy(nullptr); | 221 DummyStructPtr dummy(nullptr); |
(...skipping 20 matching lines...) Expand all Loading... |
242 | 242 |
243 TestUnionWarning(std::move(handle), | 243 TestUnionWarning(std::move(handle), |
244 mojo::internal::VALIDATION_ERROR_UNEXPECTED_INVALID_HANDLE); | 244 mojo::internal::VALIDATION_ERROR_UNEXPECTED_INVALID_HANDLE); |
245 } | 245 } |
246 | 246 |
247 } // namespace | 247 } // namespace |
248 } // namespace test | 248 } // namespace test |
249 } // namespace mojo | 249 } // namespace mojo |
250 | 250 |
251 #endif | 251 #endif |
OLD | NEW |