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, IntSerializationLimits) { |
| 27 // Test Point with the minimum int value. |
| 28 { |
| 29 gfx::Point point(std::numeric_limits<int>::min(), |
| 30 std::numeric_limits<int>::min()); |
| 31 proto::Point proto; |
| 32 PointToProto(point, &proto); |
| 33 EXPECT_EQ(point, ProtoToPoint(proto)); |
| 34 } |
| 35 |
| 36 // Test Point with the maximum int value. |
| 37 { |
| 38 gfx::Point point(std::numeric_limits<int>::max(), |
| 39 std::numeric_limits<int>::max()); |
| 40 proto::Point proto; |
| 41 PointToProto(point, &proto); |
| 42 EXPECT_EQ(point, ProtoToPoint(proto)); |
| 43 } |
| 44 |
| 45 // Test Size with the minimum int value. |
| 46 { |
| 47 gfx::Size size(std::numeric_limits<int>::min(), |
| 48 std::numeric_limits<int>::min()); |
| 49 proto::Size proto; |
| 50 SizeToProto(size, &proto); |
| 51 EXPECT_EQ(size, ProtoToSize(proto)); |
| 52 } |
| 53 |
| 54 // Test Size with the maximum int value. |
| 55 { |
| 56 gfx::Size size(std::numeric_limits<int>::max(), |
| 57 std::numeric_limits<int>::max()); |
| 58 proto::Size proto; |
| 59 SizeToProto(size, &proto); |
| 60 EXPECT_EQ(size, ProtoToSize(proto)); |
| 61 } |
| 62 } |
| 63 |
| 64 TEST(GfxProtoConversionsTest, SerializeDeserializePoint) { |
| 65 const gfx::Point point(5, 10); |
| 66 |
| 67 // Test PointToProto |
| 68 proto::Point proto; |
| 69 PointToProto(point, &proto); |
| 70 EXPECT_EQ(point.x(), proto.x()); |
| 71 EXPECT_EQ(point.y(), proto.y()); |
| 72 |
| 73 // Test protoToPoint |
| 74 EXPECT_EQ(point, ProtoToPoint(proto)); |
| 75 } |
| 76 |
| 77 TEST(GfxProtoConversionsTest, SerializeDeserializePointF) { |
| 78 const gfx::PointF point(5.1f, 10.2f); |
| 79 |
| 80 // Test PointFToProto |
| 81 proto::PointF proto; |
| 82 PointFToProto(point, &proto); |
| 83 EXPECT_EQ(point.x(), proto.x()); |
| 84 EXPECT_EQ(point.y(), proto.y()); |
| 85 |
| 86 // Test ProtoToPointF |
| 87 EXPECT_EQ(point, ProtoToPointF(proto)); |
| 88 } |
| 89 |
| 90 TEST(GfxProtoConversionsTest, SerializeDeserializeSize) { |
| 91 const gfx::Size size(5, 10); |
| 92 |
| 93 // Test SizeToProto |
| 94 proto::Size proto; |
| 95 SizeToProto(size, &proto); |
| 96 EXPECT_EQ(size.width(), proto.width()); |
| 97 EXPECT_EQ(size.height(), proto.height()); |
| 98 |
| 99 // Test ProtoToSize |
| 100 EXPECT_EQ(size, ProtoToSize(proto)); |
| 101 } |
| 102 |
| 103 TEST(GfxProtoConversionsTest, SerializeDeserializeSizeF) { |
| 104 const gfx::SizeF size(5.1f, 10.2f); |
| 105 |
| 106 // Test SizeFToProto |
| 107 proto::SizeF proto; |
| 108 SizeFToProto(size, &proto); |
| 109 EXPECT_EQ(size.width(), proto.width()); |
| 110 EXPECT_EQ(size.height(), proto.height()); |
| 111 |
| 112 // Test ProtoToSizeF |
| 113 EXPECT_EQ(size, ProtoToSizeF(proto)); |
| 114 } |
| 115 |
| 116 TEST(GfxProtoConversionsTest, SerializeDeserializeRect) { |
| 117 const gfx::Rect rect(1, 2, 3, 4); |
| 118 |
| 119 // Test RectToProto |
| 120 proto::Rect proto; |
| 121 RectToProto(rect, &proto); |
| 122 EXPECT_EQ(rect.origin().x(), proto.origin().x()); |
| 123 EXPECT_EQ(rect.origin().y(), proto.origin().y()); |
| 124 EXPECT_EQ(rect.size().width(), proto.size().width()); |
| 125 EXPECT_EQ(rect.size().height(), proto.size().height()); |
| 126 |
| 127 // Test ProtoToRect |
| 128 EXPECT_EQ(rect, ProtoToRect(proto)); |
| 129 } |
| 130 |
| 131 TEST(GfxProtoConversionsTest, SerializeDeserializeRectF) { |
| 132 const gfx::RectF rect(1.4f, 2.3f, 3.2f, 4.1f); |
| 133 |
| 134 // Test RectFToProto |
| 135 proto::RectF proto; |
| 136 RectFToProto(rect, &proto); |
| 137 EXPECT_EQ(rect.origin().x(), proto.origin().x()); |
| 138 EXPECT_EQ(rect.origin().y(), proto.origin().y()); |
| 139 EXPECT_EQ(rect.size().width(), proto.size().width()); |
| 140 EXPECT_EQ(rect.size().height(), proto.size().height()); |
| 141 |
| 142 // Test ProtoToRectF |
| 143 EXPECT_EQ(rect, ProtoToRectF(proto)); |
| 144 } |
| 145 |
| 146 TEST(GfxProtoConversionsTest, SerializeDeserializeTransform) { |
| 147 gfx::Transform transform(1.16f, 2.15f, 3.14f, 4.13f, 5.12f, 6.11f, 7.1f, 8.9f, |
| 148 9.8f, 10.7f, 11.6f, 12.5f, 13.4f, 14.3f, 15.2f, |
| 149 16.1f); |
| 150 |
| 151 // Test TransformToProto |
| 152 proto::Transform proto; |
| 153 TransformToProto(transform, &proto); |
| 154 EXPECT_EQ(16, proto.matrix_size()); |
| 155 EXPECT_EQ(transform.matrix().get(0, 0), proto.matrix(0)); |
| 156 EXPECT_EQ(transform.matrix().get(0, 1), proto.matrix(1)); |
| 157 EXPECT_EQ(transform.matrix().get(0, 2), proto.matrix(2)); |
| 158 EXPECT_EQ(transform.matrix().get(0, 3), proto.matrix(3)); |
| 159 EXPECT_EQ(transform.matrix().get(1, 0), proto.matrix(4)); |
| 160 EXPECT_EQ(transform.matrix().get(1, 1), proto.matrix(5)); |
| 161 EXPECT_EQ(transform.matrix().get(1, 2), proto.matrix(6)); |
| 162 EXPECT_EQ(transform.matrix().get(1, 3), proto.matrix(7)); |
| 163 EXPECT_EQ(transform.matrix().get(2, 0), proto.matrix(8)); |
| 164 EXPECT_EQ(transform.matrix().get(2, 1), proto.matrix(9)); |
| 165 EXPECT_EQ(transform.matrix().get(2, 2), proto.matrix(10)); |
| 166 EXPECT_EQ(transform.matrix().get(2, 3), proto.matrix(11)); |
| 167 EXPECT_EQ(transform.matrix().get(3, 0), proto.matrix(12)); |
| 168 EXPECT_EQ(transform.matrix().get(3, 1), proto.matrix(13)); |
| 169 EXPECT_EQ(transform.matrix().get(3, 2), proto.matrix(14)); |
| 170 EXPECT_EQ(transform.matrix().get(3, 3), proto.matrix(15)); |
| 171 |
| 172 // Test ProtoToTransform |
| 173 EXPECT_EQ(transform, ProtoToTransform(proto)); |
| 174 } |
| 175 |
| 176 } // namespace |
| 177 } // namespace cc |
OLD | NEW |