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

Unified Diff: mojo/public/cpp/bindings/tests/router_test_util.h

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_test_util.h
diff --git a/mojo/public/cpp/bindings/tests/router_test_util.h b/mojo/public/cpp/bindings/tests/router_test_util.h
new file mode 100644
index 0000000000000000000000000000000000000000..b40d2711a0bee981a8d603fc8c3266dc99d496a9
--- /dev/null
+++ b/mojo/public/cpp/bindings/tests/router_test_util.h
@@ -0,0 +1,81 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef MOJO_PUBLIC_CPP_BINDINGS_TESTS_ROUTER_TEST_UTIL_H_
+#define MOJO_PUBLIC_CPP_BINDINGS_TESTS_ROUTER_TEST_UTIL_H_
+
+#include <string>
+
+#include "mojo/public/cpp/bindings/message.h"
+
+namespace mojo {
+namespace test {
+
+class MessageQueue;
+
+void AllocRequestMessage(uint32_t name, const char* text, Message* message);
+void AllocResponseMessage(uint32_t name,
+ const char* text,
+ uint64_t request_id,
+ Message* message);
+
+class MessageAccumulator : public MessageReceiver {
+ public:
+ explicit MessageAccumulator(MessageQueue* queue);
+
+ bool Accept(Message* message) override;
+
+ private:
+ MessageQueue* queue_;
+};
+
+class ResponseGenerator : public MessageReceiverWithResponderStatus {
+ public:
+ ResponseGenerator();
+
+ bool Accept(Message* message) override;
+
+ bool AcceptWithResponder(Message* message,
+ MessageReceiverWithStatus* responder) override;
+
+ bool SendResponse(uint32_t name,
+ uint64_t request_id,
+ const char* request_string,
+ MessageReceiver* responder);
+};
+
+class LazyResponseGenerator : public ResponseGenerator {
+ public:
+ LazyResponseGenerator();
+
+ ~LazyResponseGenerator() override;
+
+ bool AcceptWithResponder(Message* message,
+ MessageReceiverWithStatus* responder) override;
+
+ bool has_responder() const { return !!responder_; }
+
+ bool responder_is_valid() const { return responder_->IsValid(); }
+
+ // Sends the response and delete the responder.
+ void CompleteWithResponse() { Complete(true); }
+
+ // Deletes 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);
+
+ MessageReceiverWithStatus* responder_;
+ uint32_t name_;
+ uint64_t request_id_;
+ std::string request_string_;
+};
+
+} // namespace test
+} // namespace mojo
+
+#endif // MOJO_PUBLIC_CPP_BINDINGS_TESTS_ROUTER_TEST_UTIL_H_
« no previous file with comments | « mojo/public/cpp/bindings/tests/multiplex_router_unittest.cc ('k') | mojo/public/cpp/bindings/tests/router_test_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698