| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012, Google Inc. All rights reserved. | 2 * Copyright (c) 2012, Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "platform/LayoutUnit.h" | 32 #include "platform/LayoutUnit.h" |
| 33 | 33 |
| 34 #include <gtest/gtest.h> | 34 #include <gtest/gtest.h> |
| 35 #include <limits.h> | 35 #include <limits.h> |
| 36 | 36 |
| 37 using namespace blink; | 37 namespace blink { |
| 38 | 38 |
| 39 namespace { | 39 TEST(LayoutUnitTest, LayoutUnitInt) |
| 40 | 40 { |
| 41 TEST(WebCoreLayoutUnit, LayoutUnitInt) | 41 EXPECT_EQ(intMinForLayoutUnit, LayoutUnit(INT_MIN).toInt()); |
| 42 { | 42 EXPECT_EQ(intMinForLayoutUnit, LayoutUnit(INT_MIN / 2).toInt()); |
| 43 ASSERT_EQ(LayoutUnit(INT_MIN).toInt(), intMinForLayoutUnit); | 43 EXPECT_EQ(intMinForLayoutUnit, LayoutUnit(intMinForLayoutUnit - 1).toInt()); |
| 44 ASSERT_EQ(LayoutUnit(INT_MIN / 2).toInt(), intMinForLayoutUnit); | 44 EXPECT_EQ(intMinForLayoutUnit, LayoutUnit(intMinForLayoutUnit).toInt()); |
| 45 ASSERT_EQ(LayoutUnit(intMinForLayoutUnit - 1).toInt(), intMinForLayoutUnit); | 45 EXPECT_EQ(intMinForLayoutUnit + 1, LayoutUnit(intMinForLayoutUnit + 1).toInt
()); |
| 46 ASSERT_EQ(LayoutUnit(intMinForLayoutUnit).toInt(), intMinForLayoutUnit); | 46 EXPECT_EQ(intMinForLayoutUnit / 2, LayoutUnit(intMinForLayoutUnit / 2).toInt
()); |
| 47 ASSERT_EQ(LayoutUnit(intMinForLayoutUnit + 1).toInt(), intMinForLayoutUnit +
1); | 47 EXPECT_EQ(-10000, LayoutUnit(-10000).toInt()); |
| 48 ASSERT_EQ(LayoutUnit(intMinForLayoutUnit / 2).toInt(), intMinForLayoutUnit /
2); | 48 EXPECT_EQ(-1000, LayoutUnit(-1000).toInt()); |
| 49 ASSERT_EQ(LayoutUnit(-10000).toInt(), -10000); | 49 EXPECT_EQ(-100, LayoutUnit(-100).toInt()); |
| 50 ASSERT_EQ(LayoutUnit(-1000).toInt(), -1000); | 50 EXPECT_EQ(-10, LayoutUnit(-10).toInt()); |
| 51 ASSERT_EQ(LayoutUnit(-100).toInt(), -100); | 51 EXPECT_EQ(-1, LayoutUnit(-1).toInt()); |
| 52 ASSERT_EQ(LayoutUnit(-10).toInt(), -10); | 52 EXPECT_EQ(0, LayoutUnit(0).toInt()); |
| 53 ASSERT_EQ(LayoutUnit(-1).toInt(), -1); | 53 EXPECT_EQ(1, LayoutUnit(1).toInt()); |
| 54 ASSERT_EQ(LayoutUnit(0).toInt(), 0); | 54 EXPECT_EQ(100, LayoutUnit(100).toInt()); |
| 55 ASSERT_EQ(LayoutUnit(1).toInt(), 1); | 55 EXPECT_EQ(1000, LayoutUnit(1000).toInt()); |
| 56 ASSERT_EQ(LayoutUnit(100).toInt(), 100); | 56 EXPECT_EQ(10000, LayoutUnit(10000).toInt()); |
| 57 ASSERT_EQ(LayoutUnit(1000).toInt(), 1000); | 57 EXPECT_EQ(intMaxForLayoutUnit / 2, LayoutUnit(intMaxForLayoutUnit / 2).toInt
()); |
| 58 ASSERT_EQ(LayoutUnit(10000).toInt(), 10000); | 58 EXPECT_EQ(intMaxForLayoutUnit - 1, LayoutUnit(intMaxForLayoutUnit - 1).toInt
()); |
| 59 ASSERT_EQ(LayoutUnit(intMaxForLayoutUnit / 2).toInt(), intMaxForLayoutUnit /
2); | 59 EXPECT_EQ(intMaxForLayoutUnit, LayoutUnit(intMaxForLayoutUnit).toInt()); |
| 60 ASSERT_EQ(LayoutUnit(intMaxForLayoutUnit - 1).toInt(), intMaxForLayoutUnit -
1); | 60 EXPECT_EQ(intMaxForLayoutUnit, LayoutUnit(intMaxForLayoutUnit + 1).toInt()); |
| 61 ASSERT_EQ(LayoutUnit(intMaxForLayoutUnit).toInt(), intMaxForLayoutUnit); | 61 EXPECT_EQ(intMaxForLayoutUnit, LayoutUnit(INT_MAX / 2).toInt()); |
| 62 ASSERT_EQ(LayoutUnit(intMaxForLayoutUnit + 1).toInt(), intMaxForLayoutUnit); | 62 EXPECT_EQ(intMaxForLayoutUnit, LayoutUnit(INT_MAX).toInt()); |
| 63 ASSERT_EQ(LayoutUnit(INT_MAX / 2).toInt(), intMaxForLayoutUnit); | 63 } |
| 64 ASSERT_EQ(LayoutUnit(INT_MAX).toInt(), intMaxForLayoutUnit); | 64 |
| 65 } | 65 TEST(LayoutUnitTest, LayoutUnitFloat) |
| 66 | |
| 67 TEST(WebCoreLayoutUnit, LayoutUnitFloat) | |
| 68 { | 66 { |
| 69 const float tolerance = 1.0f / kFixedPointDenominator; | 67 const float tolerance = 1.0f / kFixedPointDenominator; |
| 70 ASSERT_FLOAT_EQ(LayoutUnit(1.0f).toFloat(), 1.0f); | 68 EXPECT_FLOAT_EQ(1.0f, LayoutUnit(1.0f).toFloat()); |
| 71 ASSERT_FLOAT_EQ(LayoutUnit(1.25f).toFloat(), 1.25f); | 69 EXPECT_FLOAT_EQ(1.25f, LayoutUnit(1.25f).toFloat()); |
| 72 ASSERT_NEAR(LayoutUnit(1.1f).toFloat(), 1.1f, tolerance); | 70 EXPECT_NEAR(LayoutUnit(1.1f).toFloat(), 1.1f, tolerance); |
| 73 ASSERT_NEAR(LayoutUnit(1.33f).toFloat(), 1.33f, tolerance); | 71 EXPECT_NEAR(LayoutUnit(1.33f).toFloat(), 1.33f, tolerance); |
| 74 ASSERT_NEAR(LayoutUnit(1.3333f).toFloat(), 1.3333f, tolerance); | 72 EXPECT_NEAR(LayoutUnit(1.3333f).toFloat(), 1.3333f, tolerance); |
| 75 ASSERT_NEAR(LayoutUnit(1.53434f).toFloat(), 1.53434f, tolerance); | 73 EXPECT_NEAR(LayoutUnit(1.53434f).toFloat(), 1.53434f, tolerance); |
| 76 ASSERT_NEAR(LayoutUnit(345634).toFloat(), 345634.0f, tolerance); | 74 EXPECT_NEAR(LayoutUnit(345634).toFloat(), 345634.0f, tolerance); |
| 77 ASSERT_NEAR(LayoutUnit(345634.12335f).toFloat(), 345634.12335f, tolerance); | 75 EXPECT_NEAR(LayoutUnit(345634.12335f).toFloat(), 345634.12335f, tolerance); |
| 78 ASSERT_NEAR(LayoutUnit(-345634.12335f).toFloat(), -345634.12335f, tolerance)
; | 76 EXPECT_NEAR(LayoutUnit(-345634.12335f).toFloat(), -345634.12335f, tolerance)
; |
| 79 ASSERT_NEAR(LayoutUnit(-345634).toFloat(), -345634.0f, tolerance); | 77 EXPECT_NEAR(LayoutUnit(-345634).toFloat(), -345634.0f, tolerance); |
| 80 } | 78 } |
| 81 | 79 |
| 82 TEST(WebCoreLayoutUnit, LayoutUnitRounding) | 80 TEST(LayoutUnitTest, LayoutUnitRounding) |
| 83 { | 81 { |
| 84 ASSERT_EQ(LayoutUnit(-1.9f).round(), -2); | 82 EXPECT_EQ(-2, LayoutUnit(-1.9f).round()); |
| 85 ASSERT_EQ(LayoutUnit(-1.6f).round(), -2); | 83 EXPECT_EQ(-2, LayoutUnit(-1.6f).round()); |
| 86 ASSERT_EQ(LayoutUnit::fromFloatRound(-1.51f).round(), -2); | 84 EXPECT_EQ(-2, LayoutUnit::fromFloatRound(-1.51f).round()); |
| 87 ASSERT_EQ(LayoutUnit::fromFloatRound(-1.5f).round(), -1); | 85 EXPECT_EQ(-1, LayoutUnit::fromFloatRound(-1.5f).round()); |
| 88 ASSERT_EQ(LayoutUnit::fromFloatRound(-1.49f).round(), -1); | 86 EXPECT_EQ(-1, LayoutUnit::fromFloatRound(-1.49f).round()); |
| 89 ASSERT_EQ(LayoutUnit(-1.0f).round(), -1); | 87 EXPECT_EQ(-1, LayoutUnit(-1.0f).round()); |
| 90 ASSERT_EQ(LayoutUnit::fromFloatRound(-0.99f).round(), -1); | 88 EXPECT_EQ(-1, LayoutUnit::fromFloatRound(-0.99f).round()); |
| 91 ASSERT_EQ(LayoutUnit::fromFloatRound(-0.51f).round(), -1); | 89 EXPECT_EQ(-1, LayoutUnit::fromFloatRound(-0.51f).round()); |
| 92 ASSERT_EQ(LayoutUnit::fromFloatRound(-0.50f).round(), 0); | 90 EXPECT_EQ(0, LayoutUnit::fromFloatRound(-0.50f).round()); |
| 93 ASSERT_EQ(LayoutUnit::fromFloatRound(-0.49f).round(), 0); | 91 EXPECT_EQ(0, LayoutUnit::fromFloatRound(-0.49f).round()); |
| 94 ASSERT_EQ(LayoutUnit(-0.1f).round(), 0); | 92 EXPECT_EQ(0, LayoutUnit(-0.1f).round()); |
| 95 ASSERT_EQ(LayoutUnit(0.0f).round(), 0); | 93 EXPECT_EQ(0, LayoutUnit(0.0f).round()); |
| 96 ASSERT_EQ(LayoutUnit(0.1f).round(), 0); | 94 EXPECT_EQ(0, LayoutUnit(0.1f).round()); |
| 97 ASSERT_EQ(LayoutUnit::fromFloatRound(0.49f).round(), 0); | 95 EXPECT_EQ(0, LayoutUnit::fromFloatRound(0.49f).round()); |
| 98 ASSERT_EQ(LayoutUnit::fromFloatRound(0.50f).round(), 1); | 96 EXPECT_EQ(1, LayoutUnit::fromFloatRound(0.50f).round()); |
| 99 ASSERT_EQ(LayoutUnit::fromFloatRound(0.51f).round(), 1); | 97 EXPECT_EQ(1, LayoutUnit::fromFloatRound(0.51f).round()); |
| 100 ASSERT_EQ(LayoutUnit(0.99f).round(), 1); | 98 EXPECT_EQ(1, LayoutUnit(0.99f).round()); |
| 101 ASSERT_EQ(LayoutUnit(1.0f).round(), 1); | 99 EXPECT_EQ(1, LayoutUnit(1.0f).round()); |
| 102 ASSERT_EQ(LayoutUnit::fromFloatRound(1.49f).round(), 1); | 100 EXPECT_EQ(1, LayoutUnit::fromFloatRound(1.49f).round()); |
| 103 ASSERT_EQ(LayoutUnit::fromFloatRound(1.5f).round(), 2); | 101 EXPECT_EQ(2, LayoutUnit::fromFloatRound(1.5f).round()); |
| 104 ASSERT_EQ(LayoutUnit::fromFloatRound(1.51f).round(), 2); | 102 EXPECT_EQ(2, LayoutUnit::fromFloatRound(1.51f).round()); |
| 105 } | 103 } |
| 106 | 104 |
| 107 TEST(WebCoreLayoutUnit, LayoutUnitSnapSizeToPixel) | 105 TEST(LayoutUnitTest, LayoutUnitSnapSizeToPixel) |
| 108 { | 106 { |
| 109 ASSERT_EQ(snapSizeToPixel(LayoutUnit(1), LayoutUnit(0)), 1); | 107 EXPECT_EQ(1, snapSizeToPixel(LayoutUnit(1), LayoutUnit(0))); |
| 110 ASSERT_EQ(snapSizeToPixel(LayoutUnit(1), LayoutUnit(0.5)), 1); | 108 EXPECT_EQ(1, snapSizeToPixel(LayoutUnit(1), LayoutUnit(0.5))); |
| 111 ASSERT_EQ(snapSizeToPixel(LayoutUnit(1.5), LayoutUnit(0)), 2); | 109 EXPECT_EQ(2, snapSizeToPixel(LayoutUnit(1.5), LayoutUnit(0))); |
| 112 ASSERT_EQ(snapSizeToPixel(LayoutUnit(1.5), LayoutUnit(0.49)), 2); | 110 EXPECT_EQ(2, snapSizeToPixel(LayoutUnit(1.5), LayoutUnit(0.49))); |
| 113 ASSERT_EQ(snapSizeToPixel(LayoutUnit(1.5), LayoutUnit(0.5)), 1); | 111 EXPECT_EQ(1, snapSizeToPixel(LayoutUnit(1.5), LayoutUnit(0.5))); |
| 114 ASSERT_EQ(snapSizeToPixel(LayoutUnit(1.5), LayoutUnit(0.75)), 1); | 112 EXPECT_EQ(1, snapSizeToPixel(LayoutUnit(1.5), LayoutUnit(0.75))); |
| 115 ASSERT_EQ(snapSizeToPixel(LayoutUnit(1.5), LayoutUnit(0.99)), 1); | 113 EXPECT_EQ(1, snapSizeToPixel(LayoutUnit(1.5), LayoutUnit(0.99))); |
| 116 ASSERT_EQ(snapSizeToPixel(LayoutUnit(1.5), LayoutUnit(1)), 2); | 114 EXPECT_EQ(2, snapSizeToPixel(LayoutUnit(1.5), LayoutUnit(1))); |
| 117 | 115 |
| 118 ASSERT_EQ(snapSizeToPixel(LayoutUnit(0.5), LayoutUnit(1.5)), 0); | 116 EXPECT_EQ(0, snapSizeToPixel(LayoutUnit(0.5), LayoutUnit(1.5))); |
| 119 ASSERT_EQ(snapSizeToPixel(LayoutUnit(0.99), LayoutUnit(1.5)), 0); | 117 EXPECT_EQ(0, snapSizeToPixel(LayoutUnit(0.99), LayoutUnit(1.5))); |
| 120 ASSERT_EQ(snapSizeToPixel(LayoutUnit(1.0), LayoutUnit(1.5)), 1); | 118 EXPECT_EQ(1, snapSizeToPixel(LayoutUnit(1.0), LayoutUnit(1.5))); |
| 121 ASSERT_EQ(snapSizeToPixel(LayoutUnit(1.49), LayoutUnit(1.5)), 1); | 119 EXPECT_EQ(1, snapSizeToPixel(LayoutUnit(1.49), LayoutUnit(1.5))); |
| 122 ASSERT_EQ(snapSizeToPixel(LayoutUnit(1.5), LayoutUnit(1.5)), 1); | 120 EXPECT_EQ(1, snapSizeToPixel(LayoutUnit(1.5), LayoutUnit(1.5))); |
| 123 | 121 |
| 124 ASSERT_EQ(snapSizeToPixel(LayoutUnit(100.5), LayoutUnit(100)), 101); | 122 EXPECT_EQ(101, snapSizeToPixel(LayoutUnit(100.5), LayoutUnit(100))); |
| 125 ASSERT_EQ(snapSizeToPixel(LayoutUnit(intMaxForLayoutUnit), LayoutUnit(0.3)),
intMaxForLayoutUnit); | 123 EXPECT_EQ(intMaxForLayoutUnit, snapSizeToPixel(LayoutUnit(intMaxForLayoutUni
t), LayoutUnit(0.3))); |
| 126 ASSERT_EQ(snapSizeToPixel(LayoutUnit(intMinForLayoutUnit), LayoutUnit(-0.3))
, intMinForLayoutUnit); | 124 EXPECT_EQ(intMinForLayoutUnit, snapSizeToPixel(LayoutUnit(intMinForLayoutUni
t), LayoutUnit(-0.3))); |
| 127 } | 125 } |
| 128 | 126 |
| 129 TEST(WebCoreLayoutUnit, LayoutUnitMultiplication) | 127 TEST(LayoutUnitTest, LayoutUnitMultiplication) |
| 130 { | 128 { |
| 131 ASSERT_EQ((LayoutUnit(1) * LayoutUnit(1)).toInt(), 1); | 129 EXPECT_EQ(1, (LayoutUnit(1) * LayoutUnit(1)).toInt()); |
| 132 ASSERT_EQ((LayoutUnit(1) * LayoutUnit(2)).toInt(), 2); | 130 EXPECT_EQ(2, (LayoutUnit(1) * LayoutUnit(2)).toInt()); |
| 133 ASSERT_EQ((LayoutUnit(2) * LayoutUnit(1)).toInt(), 2); | 131 EXPECT_EQ(2, (LayoutUnit(2) * LayoutUnit(1)).toInt()); |
| 134 ASSERT_EQ((LayoutUnit(2) * LayoutUnit(0.5)).toInt(), 1); | 132 EXPECT_EQ(1, (LayoutUnit(2) * LayoutUnit(0.5)).toInt()); |
| 135 ASSERT_EQ((LayoutUnit(0.5) * LayoutUnit(2)).toInt(), 1); | 133 EXPECT_EQ(1, (LayoutUnit(0.5) * LayoutUnit(2)).toInt()); |
| 136 ASSERT_EQ((LayoutUnit(100) * LayoutUnit(1)).toInt(), 100); | 134 EXPECT_EQ(100, (LayoutUnit(100) * LayoutUnit(1)).toInt()); |
| 137 | 135 |
| 138 ASSERT_EQ((LayoutUnit(-1) * LayoutUnit(1)).toInt(), -1); | 136 EXPECT_EQ(-1, (LayoutUnit(-1) * LayoutUnit(1)).toInt()); |
| 139 ASSERT_EQ((LayoutUnit(-1) * LayoutUnit(2)).toInt(), -2); | 137 EXPECT_EQ(-2, (LayoutUnit(-1) * LayoutUnit(2)).toInt()); |
| 140 ASSERT_EQ((LayoutUnit(-2) * LayoutUnit(1)).toInt(), -2); | 138 EXPECT_EQ(-2, (LayoutUnit(-2) * LayoutUnit(1)).toInt()); |
| 141 ASSERT_EQ((LayoutUnit(-2) * LayoutUnit(0.5)).toInt(), -1); | 139 EXPECT_EQ(-1, (LayoutUnit(-2) * LayoutUnit(0.5)).toInt()); |
| 142 ASSERT_EQ((LayoutUnit(-0.5) * LayoutUnit(2)).toInt(), -1); | 140 EXPECT_EQ(-1, (LayoutUnit(-0.5) * LayoutUnit(2)).toInt()); |
| 143 ASSERT_EQ((LayoutUnit(-100) * LayoutUnit(1)).toInt(), -100); | 141 EXPECT_EQ(-100, (LayoutUnit(-100) * LayoutUnit(1)).toInt()); |
| 144 | 142 |
| 145 ASSERT_EQ((LayoutUnit(-1) * LayoutUnit(-1)).toInt(), 1); | 143 EXPECT_EQ(1, (LayoutUnit(-1) * LayoutUnit(-1)).toInt()); |
| 146 ASSERT_EQ((LayoutUnit(-1) * LayoutUnit(-2)).toInt(), 2); | 144 EXPECT_EQ(2, (LayoutUnit(-1) * LayoutUnit(-2)).toInt()); |
| 147 ASSERT_EQ((LayoutUnit(-2) * LayoutUnit(-1)).toInt(), 2); | 145 EXPECT_EQ(2, (LayoutUnit(-2) * LayoutUnit(-1)).toInt()); |
| 148 ASSERT_EQ((LayoutUnit(-2) * LayoutUnit(-0.5)).toInt(), 1); | 146 EXPECT_EQ(1, (LayoutUnit(-2) * LayoutUnit(-0.5)).toInt()); |
| 149 ASSERT_EQ((LayoutUnit(-0.5) * LayoutUnit(-2)).toInt(), 1); | 147 EXPECT_EQ(1, (LayoutUnit(-0.5) * LayoutUnit(-2)).toInt()); |
| 150 ASSERT_EQ((LayoutUnit(-100) * LayoutUnit(-1)).toInt(), 100); | 148 EXPECT_EQ(100, (LayoutUnit(-100) * LayoutUnit(-1)).toInt()); |
| 151 | 149 |
| 152 ASSERT_EQ((LayoutUnit(100) * LayoutUnit(3.33)).round(), 333); | 150 EXPECT_EQ(333, (LayoutUnit(100) * LayoutUnit(3.33)).round()); |
| 153 ASSERT_EQ((LayoutUnit(-100) * LayoutUnit(3.33)).round(), -333); | 151 EXPECT_EQ(-333, (LayoutUnit(-100) * LayoutUnit(3.33)).round()); |
| 154 ASSERT_EQ((LayoutUnit(-100) * LayoutUnit(-3.33)).round(), 333); | 152 EXPECT_EQ(333, (LayoutUnit(-100) * LayoutUnit(-3.33)).round()); |
| 155 | 153 |
| 156 size_t aHundredSizeT = 100; | 154 size_t aHundredSizeT = 100; |
| 157 ASSERT_EQ((LayoutUnit(aHundredSizeT) * LayoutUnit(1)).toInt(), 100); | 155 EXPECT_EQ(100, (LayoutUnit(aHundredSizeT) * LayoutUnit(1)).toInt()); |
| 158 ASSERT_EQ((aHundredSizeT * LayoutUnit(4)).toInt(), 400); | 156 EXPECT_EQ(400, (aHundredSizeT * LayoutUnit(4)).toInt()); |
| 159 ASSERT_EQ((LayoutUnit(4) * aHundredSizeT).toInt(), 400); | 157 EXPECT_EQ(400, (LayoutUnit(4) * aHundredSizeT).toInt()); |
| 160 | 158 |
| 161 int quarterMax = intMaxForLayoutUnit / 4; | 159 int quarterMax = intMaxForLayoutUnit / 4; |
| 162 ASSERT_EQ((LayoutUnit(quarterMax) * LayoutUnit(2)).toInt(), quarterMax * 2); | 160 EXPECT_EQ(quarterMax * 2, (LayoutUnit(quarterMax) * LayoutUnit(2)).toInt()); |
| 163 ASSERT_EQ((LayoutUnit(quarterMax) * LayoutUnit(3)).toInt(), quarterMax * 3); | 161 EXPECT_EQ(quarterMax * 3, (LayoutUnit(quarterMax) * LayoutUnit(3)).toInt()); |
| 164 ASSERT_EQ((LayoutUnit(quarterMax) * LayoutUnit(4)).toInt(), quarterMax * 4); | 162 EXPECT_EQ(quarterMax * 4, (LayoutUnit(quarterMax) * LayoutUnit(4)).toInt()); |
| 165 ASSERT_EQ((LayoutUnit(quarterMax) * LayoutUnit(5)).toInt(), intMaxForLayoutU
nit); | 163 EXPECT_EQ(intMaxForLayoutUnit, (LayoutUnit(quarterMax) * LayoutUnit(5)).toIn
t()); |
| 166 | 164 |
| 167 size_t overflowIntSizeT = intMaxForLayoutUnit * 4; | 165 size_t overflowIntSizeT = intMaxForLayoutUnit * 4; |
| 168 ASSERT_EQ((LayoutUnit(overflowIntSizeT) * LayoutUnit(2)).toInt(), intMaxForL
ayoutUnit); | 166 EXPECT_EQ(intMaxForLayoutUnit, (LayoutUnit(overflowIntSizeT) * LayoutUnit(2)
).toInt()); |
| 169 ASSERT_EQ((overflowIntSizeT * LayoutUnit(4)).toInt(), intMaxForLayoutUnit); | 167 EXPECT_EQ(intMaxForLayoutUnit, (overflowIntSizeT * LayoutUnit(4)).toInt()); |
| 170 ASSERT_EQ((LayoutUnit(4) * overflowIntSizeT).toInt(), intMaxForLayoutUnit); | 168 EXPECT_EQ(intMaxForLayoutUnit, (LayoutUnit(4) * overflowIntSizeT).toInt()); |
| 171 } | 169 } |
| 172 | 170 |
| 173 TEST(WebCoreLayoutUnit, LayoutUnitDivision) | 171 TEST(LayoutUnitTest, LayoutUnitDivision) |
| 174 { | 172 { |
| 175 ASSERT_EQ((LayoutUnit(1) / LayoutUnit(1)).toInt(), 1); | 173 EXPECT_EQ(1, (LayoutUnit(1) / LayoutUnit(1)).toInt()); |
| 176 ASSERT_EQ((LayoutUnit(1) / LayoutUnit(2)).toInt(), 0); | 174 EXPECT_EQ(0, (LayoutUnit(1) / LayoutUnit(2)).toInt()); |
| 177 ASSERT_EQ((LayoutUnit(2) / LayoutUnit(1)).toInt(), 2); | 175 EXPECT_EQ(2, (LayoutUnit(2) / LayoutUnit(1)).toInt()); |
| 178 ASSERT_EQ((LayoutUnit(2) / LayoutUnit(0.5)).toInt(), 4); | 176 EXPECT_EQ(4, (LayoutUnit(2) / LayoutUnit(0.5)).toInt()); |
| 179 ASSERT_EQ((LayoutUnit(0.5) / LayoutUnit(2)).toInt(), 0); | 177 EXPECT_EQ(0, (LayoutUnit(0.5) / LayoutUnit(2)).toInt()); |
| 180 ASSERT_EQ((LayoutUnit(100) / LayoutUnit(10)).toInt(), 10); | 178 EXPECT_EQ(10, (LayoutUnit(100) / LayoutUnit(10)).toInt()); |
| 181 ASSERT_FLOAT_EQ((LayoutUnit(1) / LayoutUnit(2)).toFloat(), 0.5f); | 179 EXPECT_FLOAT_EQ(0.5f, (LayoutUnit(1) / LayoutUnit(2)).toFloat()); |
| 182 ASSERT_FLOAT_EQ((LayoutUnit(0.5) / LayoutUnit(2)).toFloat(), 0.25f); | 180 EXPECT_FLOAT_EQ(0.25f, (LayoutUnit(0.5) / LayoutUnit(2)).toFloat()); |
| 183 | 181 |
| 184 ASSERT_EQ((LayoutUnit(-1) / LayoutUnit(1)).toInt(), -1); | 182 EXPECT_EQ(-1, (LayoutUnit(-1) / LayoutUnit(1)).toInt()); |
| 185 ASSERT_EQ((LayoutUnit(-1) / LayoutUnit(2)).toInt(), 0); | 183 EXPECT_EQ(0, (LayoutUnit(-1) / LayoutUnit(2)).toInt()); |
| 186 ASSERT_EQ((LayoutUnit(-2) / LayoutUnit(1)).toInt(), -2); | 184 EXPECT_EQ(-2, (LayoutUnit(-2) / LayoutUnit(1)).toInt()); |
| 187 ASSERT_EQ((LayoutUnit(-2) / LayoutUnit(0.5)).toInt(), -4); | 185 EXPECT_EQ(-4, (LayoutUnit(-2) / LayoutUnit(0.5)).toInt()); |
| 188 ASSERT_EQ((LayoutUnit(-0.5) / LayoutUnit(2)).toInt(), 0); | 186 EXPECT_EQ(0, (LayoutUnit(-0.5) / LayoutUnit(2)).toInt()); |
| 189 ASSERT_EQ((LayoutUnit(-100) / LayoutUnit(10)).toInt(), -10); | 187 EXPECT_EQ(-10, (LayoutUnit(-100) / LayoutUnit(10)).toInt()); |
| 190 ASSERT_FLOAT_EQ((LayoutUnit(-1) / LayoutUnit(2)).toFloat(), -0.5f); | 188 EXPECT_FLOAT_EQ(-0.5f, (LayoutUnit(-1) / LayoutUnit(2)).toFloat()); |
| 191 ASSERT_FLOAT_EQ((LayoutUnit(-0.5) / LayoutUnit(2)).toFloat(), -0.25f); | 189 EXPECT_FLOAT_EQ(-0.25f, (LayoutUnit(-0.5) / LayoutUnit(2)).toFloat()); |
| 192 | 190 |
| 193 ASSERT_EQ((LayoutUnit(-1) / LayoutUnit(-1)).toInt(), 1); | 191 EXPECT_EQ(1, (LayoutUnit(-1) / LayoutUnit(-1)).toInt()); |
| 194 ASSERT_EQ((LayoutUnit(-1) / LayoutUnit(-2)).toInt(), 0); | 192 EXPECT_EQ(0, (LayoutUnit(-1) / LayoutUnit(-2)).toInt()); |
| 195 ASSERT_EQ((LayoutUnit(-2) / LayoutUnit(-1)).toInt(), 2); | 193 EXPECT_EQ(2, (LayoutUnit(-2) / LayoutUnit(-1)).toInt()); |
| 196 ASSERT_EQ((LayoutUnit(-2) / LayoutUnit(-0.5)).toInt(), 4); | 194 EXPECT_EQ(4, (LayoutUnit(-2) / LayoutUnit(-0.5)).toInt()); |
| 197 ASSERT_EQ((LayoutUnit(-0.5) / LayoutUnit(-2)).toInt(), 0); | 195 EXPECT_EQ(0, (LayoutUnit(-0.5) / LayoutUnit(-2)).toInt()); |
| 198 ASSERT_EQ((LayoutUnit(-100) / LayoutUnit(-10)).toInt(), 10); | 196 EXPECT_EQ(10, (LayoutUnit(-100) / LayoutUnit(-10)).toInt()); |
| 199 ASSERT_FLOAT_EQ((LayoutUnit(-1) / LayoutUnit(-2)).toFloat(), 0.5f); | 197 EXPECT_FLOAT_EQ(0.5f, (LayoutUnit(-1) / LayoutUnit(-2)).toFloat()); |
| 200 ASSERT_FLOAT_EQ((LayoutUnit(-0.5) / LayoutUnit(-2)).toFloat(), 0.25f); | 198 EXPECT_FLOAT_EQ(0.25f, (LayoutUnit(-0.5) / LayoutUnit(-2)).toFloat()); |
| 201 | 199 |
| 202 size_t aHundredSizeT = 100; | 200 size_t aHundredSizeT = 100; |
| 203 ASSERT_EQ((LayoutUnit(aHundredSizeT) / LayoutUnit(2)).toInt(), 50); | 201 EXPECT_EQ(50, (LayoutUnit(aHundredSizeT) / LayoutUnit(2)).toInt()); |
| 204 ASSERT_EQ((aHundredSizeT / LayoutUnit(4)).toInt(), 25); | 202 EXPECT_EQ(25, (aHundredSizeT / LayoutUnit(4)).toInt()); |
| 205 ASSERT_EQ((LayoutUnit(400) / aHundredSizeT).toInt(), 4); | 203 EXPECT_EQ(4, (LayoutUnit(400) / aHundredSizeT).toInt()); |
| 206 | 204 |
| 207 ASSERT_EQ((LayoutUnit(intMaxForLayoutUnit) / LayoutUnit(2)).toInt(), intMaxF
orLayoutUnit / 2); | 205 EXPECT_EQ(intMaxForLayoutUnit / 2, (LayoutUnit(intMaxForLayoutUnit) / Layout
Unit(2)).toInt()); |
| 208 ASSERT_EQ((LayoutUnit(intMaxForLayoutUnit) / LayoutUnit(0.5)).toInt(), intMa
xForLayoutUnit); | 206 EXPECT_EQ(intMaxForLayoutUnit, (LayoutUnit(intMaxForLayoutUnit) / LayoutUnit
(0.5)).toInt()); |
| 209 } | 207 } |
| 210 | 208 |
| 211 TEST(WebCoreLayoutUnit, LayoutUnitCeil) | 209 TEST(LayoutUnitTest, LayoutUnitCeil) |
| 212 { | 210 { |
| 213 ASSERT_EQ(LayoutUnit(0).ceil(), 0); | 211 EXPECT_EQ(0, LayoutUnit(0).ceil()); |
| 214 ASSERT_EQ(LayoutUnit(0.1).ceil(), 1); | 212 EXPECT_EQ(1, LayoutUnit(0.1).ceil()); |
| 215 ASSERT_EQ(LayoutUnit(0.5).ceil(), 1); | 213 EXPECT_EQ(1, LayoutUnit(0.5).ceil()); |
| 216 ASSERT_EQ(LayoutUnit(0.9).ceil(), 1); | 214 EXPECT_EQ(1, LayoutUnit(0.9).ceil()); |
| 217 ASSERT_EQ(LayoutUnit(1.0).ceil(), 1); | 215 EXPECT_EQ(1, LayoutUnit(1.0).ceil()); |
| 218 ASSERT_EQ(LayoutUnit(1.1).ceil(), 2); | 216 EXPECT_EQ(2, LayoutUnit(1.1).ceil()); |
| 219 | 217 |
| 220 ASSERT_EQ(LayoutUnit(-0.1).ceil(), 0); | 218 EXPECT_EQ(0, LayoutUnit(-0.1).ceil()); |
| 221 ASSERT_EQ(LayoutUnit(-0.5).ceil(), 0); | 219 EXPECT_EQ(0, LayoutUnit(-0.5).ceil()); |
| 222 ASSERT_EQ(LayoutUnit(-0.9).ceil(), 0); | 220 EXPECT_EQ(0, LayoutUnit(-0.9).ceil()); |
| 223 ASSERT_EQ(LayoutUnit(-1.0).ceil(), -1); | 221 EXPECT_EQ(-1, LayoutUnit(-1.0).ceil()); |
| 224 | 222 |
| 225 ASSERT_EQ(LayoutUnit(intMaxForLayoutUnit).ceil(), intMaxForLayoutUnit); | 223 EXPECT_EQ(intMaxForLayoutUnit, LayoutUnit(intMaxForLayoutUnit).ceil()); |
| 226 ASSERT_EQ((LayoutUnit(intMaxForLayoutUnit) - LayoutUnit(0.5)).ceil(), intMax
ForLayoutUnit); | 224 EXPECT_EQ(intMaxForLayoutUnit, (LayoutUnit(intMaxForLayoutUnit) - LayoutUnit
(0.5)).ceil()); |
| 227 ASSERT_EQ((LayoutUnit(intMaxForLayoutUnit) - LayoutUnit(1)).ceil(), intMaxFo
rLayoutUnit - 1); | 225 EXPECT_EQ(intMaxForLayoutUnit - 1, (LayoutUnit(intMaxForLayoutUnit) - Layout
Unit(1)).ceil()); |
| 228 | 226 |
| 229 ASSERT_EQ(LayoutUnit(intMinForLayoutUnit).ceil(), intMinForLayoutUnit); | 227 EXPECT_EQ(intMinForLayoutUnit, LayoutUnit(intMinForLayoutUnit).ceil()); |
| 230 } | 228 } |
| 231 | 229 |
| 232 TEST(WebCoreLayoutUnit, LayoutUnitFloor) | 230 TEST(LayoutUnitTest, LayoutUnitFloor) |
| 233 { | 231 { |
| 234 ASSERT_EQ(LayoutUnit(0).floor(), 0); | 232 EXPECT_EQ(0, LayoutUnit(0).floor()); |
| 235 ASSERT_EQ(LayoutUnit(0.1).floor(), 0); | 233 EXPECT_EQ(0, LayoutUnit(0.1).floor()); |
| 236 ASSERT_EQ(LayoutUnit(0.5).floor(), 0); | 234 EXPECT_EQ(0, LayoutUnit(0.5).floor()); |
| 237 ASSERT_EQ(LayoutUnit(0.9).floor(), 0); | 235 EXPECT_EQ(0, LayoutUnit(0.9).floor()); |
| 238 ASSERT_EQ(LayoutUnit(1.0).floor(), 1); | 236 EXPECT_EQ(1, LayoutUnit(1.0).floor()); |
| 239 ASSERT_EQ(LayoutUnit(1.1).floor(), 1); | 237 EXPECT_EQ(1, LayoutUnit(1.1).floor()); |
| 240 | 238 |
| 241 ASSERT_EQ(LayoutUnit(-0.1).floor(), -1); | 239 EXPECT_EQ(-1, LayoutUnit(-0.1).floor()); |
| 242 ASSERT_EQ(LayoutUnit(-0.5).floor(), -1); | 240 EXPECT_EQ(-1, LayoutUnit(-0.5).floor()); |
| 243 ASSERT_EQ(LayoutUnit(-0.9).floor(), -1); | 241 EXPECT_EQ(-1, LayoutUnit(-0.9).floor()); |
| 244 ASSERT_EQ(LayoutUnit(-1.0).floor(), -1); | 242 EXPECT_EQ(-1, LayoutUnit(-1.0).floor()); |
| 245 | 243 |
| 246 ASSERT_EQ(LayoutUnit(intMaxForLayoutUnit).floor(), intMaxForLayoutUnit); | 244 EXPECT_EQ(intMaxForLayoutUnit, LayoutUnit(intMaxForLayoutUnit).floor()); |
| 247 | 245 |
| 248 ASSERT_EQ(LayoutUnit(intMinForLayoutUnit).floor(), intMinForLayoutUnit); | 246 EXPECT_EQ(intMinForLayoutUnit, LayoutUnit(intMinForLayoutUnit).floor()); |
| 249 ASSERT_EQ((LayoutUnit(intMinForLayoutUnit) + LayoutUnit(0.5)).floor(), intMi
nForLayoutUnit); | 247 EXPECT_EQ(intMinForLayoutUnit, (LayoutUnit(intMinForLayoutUnit) + LayoutUnit
(0.5)).floor()); |
| 250 ASSERT_EQ((LayoutUnit(intMinForLayoutUnit) + LayoutUnit(1)).floor(), intMinF
orLayoutUnit + 1); | 248 EXPECT_EQ(intMinForLayoutUnit + 1, (LayoutUnit(intMinForLayoutUnit) + Layout
Unit(1)).floor()); |
| 251 } | 249 } |
| 252 | 250 |
| 253 TEST(WebCoreLayoutUnit, LayoutUnitFloatOverflow) | 251 TEST(LayoutUnitTest, LayoutUnitFloatOverflow) |
| 254 { | 252 { |
| 255 // These should overflow to the max/min according to their sign. | 253 // These should overflow to the max/min according to their sign. |
| 256 ASSERT_EQ(intMaxForLayoutUnit, LayoutUnit(176972000.0f).toInt()); | 254 EXPECT_EQ(intMaxForLayoutUnit, LayoutUnit(176972000.0f).toInt()); |
| 257 ASSERT_EQ(intMinForLayoutUnit, LayoutUnit(-176972000.0f).toInt()); | 255 EXPECT_EQ(intMinForLayoutUnit, LayoutUnit(-176972000.0f).toInt()); |
| 258 ASSERT_EQ(intMaxForLayoutUnit, LayoutUnit(176972000.0).toInt()); | 256 EXPECT_EQ(intMaxForLayoutUnit, LayoutUnit(176972000.0).toInt()); |
| 259 ASSERT_EQ(intMinForLayoutUnit, LayoutUnit(-176972000.0).toInt()); | 257 EXPECT_EQ(intMinForLayoutUnit, LayoutUnit(-176972000.0).toInt()); |
| 260 } | 258 } |
| 261 | 259 |
| 262 } // namespace | 260 } // namespace blink |
| OLD | NEW |