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

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

Issue 1475813002: Mojo C++ bindings: support passing associated interface pointers/requests in method parameter lists… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@25_use_multiplex_router
Patch Set: Created 5 years 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_internal.h" 6 #include "mojo/public/cpp/bindings/lib/array_internal.h"
7 #include "mojo/public/cpp/bindings/lib/array_serialization.h" 7 #include "mojo/public/cpp/bindings/lib/array_serialization.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/tests/container_test_util.h" 9 #include "mojo/public/cpp/bindings/tests/container_test_util.h"
10 #include "mojo/public/interfaces/bindings/tests/test_structs.mojom.h" 10 #include "mojo/public/interfaces/bindings/tests/test_structs.mojom.h"
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 149
150 size_t size = GetSerializedSize_(array); 150 size_t size = GetSerializedSize_(array);
151 EXPECT_EQ(8U + 4 * 4U, size); 151 EXPECT_EQ(8U + 4 * 4U, size);
152 152
153 FixedBufferForTesting buf(size); 153 FixedBufferForTesting buf(size);
154 Array_Data<int32_t>* data; 154 Array_Data<int32_t>* data;
155 ArrayValidateParams validate_params(0, false, nullptr); 155 ArrayValidateParams validate_params(0, false, nullptr);
156 SerializeArray_(array.Pass(), &buf, &data, &validate_params); 156 SerializeArray_(array.Pass(), &buf, &data, &validate_params);
157 157
158 Array<int32_t> array2; 158 Array<int32_t> array2;
159 Deserialize_(data, &array2); 159 Deserialize_(data, &array2, nullptr);
160 160
161 EXPECT_EQ(4U, array2.size()); 161 EXPECT_EQ(4U, array2.size());
162 for (size_t i = 0; i < array2.size(); ++i) 162 for (size_t i = 0; i < array2.size(); ++i)
163 EXPECT_EQ(static_cast<int32_t>(i), array2[i]); 163 EXPECT_EQ(static_cast<int32_t>(i), array2[i]);
164 } 164 }
165 165
166 TEST_F(ArrayTest, Serialization_EmptyArrayOfPOD) { 166 TEST_F(ArrayTest, Serialization_EmptyArrayOfPOD) {
167 Array<int32_t> array(0); 167 Array<int32_t> array(0);
168 size_t size = GetSerializedSize_(array); 168 size_t size = GetSerializedSize_(array);
169 EXPECT_EQ(8U, size); 169 EXPECT_EQ(8U, size);
170 170
171 FixedBufferForTesting buf(size); 171 FixedBufferForTesting buf(size);
172 Array_Data<int32_t>* data; 172 Array_Data<int32_t>* data;
173 ArrayValidateParams validate_params(0, false, nullptr); 173 ArrayValidateParams validate_params(0, false, nullptr);
174 SerializeArray_(array.Pass(), &buf, &data, &validate_params); 174 SerializeArray_(array.Pass(), &buf, &data, &validate_params);
175 175
176 Array<int32_t> array2; 176 Array<int32_t> array2;
177 Deserialize_(data, &array2); 177 Deserialize_(data, &array2, nullptr);
178 EXPECT_EQ(0U, array2.size()); 178 EXPECT_EQ(0U, array2.size());
179 } 179 }
180 180
181 TEST_F(ArrayTest, Serialization_ArrayOfArrayOfPOD) { 181 TEST_F(ArrayTest, Serialization_ArrayOfArrayOfPOD) {
182 Array<Array<int32_t>> array(2); 182 Array<Array<int32_t>> array(2);
183 for (size_t j = 0; j < array.size(); ++j) { 183 for (size_t j = 0; j < array.size(); ++j) {
184 Array<int32_t> inner(4); 184 Array<int32_t> inner(4);
185 for (size_t i = 0; i < inner.size(); ++i) 185 for (size_t i = 0; i < inner.size(); ++i)
186 inner[i] = static_cast<int32_t>(i + (j * 10)); 186 inner[i] = static_cast<int32_t>(i + (j * 10));
187 array[j] = inner.Pass(); 187 array[j] = inner.Pass();
188 } 188 }
189 189
190 size_t size = GetSerializedSize_(array); 190 size_t size = GetSerializedSize_(array);
191 EXPECT_EQ(8U + 2 * 8U + 2 * (8U + 4 * 4U), size); 191 EXPECT_EQ(8U + 2 * 8U + 2 * (8U + 4 * 4U), size);
192 192
193 FixedBufferForTesting buf(size); 193 FixedBufferForTesting buf(size);
194 Array_Data<Array_Data<int32_t>*>* data; 194 Array_Data<Array_Data<int32_t>*>* data;
195 ArrayValidateParams validate_params( 195 ArrayValidateParams validate_params(
196 0, false, new ArrayValidateParams(0, false, nullptr)); 196 0, false, new ArrayValidateParams(0, false, nullptr));
197 SerializeArray_(array.Pass(), &buf, &data, &validate_params); 197 SerializeArray_(array.Pass(), &buf, &data, &validate_params);
198 198
199 Array<Array<int32_t>> array2; 199 Array<Array<int32_t>> array2;
200 Deserialize_(data, &array2); 200 Deserialize_(data, &array2, nullptr);
201 201
202 EXPECT_EQ(2U, array2.size()); 202 EXPECT_EQ(2U, array2.size());
203 for (size_t j = 0; j < array2.size(); ++j) { 203 for (size_t j = 0; j < array2.size(); ++j) {
204 const Array<int32_t>& inner = array2[j]; 204 const Array<int32_t>& inner = array2[j];
205 EXPECT_EQ(4U, inner.size()); 205 EXPECT_EQ(4U, inner.size());
206 for (size_t i = 0; i < inner.size(); ++i) 206 for (size_t i = 0; i < inner.size(); ++i)
207 EXPECT_EQ(static_cast<int32_t>(i + (j * 10)), inner[i]); 207 EXPECT_EQ(static_cast<int32_t>(i + (j * 10)), inner[i]);
208 } 208 }
209 } 209 }
210 210
211 TEST_F(ArrayTest, Serialization_ArrayOfBool) { 211 TEST_F(ArrayTest, Serialization_ArrayOfBool) {
212 Array<bool> array(10); 212 Array<bool> array(10);
213 for (size_t i = 0; i < array.size(); ++i) 213 for (size_t i = 0; i < array.size(); ++i)
214 array[i] = i % 2 ? true : false; 214 array[i] = i % 2 ? true : false;
215 215
216 size_t size = GetSerializedSize_(array); 216 size_t size = GetSerializedSize_(array);
217 EXPECT_EQ(8U + 8U, size); 217 EXPECT_EQ(8U + 8U, size);
218 218
219 FixedBufferForTesting buf(size); 219 FixedBufferForTesting buf(size);
220 Array_Data<bool>* data; 220 Array_Data<bool>* data;
221 ArrayValidateParams validate_params(0, false, nullptr); 221 ArrayValidateParams validate_params(0, false, nullptr);
222 SerializeArray_(array.Pass(), &buf, &data, &validate_params); 222 SerializeArray_(array.Pass(), &buf, &data, &validate_params);
223 223
224 Array<bool> array2; 224 Array<bool> array2;
225 Deserialize_(data, &array2); 225 Deserialize_(data, &array2, nullptr);
226 226
227 EXPECT_EQ(10U, array2.size()); 227 EXPECT_EQ(10U, array2.size());
228 for (size_t i = 0; i < array2.size(); ++i) 228 for (size_t i = 0; i < array2.size(); ++i)
229 EXPECT_EQ(i % 2 ? true : false, array2[i]); 229 EXPECT_EQ(i % 2 ? true : false, array2[i]);
230 } 230 }
231 231
232 TEST_F(ArrayTest, Serialization_ArrayOfString) { 232 TEST_F(ArrayTest, Serialization_ArrayOfString) {
233 Array<String> array(10); 233 Array<String> array(10);
234 for (size_t i = 0; i < array.size(); ++i) { 234 for (size_t i = 0; i < array.size(); ++i) {
235 char c = 'A' + static_cast<char>(i); 235 char c = 'A' + static_cast<char>(i);
236 array[i] = String(&c, 1); 236 array[i] = String(&c, 1);
237 } 237 }
238 238
239 size_t size = GetSerializedSize_(array); 239 size_t size = GetSerializedSize_(array);
240 EXPECT_EQ(8U + // array header 240 EXPECT_EQ(8U + // array header
241 10 * 8U + // array payload (10 pointers) 241 10 * 8U + // array payload (10 pointers)
242 10 * (8U + // string header 242 10 * (8U + // string header
243 8U), // string length of 1 padded to 8 243 8U), // string length of 1 padded to 8
244 size); 244 size);
245 245
246 FixedBufferForTesting buf(size); 246 FixedBufferForTesting buf(size);
247 Array_Data<String_Data*>* data; 247 Array_Data<String_Data*>* data;
248 ArrayValidateParams validate_params( 248 ArrayValidateParams validate_params(
249 0, false, new ArrayValidateParams(0, false, nullptr)); 249 0, false, new ArrayValidateParams(0, false, nullptr));
250 SerializeArray_(array.Pass(), &buf, &data, &validate_params); 250 SerializeArray_(array.Pass(), &buf, &data, &validate_params);
251 251
252 Array<String> array2; 252 Array<String> array2;
253 Deserialize_(data, &array2); 253 Deserialize_(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 char c = 'A' + static_cast<char>(i); 257 char c = 'A' + static_cast<char>(i);
258 EXPECT_EQ(String(&c, 1), array2[i]); 258 EXPECT_EQ(String(&c, 1), array2[i]);
259 } 259 }
260 } 260 }
261 261
262 TEST_F(ArrayTest, Resize_Copyable) { 262 TEST_F(ArrayTest, Resize_Copyable) {
263 ASSERT_EQ(0u, CopyableType::num_instances()); 263 ASSERT_EQ(0u, CopyableType::num_instances());
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 EXPECT_TRUE(array[i].moved()); 429 EXPECT_TRUE(array[i].moved());
430 EXPECT_EQ(value_ptrs[i], array[i].ptr()); 430 EXPECT_EQ(value_ptrs[i], array[i].ptr());
431 } 431 }
432 array.reset(); 432 array.reset();
433 EXPECT_EQ(0u, MoveOnlyType::num_instances()); 433 EXPECT_EQ(0u, MoveOnlyType::num_instances());
434 } 434 }
435 435
436 } // namespace 436 } // namespace
437 } // namespace test 437 } // namespace test
438 } // namespace mojo 438 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/string_serialization.cc ('k') | mojo/public/cpp/bindings/tests/associated_interface_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698