| 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 <stdlib.h> | 5 #include <stdlib.h> |
| 6 #include <string.h> | 6 #include <string.h> |
| 7 | 7 |
| 8 #include "mojo/public/cpp/bindings/lib/message_builder.h" | 8 #include "mojo/public/cpp/bindings/lib/message_builder.h" |
| 9 #include "mojo/public/cpp/bindings/lib/message_queue.h" | 9 #include "mojo/public/cpp/bindings/lib/message_queue.h" |
| 10 #include "mojo/public/cpp/bindings/lib/router.h" | 10 #include "mojo/public/cpp/bindings/lib/router.h" |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 | 188 |
| 189 ResponseGenerator generator; | 189 ResponseGenerator generator; |
| 190 router1.set_incoming_receiver(&generator); | 190 router1.set_incoming_receiver(&generator); |
| 191 | 191 |
| 192 Message request; | 192 Message request; |
| 193 AllocRequestMessage(1, "hello", &request); | 193 AllocRequestMessage(1, "hello", &request); |
| 194 | 194 |
| 195 internal::MessageQueue message_queue; | 195 internal::MessageQueue message_queue; |
| 196 router0.AcceptWithResponder(&request, new MessageAccumulator(&message_queue)); | 196 router0.AcceptWithResponder(&request, new MessageAccumulator(&message_queue)); |
| 197 | 197 |
| 198 router1.WaitForIncomingMessage(); | 198 router1.WaitForIncomingMessage(MOJO_DEADLINE_INDEFINITE); |
| 199 router0.WaitForIncomingMessage(); | 199 router0.WaitForIncomingMessage(MOJO_DEADLINE_INDEFINITE); |
| 200 | 200 |
| 201 EXPECT_FALSE(message_queue.IsEmpty()); | 201 EXPECT_FALSE(message_queue.IsEmpty()); |
| 202 | 202 |
| 203 Message response; | 203 Message response; |
| 204 message_queue.Pop(&response); | 204 message_queue.Pop(&response); |
| 205 | 205 |
| 206 EXPECT_EQ(std::string("hello world!"), | 206 EXPECT_EQ(std::string("hello world!"), |
| 207 std::string(reinterpret_cast<const char*>(response.payload()))); | 207 std::string(reinterpret_cast<const char*>(response.payload()))); |
| 208 | 208 |
| 209 // Send a second message on the pipe. | 209 // Send a second message on the pipe. |
| 210 Message request2; | 210 Message request2; |
| 211 AllocRequestMessage(1, "hello again", &request2); | 211 AllocRequestMessage(1, "hello again", &request2); |
| 212 | 212 |
| 213 router0.AcceptWithResponder(&request2, | 213 router0.AcceptWithResponder(&request2, |
| 214 new MessageAccumulator(&message_queue)); | 214 new MessageAccumulator(&message_queue)); |
| 215 | 215 |
| 216 router1.WaitForIncomingMessage(); | 216 router1.WaitForIncomingMessage(MOJO_DEADLINE_INDEFINITE); |
| 217 router0.WaitForIncomingMessage(); | 217 router0.WaitForIncomingMessage(MOJO_DEADLINE_INDEFINITE); |
| 218 | 218 |
| 219 EXPECT_FALSE(message_queue.IsEmpty()); | 219 EXPECT_FALSE(message_queue.IsEmpty()); |
| 220 | 220 |
| 221 message_queue.Pop(&response); | 221 message_queue.Pop(&response); |
| 222 | 222 |
| 223 EXPECT_EQ(std::string("hello again world!"), | 223 EXPECT_EQ(std::string("hello again world!"), |
| 224 std::string(reinterpret_cast<const char*>(response.payload()))); | 224 std::string(reinterpret_cast<const char*>(response.payload()))); |
| 225 } | 225 } |
| 226 | 226 |
| 227 TEST_F(RouterTest, RequestWithNoReceiver) { | 227 TEST_F(RouterTest, RequestWithNoReceiver) { |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 EXPECT_TRUE(generator.has_responder()); | 363 EXPECT_TRUE(generator.has_responder()); |
| 364 } | 364 } |
| 365 | 365 |
| 366 EXPECT_FALSE(generator.responder_is_valid()); | 366 EXPECT_FALSE(generator.responder_is_valid()); |
| 367 generator.CompleteWithResponse(); // This should end up doing nothing. | 367 generator.CompleteWithResponse(); // This should end up doing nothing. |
| 368 } | 368 } |
| 369 | 369 |
| 370 } // namespace | 370 } // namespace |
| 371 } // namespace test | 371 } // namespace test |
| 372 } // namespace mojo | 372 } // namespace mojo |
| OLD | NEW |