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

Unified Diff: mojo/public/cpp/bindings/tests/handle_passing_unittest.cc

Issue 294833002: Mojo: more idiomatic C++ bindings (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more Created 6 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: mojo/public/cpp/bindings/tests/handle_passing_unittest.cc
diff --git a/mojo/public/cpp/bindings/tests/handle_passing_unittest.cc b/mojo/public/cpp/bindings/tests/handle_passing_unittest.cc
index 264e7b31bf8bbc83cd3d5a92828704e2375cce28..6863ce2ce3dcd81d3d845bfec5859c7902fcfdd8 100644
--- a/mojo/public/cpp/bindings/tests/handle_passing_unittest.cc
+++ b/mojo/public/cpp/bindings/tests/handle_passing_unittest.cc
@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "mojo/public/cpp/bindings/allocation_scope.h"
#include "mojo/public/cpp/environment/environment.h"
#include "mojo/public/cpp/test_support/test_utils.h"
#include "mojo/public/cpp/utility/run_loop.h"
@@ -22,18 +21,18 @@ class SampleFactoryImpl : public InterfaceImpl<sample::Factory> {
delete this;
}
- virtual void DoStuff(const sample::Request& request,
+ virtual void DoStuff(sample::RequestPtr request,
ScopedMessagePipeHandle pipe) MOJO_OVERRIDE {
std::string text1;
if (pipe.is_valid())
EXPECT_TRUE(ReadTextMessage(pipe.get(), &text1));
std::string text2;
- if (request.pipe().is_valid()) {
- EXPECT_TRUE(ReadTextMessage(request.pipe().get(), &text2));
+ if (request->pipe.is_valid()) {
+ EXPECT_TRUE(ReadTextMessage(request->pipe.get(), &text2));
- // Ensure that simply accessing request.pipe() does not close it.
- EXPECT_TRUE(request.pipe().is_valid());
+ // Ensure that simply accessing request->pipe does not close it.
+ EXPECT_TRUE(request->pipe.is_valid());
}
ScopedMessagePipeHandle pipe0;
@@ -42,11 +41,10 @@ class SampleFactoryImpl : public InterfaceImpl<sample::Factory> {
EXPECT_TRUE(WriteTextMessage(pipe1_.get(), text2));
}
- AllocationScope scope;
- sample::Response::Builder response;
- response.set_x(2);
- response.set_pipe(pipe0.Pass());
- client()->DidStuff(response.Finish(), text1);
+ sample::ResponsePtr response(sample::Response::New());
+ response->x = 2;
+ response->pipe = pipe0.Pass();
+ client()->DidStuff(response.Pass(), String::From(text1));
}
virtual void DoStuff2(ScopedDataPipeConsumerHandle pipe) MOJO_OVERRIDE {
@@ -64,8 +62,7 @@ class SampleFactoryImpl : public InterfaceImpl<sample::Factory> {
ReadDataRaw(pipe.get(), data, &data_size,
MOJO_READ_DATA_FLAG_ALL_OR_NONE));
- AllocationScope scope;
- client()->DidStuff2(String(std::string(data)));
+ client()->DidStuff2(String::From(data));
}
private:
@@ -85,29 +82,29 @@ class SampleFactoryClientImpl : public sample::FactoryClient {
return got_response_;
}
- virtual void DidStuff(const sample::Response& response,
- const String& text_reply) MOJO_OVERRIDE {
+ virtual void DidStuff(sample::ResponsePtr response,
+ String text_reply) MOJO_OVERRIDE {
EXPECT_EQ(expected_text_reply_, text_reply.To<std::string>());
- if (response.pipe().is_valid()) {
+ if (response->pipe.is_valid()) {
std::string text2;
- EXPECT_TRUE(ReadTextMessage(response.pipe().get(), &text2));
+ EXPECT_TRUE(ReadTextMessage(response->pipe.get(), &text2));
- // Ensure that simply accessing response.pipe() does not close it.
- EXPECT_TRUE(response.pipe().is_valid());
+ // Ensure that simply accessing response.pipe does not close it.
+ EXPECT_TRUE(response->pipe.is_valid());
EXPECT_EQ(std::string(kText2), text2);
// Do some more tests of handle passing:
- ScopedMessagePipeHandle p = response.pipe().Pass();
+ ScopedMessagePipeHandle p = response->pipe.Pass();
EXPECT_TRUE(p.is_valid());
- EXPECT_FALSE(response.pipe().is_valid());
+ EXPECT_FALSE(response->pipe.is_valid());
}
got_response_ = true;
}
- virtual void DidStuff2(const String& text_reply) MOJO_OVERRIDE {
+ virtual void DidStuff2(String text_reply) MOJO_OVERRIDE {
got_response_ = true;
EXPECT_EQ(expected_text_reply_, text_reply.To<std::string>());
}
@@ -153,13 +150,10 @@ TEST_F(HandlePassingTest, Basic) {
EXPECT_TRUE(WriteTextMessage(pipe3.get(), kText2));
- {
- AllocationScope scope;
- sample::Request::Builder request;
- request.set_x(1);
- request.set_pipe(pipe2.Pass());
- factory->DoStuff(request.Finish(), pipe0.Pass());
- }
+ sample::RequestPtr request(sample::Request::New());
+ request->x = 1;
+ request->pipe = pipe2.Pass();
+ factory->DoStuff(request.Pass(), pipe0.Pass());
EXPECT_FALSE(factory_client.got_response());
@@ -175,12 +169,9 @@ TEST_F(HandlePassingTest, PassInvalid) {
SampleFactoryClientImpl factory_client;
factory->SetClient(&factory_client);
- {
- AllocationScope scope;
- sample::Request::Builder request;
- request.set_x(1);
- factory->DoStuff(request.Finish(), ScopedMessagePipeHandle().Pass());
- }
+ sample::RequestPtr request(sample::Request::New());
+ request->x = 1;
+ factory->DoStuff(request.Pass(), ScopedMessagePipeHandle().Pass());
EXPECT_FALSE(factory_client.got_response());
@@ -216,10 +207,7 @@ TEST_F(HandlePassingTest, DataPipe) {
WriteDataRaw(producer_handle.get(), expected_text_reply.c_str(),
&data_size, MOJO_WRITE_DATA_FLAG_ALL_OR_NONE));
- {
- AllocationScope scope;
- factory->DoStuff2(consumer_handle.Pass());
- }
+ factory->DoStuff2(consumer_handle.Pass());
EXPECT_FALSE(factory_client.got_response());
@@ -241,22 +229,18 @@ TEST_F(HandlePassingTest, PipesAreClosed) {
MojoHandle handle1_value = extra_pipe.handle1.get().value();
{
- AllocationScope scope;
-
- Array<MessagePipeHandle>::Builder pipes(2);
+ Array<ScopedMessagePipeHandle> pipes(2);
pipes[0] = extra_pipe.handle0.Pass();
pipes[1] = extra_pipe.handle1.Pass();
- sample::Request::Builder request_builder;
- request_builder.set_more_pipes(pipes.Finish());
-
- sample::Request request = request_builder.Finish();
+ sample::RequestPtr request(sample::Request::New());
+ request->more_pipes = pipes.Pass();
- factory->DoStuff(request, ScopedMessagePipeHandle());
+ factory->DoStuff(request.Pass(), ScopedMessagePipeHandle());
// The handles should have been transferred to the underlying Message.
- EXPECT_EQ(MOJO_HANDLE_INVALID, request.more_pipes()[0].get().value());
- EXPECT_EQ(MOJO_HANDLE_INVALID, request.more_pipes()[1].get().value());
+ EXPECT_EQ(MOJO_HANDLE_INVALID, request->more_pipes[0].get().value());
+ EXPECT_EQ(MOJO_HANDLE_INVALID, request->more_pipes[1].get().value());
}
// We expect the pipes to have been closed.

Powered by Google App Engine
This is Rietveld 408576698