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

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

Issue 2259283003: Mojo C++ bindings: share DataView class between chromium and blink variants. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@92_change_traits_param
Patch Set: . Created 4 years, 4 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 "mojo/public/cpp/bindings/array.h" 5 #include "mojo/public/cpp/bindings/array.h"
6 #include "mojo/public/cpp/bindings/lib/fixed_buffer.h" 6 #include "mojo/public/cpp/bindings/lib/fixed_buffer.h"
7 #include "mojo/public/cpp/bindings/lib/serialization.h" 7 #include "mojo/public/cpp/bindings/lib/serialization.h"
8 #include "mojo/public/cpp/bindings/lib/validate_params.h" 8 #include "mojo/public/cpp/bindings/lib/validate_params.h"
9 #include "mojo/public/cpp/bindings/map.h" 9 #include "mojo/public/cpp/bindings/map.h"
10 #include "mojo/public/cpp/bindings/string.h" 10 #include "mojo/public/cpp/bindings/string.h"
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 for (size_t i = 0; i < kStringIntDataSize; ++i) { 148 for (size_t i = 0; i < kStringIntDataSize; ++i) {
149 ASSERT_NE(m2.end(), m2.find(kStringIntData[i].string_data)); 149 ASSERT_NE(m2.end(), m2.find(kStringIntData[i].string_data));
150 ASSERT_EQ(1u, m2[kStringIntData[i].string_data].size()); 150 ASSERT_EQ(1u, m2[kStringIntData[i].string_data].size());
151 EXPECT_EQ(StringType(kStringIntData[i].string_data), 151 EXPECT_EQ(StringType(kStringIntData[i].string_data),
152 m2[kStringIntData[i].string_data][0]); 152 m2[kStringIntData[i].string_data][0]);
153 } 153 }
154 } 154 }
155 155
156 static void ArrayOfMap() { 156 static void ArrayOfMap() {
157 { 157 {
158 using MojomType = Array<Map<int32_t, int8_t>>; 158 using MojomType = ArrayDataView<MapDataView<int32_t, int8_t>>;
159 using UserType = ArrayType<MapType<int32_t, int8_t>>; 159 using UserType = ArrayType<MapType<int32_t, int8_t>>;
160 160
161 UserType array(1); 161 UserType array(1);
162 array[0].insert(1, 42); 162 array[0].insert(1, 42);
163 163
164 mojo::internal::SerializationContext context; 164 mojo::internal::SerializationContext context;
165 size_t size = 165 size_t size =
166 mojo::internal::PrepareToSerialize<MojomType>(array, &context); 166 mojo::internal::PrepareToSerialize<MojomType>(array, &context);
167 mojo::internal::FixedBufferForTesting buf(size); 167 mojo::internal::FixedBufferForTesting buf(size);
168 typename mojo::internal::MojomTypeTraits<MojomType>::Data* data; 168 typename mojo::internal::MojomTypeTraits<MojomType>::Data* data;
169 mojo::internal::ContainerValidateParams validate_params( 169 mojo::internal::ContainerValidateParams validate_params(
170 0, false, 170 0, false,
171 new mojo::internal::ContainerValidateParams( 171 new mojo::internal::ContainerValidateParams(
172 new mojo::internal::ContainerValidateParams(0, false, nullptr), 172 new mojo::internal::ContainerValidateParams(0, false, nullptr),
173 new mojo::internal::ContainerValidateParams(0, false, nullptr))); 173 new mojo::internal::ContainerValidateParams(0, false, nullptr)));
174 174
175 mojo::internal::Serialize<MojomType>(array, &buf, &data, &validate_params, 175 mojo::internal::Serialize<MojomType>(array, &buf, &data, &validate_params,
176 &context); 176 &context);
177 177
178 UserType deserialized_array; 178 UserType deserialized_array;
179 mojo::internal::Deserialize<MojomType>(data, &deserialized_array, 179 mojo::internal::Deserialize<MojomType>(data, &deserialized_array,
180 &context); 180 &context);
181 181
182 ASSERT_EQ(1u, deserialized_array.size()); 182 ASSERT_EQ(1u, deserialized_array.size());
183 ASSERT_EQ(1u, deserialized_array[0].size()); 183 ASSERT_EQ(1u, deserialized_array[0].size());
184 ASSERT_EQ(42, deserialized_array[0].at(1)); 184 ASSERT_EQ(42, deserialized_array[0].at(1));
185 } 185 }
186 186
187 { 187 {
188 using MojomType = Array<Map<String, Array<bool>>>; 188 using MojomType =
189 ArrayDataView<MapDataView<StringDataView, ArrayDataView<bool>>>;
189 using UserType = ArrayType<MapType<StringType, ArrayType<bool>>>; 190 using UserType = ArrayType<MapType<StringType, ArrayType<bool>>>;
190 191
191 UserType array(1); 192 UserType array(1);
192 ArrayType<bool> map_value(2); 193 ArrayType<bool> map_value(2);
193 map_value[0] = false; 194 map_value[0] = false;
194 map_value[1] = true; 195 map_value[1] = true;
195 array[0].insert("hello world", std::move(map_value)); 196 array[0].insert("hello world", std::move(map_value));
196 197
197 mojo::internal::SerializationContext context; 198 mojo::internal::SerializationContext context;
198 size_t size = 199 size_t size =
(...skipping 22 matching lines...) Expand all
221 ASSERT_TRUE(deserialized_array[0].at("hello world")[1]); 222 ASSERT_TRUE(deserialized_array[0].at("hello world")[1]);
222 } 223 }
223 } 224 }
224 }; 225 };
225 226
226 #define MAP_COMMON_TEST(MapType, test_name) \ 227 #define MAP_COMMON_TEST(MapType, test_name) \
227 TEST_F(MapType##Test, test_name) { MapCommonTest<MapType>::test_name(); } 228 TEST_F(MapType##Test, test_name) { MapCommonTest<MapType>::test_name(); }
228 229
229 } // namespace test 230 } // namespace test
230 } // namespace mojo 231 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/tests/data_view_unittest.cc ('k') | mojo/public/cpp/bindings/tests/rect_blink.typemap » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698