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

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

Issue 632603002: Mojo C++ bindings: support Arrays that contain Maps. Base URL: https://chromium.googlesource.com/chromium/src.git@4_mojo_map
Patch Set: Created 6 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
« no previous file with comments | « mojo/public/cpp/bindings/lib/map_serialization.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/fixed_buffer.h" 7 #include "mojo/public/cpp/bindings/lib/fixed_buffer.h"
8 #include "mojo/public/cpp/bindings/lib/map_serialization.h"
8 #include "mojo/public/cpp/bindings/map.h" 9 #include "mojo/public/cpp/bindings/map.h"
9 #include "mojo/public/cpp/bindings/string.h" 10 #include "mojo/public/cpp/bindings/string.h"
10 #include "mojo/public/cpp/environment/environment.h" 11 #include "mojo/public/cpp/environment/environment.h"
11 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
12 13
13 namespace mojo { 14 namespace mojo {
14 namespace test { 15 namespace test {
15 16
16 namespace { 17 namespace {
17 18
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 } 244 }
244 245
245 Map<String, Array<String> > m2 = m.Clone(); 246 Map<String, Array<String> > m2 = m.Clone();
246 247
247 for (auto it = m2.begin(); it != m2.end(); ++it) { 248 for (auto it = m2.begin(); it != m2.end(); ++it) {
248 ASSERT_EQ(1u, it.GetValue().size()); 249 ASSERT_EQ(1u, it.GetValue().size());
249 EXPECT_EQ(it.GetKey(), it.GetValue().at(0)); 250 EXPECT_EQ(it.GetKey(), it.GetValue().at(0));
250 } 251 }
251 } 252 }
252 253
254 TEST_F(MapTest, ArrayOfMap) {
255 {
256 Array<Map<int32_t, int8_t>> array(1);
257 array[0].insert(1, 42);
258
259 size_t size = GetSerializedSize_(array);
260
261 internal::FixedBuffer buf(size);
262 internal::Array_Data<internal::MapPointerPair<int32_t, int8_t>>* data;
263 SerializeArray_<
264 internal::ArrayValidateParams<0, false,
265 internal::ArrayValidateParams<0, false,
266 internal::NoValidateParams>>>(array.Pass(), &buf, &data);
267
268 Array<Map<int32_t, int8_t>> array2;
269 Deserialize_(data, &array2);
270 ASSERT_EQ(1u, array2.size());
271 ASSERT_EQ(1u, array2[0].size());
272 ASSERT_EQ(42, array2[0].at(1));
273 }
274
275 {
276 Array<Map<String, Array<bool>>> array(1);
277 Array<bool> map_value(2);
278 map_value[0] = false;
279 map_value[1] = true;
280
281 array[0].insert("hello world", map_value.Pass());
282
283 size_t size = GetSerializedSize_(array);
284
285 internal::FixedBuffer buf(size);
286 internal::Array_Data<
287 internal::MapPointerPair<internal::String_Data*,
288 internal::Array_Data<bool>*>>* data;
289 SerializeArray_<
290 internal::ArrayValidateParams<0, false,
291 internal::ArrayValidateParams<0, false,
292 internal::ArrayValidateParams<0, false,
293 internal::NoValidateParams>>>>(array.Pass(), &buf, &data);
294
295 Array<Map<String, Array<bool>>> array2;
296 Deserialize_(data, &array2);
297 ASSERT_EQ(1u, array2.size());
298 ASSERT_EQ(1u, array2[0].size());
299 ASSERT_FALSE(array2[0].at("hello world")[0]);
300 ASSERT_TRUE(array2[0].at("hello world")[1]);
301 }
302
303 // TODO(yzshen): More tests...
304 }
305
253 } // namespace 306 } // namespace
254 } // namespace test 307 } // namespace test
255 } // namespace mojo 308 } // namespace mojo
256 309
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/map_serialization.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698