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

Side by Side Diff: third_party/WebKit/Source/platform/geometry/FloatRectTest.cpp

Issue 2191233002: Add platform/geometry pretty printers for logging and testing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adjust tests to work around uninteresting cross-platform differences Created 4 years, 4 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "platform/geometry/FloatRect.h" 5 #include "platform/geometry/FloatRect.h"
6 6
7 #include "platform/geometry/FloatPoint.h" 7 #include "platform/geometry/FloatPoint.h"
8 #include "platform/geometry/GeometryTestHelpers.h" 8 #include "platform/geometry/GeometryTestHelpers.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "wtf/text/WTFString.h"
11 10
12 namespace blink { 11 namespace blink {
13 12
14 TEST(FloatRectTest, SquaredDistanceToTest) 13 TEST(FloatRectTest, SquaredDistanceToTest)
15 { 14 {
16 15
17 // 16 //
18 // O--x 17 // O--x
19 // | 18 // |
20 // y 19 // y
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 104
106 // `8` case 105 // `8` case
107 FloatPoint p23(180, 300); 106 FloatPoint p23(180, 300);
108 EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p2 3), 2500.f); 107 EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p2 3), 2500.f);
109 108
110 // `9` case 109 // `9` case
111 FloatPoint p24(450, 450); 110 FloatPoint p24(450, 450);
112 EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p2 4), 50000.f); 111 EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p2 4), 50000.f);
113 } 112 }
114 113
115 #ifndef NDEBUG 114 TEST(FloatRectTest, Formatting)
116 TEST(FloatRectTest, ToString)
117 { 115 {
118 FloatRect emptyRect = FloatRect(); 116 FloatRect emptyRect = FloatRect();
119 EXPECT_EQ(String("0.000000,0.000000 0.000000x0.000000"), emptyRect.toString( )); 117 std::ostringstream emptyRectStream;
118 emptyRectStream << emptyRect;
119 EXPECT_EQ("FloatRect(x=0, y=0, width=0, height=0)", emptyRectStream.str());
120 120
121 FloatRect rect(1, 2, 3, 4); 121 FloatRect rect(1, 2, 3, 4);
122 EXPECT_EQ(String("1.000000,2.000000 3.000000x4.000000"), rect.toString()); 122 std::ostringstream rectStream;
123 rectStream << rect;
124 EXPECT_EQ("FloatRect(x=1, y=2, width=3, height=4)", rectStream.str());
123 125
124 FloatRect granularRect(1.6f, 2.7f, 3.8f, 4.9f); 126 FloatRect granularRect(1.6f, 2.7f, 3.8f, 4.9f);
125 EXPECT_EQ(String("1.600000,2.700000 3.800000x4.900000"), granularRect.toStri ng()); 127 std::ostringstream granularRectStream;
128 granularRectStream << granularRect;
129 EXPECT_EQ("FloatRect(x=1.6, y=2.7, width=3.8, height=4.9)", granularRectStre am.str());
130
131 FloatRect minMaxRect(std::numeric_limits<float>::min(), std::numeric_limits< float>::max(), std::numeric_limits<float>::min(), std::numeric_limits<float>::ma x());
132 std::ostringstream minMaxRectStream;
133 minMaxRectStream << minMaxRect;
134 EXPECT_EQ("FloatRect(x=1.17549e-38, y=3.40282e+38, width=1.17549e-38, height =3.40282e+38)", minMaxRectStream.str());
135
136 FloatRect infiniteRect(-std::numeric_limits<float>::infinity(), -std::numeri c_limits<float>::infinity(), std::numeric_limits<float>::infinity(), std::numeri c_limits<float>::infinity());
137 std::ostringstream infiniteRectStream;
138 infiniteRectStream << infiniteRect;
139 EXPECT_EQ("FloatRect(x=-inf, y=-inf, width=inf, height=inf)", infiniteRectSt ream.str());
140
141 FloatRect nanRect(0, 0, std::numeric_limits<float>::signaling_NaN(), std::nu meric_limits<float>::signaling_NaN());
142 std::ostringstream nanRectStream;
143 nanRectStream << nanRect;
144 EXPECT_EQ("FloatRect(x=0, y=0, width=nan, height=nan)", nanRectStream.str()) ;
126 } 145 }
127 #endif
128 146
129 } // namespace blink 147 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698