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

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

Issue 2136733002: Mojo C++ bindings: add a new mode to generator to use native STL/WTF types (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@67_new
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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 <string> 5 #include <string>
6 #include <utility> 6 #include <utility>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 const PassPickledEnumCallback& callback) override { 98 const PassPickledEnumCallback& callback) override {
99 callback.Run(pickle); 99 callback.Run(pickle);
100 } 100 }
101 101
102 void PassPickleContainer( 102 void PassPickleContainer(
103 PickleContainerPtr container, 103 PickleContainerPtr container,
104 const PassPickleContainerCallback& callback) override { 104 const PassPickleContainerCallback& callback) override {
105 callback.Run(std::move(container)); 105 callback.Run(std::move(container));
106 } 106 }
107 107
108 void PassPickles(Array<PickledStructChromium> pickles, 108 void PassPickles(const std::vector<PickledStructChromium>& pickles,
109 const PassPicklesCallback& callback) override { 109 const PassPicklesCallback& callback) override {
110 callback.Run(std::move(pickles)); 110 callback.Run(pickles);
111 } 111 }
112 112
113 void PassPickleArrays(Array<Array<PickledStructChromium>> pickle_arrays, 113 void PassPickleArrays(
114 const PassPickleArraysCallback& callback) override { 114 const std::vector<std::vector<PickledStructChromium>>& pickle_arrays,
115 callback.Run(std::move(pickle_arrays)); 115 const PassPickleArraysCallback& callback) override {
116 callback.Run(pickle_arrays);
116 } 117 }
117 }; 118 };
118 119
119 // This implements the generated Blink variant of PicklePasser. 120 // This implements the generated Blink variant of PicklePasser.
120 class BlinkPicklePasserImpl : public blink::PicklePasser { 121 class BlinkPicklePasserImpl : public blink::PicklePasser {
121 public: 122 public:
122 BlinkPicklePasserImpl() {} 123 BlinkPicklePasserImpl() {}
123 124
124 // mojo::test::blink::PicklePasser: 125 // mojo::test::blink::PicklePasser:
125 void PassPickledStruct(const PickledStructBlink& pickle, 126 void PassPickledStruct(const PickledStructBlink& pickle,
126 const PassPickledStructCallback& callback) override { 127 const PassPickledStructCallback& callback) override {
127 callback.Run(pickle); 128 callback.Run(pickle);
128 } 129 }
129 130
130 void PassPickledEnum(PickledEnumBlink pickle, 131 void PassPickledEnum(PickledEnumBlink pickle,
131 const PassPickledEnumCallback& callback) override { 132 const PassPickledEnumCallback& callback) override {
132 callback.Run(pickle); 133 callback.Run(pickle);
133 } 134 }
134 135
135 void PassPickleContainer( 136 void PassPickleContainer(
136 blink::PickleContainerPtr container, 137 blink::PickleContainerPtr container,
137 const PassPickleContainerCallback& callback) override { 138 const PassPickleContainerCallback& callback) override {
138 callback.Run(std::move(container)); 139 callback.Run(std::move(container));
139 } 140 }
140 141
141 void PassPickles(WTFArray<PickledStructBlink> pickles, 142 void PassPickles(const WTF::Vector<PickledStructBlink>& pickles,
142 const PassPicklesCallback& callback) override { 143 const PassPicklesCallback& callback) override {
143 callback.Run(std::move(pickles)); 144 callback.Run(pickles);
144 } 145 }
145 146
146 void PassPickleArrays(WTFArray<WTFArray<PickledStructBlink>> pickle_arrays, 147 void PassPickleArrays(
147 const PassPickleArraysCallback& callback) override { 148 const WTF::Vector<WTF::Vector<PickledStructBlink>>& pickle_arrays,
148 callback.Run(std::move(pickle_arrays)); 149 const PassPickleArraysCallback& callback) override {
150 callback.Run(pickle_arrays);
149 } 151 }
150 }; 152 };
151 153
152 // A test which runs both Chromium and Blink implementations of the 154 // A test which runs both Chromium and Blink implementations of the
153 // PicklePasser service. 155 // PicklePasser service.
154 class PickleTest : public testing::Test { 156 class PickleTest : public testing::Test {
155 public: 157 public:
156 PickleTest() {} 158 PickleTest() {}
157 159
158 template <typename ProxyType = PicklePasser> 160 template <typename ProxyType = PicklePasser>
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 pickles[0].set_baz(100); 307 pickles[0].set_baz(100);
306 pickles[1].set_foo(3); 308 pickles[1].set_foo(3);
307 pickles[1].set_bar(4); 309 pickles[1].set_bar(4);
308 pickles[1].set_baz(100); 310 pickles[1].set_baz(100);
309 { 311 {
310 base::RunLoop run_loop; 312 base::RunLoop run_loop;
311 // Verify that the array of pickled structs can be serialized and 313 // Verify that the array of pickled structs can be serialized and
312 // deserialized intact. This ensures that the ParamTraits are actually used 314 // deserialized intact. This ensures that the ParamTraits are actually used
313 // rather than doing a byte-for-byte copy of the element data, beacuse the 315 // rather than doing a byte-for-byte copy of the element data, beacuse the
314 // |baz| field should never be serialized. 316 // |baz| field should never be serialized.
315 proxy->PassPickles(std::move(pickles), 317 proxy->PassPickles(
316 BindSimpleLambda<Array<PickledStructChromium>>( 318 std::move(pickles),
317 [&](Array<PickledStructChromium> passed) { 319 BindSimpleLambda<const std::vector<PickledStructChromium>&>(
318 ASSERT_FALSE(passed.is_null()); 320 [&](const std::vector<PickledStructChromium>& passed) {
319 ASSERT_EQ(2u, passed.size()); 321 ASSERT_EQ(2u, passed.size());
320 EXPECT_EQ(1, passed[0].foo()); 322 EXPECT_EQ(1, passed[0].foo());
321 EXPECT_EQ(2, passed[0].bar()); 323 EXPECT_EQ(2, passed[0].bar());
322 EXPECT_EQ(0, passed[0].baz()); 324 EXPECT_EQ(0, passed[0].baz());
323 EXPECT_EQ(3, passed[1].foo()); 325 EXPECT_EQ(3, passed[1].foo());
324 EXPECT_EQ(4, passed[1].bar()); 326 EXPECT_EQ(4, passed[1].bar());
325 EXPECT_EQ(0, passed[1].baz()); 327 EXPECT_EQ(0, passed[1].baz());
326 run_loop.Quit(); 328 run_loop.Quit();
327 })); 329 }));
328 run_loop.Run(); 330 run_loop.Run();
329 } 331 }
330 } 332 }
331 333
332 TEST_F(PickleTest, PickleArrayArray) { 334 TEST_F(PickleTest, PickleArrayArray) {
333 auto proxy = ConnectToChromiumService(); 335 auto proxy = ConnectToChromiumService();
334 auto pickle_arrays = Array<Array<PickledStructChromium>>::New(2); 336 auto pickle_arrays = std::vector<std::vector<PickledStructChromium>>(2);
335 for (size_t i = 0; i < 2; ++i) 337 for (size_t i = 0; i < 2; ++i)
336 pickle_arrays[i] = Array<PickledStructChromium>::New(2); 338 pickle_arrays[i] = std::vector<PickledStructChromium>(2);
337 339
338 pickle_arrays[0][0].set_foo(1); 340 pickle_arrays[0][0].set_foo(1);
339 pickle_arrays[0][0].set_bar(2); 341 pickle_arrays[0][0].set_bar(2);
340 pickle_arrays[0][0].set_baz(100); 342 pickle_arrays[0][0].set_baz(100);
341 pickle_arrays[0][1].set_foo(3); 343 pickle_arrays[0][1].set_foo(3);
342 pickle_arrays[0][1].set_bar(4); 344 pickle_arrays[0][1].set_bar(4);
343 pickle_arrays[0][1].set_baz(100); 345 pickle_arrays[0][1].set_baz(100);
344 pickle_arrays[1][0].set_foo(5); 346 pickle_arrays[1][0].set_foo(5);
345 pickle_arrays[1][0].set_bar(6); 347 pickle_arrays[1][0].set_bar(6);
346 pickle_arrays[1][0].set_baz(100); 348 pickle_arrays[1][0].set_baz(100);
347 pickle_arrays[1][1].set_foo(7); 349 pickle_arrays[1][1].set_foo(7);
348 pickle_arrays[1][1].set_bar(8); 350 pickle_arrays[1][1].set_bar(8);
349 pickle_arrays[1][1].set_baz(100); 351 pickle_arrays[1][1].set_baz(100);
350 { 352 {
351 base::RunLoop run_loop; 353 base::RunLoop run_loop;
352 // Verify that the array-of-arrays serializes and deserializes properly. 354 // Verify that the array-of-arrays serializes and deserializes properly.
353 proxy->PassPickleArrays( 355 proxy->PassPickleArrays(
354 std::move(pickle_arrays), 356 pickle_arrays,
355 BindSimpleLambda<Array<Array<PickledStructChromium>>>( 357 BindSimpleLambda<
356 [&](Array<Array<PickledStructChromium>> passed) { 358 const std::vector<std::vector<PickledStructChromium>>&>(
357 ASSERT_FALSE(passed.is_null()); 359 [&](const std::vector<std::vector<PickledStructChromium>>& passed) {
358 ASSERT_EQ(2u, passed.size()); 360 ASSERT_EQ(2u, passed.size());
359 ASSERT_EQ(2u, passed[0].size()); 361 ASSERT_EQ(2u, passed[0].size());
360 ASSERT_EQ(2u, passed[1].size()); 362 ASSERT_EQ(2u, passed[1].size());
361 EXPECT_EQ(1, passed[0][0].foo()); 363 EXPECT_EQ(1, passed[0][0].foo());
362 EXPECT_EQ(2, passed[0][0].bar()); 364 EXPECT_EQ(2, passed[0][0].bar());
363 EXPECT_EQ(0, passed[0][0].baz()); 365 EXPECT_EQ(0, passed[0][0].baz());
364 EXPECT_EQ(3, passed[0][1].foo()); 366 EXPECT_EQ(3, passed[0][1].foo());
365 EXPECT_EQ(4, passed[0][1].bar()); 367 EXPECT_EQ(4, passed[0][1].bar());
366 EXPECT_EQ(0, passed[0][1].baz()); 368 EXPECT_EQ(0, passed[0][1].baz());
367 EXPECT_EQ(5, passed[1][0].foo()); 369 EXPECT_EQ(5, passed[1][0].foo());
(...skipping 29 matching lines...) Expand all
397 EXPECT_EQ(PickledEnumChromium::VALUE_1, 399 EXPECT_EQ(PickledEnumChromium::VALUE_1,
398 passed->f_enum); 400 passed->f_enum);
399 run_loop.Quit(); 401 run_loop.Quit();
400 })); 402 }));
401 run_loop.Run(); 403 run_loop.Run();
402 } 404 }
403 } 405 }
404 406
405 } // namespace test 407 } // namespace test
406 } // namespace mojo 408 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/tests/handle_passing_unittest.cc ('k') | mojo/public/cpp/bindings/tests/request_response_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698