OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <utility> |
| 6 |
5 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
6 #include "mojo/message_pump/message_pump_mojo.h" | 8 #include "mojo/message_pump/message_pump_mojo.h" |
7 #include "mojo/public/cpp/bindings/binding.h" | 9 #include "mojo/public/cpp/bindings/binding.h" |
8 #include "mojo/public/cpp/test_support/test_utils.h" | 10 #include "mojo/public/cpp/test_support/test_utils.h" |
9 #include "mojo/public/interfaces/bindings/tests/sample_import.mojom.h" | 11 #include "mojo/public/interfaces/bindings/tests/sample_import.mojom.h" |
10 #include "mojo/public/interfaces/bindings/tests/sample_interfaces.mojom.h" | 12 #include "mojo/public/interfaces/bindings/tests/sample_interfaces.mojom.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
12 | 14 |
13 namespace mojo { | 15 namespace mojo { |
14 namespace test { | 16 namespace test { |
15 namespace { | 17 namespace { |
16 | 18 |
17 class ProviderImpl : public sample::Provider { | 19 class ProviderImpl : public sample::Provider { |
18 public: | 20 public: |
19 explicit ProviderImpl(InterfaceRequest<sample::Provider> request) | 21 explicit ProviderImpl(InterfaceRequest<sample::Provider> request) |
20 : binding_(this, request.Pass()) {} | 22 : binding_(this, std::move(request)) {} |
21 | 23 |
22 void EchoString(const String& a, | 24 void EchoString(const String& a, |
23 const Callback<void(String)>& callback) override { | 25 const Callback<void(String)>& callback) override { |
24 Callback<void(String)> callback_copy; | 26 Callback<void(String)> callback_copy; |
25 // Make sure operator= is used. | 27 // Make sure operator= is used. |
26 callback_copy = callback; | 28 callback_copy = callback; |
27 callback_copy.Run(a); | 29 callback_copy.Run(a); |
28 } | 30 } |
29 | 31 |
30 void EchoStrings(const String& a, | 32 void EchoStrings(const String& a, |
31 const String& b, | 33 const String& b, |
32 const Callback<void(String, String)>& callback) override { | 34 const Callback<void(String, String)>& callback) override { |
33 callback.Run(a, b); | 35 callback.Run(a, b); |
34 } | 36 } |
35 | 37 |
36 void EchoMessagePipeHandle( | 38 void EchoMessagePipeHandle( |
37 ScopedMessagePipeHandle a, | 39 ScopedMessagePipeHandle a, |
38 const Callback<void(ScopedMessagePipeHandle)>& callback) override { | 40 const Callback<void(ScopedMessagePipeHandle)>& callback) override { |
39 callback.Run(a.Pass()); | 41 callback.Run(std::move(a)); |
40 } | 42 } |
41 | 43 |
42 void EchoEnum(sample::Enum a, | 44 void EchoEnum(sample::Enum a, |
43 const Callback<void(sample::Enum)>& callback) override { | 45 const Callback<void(sample::Enum)>& callback) override { |
44 callback.Run(a); | 46 callback.Run(a); |
45 } | 47 } |
46 | 48 |
47 void EchoInt(int32_t a, const EchoIntCallback& callback) override { | 49 void EchoInt(int32_t a, const EchoIntCallback& callback) override { |
48 callback.Run(a); | 50 callback.Run(a); |
49 } | 51 } |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 PumpMessages(); | 119 PumpMessages(); |
118 | 120 |
119 EXPECT_EQ(std::string("hello world"), buf); | 121 EXPECT_EQ(std::string("hello world"), buf); |
120 } | 122 } |
121 | 123 |
122 TEST_F(RequestResponseTest, EchoMessagePipeHandle) { | 124 TEST_F(RequestResponseTest, EchoMessagePipeHandle) { |
123 sample::ProviderPtr provider; | 125 sample::ProviderPtr provider; |
124 ProviderImpl provider_impl(GetProxy(&provider)); | 126 ProviderImpl provider_impl(GetProxy(&provider)); |
125 | 127 |
126 MessagePipe pipe2; | 128 MessagePipe pipe2; |
127 provider->EchoMessagePipeHandle(pipe2.handle1.Pass(), | 129 provider->EchoMessagePipeHandle(std::move(pipe2.handle1), |
128 MessagePipeWriter("hello")); | 130 MessagePipeWriter("hello")); |
129 | 131 |
130 PumpMessages(); | 132 PumpMessages(); |
131 | 133 |
132 std::string value; | 134 std::string value; |
133 ReadTextMessage(pipe2.handle0.get(), &value); | 135 ReadTextMessage(pipe2.handle0.get(), &value); |
134 | 136 |
135 EXPECT_EQ(std::string("hello"), value); | 137 EXPECT_EQ(std::string("hello"), value); |
136 } | 138 } |
137 | 139 |
138 TEST_F(RequestResponseTest, EchoEnum) { | 140 TEST_F(RequestResponseTest, EchoEnum) { |
139 sample::ProviderPtr provider; | 141 sample::ProviderPtr provider; |
140 ProviderImpl provider_impl(GetProxy(&provider)); | 142 ProviderImpl provider_impl(GetProxy(&provider)); |
141 | 143 |
142 sample::Enum value; | 144 sample::Enum value; |
143 provider->EchoEnum(sample::ENUM_VALUE, EnumRecorder(&value)); | 145 provider->EchoEnum(sample::ENUM_VALUE, EnumRecorder(&value)); |
144 | 146 |
145 PumpMessages(); | 147 PumpMessages(); |
146 | 148 |
147 EXPECT_EQ(sample::ENUM_VALUE, value); | 149 EXPECT_EQ(sample::ENUM_VALUE, value); |
148 } | 150 } |
149 | 151 |
150 } // namespace | 152 } // namespace |
151 } // namespace test | 153 } // namespace test |
152 } // namespace mojo | 154 } // namespace mojo |
OLD | NEW |