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

Side by Side 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: rebase + fix error in sample_service.h 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "mojo/public/bindings/lib/remote_ptr.h"
6 #include "mojo/public/tests/mojom/math_calculator.h"
7 #include "mojo/public/tests/simple_bindings_support.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9
10 namespace mojo {
11 namespace test {
12
13 class MathCalculatorImpl : public math::CalculatorStub {
14 public:
15 explicit MathCalculatorImpl(Handle pipe)
16 : ui_(pipe),
17 total_(0.0) {
18 ui_.SetPeer(this);
19 }
20
21 virtual void Clear() MOJO_OVERRIDE {
22 ui_->Output(total_);
23 }
24
25 virtual void Add(double value) MOJO_OVERRIDE {
26 total_ += value;
27 ui_->Output(total_);
28 }
29
30 virtual void Multiply(double value) MOJO_OVERRIDE {
31 total_ *= value;
32 ui_->Output(total_);
33 }
34
35 private:
36 RemotePtr<math::CalculatorUI> ui_;
37 double total_;
38 };
39
40 class MathCalculatorUIImpl : public math::CalculatorUIStub {
41 public:
42 explicit MathCalculatorUIImpl(Handle pipe)
43 : calculator_(pipe),
44 output_(0.0) {
45 calculator_.SetPeer(this);
46 }
47
48 void Add(double value) {
49 calculator_->Add(value);
50 }
51
52 void Subtract(double value) {
53 calculator_->Add(-value);
54 }
55
56 void Multiply(double value) {
57 calculator_->Multiply(value);
58 }
59
60 void Divide(double value) {
61 calculator_->Multiply(1.0 / value);
62 }
63
64 double GetOutput() const {
65 return output_;
66 }
67
68 private:
69 // math::CalculatorUI implementation:
70 virtual void Output(double value) MOJO_OVERRIDE {
71 output_ = value;
72 }
73
74 RemotePtr<math::Calculator> calculator_;
75 double output_;
76 };
77
78 class BindingsRemotePtrTest : public testing::Test {
79 public:
80 BindingsRemotePtrTest() {
81 CreateMessagePipe(&pipe0_, &pipe1_);
82 }
83
84 virtual ~BindingsRemotePtrTest() {
85 Close(pipe0_);
86 Close(pipe1_);
87 }
88
89 void PumpMessages() {
90 bindings_support_.Process();
91 }
92
93 protected:
94 Handle pipe0_;
95 Handle pipe1_;
96
97 private:
98 SimpleBindingsSupport bindings_support_;
99 };
100
101 TEST_F(BindingsRemotePtrTest, EndToEnd) {
102 // Suppose this is instantiated in a process that has pipe0_.
103 MathCalculatorImpl calculator(pipe0_);
104
105 // Suppose this is instantiated in a process that has pipe1_.
106 MathCalculatorUIImpl calculator_ui(pipe1_);
107
108 calculator_ui.Add(2.0);
109 calculator_ui.Multiply(5.0);
110
111 PumpMessages();
112
113 EXPECT_EQ(10.0, calculator_ui.GetOutput());
114 }
115
116 } // namespace test
117 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/bindings/sample/sample_service.mojom ('k') | mojo/public/tests/math_calculator.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698