summaryrefslogtreecommitdiffstats
path: root/ui/gfx/point_unittest.cc
diff options
context:
space:
mode:
authordanakj@chromium.org <danakj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-11 21:52:22 +0000
committerdanakj@chromium.org <danakj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-11 21:52:22 +0000
commit95af087dc056a84e8047eb1e8c195f99119f9de3 (patch)
tree908d33204819f4274080dfdce7652fa5bb2c5178 /ui/gfx/point_unittest.cc
parent81289ac3e1919387b4554fa82b4d8f5d61f0380f (diff)
downloadchromium_src-95af087dc056a84e8047eb1e8c195f99119f9de3.zip
chromium_src-95af087dc056a84e8047eb1e8c195f99119f9de3.tar.gz
chromium_src-95af087dc056a84e8047eb1e8c195f99119f9de3.tar.bz2
Implicit coversion operators from integer geometry types to floating point.
This change allows you to call a function that expects a floating point object with an integer object and have things just work. The addition operator for Points is outside the Point classes so it can add/subtract integer and float points together implicitly. Tested to verify compilation with: ui_unittests:RectTest.ToRectF ui_unittests:SizeTest.ToSizeF ui_unittests:PointTest.ToPointF BUG=147395 R=sky@chromium.org Review URL: https://chromiumcodereview.appspot.com/11028127 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@161415 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/gfx/point_unittest.cc')
-rw-r--r--ui/gfx/point_unittest.cc31
1 files changed, 31 insertions, 0 deletions
diff --git a/ui/gfx/point_unittest.cc b/ui/gfx/point_unittest.cc
new file mode 100644
index 0000000..cac1b1e
--- /dev/null
+++ b/ui/gfx/point_unittest.cc
@@ -0,0 +1,31 @@
+// Copyright (c) 2012 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 "ui/gfx/point_base.h"
+
+#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/gfx/point.h"
+#include "ui/gfx/point_f.h"
+
+namespace ui {
+
+static int test_pointf(const gfx::PointF& p) {
+ return p.x();
+}
+
+TEST(PointTest, ToPointF) {
+ // Check that implicit conversion from integer to float compiles.
+ gfx::Point a(10, 20);
+ float x = test_pointf(a);
+ EXPECT_EQ(x, a.x());
+
+ gfx::PointF b(10, 20);
+ bool equals = a == b;
+ EXPECT_EQ(true, equals);
+
+ equals = b == a;
+ EXPECT_EQ(true, equals);
+}
+
+} // namespace ui