Add more Checked<> tests
authoroliver@apple.com <oliver@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 12 Mar 2013 21:51:39 +0000 (21:51 +0000)
committeroliver@apple.com <oliver@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 12 Mar 2013 21:51:39 +0000 (21:51 +0000)
https://bugs.webkit.org/show_bug.cgi?id=112190

Reviewed by Geoffrey Garen.

Source/WTF:

Export the CheckedState enum type

* wtf/CheckedArithmetic.h:

Tools:

Tests!

* TestWebKitAPI/Tests/WTF/CheckedArithmeticOperations.cpp:
(TestWebKitAPI):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@145587 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WTF/ChangeLog
Source/WTF/wtf/CheckedArithmetic.h
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WTF/CheckedArithmeticOperations.cpp

index 2cec5f6..73523a8 100644 (file)
@@ -1,5 +1,16 @@
 2013-03-12  Oliver Hunt  <oliver@apple.com>
 
+        Add more Checked<> tests
+        https://bugs.webkit.org/show_bug.cgi?id=112190
+
+        Reviewed by Geoffrey Garen.
+
+        Export the CheckedState enum type
+
+        * wtf/CheckedArithmetic.h:
+
+2013-03-12  Oliver Hunt  <oliver@apple.com>
+
         Make CheckedArithmetic slightly more sane
         https://bugs.webkit.org/show_bug.cgi?id=112178
 
index a2c688e..84a4e55 100644 (file)
@@ -712,6 +712,7 @@ template <typename U, typename V, typename OverflowHandler> static inline Checke
 }
 
 using WTF::Checked;
+using WTF::CheckedState;
 using WTF::RecordOverflow;
 
 #endif
index 0dad28c..3193905 100644 (file)
@@ -1,3 +1,15 @@
+2013-03-12  Oliver Hunt  <oliver@apple.com>
+
+        Add more Checked<> tests
+        https://bugs.webkit.org/show_bug.cgi?id=112190
+
+        Reviewed by Geoffrey Garen.
+
+        Tests!
+
+        * TestWebKitAPI/Tests/WTF/CheckedArithmeticOperations.cpp:
+        (TestWebKitAPI):
+
 2013-03-12  Julie Parent  <jparent@chromium.org>
 
         Cleanup: Move loading complete function into callback, rather than global.
index 768c7d3..52c05f4 100644 (file)
@@ -70,6 +70,13 @@ namespace TestWebKitAPI {
         EXPECT_EQ(true, (value += coerceLiteral(1)).hasOverflowed()); \
         EXPECT_EQ(true, value.hasOverflowed()); \
         value = 10; \
+        type _value; \
+        EXPECT_EQ(true, CheckedState::DidNotOverflow == (value * Checked<type, RecordOverflow>(0)).safeGet(_value)); \
+        EXPECT_EQ(true, 10 == _value); \
+        _value = 0; \
+        EXPECT_EQ(true, CheckedState::DidNotOverflow == (Checked<type, RecordOverflow>(0) * value).safeGet(_value)); \
+        EXPECT_EQ(true, 10 == _value); \
+        EXPECT_EQ(true, CheckedState::DidOverflow != (value * Checked<type, RecordOverflow>(std::numeric_limits<type>::max())).safeGet(_value)); \
         MixedSignednessTest(EXPECT_EQ(coerceLiteral(0), (value + -10).unsafeGet())); \
         MixedSignednessTest(EXPECT_EQ(0U, (value - 10U).unsafeGet())); \
         MixedSignednessTest(EXPECT_EQ(coerceLiteral(0), (-10 + value).unsafeGet())); \