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

Side by Side Diff: mojo/public/cpp/bindings/tests/array_common_test.h

Issue 2112093002: Mojo C++ bindings: Merge EncodePointers/DecodePointers into Serialize/Deserialize, respectively. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@61_array_fix
Patch Set: . Created 4 years, 5 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 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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 #include <utility> 7 #include <utility>
8 8
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/fixed_buffer.h" 10 #include "mojo/public/cpp/bindings/lib/fixed_buffer.h"
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 for (size_t i = 0; i < inner.size(); ++i) 208 for (size_t i = 0; i < inner.size(); ++i)
209 inner[i] = static_cast<int32_t>(i + (j * 10)); 209 inner[i] = static_cast<int32_t>(i + (j * 10));
210 array[j] = std::move(inner); 210 array[j] = std::move(inner);
211 } 211 }
212 212
213 size_t size = mojo::internal::PrepareToSerialize<Array<Array<int32_t>>>( 213 size_t size = mojo::internal::PrepareToSerialize<Array<Array<int32_t>>>(
214 array, nullptr); 214 array, nullptr);
215 EXPECT_EQ(8U + 2 * 8U + 2 * (8U + 4 * 4U), size); 215 EXPECT_EQ(8U + 2 * 8U + 2 * (8U + 4 * 4U), size);
216 216
217 mojo::internal::FixedBufferForTesting buf(size); 217 mojo::internal::FixedBufferForTesting buf(size);
218 mojo::internal::Array_Data<mojo::internal::Array_Data<int32_t>*>* data; 218 typename mojo::internal::MojomTypeTraits<Array<Array<int32_t>>>::Data* data;
219 mojo::internal::ContainerValidateParams validate_params( 219 mojo::internal::ContainerValidateParams validate_params(
220 0, false, 220 0, false,
221 new mojo::internal::ContainerValidateParams(0, false, nullptr)); 221 new mojo::internal::ContainerValidateParams(0, false, nullptr));
222 mojo::internal::Serialize<Array<Array<int32_t>>>(array, &buf, &data, 222 mojo::internal::Serialize<Array<Array<int32_t>>>(array, &buf, &data,
223 &validate_params, nullptr); 223 &validate_params, nullptr);
224 224
225 ArrayType<ArrayType<int32_t>> array2; 225 ArrayType<ArrayType<int32_t>> array2;
226 mojo::internal::Deserialize<Array<Array<int32_t>>>(data, &array2, nullptr); 226 mojo::internal::Deserialize<Array<Array<int32_t>>>(data, &array2, nullptr);
227 227
228 EXPECT_EQ(2U, array2.size()); 228 EXPECT_EQ(2U, array2.size());
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 266
267 size_t size = 267 size_t size =
268 mojo::internal::PrepareToSerialize<Array<String>>(array, nullptr); 268 mojo::internal::PrepareToSerialize<Array<String>>(array, nullptr);
269 EXPECT_EQ(8U + // array header 269 EXPECT_EQ(8U + // array header
270 10 * 8U + // array payload (10 pointers) 270 10 * 8U + // array payload (10 pointers)
271 10 * (8U + // string header 271 10 * (8U + // string header
272 8U), // string length of 1 padded to 8 272 8U), // string length of 1 padded to 8
273 size); 273 size);
274 274
275 mojo::internal::FixedBufferForTesting buf(size); 275 mojo::internal::FixedBufferForTesting buf(size);
276 mojo::internal::Array_Data<mojo::internal::String_Data*>* data; 276 typename mojo::internal::MojomTypeTraits<Array<String>>::Data* data;
277 mojo::internal::ContainerValidateParams validate_params( 277 mojo::internal::ContainerValidateParams validate_params(
278 0, false, 278 0, false,
279 new mojo::internal::ContainerValidateParams(0, false, nullptr)); 279 new mojo::internal::ContainerValidateParams(0, false, nullptr));
280 mojo::internal::Serialize<Array<String>>(array, &buf, &data, 280 mojo::internal::Serialize<Array<String>>(array, &buf, &data,
281 &validate_params, nullptr); 281 &validate_params, nullptr);
282 282
283 ArrayType<String> array2; 283 ArrayType<String> array2;
284 mojo::internal::Deserialize<Array<String>>(data, &array2, nullptr); 284 mojo::internal::Deserialize<Array<String>>(data, &array2, nullptr);
285 285
286 EXPECT_EQ(10U, array2.size()); 286 EXPECT_EQ(10U, array2.size());
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 } 395 }
396 }; 396 };
397 397
398 #define ARRAY_COMMON_TEST(ArrayType, test_name) \ 398 #define ARRAY_COMMON_TEST(ArrayType, test_name) \
399 TEST_F(ArrayType##Test, test_name) { \ 399 TEST_F(ArrayType##Test, test_name) { \
400 ArrayCommonTest<ArrayType>::test_name(); \ 400 ArrayCommonTest<ArrayType>::test_name(); \
401 } 401 }
402 402
403 } // namespace test 403 } // namespace test
404 } // namespace mojo 404 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/validation_util.h ('k') | mojo/public/cpp/bindings/tests/struct_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698