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

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

Issue 1387993002: mojo::Serialize*_() calls now propogate/return validation errors. (Closed) Base URL: https://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. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
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 #include "mojo/public/cpp/bindings/array.h" 5 #include "mojo/public/cpp/bindings/array.h"
6 #include "mojo/public/cpp/bindings/lib/array_serialization.h" 6 #include "mojo/public/cpp/bindings/lib/array_serialization.h"
7 #include "mojo/public/cpp/bindings/lib/bindings_internal.h" 7 #include "mojo/public/cpp/bindings/lib/bindings_internal.h"
8 #include "mojo/public/cpp/bindings/lib/fixed_buffer.h" 8 #include "mojo/public/cpp/bindings/lib/fixed_buffer.h"
9 #include "mojo/public/cpp/bindings/lib/map_serialization.h" 9 #include "mojo/public/cpp/bindings/lib/map_serialization.h"
10 #include "mojo/public/cpp/bindings/lib/validate_params.h" 10 #include "mojo/public/cpp/bindings/lib/validate_params.h"
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 TEST_F(MapTest, ArrayOfMap) { 239 TEST_F(MapTest, ArrayOfMap) {
240 { 240 {
241 Array<Map<int32_t, int8_t>> array(1); 241 Array<Map<int32_t, int8_t>> array(1);
242 array[0].insert(1, 42); 242 array[0].insert(1, 42);
243 243
244 size_t size = GetSerializedSize_(array); 244 size_t size = GetSerializedSize_(array);
245 FixedBufferForTesting buf(size); 245 FixedBufferForTesting buf(size);
246 Array_Data<Map_Data<int32_t, int8_t>*>* data; 246 Array_Data<Map_Data<int32_t, int8_t>*>* data;
247 ArrayValidateParams validate_params( 247 ArrayValidateParams validate_params(
248 0, false, new ArrayValidateParams(0, false, nullptr)); 248 0, false, new ArrayValidateParams(0, false, nullptr));
249 SerializeArray_(&array, &buf, &data, &validate_params); 249 EXPECT_EQ(internal::ValidationError::VALIDATION_ERROR_NONE,
250 SerializeArray_(&array, &buf, &data, &validate_params));
250 251
251 Array<Map<int32_t, int8_t>> deserialized_array; 252 Array<Map<int32_t, int8_t>> deserialized_array;
252 Deserialize_(data, &deserialized_array); 253 Deserialize_(data, &deserialized_array);
253 254
254 ASSERT_EQ(1u, deserialized_array.size()); 255 ASSERT_EQ(1u, deserialized_array.size());
255 ASSERT_EQ(1u, deserialized_array[0].size()); 256 ASSERT_EQ(1u, deserialized_array[0].size());
256 ASSERT_EQ(42, deserialized_array[0].at(1)); 257 ASSERT_EQ(42, deserialized_array[0].at(1));
257 } 258 }
258 259
259 { 260 {
260 Array<Map<String, Array<bool>>> array(1); 261 Array<Map<String, Array<bool>>> array(1);
261 Array<bool> map_value(2); 262 Array<bool> map_value(2);
262 map_value[0] = false; 263 map_value[0] = false;
263 map_value[1] = true; 264 map_value[1] = true;
264 array[0].insert("hello world", map_value.Pass()); 265 array[0].insert("hello world", map_value.Pass());
265 266
266 size_t size = GetSerializedSize_(array); 267 size_t size = GetSerializedSize_(array);
267 FixedBufferForTesting buf(size); 268 FixedBufferForTesting buf(size);
268 Array_Data<Map_Data<String_Data*, Array_Data<bool>*>*>* data; 269 Array_Data<Map_Data<String_Data*, Array_Data<bool>*>*>* data;
269 ArrayValidateParams validate_params( 270 ArrayValidateParams validate_params(
270 0, false, new ArrayValidateParams( 271 0, false, new ArrayValidateParams(
271 0, false, new ArrayValidateParams(0, false, nullptr))); 272 0, false, new ArrayValidateParams(0, false, nullptr)));
272 SerializeArray_(&array, &buf, &data, &validate_params); 273 EXPECT_EQ(internal::ValidationError::VALIDATION_ERROR_NONE,
274 SerializeArray_(&array, &buf, &data, &validate_params));
273 275
274 Array<Map<String, Array<bool>>> deserialized_array; 276 Array<Map<String, Array<bool>>> deserialized_array;
275 Deserialize_(data, &deserialized_array); 277 Deserialize_(data, &deserialized_array);
276 278
277 ASSERT_EQ(1u, deserialized_array.size()); 279 ASSERT_EQ(1u, deserialized_array.size());
278 ASSERT_EQ(1u, deserialized_array[0].size()); 280 ASSERT_EQ(1u, deserialized_array[0].size());
279 ASSERT_FALSE(deserialized_array[0].at("hello world")[0]); 281 ASSERT_FALSE(deserialized_array[0].at("hello world")[0]);
280 ASSERT_TRUE(deserialized_array[0].at("hello world")[1]); 282 ASSERT_TRUE(deserialized_array[0].at("hello world")[1]);
281 } 283 }
282 } 284 }
283 285
284 } // namespace 286 } // namespace
285 } // namespace test 287 } // namespace test
286 } // namespace mojo 288 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698