Chromium Code Reviews

Side by Side Diff: mojo/public/cpp/bindings/tests/serialization_warning_unittest.cc

Issue 1397133002: Remove callers of mojo::Array<size_t> constructor in favor of ::New (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
OLDNEW
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 in debug build. 5 // Serialization warnings are only recorded in debug build.
6 #ifndef NDEBUG 6 #ifndef NDEBUG
7 7
8 #include "mojo/public/cpp/bindings/array.h" 8 #include "mojo/public/cpp/bindings/array.h"
9 #include "mojo/public/cpp/bindings/lib/array_internal.h" 9 #include "mojo/public/cpp/bindings/lib/array_internal.h"
10 #include "mojo/public/cpp/bindings/lib/array_serialization.h" 10 #include "mojo/public/cpp/bindings/lib/array_serialization.h"
11 #include "mojo/public/cpp/bindings/lib/fixed_buffer.h" 11 #include "mojo/public/cpp/bindings/lib/fixed_buffer.h"
12 #include "mojo/public/cpp/bindings/lib/validation_errors.h" 12 #include "mojo/public/cpp/bindings/lib/validation_errors.h"
13 #include "mojo/public/cpp/bindings/string.h" 13 #include "mojo/public/cpp/bindings/string.h"
14 #include "mojo/public/cpp/environment/environment.h" 14 #include "mojo/public/cpp/environment/environment.h"
15 #include "mojo/public/cpp/system/message_pipe.h" 15 #include "mojo/public/cpp/system/message_pipe.h"
16 #include "mojo/public/interfaces/bindings/tests/serialization_test_structs.mojom .h" 16 #include "mojo/public/interfaces/bindings/tests/serialization_test_structs.mojom .h"
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 18
19 namespace mojo { 19 namespace mojo {
20 namespace test { 20 namespace test {
21 namespace { 21 namespace {
22 22
23 using mojo::internal::ArrayValidateParams; 23 using mojo::internal::ArrayValidateParams;
24 24
25 // Creates an array of arrays of handles (2 X 3) for testing. 25 // Creates an array of arrays of handles (2 X 3) for testing.
26 Array<Array<ScopedHandle>> CreateTestNestedHandleArray() { 26 Array<Array<ScopedHandle>> CreateTestNestedHandleArray() {
27 Array<Array<ScopedHandle>> array(2); 27 auto array = Array<Array<ScopedHandle>>::New(2);
28 for (size_t i = 0; i < array.size(); ++i) { 28 for (size_t i = 0; i < array.size(); ++i) {
29 Array<ScopedHandle> nested_array(3); 29 auto nested_array = Array<ScopedHandle>::New(3);
30 for (size_t j = 0; j < nested_array.size(); ++j) { 30 for (size_t j = 0; j < nested_array.size(); ++j) {
31 MessagePipe pipe; 31 MessagePipe pipe;
32 nested_array[j] = ScopedHandle::From(pipe.handle1.Pass()); 32 nested_array[j] = ScopedHandle::From(pipe.handle1.Pass());
33 } 33 }
34 array[i] = nested_array.Pass(); 34 array[i] = nested_array.Pass();
35 } 35 }
36 36
37 return array.Pass(); 37 return array.Pass();
38 } 38 }
39 39
(...skipping 151 matching lines...)
191 test_array = CreateTestNestedHandleArray(); 191 test_array = CreateTestNestedHandleArray();
192 test_array[1][0] = ScopedHandle(); 192 test_array[1][0] = ScopedHandle();
193 ArrayValidateParams validate_params_2( 193 ArrayValidateParams validate_params_2(
194 0, true, new ArrayValidateParams(0, false, nullptr)); 194 0, true, new ArrayValidateParams(0, false, nullptr));
195 TestArrayWarning(test_array.Pass(), 195 TestArrayWarning(test_array.Pass(),
196 mojo::internal::VALIDATION_ERROR_UNEXPECTED_INVALID_HANDLE, 196 mojo::internal::VALIDATION_ERROR_UNEXPECTED_INVALID_HANDLE,
197 &validate_params_2); 197 &validate_params_2);
198 } 198 }
199 199
200 TEST_F(SerializationWarningTest, ArrayOfStrings) { 200 TEST_F(SerializationWarningTest, ArrayOfStrings) {
201 Array<String> test_array(3); 201 auto test_array = Array<String>::New(3);
202 for (size_t i = 0; i < test_array.size(); ++i) 202 for (size_t i = 0; i < test_array.size(); ++i)
203 test_array[i] = "hello"; 203 test_array[i] = "hello";
204 204
205 ArrayValidateParams validate_params_0( 205 ArrayValidateParams validate_params_0(
206 0, true, new ArrayValidateParams(0, false, nullptr)); 206 0, true, new ArrayValidateParams(0, false, nullptr));
207 TestArrayWarning(test_array.Pass(), mojo::internal::VALIDATION_ERROR_NONE, 207 TestArrayWarning(test_array.Pass(), mojo::internal::VALIDATION_ERROR_NONE,
208 &validate_params_0); 208 &validate_params_0);
209 209
210 test_array = Array<String>(3); 210 test_array = Array<String>::New(3);
211 ArrayValidateParams validate_params_1( 211 ArrayValidateParams validate_params_1(
212 0, false, new ArrayValidateParams(0, false, nullptr)); 212 0, false, new ArrayValidateParams(0, false, nullptr));
213 TestArrayWarning(test_array.Pass(), 213 TestArrayWarning(test_array.Pass(),
214 mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER, 214 mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER,
215 &validate_params_1); 215 &validate_params_1);
216 216
217 test_array = Array<String>(2); 217 test_array = Array<String>::New(2);
218 ArrayValidateParams validate_params_2( 218 ArrayValidateParams validate_params_2(
219 3, true, new ArrayValidateParams(0, false, nullptr)); 219 3, true, new ArrayValidateParams(0, false, nullptr));
220 TestArrayWarning(test_array.Pass(), 220 TestArrayWarning(test_array.Pass(),
221 mojo::internal::VALIDATION_ERROR_UNEXPECTED_ARRAY_HEADER, 221 mojo::internal::VALIDATION_ERROR_UNEXPECTED_ARRAY_HEADER,
222 &validate_params_2); 222 &validate_params_2);
223 } 223 }
224 224
225 } // namespace 225 } // namespace
226 } // namespace test 226 } // namespace test
227 } // namespace mojo 227 } // namespace mojo
228 228
229 #endif 229 #endif
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/tests/sample_service_unittest.cc ('k') | mojo/public/cpp/bindings/tests/struct_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine