| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "mojo/public/cpp/bindings/error_handler.h" | 5 #include "mojo/public/cpp/bindings/error_handler.h" |
| 6 #include "mojo/public/cpp/environment/environment.h" | 6 #include "mojo/public/cpp/environment/environment.h" |
| 7 #include "mojo/public/cpp/utility/run_loop.h" | 7 #include "mojo/public/cpp/utility/run_loop.h" |
| 8 #include "mojo/public/interfaces/bindings/tests/math_calculator.mojom.h" | 8 #include "mojo/public/interfaces/bindings/tests/math_calculator.mojom.h" |
| 9 #include "mojo/public/interfaces/bindings/tests/sample_service.mojom.h" | 9 #include "mojo/public/interfaces/bindings/tests/sample_service.mojom.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 } | 25 } |
| 26 | 26 |
| 27 private: | 27 private: |
| 28 bool encountered_error_; | 28 bool encountered_error_; |
| 29 }; | 29 }; |
| 30 | 30 |
| 31 class MathCalculatorImpl : public InterfaceImpl<math::Calculator> { | 31 class MathCalculatorImpl : public InterfaceImpl<math::Calculator> { |
| 32 public: | 32 public: |
| 33 virtual ~MathCalculatorImpl() {} | 33 virtual ~MathCalculatorImpl() {} |
| 34 | 34 |
| 35 MathCalculatorImpl() | 35 MathCalculatorImpl() : total_(0.0) { |
| 36 : total_(0.0), | |
| 37 got_connection_(false) { | |
| 38 } | |
| 39 | |
| 40 virtual void OnConnectionEstablished() MOJO_OVERRIDE { | |
| 41 got_connection_ = true; | |
| 42 } | 36 } |
| 43 | 37 |
| 44 virtual void OnConnectionError() MOJO_OVERRIDE { | 38 virtual void OnConnectionError() MOJO_OVERRIDE { |
| 45 delete this; | 39 delete this; |
| 46 } | 40 } |
| 47 | 41 |
| 48 virtual void Clear() MOJO_OVERRIDE { | 42 virtual void Clear() MOJO_OVERRIDE { |
| 49 client()->Output(total_); | 43 client()->Output(total_); |
| 50 } | 44 } |
| 51 | 45 |
| 52 virtual void Add(double value) MOJO_OVERRIDE { | 46 virtual void Add(double value) MOJO_OVERRIDE { |
| 53 total_ += value; | 47 total_ += value; |
| 54 client()->Output(total_); | 48 client()->Output(total_); |
| 55 } | 49 } |
| 56 | 50 |
| 57 virtual void Multiply(double value) MOJO_OVERRIDE { | 51 virtual void Multiply(double value) MOJO_OVERRIDE { |
| 58 total_ *= value; | 52 total_ *= value; |
| 59 client()->Output(total_); | 53 client()->Output(total_); |
| 60 } | 54 } |
| 61 | 55 |
| 62 bool got_connection() const { | 56 private: |
| 63 return got_connection_; | |
| 64 } | |
| 65 | |
| 66 private: | |
| 67 double total_; | 57 double total_; |
| 68 bool got_connection_; | |
| 69 }; | 58 }; |
| 70 | 59 |
| 71 class MathCalculatorUIImpl : public math::CalculatorUI { | 60 class MathCalculatorUIImpl : public math::CalculatorUI { |
| 72 public: | 61 public: |
| 73 explicit MathCalculatorUIImpl(math::CalculatorPtr calculator) | 62 explicit MathCalculatorUIImpl(math::CalculatorPtr calculator) |
| 74 : calculator_(calculator.Pass()), | 63 : calculator_(calculator.Pass()), |
| 75 output_(0.0) { | 64 output_(0.0) { |
| 76 calculator_->SetClient(this); | 65 calculator_->SetClient(this); |
| 77 } | 66 } |
| 78 | 67 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 loop_.RunUntilIdle(); | 109 loop_.RunUntilIdle(); |
| 121 } | 110 } |
| 122 | 111 |
| 123 private: | 112 private: |
| 124 Environment env_; | 113 Environment env_; |
| 125 RunLoop loop_; | 114 RunLoop loop_; |
| 126 }; | 115 }; |
| 127 | 116 |
| 128 TEST_F(InterfacePtrTest, EndToEnd) { | 117 TEST_F(InterfacePtrTest, EndToEnd) { |
| 129 math::CalculatorPtr calc; | 118 math::CalculatorPtr calc; |
| 130 MathCalculatorImpl* impl = BindToProxy(new MathCalculatorImpl(), &calc); | 119 BindToProxy(new MathCalculatorImpl(), &calc); |
| 131 EXPECT_TRUE(impl->got_connection()); | |
| 132 | 120 |
| 133 // Suppose this is instantiated in a process that has pipe1_. | 121 // Suppose this is instantiated in a process that has pipe1_. |
| 134 MathCalculatorUIImpl calculator_ui(calc.Pass()); | 122 MathCalculatorUIImpl calculator_ui(calc.Pass()); |
| 135 | 123 |
| 136 calculator_ui.Add(2.0); | 124 calculator_ui.Add(2.0); |
| 137 calculator_ui.Multiply(5.0); | 125 calculator_ui.Multiply(5.0); |
| 138 | 126 |
| 139 PumpMessages(); | 127 PumpMessages(); |
| 140 | 128 |
| 141 EXPECT_EQ(10.0, calculator_ui.GetOutput()); | 129 EXPECT_EQ(10.0, calculator_ui.GetOutput()); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 // This is a test to ensure the following compiles. The sample::Port interface | 229 // This is a test to ensure the following compiles. The sample::Port interface |
| 242 // does not have an explicit Client attribute. | 230 // does not have an explicit Client attribute. |
| 243 sample::PortPtr port; | 231 sample::PortPtr port; |
| 244 MessagePipe pipe; | 232 MessagePipe pipe; |
| 245 port.Bind(pipe.handle0.Pass()); | 233 port.Bind(pipe.handle0.Pass()); |
| 246 } | 234 } |
| 247 | 235 |
| 248 } // namespace | 236 } // namespace |
| 249 } // namespace test | 237 } // namespace test |
| 250 } // namespace mojo | 238 } // namespace mojo |
| OLD | NEW |