OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 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 "cc/proto/gfx_conversions.h" | |
6 | |
7 #include "cc/proto/point.pb.h" | |
8 #include "cc/proto/pointf.pb.h" | |
9 #include "cc/proto/rect.pb.h" | |
10 #include "cc/proto/rectf.pb.h" | |
11 #include "cc/proto/size.pb.h" | |
12 #include "cc/proto/sizef.pb.h" | |
13 #include "cc/proto/transform.pb.h" | |
14 #include "testing/gtest/include/gtest/gtest.h" | |
15 #include "ui/gfx/geometry/point.h" | |
16 #include "ui/gfx/geometry/point_f.h" | |
17 #include "ui/gfx/geometry/rect.h" | |
18 #include "ui/gfx/geometry/rect_f.h" | |
19 #include "ui/gfx/geometry/size.h" | |
20 #include "ui/gfx/geometry/size_f.h" | |
21 #include "ui/gfx/transform.h" | |
22 | |
23 namespace cc { | |
24 namespace { | |
25 | |
26 TEST(GfxProtoConversionsTest, SerializeDeserializePoint) { | |
27 const gfx::Point point(5, 10); | |
28 | |
29 // Test gfx::PointToProto | |
30 proto::Point proto; | |
31 PointToProto(point, &proto); | |
32 EXPECT_EQ(point.x(), proto.x()); | |
33 EXPECT_EQ(point.y(), proto.y()); | |
34 | |
35 // Test protoToPoints | |
36 EXPECT_EQ(point, ProtoToPoint(proto)); | |
37 | |
38 gfx::Point new_point; | |
39 ProtoToPoint(proto, &new_point); | |
40 EXPECT_EQ(point, new_point); | |
41 } | |
42 | |
43 TEST(GfxProtoConversionsTest, SerializeDeserializePointF) { | |
44 const gfx::PointF point(5.f, 10.f); | |
45 | |
46 // Test gfx::PointFToProto | |
47 proto::PointF proto; | |
48 PointFToProto(point, &proto); | |
49 EXPECT_EQ(point.x(), proto.x()); | |
50 EXPECT_EQ(point.y(), proto.y()); | |
51 | |
52 // Test ProtoToPointFs | |
53 EXPECT_EQ(point, ProtoToPointF(proto)); | |
54 | |
55 gfx::PointF new_point; | |
56 ProtoToPointF(proto, &new_point); | |
57 EXPECT_EQ(point, new_point); | |
58 } | |
59 | |
60 TEST(GfxProtoConversionsTest, SerializeDeserializeSize) { | |
61 const gfx::Size size(5, 10); | |
62 | |
63 // Test gfx::SizeToProto | |
64 proto::Size proto; | |
65 SizeToProto(size, &proto); | |
66 EXPECT_EQ(size.width(), proto.width()); | |
67 EXPECT_EQ(size.height(), proto.height()); | |
68 | |
69 // Test ProtoToSizes | |
70 EXPECT_EQ(size, ProtoToSize(proto)); | |
71 | |
72 gfx::Size new_size; | |
73 ProtoToSize(proto, &new_size); | |
74 EXPECT_EQ(size, new_size); | |
75 } | |
76 | |
77 TEST(GfxProtoConversionsTest, SerializeDeserializeSizeF) { | |
78 const gfx::SizeF size(5.f, 10.f); | |
79 | |
80 // Test gfx::SizeFToProto | |
81 proto::SizeF proto; | |
82 SizeFToProto(size, &proto); | |
83 EXPECT_EQ(size.width(), proto.width()); | |
84 EXPECT_EQ(size.height(), proto.height()); | |
85 | |
86 // Test ProtoToSizeFs | |
87 EXPECT_EQ(size, ProtoToSizeF(proto)); | |
88 | |
89 gfx::SizeF new_size; | |
90 ProtoToSizeF(proto, &new_size); | |
91 EXPECT_EQ(size, new_size); | |
92 } | |
93 | |
94 TEST(GfxProtoConversionsTest, SerializeDeserializeRect) { | |
95 const gfx::Rect rect(1, 2, 3, 4); | |
96 | |
97 // Test gfx::RectToProto | |
98 proto::Rect proto; | |
99 RectToProto(rect, &proto); | |
100 EXPECT_EQ(rect.origin().x(), proto.origin().x()); | |
101 EXPECT_EQ(rect.origin().y(), proto.origin().y()); | |
102 EXPECT_EQ(rect.size().width(), proto.size().width()); | |
103 EXPECT_EQ(rect.size().height(), proto.size().height()); | |
104 | |
105 // Test ProtoToRects | |
106 EXPECT_EQ(rect, ProtoToRect(proto)); | |
107 | |
108 gfx::Rect new_rect; | |
109 ProtoToRect(proto, &new_rect); | |
110 EXPECT_EQ(rect, new_rect); | |
111 } | |
112 | |
113 TEST(GfxProtoConversionsTest, SerializeDeserializeRectF) { | |
114 const gfx::RectF rect(1.f, 2.f, 3.f, 4.f); | |
danakj
2015/10/14 23:10:10
can you use numbers not representable as ints for
David Trainor- moved to gerrit
2015/10/15 22:18:02
Done.
| |
115 | |
116 // Test gfx::RectFToProto | |
117 proto::RectF proto; | |
118 RectFToProto(rect, &proto); | |
119 EXPECT_EQ(rect.origin().x(), proto.origin().x()); | |
120 EXPECT_EQ(rect.origin().y(), proto.origin().y()); | |
121 EXPECT_EQ(rect.size().width(), proto.size().width()); | |
122 EXPECT_EQ(rect.size().height(), proto.size().height()); | |
123 | |
124 // Test ProtoToRectFs | |
125 EXPECT_EQ(rect, ProtoToRectF(proto)); | |
126 | |
127 gfx::RectF new_rect; | |
128 ProtoToRectF(proto, &new_rect); | |
129 EXPECT_EQ(rect, new_rect); | |
130 } | |
131 | |
132 TEST(GfxProtoConversionsTest, SerializeDeserializeTransform) { | |
133 gfx::Transform transform(1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f, 9.f, 10.f, | |
134 11.f, 12.f, 13.f, 14.f, 15.f, 16.f); | |
135 | |
136 // Test gfx::TransformToProto | |
137 proto::Transform proto; | |
138 TransformToProto(transform, &proto); | |
139 EXPECT_EQ(16, proto.matrix_size()); | |
140 EXPECT_EQ(transform.matrix().get(0, 0), proto.matrix(0)); | |
141 EXPECT_EQ(transform.matrix().get(0, 1), proto.matrix(1)); | |
142 EXPECT_EQ(transform.matrix().get(0, 2), proto.matrix(2)); | |
143 EXPECT_EQ(transform.matrix().get(0, 3), proto.matrix(3)); | |
144 EXPECT_EQ(transform.matrix().get(1, 0), proto.matrix(4)); | |
145 EXPECT_EQ(transform.matrix().get(1, 1), proto.matrix(5)); | |
146 EXPECT_EQ(transform.matrix().get(1, 2), proto.matrix(6)); | |
147 EXPECT_EQ(transform.matrix().get(1, 3), proto.matrix(7)); | |
148 EXPECT_EQ(transform.matrix().get(2, 0), proto.matrix(8)); | |
149 EXPECT_EQ(transform.matrix().get(2, 1), proto.matrix(9)); | |
150 EXPECT_EQ(transform.matrix().get(2, 2), proto.matrix(10)); | |
151 EXPECT_EQ(transform.matrix().get(2, 3), proto.matrix(11)); | |
152 EXPECT_EQ(transform.matrix().get(3, 0), proto.matrix(12)); | |
153 EXPECT_EQ(transform.matrix().get(3, 1), proto.matrix(13)); | |
154 EXPECT_EQ(transform.matrix().get(3, 2), proto.matrix(14)); | |
155 EXPECT_EQ(transform.matrix().get(3, 3), proto.matrix(15)); | |
156 | |
157 // Test ProtoToTransforms | |
158 EXPECT_EQ(transform, ProtoToTransform(proto)); | |
159 | |
160 gfx::Transform new_transform; | |
161 ProtoToTransform(proto, &new_transform); | |
162 EXPECT_EQ(transform, new_transform); | |
163 } | |
164 | |
165 } // namespace | |
166 } // namespace cc | |
OLD | NEW |