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

Unified Diff: mojo/public/tests/bindings_remote_ptr_unittest.cc

Issue 66353002: Mojo: RemotePtr<S> + bindings changes for Peer attribute. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move forward declarations to interface_declaration Created 7 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/tests/bindings_remote_ptr_unittest.cc
diff --git a/mojo/public/tests/bindings_remote_ptr_unittest.cc b/mojo/public/tests/bindings_remote_ptr_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2fe525836307d3da4cb6b9b92fb292ad59c51537
--- /dev/null
+++ b/mojo/public/tests/bindings_remote_ptr_unittest.cc
@@ -0,0 +1,119 @@
+// Copyright 2013 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.
+
+#include <stdio.h>
+
+#include "mojo/public/bindings/lib/remote_ptr.h"
+#include "mojo/public/tests/generated/math_calculator.h"
+#include "mojo/public/tests/simple_bindings_support.h"
+#include "mojo/public/tests/test_support.h"
+
+namespace mojo {
+namespace test {
+
+class MathCalculatorImpl : public math::CalculatorStub {
+ public:
+ explicit MathCalculatorImpl(Handle pipe)
+ : ui_(pipe),
+ total_(0.0) {
+ ui_.SetPeer(this);
+ }
+
+ virtual void Clear() MOJO_OVERRIDE {
+ ui_->Output(total_);
+ }
+
+ virtual void Add(double value) MOJO_OVERRIDE {
+ total_ += value;
+ ui_->Output(total_);
+ }
+
+ virtual void Multiply(double value) MOJO_OVERRIDE {
+ total_ *= value;
+ ui_->Output(total_);
+ }
+
+ private:
+ RemotePtr<math::CalculatorUI> ui_;
+ double total_;
+};
+
+class MathCalculatorUIImpl : public math::CalculatorUIStub {
+ public:
+ explicit MathCalculatorUIImpl(Handle pipe)
+ : calculator_(pipe),
+ output_(0.0) {
+ calculator_.SetPeer(this);
+ }
+
+ void Add(double value) {
+ calculator_->Add(value);
+ }
+
+ void Subtract(double value) {
+ calculator_->Add(-value);
+ }
+
+ void Multiply(double value) {
+ calculator_->Multiply(value);
+ }
+
+ void Divide(double value) {
+ calculator_->Multiply(1.0 / value);
+ }
+
+ double GetOutput() const {
+ return output_;
+ }
+
+ private:
+ // math::CalculatorUI implementation:
+ virtual void Output(double value) MOJO_OVERRIDE {
+ output_ = value;
+ }
+
+ RemotePtr<math::Calculator> calculator_;
+ double output_;
+};
+
+class BindingsRemotePtrTest : public TestBase {
+ public:
+ BindingsRemotePtrTest() {
+ CreateMessagePipe(&pipe0_, &pipe1_);
+ }
+
+ virtual ~BindingsRemotePtrTest() {
+ Close(pipe0_);
+ Close(pipe1_);
+ }
+
+ void PumpMessages() {
+ bindings_support_.Process();
+ }
+
+ protected:
+ Handle pipe0_;
+ Handle pipe1_;
+
+ private:
+ SimpleBindingsSupport bindings_support_;
+};
+
+TEST_F(BindingsRemotePtrTest, EndToEnd) {
+ // Suppose this is instantiated in a process that has pipe0_.
+ MathCalculatorImpl calculator(pipe0_);
+
+ // Suppose this is instantiated in a process that has pipe1_.
+ MathCalculatorUIImpl calculator_ui(pipe1_);
+
+ calculator_ui.Add(2.0);
+ calculator_ui.Multiply(5.0);
+
+ PumpMessages();
+
+ EXPECT_EQ(10.0, calculator_ui.GetOutput());
+}
+
+} // namespace test
+} // namespace mojo

Powered by Google App Engine
This is Rietveld 408576698