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

Side by Side Diff: mojo/public/cpp/bindings/tests/handle_passing_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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <stdint.h> 5 #include <stdint.h>
6 #include <utility> 6 #include <utility>
7 7
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "mojo/public/cpp/bindings/binding.h" 10 #include "mojo/public/cpp/bindings/binding.h"
11 #include "mojo/public/cpp/bindings/strong_binding.h" 11 #include "mojo/public/cpp/bindings/strong_binding.h"
12 #include "mojo/public/cpp/test_support/test_utils.h" 12 #include "mojo/public/cpp/test_support/test_utils.h"
13 #include "mojo/public/interfaces/bindings/tests/sample_factory.mojom.h" 13 #include "mojo/public/interfaces/bindings/tests/sample_factory.mojom.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 15
16 namespace mojo { 16 namespace mojo {
17 namespace test { 17 namespace test {
18 namespace { 18 namespace {
19 19
20 const char kText1[] = "hello"; 20 const char kText1[] = "hello";
21 const char kText2[] = "world"; 21 const char kText2[] = "world";
22 22
23 void RecordString(std::string* storage, 23 void RecordString(std::string* storage,
24 const base::Closure& closure, 24 const base::Closure& closure,
25 String str) { 25 const std::string& str) {
26 *storage = str.PassStorage(); 26 *storage = str;
27 closure.Run(); 27 closure.Run();
28 } 28 }
29 29
30 base::Callback<void(mojo::String)> MakeStringRecorder( 30 base::Callback<void(const std::string&)> MakeStringRecorder(
31 std::string* storage, 31 std::string* storage,
32 const base::Closure& closure) { 32 const base::Closure& closure) {
33 return base::Bind(&RecordString, storage, closure); 33 return base::Bind(&RecordString, storage, closure);
34 } 34 }
35 35
36 class ImportedInterfaceImpl : public imported::ImportedInterface { 36 class ImportedInterfaceImpl : public imported::ImportedInterface {
37 public: 37 public:
38 ImportedInterfaceImpl( 38 ImportedInterfaceImpl(
39 InterfaceRequest<imported::ImportedInterface> request, 39 InterfaceRequest<imported::ImportedInterface> request,
40 const base::Closure& closure) 40 const base::Closure& closure)
(...skipping 10 matching lines...) Expand all
51 static int do_something_count_; 51 static int do_something_count_;
52 Binding<ImportedInterface> binding_; 52 Binding<ImportedInterface> binding_;
53 base::Closure closure_; 53 base::Closure closure_;
54 }; 54 };
55 int ImportedInterfaceImpl::do_something_count_ = 0; 55 int ImportedInterfaceImpl::do_something_count_ = 0;
56 56
57 class SampleNamedObjectImpl : public sample::NamedObject { 57 class SampleNamedObjectImpl : public sample::NamedObject {
58 public: 58 public:
59 explicit SampleNamedObjectImpl(InterfaceRequest<sample::NamedObject> request) 59 explicit SampleNamedObjectImpl(InterfaceRequest<sample::NamedObject> request)
60 : binding_(this, std::move(request)) {} 60 : binding_(this, std::move(request)) {}
61 void SetName(const mojo::String& name) override { name_ = name; } 61 void SetName(const std::string& name) override { name_ = name; }
62 62
63 void GetName(const GetNameCallback& callback) override { 63 void GetName(const GetNameCallback& callback) override {
64 callback.Run(name_); 64 callback.Run(name_);
65 } 65 }
66 66
67 private: 67 private:
68 std::string name_; 68 std::string name_;
69 StrongBinding<sample::NamedObject> binding_; 69 StrongBinding<sample::NamedObject> binding_;
70 }; 70 };
71 71
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 void PumpMessages() { base::RunLoop().RunUntilIdle(); } 160 void PumpMessages() { base::RunLoop().RunUntilIdle(); }
161 161
162 private: 162 private:
163 base::MessageLoop loop_; 163 base::MessageLoop loop_;
164 }; 164 };
165 165
166 void DoStuff(bool* got_response, 166 void DoStuff(bool* got_response,
167 std::string* got_text_reply, 167 std::string* got_text_reply,
168 const base::Closure& closure, 168 const base::Closure& closure,
169 sample::ResponsePtr response, 169 sample::ResponsePtr response,
170 String text_reply) { 170 const std::string& text_reply) {
171 *got_text_reply = text_reply; 171 *got_text_reply = text_reply;
172 172
173 if (response->pipe.is_valid()) { 173 if (response->pipe.is_valid()) {
174 std::string text2; 174 std::string text2;
175 EXPECT_TRUE(ReadTextMessage(response->pipe.get(), &text2)); 175 EXPECT_TRUE(ReadTextMessage(response->pipe.get(), &text2));
176 176
177 // Ensure that simply accessing response.pipe does not close it. 177 // Ensure that simply accessing response.pipe does not close it.
178 EXPECT_TRUE(response->pipe.is_valid()); 178 EXPECT_TRUE(response->pipe.is_valid());
179 179
180 EXPECT_EQ(std::string(kText2), text2); 180 EXPECT_EQ(std::string(kText2), text2);
181 181
182 // Do some more tests of handle passing: 182 // Do some more tests of handle passing:
183 ScopedMessagePipeHandle p = std::move(response->pipe); 183 ScopedMessagePipeHandle p = std::move(response->pipe);
184 EXPECT_TRUE(p.is_valid()); 184 EXPECT_TRUE(p.is_valid());
185 EXPECT_FALSE(response->pipe.is_valid()); 185 EXPECT_FALSE(response->pipe.is_valid());
186 } 186 }
187 187
188 *got_response = true; 188 *got_response = true;
189 closure.Run(); 189 closure.Run();
190 } 190 }
191 191
192 void DoStuff2(bool* got_response, 192 void DoStuff2(bool* got_response,
193 std::string* got_text_reply, 193 std::string* got_text_reply,
194 const base::Closure& closure, 194 const base::Closure& closure,
195 String text_reply) { 195 const std::string& text_reply) {
196 *got_response = true; 196 *got_response = true;
197 *got_text_reply = text_reply; 197 *got_text_reply = text_reply;
198 closure.Run(); 198 closure.Run();
199 } 199 }
200 200
201 TEST_F(HandlePassingTest, Basic) { 201 TEST_F(HandlePassingTest, Basic) {
202 sample::FactoryPtr factory; 202 sample::FactoryPtr factory;
203 SampleFactoryImpl factory_impl(GetProxy(&factory)); 203 SampleFactoryImpl factory_impl(GetProxy(&factory));
204 204
205 MessagePipe pipe0; 205 MessagePipe pipe0;
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 TEST_F(HandlePassingTest, PipesAreClosed) { 297 TEST_F(HandlePassingTest, PipesAreClosed) {
298 sample::FactoryPtr factory; 298 sample::FactoryPtr factory;
299 SampleFactoryImpl factory_impl(GetProxy(&factory)); 299 SampleFactoryImpl factory_impl(GetProxy(&factory));
300 300
301 MessagePipe extra_pipe; 301 MessagePipe extra_pipe;
302 302
303 MojoHandle handle0_value = extra_pipe.handle0.get().value(); 303 MojoHandle handle0_value = extra_pipe.handle0.get().value();
304 MojoHandle handle1_value = extra_pipe.handle1.get().value(); 304 MojoHandle handle1_value = extra_pipe.handle1.get().value();
305 305
306 { 306 {
307 Array<ScopedMessagePipeHandle> pipes(2); 307 std::vector<ScopedMessagePipeHandle> pipes(2);
308 pipes[0] = std::move(extra_pipe.handle0); 308 pipes[0] = std::move(extra_pipe.handle0);
309 pipes[1] = std::move(extra_pipe.handle1); 309 pipes[1] = std::move(extra_pipe.handle1);
310 310
311 sample::RequestPtr request(sample::Request::New()); 311 sample::RequestPtr request(sample::Request::New());
312 request->more_pipes = std::move(pipes); 312 request->more_pipes = std::move(pipes);
313 313
314 factory->DoStuff(std::move(request), ScopedMessagePipeHandle(), 314 factory->DoStuff(std::move(request), ScopedMessagePipeHandle(),
315 sample::Factory::DoStuffCallback()); 315 sample::Factory::DoStuffCallback());
316 } 316 }
317 317
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 run_loop.Run(); 349 run_loop.Run();
350 run_loop2.Run(); 350 run_loop2.Run();
351 351
352 EXPECT_EQ(std::string("object1"), name1); 352 EXPECT_EQ(std::string("object1"), name1);
353 EXPECT_EQ(std::string("object2"), name2); 353 EXPECT_EQ(std::string("object2"), name2);
354 } 354 }
355 355
356 } // namespace 356 } // namespace
357 } // namespace test 357 } // namespace test
358 } // namespace mojo 358 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/tests/equals_unittest.cc ('k') | mojo/public/cpp/bindings/tests/pickle_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698