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

Side by Side Diff: ui/gfx/geometry/mojo/geometry_struct_traits_unittest.cc

Issue 2037453002: Implement ui/gfx/geometry StructTraits unit tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed windows Created 4 years, 6 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
OLDNEW
(Empty)
1 // Copyright 2016 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 "base/message_loop/message_loop.h"
6 #include "mojo/public/cpp/bindings/binding_set.h"
7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "ui/gfx/geometry/mojo/geometry_traits_test_service.mojom.h"
9 #include "ui/gfx/geometry/point.h"
10
11 namespace gfx {
12
13 namespace {
14
15 class GeometryStructTraitsTest : public testing::Test,
16 public mojom::GeometryTraitsTestService {
17 public:
18 GeometryStructTraitsTest() {}
19
20 protected:
21 mojom::GeometryTraitsTestServicePtr GetTraitsTestProxy() {
22 return traits_test_bindings_.CreateInterfacePtrAndBind(this);
23 }
24
25 private:
26 // GeometryTraitsTestService:
27 void EchoPoint(const Point& p, const EchoPointCallback& callback) override {
28 callback.Run(p);
29 }
30
31 void EchoPointF(const PointF& p,
32 const EchoPointFCallback& callback) override {
33 callback.Run(p);
34 }
35
36 void EchoSize(const Size& s, const EchoSizeCallback& callback) override {
37 callback.Run(s);
38 }
39
40 void EchoSizeF(const SizeF& s, const EchoSizeFCallback& callback) override {
41 callback.Run(s);
42 }
43
44 void EchoRect(const Rect& r, const EchoRectCallback& callback) override {
45 callback.Run(r);
46 }
47
48 void EchoRectF(const RectF& r, const EchoRectFCallback& callback) override {
49 callback.Run(r);
50 }
51
52 void EchoInsets(const Insets& i,
53 const EchoInsetsCallback& callback) override {
54 callback.Run(i);
55 }
56
57 void EchoInsetsF(const InsetsF& i,
58 const EchoInsetsFCallback& callback) override {
59 callback.Run(i);
60 }
61
62 base::MessageLoop loop_;
63 mojo::BindingSet<GeometryTraitsTestService> traits_test_bindings_;
64
65 DISALLOW_COPY_AND_ASSIGN(GeometryStructTraitsTest);
66 };
67
68 } // namespace
69
70 TEST_F(GeometryStructTraitsTest, Point) {
71 const int32_t x = 1234;
72 const int32_t y = -5678;
73 gfx::Point input(x, y);
74 mojom::GeometryTraitsTestServicePtr proxy = GetTraitsTestProxy();
75 gfx::Point output;
76 proxy->EchoPoint(input, &output);
77 EXPECT_EQ(x, output.x());
78 EXPECT_EQ(y, output.y());
79 }
80
81 TEST_F(GeometryStructTraitsTest, PointF) {
82 const float x = 1234.5f;
83 const float y = 6789.6f;
84 gfx::PointF input(x, y);
85 mojom::GeometryTraitsTestServicePtr proxy = GetTraitsTestProxy();
86 gfx::PointF output;
87 proxy->EchoPointF(input, &output);
88 EXPECT_EQ(x, output.x());
89 EXPECT_EQ(y, output.y());
90 }
91
92 TEST_F(GeometryStructTraitsTest, Size) {
93 const int32_t width = 1234;
94 const int32_t height = 5678;
95 gfx::Size input(width, height);
96 mojom::GeometryTraitsTestServicePtr proxy = GetTraitsTestProxy();
97 gfx::Size output;
98 proxy->EchoSize(input, &output);
99 EXPECT_EQ(width, output.width());
100 EXPECT_EQ(height, output.height());
101 }
102
103 TEST_F(GeometryStructTraitsTest, SizeF) {
104 const float width = 1234.5f;
105 const float height = 6789.6f;
106 gfx::SizeF input(width, height);
107 mojom::GeometryTraitsTestServicePtr proxy = GetTraitsTestProxy();
108 gfx::SizeF output;
109 proxy->EchoSizeF(input, &output);
110 EXPECT_EQ(width, output.width());
111 EXPECT_EQ(height, output.height());
112 }
113
114 TEST_F(GeometryStructTraitsTest, Rect) {
115 const int32_t x = 1234;
116 const int32_t y = 5678;
117 const int32_t width = 4321;
118 const int32_t height = 8765;
119 gfx::Rect input(x, y, width, height);
120 mojom::GeometryTraitsTestServicePtr proxy = GetTraitsTestProxy();
121 gfx::Rect output;
122 proxy->EchoRect(input, &output);
123 EXPECT_EQ(x, output.x());
124 EXPECT_EQ(y, output.y());
125 EXPECT_EQ(width, output.width());
126 EXPECT_EQ(height, output.height());
127 }
128
129 TEST_F(GeometryStructTraitsTest, RectF) {
130 const float x = 1234.1f;
131 const float y = 5678.2f;
132 const float width = 4321.3f;
133 const float height = 8765.4f;
134 gfx::RectF input(x, y, width, height);
135 mojom::GeometryTraitsTestServicePtr proxy = GetTraitsTestProxy();
136 gfx::RectF output;
137 proxy->EchoRectF(input, &output);
138 EXPECT_EQ(x, output.x());
139 EXPECT_EQ(y, output.y());
140 EXPECT_EQ(width, output.width());
141 EXPECT_EQ(height, output.height());
142 }
143
144 TEST_F(GeometryStructTraitsTest, Insets) {
145 const int32_t top = 1234;
146 const int32_t left = 5678;
147 const int32_t bottom = 4321;
148 const int32_t right = 8765;
149 gfx::Insets input(top, left, bottom, right);
150 mojom::GeometryTraitsTestServicePtr proxy = GetTraitsTestProxy();
151 gfx::Insets output;
152 proxy->EchoInsets(input, &output);
153 EXPECT_EQ(top, output.top());
154 EXPECT_EQ(left, output.left());
155 EXPECT_EQ(bottom, output.bottom());
156 EXPECT_EQ(right, output.right());
157 }
158
159 TEST_F(GeometryStructTraitsTest, InsetsF) {
160 const float top = 1234.1f;
161 const float left = 5678.2f;
162 const float bottom = 4321.3f;
163 const float right = 8765.4f;
164 gfx::InsetsF input(top, left, bottom, right);
165 mojom::GeometryTraitsTestServicePtr proxy = GetTraitsTestProxy();
166 gfx::InsetsF output;
167 proxy->EchoInsetsF(input, &output);
168 EXPECT_EQ(top, output.top());
169 EXPECT_EQ(left, output.left());
170 EXPECT_EQ(bottom, output.bottom());
171 EXPECT_EQ(right, output.right());
172 }
173
174 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/geometry/mojo/geometry.mojom ('k') | ui/gfx/geometry/mojo/geometry_traits_test_service.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698