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

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: Fix SizeF unit test 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 };
sky 2016/06/02 03:22:21 nit: DISALLOW..
Fady Samuel 2016/06/02 12:09:23 Done.
65
66 } // namespace
67
68 TEST_F(GeometryStructTraitsTest, Point) {
69 const int32_t x = 1234;
70 const int32_t y = 5678;
71 gfx::Point input(x, y);
72 mojom::GeometryTraitsTestServicePtr proxy = GetTraitsTestProxy();
73 gfx::Point output;
74 proxy->EchoPoint(input, &output);
75 EXPECT_EQ(x, output.x());
76 EXPECT_EQ(y, output.y());
77 }
78
79 TEST_F(GeometryStructTraitsTest, PointF) {
80 const float x = 1234.5f;
81 const float y = 6789.0f;
82 gfx::PointF input(x, y);
83 mojom::GeometryTraitsTestServicePtr proxy = GetTraitsTestProxy();
84 gfx::PointF output;
85 proxy->EchoPointF(input, &output);
86 EXPECT_EQ(x, output.x());
87 EXPECT_EQ(y, output.y());
88 }
89
90 TEST_F(GeometryStructTraitsTest, Size) {
91 const int32_t width = 1234;
92 const int32_t height = 5678;
93 gfx::Size input(width, height);
94 mojom::GeometryTraitsTestServicePtr proxy = GetTraitsTestProxy();
95 gfx::Size output;
96 proxy->EchoSize(input, &output);
97 EXPECT_EQ(width, output.width());
98 EXPECT_EQ(height, output.height());
99 }
100
101 TEST_F(GeometryStructTraitsTest, SizeF) {
102 const float width = 1234.5;
103 const float height = 6789.6;
104 gfx::SizeF input(width, height);
105 mojom::GeometryTraitsTestServicePtr proxy = GetTraitsTestProxy();
106 gfx::SizeF output;
107 proxy->EchoSizeF(input, &output);
108 EXPECT_EQ(width, output.width());
109 EXPECT_EQ(height, output.height());
110 }
111
112 TEST_F(GeometryStructTraitsTest, Rect) {
113 const int32_t x = 1234;
114 const int32_t y = 5678;
115 const int32_t width = 4321;
116 const int32_t height = 8765;
117 gfx::Rect input(x, y, width, height);
118 mojom::GeometryTraitsTestServicePtr proxy = GetTraitsTestProxy();
119 gfx::Rect output;
120 proxy->EchoRect(input, &output);
121 EXPECT_EQ(x, output.x());
122 EXPECT_EQ(y, output.y());
123 EXPECT_EQ(width, output.width());
124 EXPECT_EQ(height, output.height());
125 }
126
127 TEST_F(GeometryStructTraitsTest, RectF) {
128 const float x = 1234.1f;
129 const float y = 5678.2f;
130 const float width = 4321.3f;
131 const float height = 8765.4f;
132 gfx::RectF input(x, y, width, height);
133 mojom::GeometryTraitsTestServicePtr proxy = GetTraitsTestProxy();
134 gfx::RectF output;
135 proxy->EchoRectF(input, &output);
136 EXPECT_EQ(x, output.x());
137 EXPECT_EQ(y, output.y());
138 EXPECT_EQ(width, output.width());
139 EXPECT_EQ(height, output.height());
140 }
141
142 TEST_F(GeometryStructTraitsTest, Insets) {
143 const int32_t top = 1234;
144 const int32_t left = 5678;
145 const int32_t bottom = 4321;
146 const int32_t right = 8765;
147 gfx::Insets input(top, left, bottom, right);
148 mojom::GeometryTraitsTestServicePtr proxy = GetTraitsTestProxy();
149 gfx::Insets output;
150 proxy->EchoInsets(input, &output);
151 EXPECT_EQ(top, output.top());
152 EXPECT_EQ(left, output.left());
153 EXPECT_EQ(bottom, output.bottom());
154 EXPECT_EQ(right, output.right());
155 }
156
157 TEST_F(GeometryStructTraitsTest, InsetsF) {
158 const float top = 1234.1f;
159 const float left = 5678.2f;
160 const float bottom = 4321.3f;
161 const float right = 8765.4f;
162 gfx::InsetsF input(top, left, bottom, right);
163 mojom::GeometryTraitsTestServicePtr proxy = GetTraitsTestProxy();
164 gfx::InsetsF output;
165 proxy->EchoInsetsF(input, &output);
166 EXPECT_EQ(top, output.top());
167 EXPECT_EQ(left, output.left());
168 EXPECT_EQ(bottom, output.bottom());
169 EXPECT_EQ(right, output.right());
170 }
171
172 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698