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

Side by Side Diff: mojo/public/cpp/bindings/tests/interface_ptr_unittest.cc

Issue 287143003: Mojo: Internalize ServiceConnector<> (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add missing function Created 6 years, 7 months 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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() : total_(0.0) { 35 MathCalculatorImpl()
36 : total_(0.0),
37 got_connection_(false) {
38 }
39
40 virtual void OnConnectionEstablished() MOJO_OVERRIDE {
41 got_connection_ = true;
36 } 42 }
37 43
38 virtual void OnConnectionError() MOJO_OVERRIDE { 44 virtual void OnConnectionError() MOJO_OVERRIDE {
39 delete this; 45 delete this;
40 } 46 }
41 47
42 virtual void Clear() MOJO_OVERRIDE { 48 virtual void Clear() MOJO_OVERRIDE {
43 client()->Output(total_); 49 client()->Output(total_);
44 } 50 }
45 51
46 virtual void Add(double value) MOJO_OVERRIDE { 52 virtual void Add(double value) MOJO_OVERRIDE {
47 total_ += value; 53 total_ += value;
48 client()->Output(total_); 54 client()->Output(total_);
49 } 55 }
50 56
51 virtual void Multiply(double value) MOJO_OVERRIDE { 57 virtual void Multiply(double value) MOJO_OVERRIDE {
52 total_ *= value; 58 total_ *= value;
53 client()->Output(total_); 59 client()->Output(total_);
54 } 60 }
55 61
56 private: 62 bool got_connection() const {
63 return got_connection_;
64 }
65
66 private:
57 double total_; 67 double total_;
68 bool got_connection_;
58 }; 69 };
59 70
60 class MathCalculatorUIImpl : public math::CalculatorUI { 71 class MathCalculatorUIImpl : public math::CalculatorUI {
61 public: 72 public:
62 explicit MathCalculatorUIImpl(math::CalculatorPtr calculator) 73 explicit MathCalculatorUIImpl(math::CalculatorPtr calculator)
63 : calculator_(calculator.Pass()), 74 : calculator_(calculator.Pass()),
64 output_(0.0) { 75 output_(0.0) {
65 calculator_->SetClient(this); 76 calculator_->SetClient(this);
66 } 77 }
67 78
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 loop_.RunUntilIdle(); 120 loop_.RunUntilIdle();
110 } 121 }
111 122
112 private: 123 private:
113 Environment env_; 124 Environment env_;
114 RunLoop loop_; 125 RunLoop loop_;
115 }; 126 };
116 127
117 TEST_F(InterfacePtrTest, EndToEnd) { 128 TEST_F(InterfacePtrTest, EndToEnd) {
118 math::CalculatorPtr calc; 129 math::CalculatorPtr calc;
119 BindToProxy(new MathCalculatorImpl(), &calc); 130 MathCalculatorImpl* impl = BindToProxy(new MathCalculatorImpl(), &calc);
131 EXPECT_TRUE(impl->got_connection());
120 132
121 // Suppose this is instantiated in a process that has pipe1_. 133 // Suppose this is instantiated in a process that has pipe1_.
122 MathCalculatorUIImpl calculator_ui(calc.Pass()); 134 MathCalculatorUIImpl calculator_ui(calc.Pass());
123 135
124 calculator_ui.Add(2.0); 136 calculator_ui.Add(2.0);
125 calculator_ui.Multiply(5.0); 137 calculator_ui.Multiply(5.0);
126 138
127 PumpMessages(); 139 PumpMessages();
128 140
129 EXPECT_EQ(10.0, calculator_ui.GetOutput()); 141 EXPECT_EQ(10.0, calculator_ui.GetOutput());
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 // This is a test to ensure the following compiles. The sample::Port interface 241 // This is a test to ensure the following compiles. The sample::Port interface
230 // does not have an explicit Client attribute. 242 // does not have an explicit Client attribute.
231 sample::PortPtr port; 243 sample::PortPtr port;
232 MessagePipe pipe; 244 MessagePipe pipe;
233 port.Bind(pipe.handle0.Pass()); 245 port.Bind(pipe.handle0.Pass());
234 } 246 }
235 247
236 } // namespace 248 } // namespace
237 } // namespace test 249 } // namespace test
238 } // namespace mojo 250 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/interface_impl_internal.h ('k') | mojo/public/cpp/shell/application.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698