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

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

Issue 376383002: Mojo: Add support for InterfacePtr as a struct member (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: retry Created 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | mojo/public/interfaces/bindings/tests/sample_factory.mojom » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "mojo/public/cpp/environment/environment.h" 5 #include "mojo/public/cpp/environment/environment.h"
6 #include "mojo/public/cpp/test_support/test_utils.h" 6 #include "mojo/public/cpp/test_support/test_utils.h"
7 #include "mojo/public/cpp/utility/run_loop.h" 7 #include "mojo/public/cpp/utility/run_loop.h"
8 #include "mojo/public/interfaces/bindings/tests/sample_factory.mojom.h" 8 #include "mojo/public/interfaces/bindings/tests/sample_factory.mojom.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
11 namespace mojo { 11 namespace mojo {
12 namespace test { 12 namespace test {
13 namespace { 13 namespace {
14 14
15 const char kText1[] = "hello"; 15 const char kText1[] = "hello";
16 const char kText2[] = "world"; 16 const char kText2[] = "world";
17 17
18 class StringRecorder { 18 class StringRecorder {
19 public: 19 public:
20 explicit StringRecorder(std::string* buf) : buf_(buf) { 20 explicit StringRecorder(std::string* buf) : buf_(buf) {
21 } 21 }
22 void Run(const String& a) const { 22 void Run(const String& a) const {
23 *buf_ = a.To<std::string>(); 23 *buf_ = a.To<std::string>();
24 } 24 }
25 private: 25 private:
26 std::string* buf_; 26 std::string* buf_;
27 }; 27 };
28 28
29 class ImportedInterfaceImpl
30 : public InterfaceImpl<imported::ImportedInterface> {
31 public:
32 virtual void OnConnectionError() MOJO_OVERRIDE {
33 delete this;
34 }
35
36 virtual void DoSomething() MOJO_OVERRIDE {
37 do_something_count_++;
38 }
39
40 static int do_something_count() { return do_something_count_; }
41
42 private:
43 static int do_something_count_;
44 };
45 int ImportedInterfaceImpl::do_something_count_ = 0;
46
29 class SampleNamedObjectImpl : public InterfaceImpl<sample::NamedObject> { 47 class SampleNamedObjectImpl : public InterfaceImpl<sample::NamedObject> {
30 public: 48 public:
31 virtual void OnConnectionError() MOJO_OVERRIDE { 49 virtual void OnConnectionError() MOJO_OVERRIDE {
32 delete this; 50 delete this;
33 } 51 }
34 52
35 virtual void SetName(const mojo::String& name) MOJO_OVERRIDE { 53 virtual void SetName(const mojo::String& name) MOJO_OVERRIDE {
36 name_ = name; 54 name_ = name;
37 } 55 }
38 56
(...skipping 29 matching lines...) Expand all
68 ScopedMessagePipeHandle pipe0; 86 ScopedMessagePipeHandle pipe0;
69 if (!text2.empty()) { 87 if (!text2.empty()) {
70 CreateMessagePipe(NULL, &pipe0, &pipe1_); 88 CreateMessagePipe(NULL, &pipe0, &pipe1_);
71 EXPECT_TRUE(WriteTextMessage(pipe1_.get(), text2)); 89 EXPECT_TRUE(WriteTextMessage(pipe1_.get(), text2));
72 } 90 }
73 91
74 sample::ResponsePtr response(sample::Response::New()); 92 sample::ResponsePtr response(sample::Response::New());
75 response->x = 2; 93 response->x = 2;
76 response->pipe = pipe0.Pass(); 94 response->pipe = pipe0.Pass();
77 client()->DidStuff(response.Pass(), text1); 95 client()->DidStuff(response.Pass(), text1);
96
97 if (request->obj.get())
98 request->obj->DoSomething();
78 } 99 }
79 100
80 virtual void DoStuff2(ScopedDataPipeConsumerHandle pipe) MOJO_OVERRIDE { 101 virtual void DoStuff2(ScopedDataPipeConsumerHandle pipe) MOJO_OVERRIDE {
81 // Read the data from the pipe, writing the response (as a string) to 102 // Read the data from the pipe, writing the response (as a string) to
82 // DidStuff2(). 103 // DidStuff2().
83 ASSERT_TRUE(pipe.is_valid()); 104 ASSERT_TRUE(pipe.is_valid());
84 uint32_t data_size = 0; 105 uint32_t data_size = 0;
85 ASSERT_EQ(MOJO_RESULT_OK, 106 ASSERT_EQ(MOJO_RESULT_OK,
86 ReadDataRaw(pipe.get(), NULL, &data_size, 107 ReadDataRaw(pipe.get(), NULL, &data_size,
87 MOJO_READ_DATA_FLAG_QUERY)); 108 MOJO_READ_DATA_FLAG_QUERY));
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 factory_client.set_expected_text_reply(kText1); 208 factory_client.set_expected_text_reply(kText1);
188 209
189 factory.set_client(&factory_client); 210 factory.set_client(&factory_client);
190 211
191 MessagePipe pipe0; 212 MessagePipe pipe0;
192 EXPECT_TRUE(WriteTextMessage(pipe0.handle1.get(), kText1)); 213 EXPECT_TRUE(WriteTextMessage(pipe0.handle1.get(), kText1));
193 214
194 MessagePipe pipe1; 215 MessagePipe pipe1;
195 EXPECT_TRUE(WriteTextMessage(pipe1.handle1.get(), kText2)); 216 EXPECT_TRUE(WriteTextMessage(pipe1.handle1.get(), kText2));
196 217
218 imported::ImportedInterfacePtr imported;
219 BindToProxy(new ImportedInterfaceImpl(), &imported);
220
197 sample::RequestPtr request(sample::Request::New()); 221 sample::RequestPtr request(sample::Request::New());
198 request->x = 1; 222 request->x = 1;
199 request->pipe = pipe1.handle0.Pass(); 223 request->pipe = pipe1.handle0.Pass();
224 request->obj = imported.Pass();
200 factory->DoStuff(request.Pass(), pipe0.handle0.Pass()); 225 factory->DoStuff(request.Pass(), pipe0.handle0.Pass());
201 226
202 EXPECT_FALSE(factory_client.got_response()); 227 EXPECT_FALSE(factory_client.got_response());
228 int count_before = ImportedInterfaceImpl::do_something_count();
203 229
204 PumpMessages(); 230 PumpMessages();
205 231
206 EXPECT_TRUE(factory_client.got_response()); 232 EXPECT_TRUE(factory_client.got_response());
233 EXPECT_EQ(1, ImportedInterfaceImpl::do_something_count() - count_before);
207 } 234 }
208 235
209 TEST_F(HandlePassingTest, PassInvalid) { 236 TEST_F(HandlePassingTest, PassInvalid) {
210 sample::FactoryPtr factory; 237 sample::FactoryPtr factory;
211 BindToProxy(new SampleFactoryImpl(), &factory); 238 BindToProxy(new SampleFactoryImpl(), &factory);
212 239
213 SampleFactoryClientImpl factory_client; 240 SampleFactoryClientImpl factory_client;
214 factory.set_client(&factory_client); 241 factory.set_client(&factory_client);
215 242
216 sample::RequestPtr request(sample::Request::New()); 243 sample::RequestPtr request(sample::Request::New());
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 357
331 PumpMessages(); // Yield for results. 358 PumpMessages(); // Yield for results.
332 359
333 EXPECT_EQ(std::string("object1"), name1); 360 EXPECT_EQ(std::string("object1"), name1);
334 EXPECT_EQ(std::string("object2"), name2); 361 EXPECT_EQ(std::string("object2"), name2);
335 } 362 }
336 363
337 } // namespace 364 } // namespace
338 } // namespace test 365 } // namespace test
339 } // namespace mojo 366 } // namespace mojo
OLDNEW
« no previous file with comments | « no previous file | mojo/public/interfaces/bindings/tests/sample_factory.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698