summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorScott <scott@paragonie.com>2015-10-16 02:27:40 -0400
committerScott <scott@paragonie.com>2015-10-16 02:59:09 -0400
commit6056bc102e387535d9b3044adb735d6936efea61 (patch)
treea186584fcf9787557ac533bbf4e17b8e06955951 /tests
parent9a0ce69360aa22413a96f2bf93f61235e2c18486 (diff)
downloadrandom_compat-6056bc102e387535d9b3044adb735d6936efea61.zip
random_compat-6056bc102e387535d9b3044adb735d6936efea61.tar.gz
random_compat-6056bc102e387535d9b3044adb735d6936efea61.tar.bz2
Fix more integer/float boundary issues.
Diffstat (limited to 'tests')
-rwxr-xr-x[-rw-r--r--]tests/phpunit.sh0
-rw-r--r--tests/unit/RandomIntTest.php2
-rw-r--r--tests/unit/UtilityTest.php26
3 files changed, 26 insertions, 2 deletions
diff --git a/tests/phpunit.sh b/tests/phpunit.sh
index 4425b6a..4425b6a 100644..100755
--- a/tests/phpunit.sh
+++ b/tests/phpunit.sh
diff --git a/tests/unit/RandomIntTest.php b/tests/unit/RandomIntTest.php
index 6a2ab9a..c61f698 100644
--- a/tests/unit/RandomIntTest.php
+++ b/tests/unit/RandomIntTest.php
@@ -35,8 +35,10 @@ class RandomIntTest extends PHPUnit_Framework_TestCase
$this->assertTrue($integers[9] === -4);
try {
+ $h = random_int("2147483648", "2147483647");
$i = random_int("9223372036854775808", "9223372036854775807");
$this->assertFalse(is_int($i));
+ $h = random_int("-2147483648", "2147483647");
$i = random_int("-9223372036854775808", "9223372036854775807");
$this->assertFalse(true);
} catch (Error $ex) {
diff --git a/tests/unit/UtilityTest.php b/tests/unit/UtilityTest.php
index 5ad9930..54da8c3 100644
--- a/tests/unit/UtilityTest.php
+++ b/tests/unit/UtilityTest.php
@@ -49,10 +49,32 @@ class UtilityTest extends PHPUnit_Framework_TestCase
is_int(RandomCompat_intval(~PHP_INT_MAX - 1, true))
);
$this->assertFalse(
- is_int(RandomCompat_intval(PHP_INT_MAX - 0.01, true))
+ is_int(RandomCompat_intval(~PHP_INT_MAX - 0.1, true))
);
$this->assertFalse(
- is_int(RandomCompat_intval(~PHP_INT_MAX + 0.01, true))
+ is_int(RandomCompat_intval(PHP_INT_MAX + 0.1, true))
);
+
+ if (PHP_INT_SIZE === 8) {
+ $this->assertTrue(
+ is_int(RandomCompat_intval("-9223372036854775807", true))
+ );
+ $this->assertTrue(
+ is_int(RandomCompat_intval("9223372036854775806", true))
+ );
+ } else {
+ $this->assertFalse(
+ is_int(RandomCompat_intval("2147483648", true))
+ );
+ $this->assertTrue(
+ is_int(RandomCompat_intval("2147483647", true))
+ );
+ $this->assertFalse(
+ is_int(RandomCompat_intval("-2147483649", true))
+ );
+ $this->assertTrue(
+ is_int(RandomCompat_intval("-2147483648", true))
+ );
+ }
}
}