Index: cc/proto/gfx_conversions_unittest.cc |
diff --git a/cc/proto/gfx_conversions_unittest.cc b/cc/proto/gfx_conversions_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..f6c6afa90660c030cead394ae1b700252e1b75b8 |
--- /dev/null |
+++ b/cc/proto/gfx_conversions_unittest.cc |
@@ -0,0 +1,166 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "cc/proto/gfx_conversions.h" |
+ |
+#include "cc/proto/point.pb.h" |
+#include "cc/proto/pointf.pb.h" |
+#include "cc/proto/rect.pb.h" |
+#include "cc/proto/rectf.pb.h" |
+#include "cc/proto/size.pb.h" |
+#include "cc/proto/sizef.pb.h" |
+#include "cc/proto/transform.pb.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+#include "ui/gfx/geometry/point.h" |
+#include "ui/gfx/geometry/point_f.h" |
+#include "ui/gfx/geometry/rect.h" |
+#include "ui/gfx/geometry/rect_f.h" |
+#include "ui/gfx/geometry/size.h" |
+#include "ui/gfx/geometry/size_f.h" |
+#include "ui/gfx/transform.h" |
+ |
+namespace cc { |
+namespace { |
+ |
+TEST(GfxProtoConversionsTest, SerializeDeserializePoint) { |
+ const gfx::Point point(5, 10); |
+ |
+ // Test gfx::PointToProto |
+ proto::Point proto; |
+ PointToProto(point, &proto); |
+ EXPECT_EQ(point.x(), proto.x()); |
+ EXPECT_EQ(point.y(), proto.y()); |
+ |
+ // Test protoToPoints |
+ EXPECT_EQ(point, ProtoToPoint(proto)); |
+ |
+ gfx::Point new_point; |
+ ProtoToPoint(proto, &new_point); |
+ EXPECT_EQ(point, new_point); |
+} |
+ |
+TEST(GfxProtoConversionsTest, SerializeDeserializePointF) { |
+ const gfx::PointF point(5.f, 10.f); |
+ |
+ // Test gfx::PointFToProto |
+ proto::PointF proto; |
+ PointFToProto(point, &proto); |
+ EXPECT_EQ(point.x(), proto.x()); |
+ EXPECT_EQ(point.y(), proto.y()); |
+ |
+ // Test ProtoToPointFs |
+ EXPECT_EQ(point, ProtoToPointF(proto)); |
+ |
+ gfx::PointF new_point; |
+ ProtoToPointF(proto, &new_point); |
+ EXPECT_EQ(point, new_point); |
+} |
+ |
+TEST(GfxProtoConversionsTest, SerializeDeserializeSize) { |
+ const gfx::Size size(5, 10); |
+ |
+ // Test gfx::SizeToProto |
+ proto::Size proto; |
+ SizeToProto(size, &proto); |
+ EXPECT_EQ(size.width(), proto.width()); |
+ EXPECT_EQ(size.height(), proto.height()); |
+ |
+ // Test ProtoToSizes |
+ EXPECT_EQ(size, ProtoToSize(proto)); |
+ |
+ gfx::Size new_size; |
+ ProtoToSize(proto, &new_size); |
+ EXPECT_EQ(size, new_size); |
+} |
+ |
+TEST(GfxProtoConversionsTest, SerializeDeserializeSizeF) { |
+ const gfx::SizeF size(5.f, 10.f); |
+ |
+ // Test gfx::SizeFToProto |
+ proto::SizeF proto; |
+ SizeFToProto(size, &proto); |
+ EXPECT_EQ(size.width(), proto.width()); |
+ EXPECT_EQ(size.height(), proto.height()); |
+ |
+ // Test ProtoToSizeFs |
+ EXPECT_EQ(size, ProtoToSizeF(proto)); |
+ |
+ gfx::SizeF new_size; |
+ ProtoToSizeF(proto, &new_size); |
+ EXPECT_EQ(size, new_size); |
+} |
+ |
+TEST(GfxProtoConversionsTest, SerializeDeserializeRect) { |
+ const gfx::Rect rect(1, 2, 3, 4); |
+ |
+ // Test gfx::RectToProto |
+ proto::Rect proto; |
+ RectToProto(rect, &proto); |
+ EXPECT_EQ(rect.origin().x(), proto.origin().x()); |
+ EXPECT_EQ(rect.origin().y(), proto.origin().y()); |
+ EXPECT_EQ(rect.size().width(), proto.size().width()); |
+ EXPECT_EQ(rect.size().height(), proto.size().height()); |
+ |
+ // Test ProtoToRects |
+ EXPECT_EQ(rect, ProtoToRect(proto)); |
+ |
+ gfx::Rect new_rect; |
+ ProtoToRect(proto, &new_rect); |
+ EXPECT_EQ(rect, new_rect); |
+} |
+ |
+TEST(GfxProtoConversionsTest, SerializeDeserializeRectF) { |
+ 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.
|
+ |
+ // Test gfx::RectFToProto |
+ proto::RectF proto; |
+ RectFToProto(rect, &proto); |
+ EXPECT_EQ(rect.origin().x(), proto.origin().x()); |
+ EXPECT_EQ(rect.origin().y(), proto.origin().y()); |
+ EXPECT_EQ(rect.size().width(), proto.size().width()); |
+ EXPECT_EQ(rect.size().height(), proto.size().height()); |
+ |
+ // Test ProtoToRectFs |
+ EXPECT_EQ(rect, ProtoToRectF(proto)); |
+ |
+ gfx::RectF new_rect; |
+ ProtoToRectF(proto, &new_rect); |
+ EXPECT_EQ(rect, new_rect); |
+} |
+ |
+TEST(GfxProtoConversionsTest, SerializeDeserializeTransform) { |
+ gfx::Transform transform(1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f, 9.f, 10.f, |
+ 11.f, 12.f, 13.f, 14.f, 15.f, 16.f); |
+ |
+ // Test gfx::TransformToProto |
+ proto::Transform proto; |
+ TransformToProto(transform, &proto); |
+ EXPECT_EQ(16, proto.matrix_size()); |
+ EXPECT_EQ(transform.matrix().get(0, 0), proto.matrix(0)); |
+ EXPECT_EQ(transform.matrix().get(0, 1), proto.matrix(1)); |
+ EXPECT_EQ(transform.matrix().get(0, 2), proto.matrix(2)); |
+ EXPECT_EQ(transform.matrix().get(0, 3), proto.matrix(3)); |
+ EXPECT_EQ(transform.matrix().get(1, 0), proto.matrix(4)); |
+ EXPECT_EQ(transform.matrix().get(1, 1), proto.matrix(5)); |
+ EXPECT_EQ(transform.matrix().get(1, 2), proto.matrix(6)); |
+ EXPECT_EQ(transform.matrix().get(1, 3), proto.matrix(7)); |
+ EXPECT_EQ(transform.matrix().get(2, 0), proto.matrix(8)); |
+ EXPECT_EQ(transform.matrix().get(2, 1), proto.matrix(9)); |
+ EXPECT_EQ(transform.matrix().get(2, 2), proto.matrix(10)); |
+ EXPECT_EQ(transform.matrix().get(2, 3), proto.matrix(11)); |
+ EXPECT_EQ(transform.matrix().get(3, 0), proto.matrix(12)); |
+ EXPECT_EQ(transform.matrix().get(3, 1), proto.matrix(13)); |
+ EXPECT_EQ(transform.matrix().get(3, 2), proto.matrix(14)); |
+ EXPECT_EQ(transform.matrix().get(3, 3), proto.matrix(15)); |
+ |
+ // Test ProtoToTransforms |
+ EXPECT_EQ(transform, ProtoToTransform(proto)); |
+ |
+ gfx::Transform new_transform; |
+ ProtoToTransform(proto, &new_transform); |
+ EXPECT_EQ(transform, new_transform); |
+} |
+ |
+} // namespace |
+} // namespace cc |