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

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

Issue 2608513002: Remove mojo::String. (Closed)
Patch Set: Created 3 years, 11 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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 array[i] = static_cast<int32_t>(i); 102 array[i] = static_cast<int32_t>(i);
103 103
104 ArrayType<int32_t> clone_array = array.Clone(); 104 ArrayType<int32_t> clone_array = array.Clone();
105 EXPECT_EQ(array.size(), clone_array.size()); 105 EXPECT_EQ(array.size(), clone_array.size());
106 for (size_t i = 0; i < array.size(); ++i) 106 for (size_t i = 0; i < array.size(); ++i)
107 EXPECT_EQ(array[i], clone_array[i]); 107 EXPECT_EQ(array[i], clone_array[i]);
108 } 108 }
109 109
110 { 110 {
111 // Test copyable object. 111 // Test copyable object.
112 ArrayType<String> array(2); 112 ArrayType<std::string> array(2);
113 array[0] = "hello"; 113 array[0] = "hello";
114 array[1] = "world"; 114 array[1] = "world";
115 115
116 ArrayType<String> clone_array = array.Clone(); 116 ArrayType<std::string> clone_array = array.Clone();
117 EXPECT_EQ(array.size(), clone_array.size()); 117 EXPECT_EQ(array.size(), clone_array.size());
118 for (size_t i = 0; i < array.size(); ++i) 118 for (size_t i = 0; i < array.size(); ++i)
119 EXPECT_EQ(array[i], clone_array[i]); 119 EXPECT_EQ(array[i], clone_array[i]);
120 } 120 }
121 121
122 { 122 {
123 // Test struct. 123 // Test struct.
124 ArrayType<RectPtr> array(2); 124 ArrayType<RectPtr> array(2);
125 array[1] = Rect::New(); 125 array[1] = Rect::New();
126 array[1]->x = 1; 126 array[1]->x = 1;
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 ArrayType<bool> array2; 252 ArrayType<bool> array2;
253 mojo::internal::Deserialize<ArrayDataView<bool>>(data, &array2, nullptr); 253 mojo::internal::Deserialize<ArrayDataView<bool>>(data, &array2, nullptr);
254 254
255 EXPECT_EQ(10U, array2.size()); 255 EXPECT_EQ(10U, array2.size());
256 for (size_t i = 0; i < array2.size(); ++i) 256 for (size_t i = 0; i < array2.size(); ++i)
257 EXPECT_EQ(i % 2 ? true : false, array2[i]); 257 EXPECT_EQ(i % 2 ? true : false, array2[i]);
258 } 258 }
259 259
260 static void Serialization_ArrayOfString() { 260 static void Serialization_ArrayOfString() {
261 using MojomType = ArrayDataView<StringDataView>; 261 using MojomType = ArrayDataView<StringDataView>;
262 ArrayType<String> array(10); 262 ArrayType<std::string> array(10);
263 for (size_t i = 0; i < array.size(); ++i) { 263 for (size_t i = 0; i < array.size(); ++i) {
264 char c = 'A' + static_cast<char>(i); 264 char c = 'A' + static_cast<char>(i);
265 array[i] = String(&c, 1); 265 array[i] = std::string(&c, 1);
266 } 266 }
267 267
268 size_t size = mojo::internal::PrepareToSerialize<MojomType>(array, nullptr); 268 size_t size = mojo::internal::PrepareToSerialize<MojomType>(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 typename mojo::internal::MojomTypeTraits<MojomType>::Data* data; 276 typename mojo::internal::MojomTypeTraits<MojomType>::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<MojomType>(array, &buf, &data, &validate_params, 280 mojo::internal::Serialize<MojomType>(array, &buf, &data, &validate_params,
281 nullptr); 281 nullptr);
282 282
283 ArrayType<String> array2; 283 ArrayType<std::string> array2;
284 mojo::internal::Deserialize<MojomType>(data, &array2, nullptr); 284 mojo::internal::Deserialize<MojomType>(data, &array2, nullptr);
285 285
286 EXPECT_EQ(10U, array2.size()); 286 EXPECT_EQ(10U, array2.size());
287 for (size_t i = 0; i < array2.size(); ++i) { 287 for (size_t i = 0; i < array2.size(); ++i) {
288 char c = 'A' + static_cast<char>(i); 288 char c = 'A' + static_cast<char>(i);
289 EXPECT_EQ(String(&c, 1), array2[i]); 289 EXPECT_EQ(std::string(&c, 1), array2[i]);
290 } 290 }
291 } 291 }
292 292
293 static void Resize_Copyable() { 293 static void Resize_Copyable() {
294 ASSERT_EQ(0u, CopyableType::num_instances()); 294 ASSERT_EQ(0u, CopyableType::num_instances());
295 ArrayType<CopyableType> array(3); 295 ArrayType<CopyableType> array(3);
296 std::vector<CopyableType*> value_ptrs; 296 std::vector<CopyableType*> value_ptrs;
297 value_ptrs.push_back(array[0].ptr()); 297 value_ptrs.push_back(array[0].ptr());
298 value_ptrs.push_back(array[1].ptr()); 298 value_ptrs.push_back(array[1].ptr());
299 299
(...skipping 95 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

Powered by Google App Engine
This is Rietveld 408576698