Log Message
Clamp values in LayoutUnit::operator/ when SATURATED_LAYOUT_ARITHMETIC is enabled https://bugs.webkit.org/show_bug.cgi?id=104955
Reviewed by Julien Chaffraix. Source/WebCore: LayoutUnit::operator/ currently does not clamp values and instead overflows when given a value greater than INT_MAX or less than INT_MIN. Test: TestWebKitAPI/Tests/WebCore/LayoutUnit.cpp * platform/LayoutUnit.h: (WebCore::operator/): Clamp value if SATURATED_LAYOUT_ARITHMETIC is enabled. Tools: Add tests for LayoutUnit. * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/ForwardingHeaders: Added. * TestWebKitAPI/ForwardingHeaders/WebCore: Added. * TestWebKitAPI/ForwardingHeaders/WebCore/LayoutUnit.h: Added. * TestWebKitAPI/TestWebKitAPI.gyp/TestWebKitAPI.gyp: * TestWebKitAPI/TestWebKitAPI.gypi: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WebCore/LayoutUnit.cpp: Added. (TestWebKitAPI): (TestWebKitAPI::TEST): * TestWebKitAPI/win/TestWebKitAPI.vcproj:
Modified Paths
- trunk/Source/WebCore/ChangeLog
- trunk/Source/WebCore/platform/LayoutUnit.h
- trunk/Tools/ChangeLog
- trunk/Tools/TestWebKitAPI/CMakeLists.txt
- trunk/Tools/TestWebKitAPI/TestWebKitAPI.gyp/TestWebKitAPI.gyp
- trunk/Tools/TestWebKitAPI/TestWebKitAPI.gypi
- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
- trunk/Tools/TestWebKitAPI/win/TestWebKitAPI.vcproj
Added Paths
- trunk/Tools/TestWebKitAPI/ForwardingHeaders/
- trunk/Tools/TestWebKitAPI/ForwardingHeaders/WebCore/
- trunk/Tools/TestWebKitAPI/ForwardingHeaders/WebCore/LayoutUnit.h
- trunk/Tools/TestWebKitAPI/Tests/WebCore/LayoutUnit.cpp
Diff
Modified: trunk/Source/WebCore/ChangeLog (137923 => 137924)
--- trunk/Source/WebCore/ChangeLog 2012-12-17 18:59:26 UTC (rev 137923)
+++ trunk/Source/WebCore/ChangeLog 2012-12-17 19:12:45 UTC (rev 137924)
@@ -1,3 +1,20 @@
+2012-12-17 Emil A Eklund <[email protected]>
+
+ Clamp values in LayoutUnit::operator/ when SATURATED_LAYOUT_ARITHMETIC is enabled
+ https://bugs.webkit.org/show_bug.cgi?id=104955
+
+ Reviewed by Julien Chaffraix.
+
+ LayoutUnit::operator/ currently does not clamp values and
+ instead overflows when given a value greater than INT_MAX or
+ less than INT_MIN.
+
+ Test: TestWebKitAPI/Tests/WebCore/LayoutUnit.cpp
+
+ * platform/LayoutUnit.h:
+ (WebCore::operator/):
+ Clamp value if SATURATED_LAYOUT_ARITHMETIC is enabled.
+
2012-12-17 Simon Fraser <[email protected]>
Don't allow edge TileCache tiles to be larger than necessary
Modified: trunk/Source/WebCore/platform/LayoutUnit.h (137923 => 137924)
--- trunk/Source/WebCore/platform/LayoutUnit.h 2012-12-17 18:59:26 UTC (rev 137923)
+++ trunk/Source/WebCore/platform/LayoutUnit.h 2012-12-17 19:12:45 UTC (rev 137924)
@@ -553,7 +553,11 @@
#if ENABLE(SUBPIXEL_LAYOUT)
LayoutUnit returnVal;
long long rawVal = static_cast<long long>(kFixedPointDenominator) * a.rawValue() / b.rawValue();
+#if ENABLE(SATURATED_LAYOUT_ARITHMETIC)
+ returnVal.setRawValue(clampTo<int>(rawVal));
+#else
returnVal.setRawValue(rawVal);
+#endif
return returnVal;
#else
return a.rawValue() / b.rawValue();
Modified: trunk/Tools/ChangeLog (137923 => 137924)
--- trunk/Tools/ChangeLog 2012-12-17 18:59:26 UTC (rev 137923)
+++ trunk/Tools/ChangeLog 2012-12-17 19:12:45 UTC (rev 137924)
@@ -1,3 +1,24 @@
+2012-12-17 Emil A Eklund <[email protected]>
+
+ Clamp values in LayoutUnit::operator/ when SATURATED_LAYOUT_ARITHMETIC is enabled
+ https://bugs.webkit.org/show_bug.cgi?id=104955
+
+ Reviewed by Julien Chaffraix.
+
+ Add tests for LayoutUnit.
+
+ * TestWebKitAPI/CMakeLists.txt:
+ * TestWebKitAPI/ForwardingHeaders: Added.
+ * TestWebKitAPI/ForwardingHeaders/WebCore: Added.
+ * TestWebKitAPI/ForwardingHeaders/WebCore/LayoutUnit.h: Added.
+ * TestWebKitAPI/TestWebKitAPI.gyp/TestWebKitAPI.gyp:
+ * TestWebKitAPI/TestWebKitAPI.gypi:
+ * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+ * TestWebKitAPI/Tests/WebCore/LayoutUnit.cpp: Added.
+ (TestWebKitAPI):
+ (TestWebKitAPI::TEST):
+ * TestWebKitAPI/win/TestWebKitAPI.vcproj:
+
2012-12-17 Jochen Eisinger <[email protected]>
[chromium] removed unused preferences from testRunner.overridePreference
Modified: trunk/Tools/TestWebKitAPI/CMakeLists.txt (137923 => 137924)
--- trunk/Tools/TestWebKitAPI/CMakeLists.txt 2012-12-17 18:59:26 UTC (rev 137923)
+++ trunk/Tools/TestWebKitAPI/CMakeLists.txt 2012-12-17 19:12:45 UTC (rev 137924)
@@ -104,6 +104,7 @@
${test_main_SOURCES}
${TESTWEBKITAPI_DIR}/TestsController.cpp
${TESTWEBKITAPI_DIR}/Tests/WebCore/KURL.cpp
+ ${TESTWEBKITAPI_DIR}/Tests/WebCore/LayoutUnit.cpp
)
target_link_libraries(test_webcore ${test_webcore_LIBRARIES})
Added: trunk/Tools/TestWebKitAPI/ForwardingHeaders/WebCore/LayoutUnit.h (0 => 137924)
--- trunk/Tools/TestWebKitAPI/ForwardingHeaders/WebCore/LayoutUnit.h (rev 0)
+++ trunk/Tools/TestWebKitAPI/ForwardingHeaders/WebCore/LayoutUnit.h 2012-12-17 19:12:45 UTC (rev 137924)
@@ -0,0 +1,4 @@
+#ifndef TestWebKitAPI_FWD_LayoutUnit_h
+#define TestWebKitAPI_FWD_LayoutUnit_h
+#include <LayoutUnit.h>
+#endif
Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.gyp/TestWebKitAPI.gyp (137923 => 137924)
--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.gyp/TestWebKitAPI.gyp 2012-12-17 18:59:26 UTC (rev 137923)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.gyp/TestWebKitAPI.gyp 2012-12-17 19:12:45 UTC (rev 137924)
@@ -54,6 +54,7 @@
'target_name': 'TestWebKitAPI',
'type': 'executable',
'dependencies': [
+ '<(source_dir)/WebCore/WebCore.gyp/WebCore.gyp:webcore',
'<(source_dir)/WebKit/chromium/WebKit.gyp:webkit',
'<(source_dir)/WTF/WTF.gyp/WTF.gyp:wtf',
'<(chromium_src_dir)/build/temp_gyp/googleurl.gyp:googleurl',
@@ -68,6 +69,7 @@
# Needed by tests/RunAllTests.cpp, as well as ChromiumCurrentTime.cpp and
# ChromiumThreading.cpp in chromium shared library configuration.
'<(source_dir)/WebKit/chromium/public',
+ '<(tools_dir)/TestWebKitAPI/ForwardingHeaders',
],
'sources': [
# Reuse the same testing driver of Chromium's webkit_unit_tests.
Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.gypi (137923 => 137924)
--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.gypi 2012-12-17 18:59:26 UTC (rev 137923)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.gypi 2012-12-17 19:12:45 UTC (rev 137924)
@@ -31,6 +31,7 @@
{
'variables': {
'TestWebKitAPI_files': [
+ 'Tests/WebCore/LayoutUnit.cpp',
'Tests/WTF/AtomicString.cpp',
'Tests/WTF/CheckedArithmeticOperations.cpp',
'Tests/WTF/CString.cpp',
Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (137923 => 137924)
--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2012-12-17 18:59:26 UTC (rev 137923)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2012-12-17 19:12:45 UTC (rev 137924)
@@ -13,6 +13,7 @@
0F17BBD615AF6C4D007AB753 /* WebCoreStatisticsWithNoWebProcess.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0F17BBD415AF6C4D007AB753 /* WebCoreStatisticsWithNoWebProcess.cpp */; };
0FC6C4CC141027E0005B7F0C /* RedBlackTree.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0FC6C4CB141027E0005B7F0C /* RedBlackTree.cpp */; };
0FC6C4CF141034AD005B7F0C /* MetaAllocator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0FC6C4CE141034AD005B7F0C /* MetaAllocator.cpp */; };
+ 14464013167A8305000BD218 /* LayoutUnit.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 14464012167A8305000BD218 /* LayoutUnit.cpp */; };
14F3B11315E45EAB00210069 /* SaturatedArithmeticOperations.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 14F3B11215E45EAB00210069 /* SaturatedArithmeticOperations.cpp */; };
1A02C84F125D4A8400E3F4BD /* Find.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A02C84E125D4A8400E3F4BD /* Find.cpp */; };
1A02C870125D4CFD00E3F4BD /* find.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 1A02C84B125D4A5E00E3F4BD /* find.html */; };
@@ -259,6 +260,7 @@
0F17BBD415AF6C4D007AB753 /* WebCoreStatisticsWithNoWebProcess.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebCoreStatisticsWithNoWebProcess.cpp; sourceTree = "<group>"; };
0FC6C4CB141027E0005B7F0C /* RedBlackTree.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = RedBlackTree.cpp; path = WTF/RedBlackTree.cpp; sourceTree = "<group>"; };
0FC6C4CE141034AD005B7F0C /* MetaAllocator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = MetaAllocator.cpp; path = WTF/MetaAllocator.cpp; sourceTree = "<group>"; };
+ 14464012167A8305000BD218 /* LayoutUnit.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LayoutUnit.cpp; sourceTree = "<group>"; };
14F3B11215E45EAB00210069 /* SaturatedArithmeticOperations.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SaturatedArithmeticOperations.cpp; path = WTF/SaturatedArithmeticOperations.cpp; sourceTree = "<group>"; };
1A02C84B125D4A5E00E3F4BD /* find.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = find.html; sourceTree = "<group>"; };
1A02C84E125D4A8400E3F4BD /* Find.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Find.cpp; sourceTree = "<group>"; };
@@ -532,6 +534,7 @@
440A1D3614A01000008A66F2 /* WebCore */ = {
isa = PBXGroup;
children = (
+ 14464012167A8305000BD218 /* LayoutUnit.cpp */,
440A1D3814A0103A008A66F2 /* KURL.cpp */,
);
path = WebCore;
@@ -1030,6 +1033,7 @@
FE217ECD1640A54A0052988B /* VMInspector.cpp in Sources */,
29AB8AA1164C735800D49BEC /* CustomProtocolsTest.mm in Sources */,
29AB8AA4164C7A9300D49BEC /* TestBrowsingContextLoadDelegate.mm in Sources */,
+ 14464013167A8305000BD218 /* LayoutUnit.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Added: trunk/Tools/TestWebKitAPI/Tests/WebCore/LayoutUnit.cpp (0 => 137924)
--- trunk/Tools/TestWebKitAPI/Tests/WebCore/LayoutUnit.cpp (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebCore/LayoutUnit.cpp 2012-12-17 19:12:45 UTC (rev 137924)
@@ -0,0 +1,191 @@
+/*
+ * Copyright (c) 2012, Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#define ENABLE_SUBPIXEL_LAYOUT 1
+#define ENABLE_SATURATED_LAYOUT_ARITHMETIC 1
+#include "config.h"
+
+#include <WebCore/LayoutUnit.h>
+
+using namespace WebCore;
+
+namespace TestWebKitAPI {
+
+TEST(WebCore, LayoutUnitInt)
+{
+ ASSERT_EQ(LayoutUnit(INT_MIN).toInt(), intMinForLayoutUnit);
+ ASSERT_EQ(LayoutUnit(INT_MIN / 2).toInt(), intMinForLayoutUnit);
+ ASSERT_EQ(LayoutUnit(intMinForLayoutUnit - 1).toInt(), intMinForLayoutUnit);
+ ASSERT_EQ(LayoutUnit(intMinForLayoutUnit).toInt(), intMinForLayoutUnit);
+ ASSERT_EQ(LayoutUnit(intMinForLayoutUnit + 1).toInt(), intMinForLayoutUnit + 1);
+ ASSERT_EQ(LayoutUnit(intMinForLayoutUnit / 2).toInt(), intMinForLayoutUnit / 2);
+ ASSERT_EQ(LayoutUnit(-10000).toInt(), -10000);
+ ASSERT_EQ(LayoutUnit(-1000).toInt(), -1000);
+ ASSERT_EQ(LayoutUnit(-100).toInt(), -100);
+ ASSERT_EQ(LayoutUnit(-10).toInt(), -10);
+ ASSERT_EQ(LayoutUnit(-1).toInt(), -1);
+ ASSERT_EQ(LayoutUnit(0).toInt(), 0);
+ ASSERT_EQ(LayoutUnit(1).toInt(), 1);
+ ASSERT_EQ(LayoutUnit(100).toInt(), 100);
+ ASSERT_EQ(LayoutUnit(1000).toInt(), 1000);
+ ASSERT_EQ(LayoutUnit(10000).toInt(), 10000);
+ ASSERT_EQ(LayoutUnit(intMaxForLayoutUnit / 2).toInt(), intMaxForLayoutUnit / 2);
+ ASSERT_EQ(LayoutUnit(intMaxForLayoutUnit - 1).toInt(), intMaxForLayoutUnit - 1);
+ ASSERT_EQ(LayoutUnit(intMaxForLayoutUnit).toInt(), intMaxForLayoutUnit);
+ ASSERT_EQ(LayoutUnit(intMaxForLayoutUnit + 1).toInt(), intMaxForLayoutUnit);
+ ASSERT_EQ(LayoutUnit(INT_MAX / 2).toInt(), intMaxForLayoutUnit);
+ ASSERT_EQ(LayoutUnit(INT_MAX).toInt(), intMaxForLayoutUnit);
+}
+
+TEST(WebCore, LayoutUnitFloat)
+{
+ const float tolerance = 1.0f / kFixedPointDenominator;
+ ASSERT_FLOAT_EQ(LayoutUnit(1.0f).toFloat(), 1.0f);
+ ASSERT_FLOAT_EQ(LayoutUnit(1.25f).toFloat(), 1.25f);
+ ASSERT_NEAR(LayoutUnit(1.1f).toFloat(), 1.1f, tolerance);
+ ASSERT_NEAR(LayoutUnit(1.33f).toFloat(), 1.33f, tolerance);
+ ASSERT_NEAR(LayoutUnit(1.3333f).toFloat(), 1.3333f, tolerance);
+ ASSERT_NEAR(LayoutUnit(1.53434f).toFloat(), 1.53434f, tolerance);
+ ASSERT_NEAR(LayoutUnit(345634).toFloat(), 345634.0f, tolerance);
+ ASSERT_NEAR(LayoutUnit(345634.12335f).toFloat(), 345634.12335f, tolerance);
+ ASSERT_NEAR(LayoutUnit(-345634.12335f).toFloat(), -345634.12335f, tolerance);
+ ASSERT_NEAR(LayoutUnit(-345634).toFloat(), -345634.0f, tolerance);
+}
+
+TEST(WebCore, LayoutUnitRounding)
+{
+ ASSERT_EQ(LayoutUnit(-1.5f).round(), -2);
+ ASSERT_EQ(LayoutUnit(-1.49f).round(), -1);
+ ASSERT_EQ(LayoutUnit(-1.0f).round(), -1);
+ ASSERT_EQ(LayoutUnit(-0.99f).round(), -1);
+ ASSERT_EQ(LayoutUnit(-0.50f).round(), -1);
+ ASSERT_EQ(LayoutUnit(-0.49f).round(), 0);
+ ASSERT_EQ(LayoutUnit(-0.1f).round(), 0);
+ ASSERT_EQ(LayoutUnit(0.0f).round(), 0);
+ ASSERT_EQ(LayoutUnit(0.1f).round(), 0);
+ ASSERT_EQ(LayoutUnit(0.49f).round(), 0);
+ ASSERT_EQ(LayoutUnit(0.50f).round(), 1);
+ ASSERT_EQ(LayoutUnit(0.99f).round(), 1);
+ ASSERT_EQ(LayoutUnit(1.0f).round(), 1);
+ ASSERT_EQ(LayoutUnit(1.49f).round(), 1);
+ ASSERT_EQ(LayoutUnit(1.5f).round(), 2);
+}
+
+TEST(WebCore, LayoutUnitSnapSizeToPixel)
+{
+ ASSERT_EQ(snapSizeToPixel(LayoutUnit(1), LayoutUnit(0)), 1);
+ ASSERT_EQ(snapSizeToPixel(LayoutUnit(1), LayoutUnit(0.5)), 1);
+ ASSERT_EQ(snapSizeToPixel(LayoutUnit(1.5), LayoutUnit(0)), 2);
+ ASSERT_EQ(snapSizeToPixel(LayoutUnit(1.5), LayoutUnit(0.49)), 2);
+ ASSERT_EQ(snapSizeToPixel(LayoutUnit(1.5), LayoutUnit(0.5)), 1);
+ ASSERT_EQ(snapSizeToPixel(LayoutUnit(1.5), LayoutUnit(0.75)), 1);
+ ASSERT_EQ(snapSizeToPixel(LayoutUnit(1.5), LayoutUnit(0.99)), 1);
+ ASSERT_EQ(snapSizeToPixel(LayoutUnit(1.5), LayoutUnit(1)), 2);
+
+ ASSERT_EQ(snapSizeToPixel(LayoutUnit(0.5), LayoutUnit(1.5)), 0);
+ ASSERT_EQ(snapSizeToPixel(LayoutUnit(0.99), LayoutUnit(1.5)), 0);
+ ASSERT_EQ(snapSizeToPixel(LayoutUnit(1.0), LayoutUnit(1.5)), 1);
+ ASSERT_EQ(snapSizeToPixel(LayoutUnit(1.49), LayoutUnit(1.5)), 1);
+ ASSERT_EQ(snapSizeToPixel(LayoutUnit(1.5), LayoutUnit(1.5)), 1);
+
+ ASSERT_EQ(snapSizeToPixel(LayoutUnit(100.5), LayoutUnit(100)), 101);
+ ASSERT_EQ(snapSizeToPixel(LayoutUnit(intMaxForLayoutUnit), LayoutUnit(0.3)), intMaxForLayoutUnit);
+ ASSERT_EQ(snapSizeToPixel(LayoutUnit(intMinForLayoutUnit), LayoutUnit(-0.3)), intMinForLayoutUnit);
+}
+
+TEST(WebCore, LayoutUnitMultiplication)
+{
+ ASSERT_EQ((LayoutUnit(1) * LayoutUnit(1)).toInt(), 1);
+ ASSERT_EQ((LayoutUnit(1) * LayoutUnit(2)).toInt(), 2);
+ ASSERT_EQ((LayoutUnit(2) * LayoutUnit(1)).toInt(), 2);
+ ASSERT_EQ((LayoutUnit(2) * LayoutUnit(0.5)).toInt(), 1);
+ ASSERT_EQ((LayoutUnit(0.5) * LayoutUnit(2)).toInt(), 1);
+ ASSERT_EQ((LayoutUnit(100) * LayoutUnit(1)).toInt(), 100);
+
+ ASSERT_EQ((LayoutUnit(-1) * LayoutUnit(1)).toInt(), -1);
+ ASSERT_EQ((LayoutUnit(-1) * LayoutUnit(2)).toInt(), -2);
+ ASSERT_EQ((LayoutUnit(-2) * LayoutUnit(1)).toInt(), -2);
+ ASSERT_EQ((LayoutUnit(-2) * LayoutUnit(0.5)).toInt(), -1);
+ ASSERT_EQ((LayoutUnit(-0.5) * LayoutUnit(2)).toInt(), -1);
+ ASSERT_EQ((LayoutUnit(-100) * LayoutUnit(1)).toInt(), -100);
+
+ ASSERT_EQ((LayoutUnit(-1) * LayoutUnit(-1)).toInt(), 1);
+ ASSERT_EQ((LayoutUnit(-1) * LayoutUnit(-2)).toInt(), 2);
+ ASSERT_EQ((LayoutUnit(-2) * LayoutUnit(-1)).toInt(), 2);
+ ASSERT_EQ((LayoutUnit(-2) * LayoutUnit(-0.5)).toInt(), 1);
+ ASSERT_EQ((LayoutUnit(-0.5) * LayoutUnit(-2)).toInt(), 1);
+ ASSERT_EQ((LayoutUnit(-100) * LayoutUnit(-1)).toInt(), 100);
+
+ ASSERT_EQ((LayoutUnit(100) * LayoutUnit(3.33)).round(), 333);
+ ASSERT_EQ((LayoutUnit(-100) * LayoutUnit(3.33)).round(), -333);
+ ASSERT_EQ((LayoutUnit(-100) * LayoutUnit(-3.33)).round(), 333);
+
+ int quarterMax = intMaxForLayoutUnit / 4;
+ ASSERT_EQ((LayoutUnit(quarterMax) * LayoutUnit(2)).toInt(), quarterMax * 2);
+ ASSERT_EQ((LayoutUnit(quarterMax) * LayoutUnit(3)).toInt(), quarterMax * 3);
+ ASSERT_EQ((LayoutUnit(quarterMax) * LayoutUnit(4)).toInt(), quarterMax * 4);
+ ASSERT_EQ((LayoutUnit(quarterMax) * LayoutUnit(5)).toInt(), intMaxForLayoutUnit);
+}
+
+TEST(WebCore, LayoutUnitDivision)
+{
+ ASSERT_EQ((LayoutUnit(1) / LayoutUnit(1)).toInt(), 1);
+ ASSERT_EQ((LayoutUnit(1) / LayoutUnit(2)).toInt(), 0);
+ ASSERT_EQ((LayoutUnit(2) / LayoutUnit(1)).toInt(), 2);
+ ASSERT_EQ((LayoutUnit(2) / LayoutUnit(0.5)).toInt(), 4);
+ ASSERT_EQ((LayoutUnit(0.5) / LayoutUnit(2)).toInt(), 0);
+ ASSERT_EQ((LayoutUnit(100) / LayoutUnit(10)).toInt(), 10);
+ ASSERT_FLOAT_EQ((LayoutUnit(1) / LayoutUnit(2)).toFloat(), 0.5f);
+ ASSERT_FLOAT_EQ((LayoutUnit(0.5) / LayoutUnit(2)).toFloat(), 0.25f);
+
+ ASSERT_EQ((LayoutUnit(-1) / LayoutUnit(1)).toInt(), -1);
+ ASSERT_EQ((LayoutUnit(-1) / LayoutUnit(2)).toInt(), 0);
+ ASSERT_EQ((LayoutUnit(-2) / LayoutUnit(1)).toInt(), -2);
+ ASSERT_EQ((LayoutUnit(-2) / LayoutUnit(0.5)).toInt(), -4);
+ ASSERT_EQ((LayoutUnit(-0.5) / LayoutUnit(2)).toInt(), 0);
+ ASSERT_EQ((LayoutUnit(-100) / LayoutUnit(10)).toInt(), -10);
+ ASSERT_FLOAT_EQ((LayoutUnit(-1) / LayoutUnit(2)).toFloat(), -0.5f);
+ ASSERT_FLOAT_EQ((LayoutUnit(-0.5) / LayoutUnit(2)).toFloat(), -0.25f);
+
+ ASSERT_EQ((LayoutUnit(-1) / LayoutUnit(-1)).toInt(), 1);
+ ASSERT_EQ((LayoutUnit(-1) / LayoutUnit(-2)).toInt(), 0);
+ ASSERT_EQ((LayoutUnit(-2) / LayoutUnit(-1)).toInt(), 2);
+ ASSERT_EQ((LayoutUnit(-2) / LayoutUnit(-0.5)).toInt(), 4);
+ ASSERT_EQ((LayoutUnit(-0.5) / LayoutUnit(-2)).toInt(), 0);
+ ASSERT_EQ((LayoutUnit(-100) / LayoutUnit(-10)).toInt(), 10);
+ ASSERT_FLOAT_EQ((LayoutUnit(-1) / LayoutUnit(-2)).toFloat(), 0.5f);
+ ASSERT_FLOAT_EQ((LayoutUnit(-0.5) / LayoutUnit(-2)).toFloat(), 0.25f);
+
+ ASSERT_EQ((LayoutUnit(intMaxForLayoutUnit) / LayoutUnit(2)).toInt(), intMaxForLayoutUnit / 2);
+ ASSERT_EQ((LayoutUnit(intMaxForLayoutUnit) / LayoutUnit(0.5)).toInt(), intMaxForLayoutUnit);
+}
+
+
+} // namespace TestWebKitAPI
Modified: trunk/Tools/TestWebKitAPI/win/TestWebKitAPI.vcproj (137923 => 137924)
--- trunk/Tools/TestWebKitAPI/win/TestWebKitAPI.vcproj 2012-12-17 18:59:26 UTC (rev 137923)
+++ trunk/Tools/TestWebKitAPI/win/TestWebKitAPI.vcproj 2012-12-17 19:12:45 UTC (rev 137924)
@@ -415,6 +415,10 @@
>
</File>
</Filter>
+ <File
+ RelativePath="..\Tests\WebCore\LayoutUnit.cpp"
+ >
+ </File>
</Filter>
<Filter
Name="WTF"
_______________________________________________ webkit-changes mailing list [email protected] http://lists.webkit.org/mailman/listinfo/webkit-changes
