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

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

Issue 1455063004: Mojo C++ bindings: introduce MultiplexRouter and related classes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 1 month 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/router_unittest.cc
diff --git a/mojo/public/cpp/bindings/tests/router_unittest.cc b/mojo/public/cpp/bindings/tests/router_unittest.cc
index c9c9f01813af766a56cf2baa8c7bcce2015b79d3..6e6a8edb29ea053659dfd1c122815309ffbb673e 100644
--- a/mojo/public/cpp/bindings/tests/router_unittest.cc
+++ b/mojo/public/cpp/bindings/tests/router_unittest.cc
@@ -2,14 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include <stdlib.h>
-#include <string.h>
-
#include "base/message_loop/message_loop.h"
#include "mojo/message_pump/message_pump_mojo.h"
-#include "mojo/public/cpp/bindings/lib/message_builder.h"
#include "mojo/public/cpp/bindings/lib/router.h"
#include "mojo/public/cpp/bindings/tests/message_queue.h"
+#include "mojo/public/cpp/bindings/tests/router_test_util.h"
#include "mojo/public/cpp/system/macros.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -17,112 +14,6 @@ namespace mojo {
namespace test {
namespace {
-void AllocRequestMessage(uint32_t name, const char* text, Message* message) {
- size_t payload_size = strlen(text) + 1; // Plus null terminator.
- internal::RequestMessageBuilder builder(name, payload_size);
- memcpy(builder.buffer()->Allocate(payload_size), text, payload_size);
-
- builder.message()->MoveTo(message);
-}
-
-void AllocResponseMessage(uint32_t name,
- const char* text,
- uint64_t request_id,
- Message* message) {
- size_t payload_size = strlen(text) + 1; // Plus null terminator.
- internal::ResponseMessageBuilder builder(name, payload_size, request_id);
- memcpy(builder.buffer()->Allocate(payload_size), text, payload_size);
-
- builder.message()->MoveTo(message);
-}
-
-class MessageAccumulator : public MessageReceiver {
- public:
- explicit MessageAccumulator(MessageQueue* queue) : queue_(queue) {}
-
- bool Accept(Message* message) override {
- queue_->Push(message);
- return true;
- }
-
- private:
- MessageQueue* queue_;
-};
-
-class ResponseGenerator : public MessageReceiverWithResponderStatus {
- public:
- ResponseGenerator() {}
-
- bool Accept(Message* message) override { return false; }
-
- bool AcceptWithResponder(Message* message,
- MessageReceiverWithStatus* responder) override {
- EXPECT_TRUE(message->has_flag(internal::kMessageExpectsResponse));
-
- bool result = SendResponse(
- message->name(), message->request_id(),
- reinterpret_cast<const char*>(message->payload()), responder);
- EXPECT_TRUE(responder->IsValid());
- delete responder;
- return result;
- }
-
- bool SendResponse(uint32_t name,
- uint64_t request_id,
- const char* request_string,
- MessageReceiver* responder) {
- Message response;
- std::string response_string(request_string);
- response_string += " world!";
- AllocResponseMessage(name, response_string.c_str(), request_id, &response);
-
- return responder->Accept(&response);
- }
-};
-
-class LazyResponseGenerator : public ResponseGenerator {
- public:
- LazyResponseGenerator() : responder_(nullptr), name_(0), request_id_(0) {}
-
- ~LazyResponseGenerator() override { delete responder_; }
-
- bool AcceptWithResponder(Message* message,
- MessageReceiverWithStatus* responder) override {
- name_ = message->name();
- request_id_ = message->request_id();
- request_string_ =
- std::string(reinterpret_cast<const char*>(message->payload()));
- responder_ = responder;
- return true;
- }
-
- bool has_responder() const { return !!responder_; }
-
- bool responder_is_valid() const { return responder_->IsValid(); }
-
- // Send the response and delete the responder.
- void CompleteWithResponse() { Complete(true); }
-
- // Delete the responder without sending a response.
- void CompleteWithoutResponse() { Complete(false); }
-
- private:
- // Completes the request handling by deleting responder_. Optionally
- // also sends a response.
- void Complete(bool send_response) {
- if (send_response) {
- SendResponse(name_, request_id_, request_string_.c_str(), responder_);
- }
- delete responder_;
- responder_ = nullptr;
- }
-
- MessageReceiverWithStatus* responder_;
- uint32_t name_;
- uint64_t request_id_;
- std::string request_string_;
-};
-
class RouterTest : public testing::Test {
public:
RouterTest() : loop_(common::MessagePumpMojo::Create()) {}
« no previous file with comments | « mojo/public/cpp/bindings/tests/router_test_util.cc ('k') | mojo/public/cpp/bindings/tests/validation_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698