Split GMP tests testing multiple functions
authorNikita Popov <nikic@php.net>
Thu, 4 Sep 2014 19:14:17 +0000 (21:14 +0200)
committerNikita Popov <nikic@php.net>
Thu, 4 Sep 2014 19:18:37 +0000 (21:18 +0200)
Also drop dummy test

ext/gmp/tests/001.phpt [deleted file]
ext/gmp/tests/gmp_export.phpt [new file with mode: 0644]
ext/gmp/tests/gmp_import.phpt [moved from ext/gmp/tests/import-export.phpt with 53% similarity]
ext/gmp/tests/gmp_remroot.phpt [moved from ext/gmp/tests/041.phpt with 63% similarity]
ext/gmp/tests/gmp_root.phpt [new file with mode: 0644]

diff --git a/ext/gmp/tests/001.phpt b/ext/gmp/tests/001.phpt
deleted file mode 100644 (file)
index 5126f73..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
---TEST--
-Check for gmp presence
---SKIPIF--
-<?php if (!extension_loaded("gmp")) print "skip"; ?>
---FILE--
-<?php 
-echo "gmp extension is available";
-/*
-       you can add regression tests for your extension here
-
-  the output of your test code has to be equal to the
-  text in the --EXPECT-- section below for the tests
-  to pass, differences between the output and the
-  expected text are interpreted as failure
-
-       see php5/tests/README for further information on
-  writing regression tests
-*/
-?>
---EXPECT--
-gmp extension is available
diff --git a/ext/gmp/tests/gmp_export.phpt b/ext/gmp/tests/gmp_export.phpt
new file mode 100644 (file)
index 0000000..fbc8901
--- /dev/null
@@ -0,0 +1,80 @@
+--TEST--
+gmp_export() basic tests
+--SKIPIF--
+<?php if (!extension_loaded("gmp")) echo "skip"; ?>
+--FILE--
+<?php
+
+// Tests taken from GMPs own test suite.
+
+// format is [output, size, options, expected]
+$export = [
+    ['0',1,GMP_BIG_ENDIAN,''],
+    ['0',2,GMP_BIG_ENDIAN,''],
+    ['0',3,GMP_BIG_ENDIAN,''],
+    ['12345678',1,GMP_BIG_ENDIAN,'12345678'],
+    ['12345678',4,GMP_BIG_ENDIAN,'12345678'],
+    ['12345678',4,GMP_LSW_FIRST | GMP_BIG_ENDIAN,'12345678'],
+    ['12345678',1,GMP_LSW_FIRST | GMP_LITTLE_ENDIAN,'78563412'],
+    ['12345678',4,GMP_LITTLE_ENDIAN,'78563412'],
+    ['12345678',4,GMP_LSW_FIRST | GMP_LITTLE_ENDIAN,'78563412'],
+    ['123456789ABC',2,GMP_BIG_ENDIAN,'123456789abc'],
+    ['123456789ABC',2,GMP_LSW_FIRST | GMP_BIG_ENDIAN,'9abc56781234'],
+    ['123456789ABC',2,GMP_LITTLE_ENDIAN,'34127856bc9a'],
+    ['123456789ABC',2,GMP_LSW_FIRST | GMP_LITTLE_ENDIAN,'bc9a78563412'],
+    ['112233445566778899AABBCC',4,GMP_BIG_ENDIAN,'112233445566778899aabbcc'],
+    ['112233445566778899AABBCC',4,GMP_LSW_FIRST | GMP_BIG_ENDIAN,'99aabbcc5566778811223344'],
+    ['112233445566778899AABBCC',4,GMP_LITTLE_ENDIAN,'4433221188776655ccbbaa99'],
+    ['112233445566778899AABBCC',4,GMP_LSW_FIRST | GMP_LITTLE_ENDIAN,'ccbbaa998877665544332211'],
+    ['100120023003400450056006700780089009A00AB00BC00C',8,GMP_BIG_ENDIAN,'100120023003400450056006700780089009a00ab00bc00c'],
+    ['100120023003400450056006700780089009A00AB00BC00C',8,GMP_LSW_FIRST | GMP_BIG_ENDIAN,'9009a00ab00bc00c50056006700780081001200230034004'],
+    ['100120023003400450056006700780089009A00AB00BC00C',8,GMP_LITTLE_ENDIAN,'044003300220011008800770066005500cc00bb00aa00990'],
+    ['100120023003400450056006700780089009A00AB00BC00C',8,GMP_LSW_FIRST | GMP_LITTLE_ENDIAN,'0cc00bb00aa0099008800770066005500440033002200110']
+];
+
+$passed = true;
+foreach ($export as $k => $test) {
+    $gmp = gmp_init($test[0], 16);
+    $str = gmp_export($gmp, $test[1], $test[2]);
+    if (is_string($str)) {
+        $result = bin2hex($str);
+        if ($result !== $test[3]) {
+            echo "$k: '$result' !== '{$test[3]}'\n";
+            $passed = false;
+        }
+    } else {
+        $type = gettype($str);
+        echo "$k: $type !== '{$test[3]}'\n";
+    }
+}
+
+var_dump($passed);
+
+// Invalid arguments (zpp failure)
+var_dump(gmp_export());
+
+// Invalid word sizes
+var_dump(gmp_export(123, -1));
+var_dump(gmp_export(123, 0));
+
+// Invalid options
+var_dump(gmp_export(123, 1, GMP_MSW_FIRST | GMP_LSW_FIRST));
+var_dump(gmp_export(123, 1, GMP_BIG_ENDIAN | GMP_LITTLE_ENDIAN));
+
+--EXPECTF--
+bool(true)
+
+Warning: gmp_export() expects at least 1 parameter, 0 given in %s on line %d
+NULL
+
+Warning: gmp_export(): Word size must be positive, -1 given in %s on line %d
+bool(false)
+
+Warning: gmp_export(): Word size must be positive, 0 given in %s on line %d
+bool(false)
+
+Warning: gmp_export(): Invalid options: Conflicting word orders in %s on line %d
+bool(false)
+
+Warning: gmp_export(): Invalid options: Conflicting word endianness in %s on line %d
+bool(false)
similarity index 53%
rename from ext/gmp/tests/import-export.phpt
rename to ext/gmp/tests/gmp_import.phpt
index 42000a10fc67aa5ebb405b71518190e6226bff28..b7ae6600edd4bf84a0eb02eaad50847f5a8c80f3 100644 (file)
@@ -1,5 +1,5 @@
 --TEST--
-Check gmp_import and gmp_export behave as intended
+gmp_import() basic tests
 --SKIPIF--
 <?php if (!extension_loaded("gmp")) echo "skip"; ?>
 --FILE--
@@ -30,32 +30,6 @@ $import = [
     ['100120023003400450056006700780089009a00ab00bc00c',8,GMP_LSW_FIRST | GMP_LITTLE_ENDIAN,'0cc00bb00aa0099008800770066005500440033002200110']
 ];
 
-// format is [output, size, options, expected]
-$export = [
-    ['0',1,GMP_BIG_ENDIAN,''],
-    ['0',2,GMP_BIG_ENDIAN,''],
-    ['0',3,GMP_BIG_ENDIAN,''],
-    ['12345678',1,GMP_BIG_ENDIAN,'12345678'],
-    ['12345678',4,GMP_BIG_ENDIAN,'12345678'],
-    ['12345678',4,GMP_LSW_FIRST | GMP_BIG_ENDIAN,'12345678'],
-    ['12345678',1,GMP_LSW_FIRST | GMP_LITTLE_ENDIAN,'78563412'],
-    ['12345678',4,GMP_LITTLE_ENDIAN,'78563412'],
-    ['12345678',4,GMP_LSW_FIRST | GMP_LITTLE_ENDIAN,'78563412'],
-    ['123456789ABC',2,GMP_BIG_ENDIAN,'123456789abc'],
-    ['123456789ABC',2,GMP_LSW_FIRST | GMP_BIG_ENDIAN,'9abc56781234'],
-    ['123456789ABC',2,GMP_LITTLE_ENDIAN,'34127856bc9a'],
-    ['123456789ABC',2,GMP_LSW_FIRST | GMP_LITTLE_ENDIAN,'bc9a78563412'],
-    ['112233445566778899AABBCC',4,GMP_BIG_ENDIAN,'112233445566778899aabbcc'],
-    ['112233445566778899AABBCC',4,GMP_LSW_FIRST | GMP_BIG_ENDIAN,'99aabbcc5566778811223344'],
-    ['112233445566778899AABBCC',4,GMP_LITTLE_ENDIAN,'4433221188776655ccbbaa99'],
-    ['112233445566778899AABBCC',4,GMP_LSW_FIRST | GMP_LITTLE_ENDIAN,'ccbbaa998877665544332211'],
-    ['100120023003400450056006700780089009A00AB00BC00C',8,GMP_BIG_ENDIAN,'100120023003400450056006700780089009a00ab00bc00c'],
-    ['100120023003400450056006700780089009A00AB00BC00C',8,GMP_LSW_FIRST | GMP_BIG_ENDIAN,'9009a00ab00bc00c50056006700780081001200230034004'],
-    ['100120023003400450056006700780089009A00AB00BC00C',8,GMP_LITTLE_ENDIAN,'044003300220011008800770066005500cc00bb00aa00990'],
-    ['100120023003400450056006700780089009A00AB00BC00C',8,GMP_LSW_FIRST | GMP_LITTLE_ENDIAN,'0cc00bb00aa0099008800770066005500440033002200110']
-];
-
-echo "Import:\n";
 $passed = true;
 foreach ($import as $k => $test) {
     $gmp = gmp_import(hex2bin($test[3]), $test[1], $test[2]);
@@ -73,34 +47,12 @@ foreach ($import as $k => $test) {
 
 var_dump($passed);
 
-echo "\nExport:\n";
-$passed = true;
-foreach ($export as $k => $test) {
-    $gmp = gmp_init($test[0], 16);
-    $str = gmp_export($gmp, $test[1], $test[2]);
-    if (is_string($str)) {
-        $result = bin2hex($str);
-        if ($result !== $test[3]) {
-            echo "$k: '$result' !== '{$test[3]}'\n";
-            $passed = false;
-        }
-    } else {
-        $type = gettype($str);
-        echo "$k: $type !== '{$test[3]}'\n";
-    }
-}
-
-var_dump($passed);
-
 // Invalid arguments (zpp failure)
 var_dump(gmp_import());
-var_dump(gmp_export());
 
 // Invalid word sizes
 var_dump(gmp_import('a', -1));
 var_dump(gmp_import('a', 0));
-var_dump(gmp_export(123, -1));
-var_dump(gmp_export(123, 0));
 
 // Invalid data lengths
 var_dump(gmp_import('a', 2));
@@ -111,34 +63,18 @@ var_dump(gmp_import(str_repeat('a', 100), 64));
 var_dump(gmp_import('a', 1, GMP_MSW_FIRST | GMP_LSW_FIRST));
 var_dump(gmp_import('a', 1, GMP_BIG_ENDIAN | GMP_LITTLE_ENDIAN));
 
-var_dump(gmp_export(123, 1, GMP_MSW_FIRST | GMP_LSW_FIRST));
-var_dump(gmp_export(123, 1, GMP_BIG_ENDIAN | GMP_LITTLE_ENDIAN));
-
 --EXPECTF--
-Import:
-bool(true)
-
-Export:
 bool(true)
 
 Warning: gmp_import() expects at least 1 parameter, 0 given in %s on line %d
 NULL
 
-Warning: gmp_export() expects at least 1 parameter, 0 given in %s on line %d
-NULL
-
 Warning: gmp_import(): Word size must be positive, -1 given in %s on line %d
 bool(false)
 
 Warning: gmp_import(): Word size must be positive, 0 given in %s on line %d
 bool(false)
 
-Warning: gmp_export(): Word size must be positive, -1 given in %s on line %d
-bool(false)
-
-Warning: gmp_export(): Word size must be positive, 0 given in %s on line %d
-bool(false)
-
 Warning: gmp_import(): Input length must be a multiple of word size in %s on line %d
 bool(false)
 
@@ -153,9 +89,3 @@ bool(false)
 
 Warning: gmp_import(): Invalid options: Conflicting word endianness in %s on line %d
 bool(false)
-
-Warning: gmp_export(): Invalid options: Conflicting word orders in %s on line %d
-bool(false)
-
-Warning: gmp_export(): Invalid options: Conflicting word endianness in %s on line %d
-bool(false)
similarity index 63%
rename from ext/gmp/tests/041.phpt
rename to ext/gmp/tests/gmp_remroot.phpt
index cd442b1a54fb0703c0d5c46d4873a4b13b42f405..4a3539d87cb436ae4804fe958832bec413c61428 100644 (file)
@@ -1,25 +1,12 @@
 --TEST--
-gmp_root() and gmp_rootrem() basic tests
+gmp_rootrem() basic tests
 --SKIPIF--
 <?php if (!extension_loaded("gmp")) print "skip"; ?>
 --FILE--
 <?php
 
-var_dump(gmp_root());
 var_dump(gmp_rootrem());
 
-var_dump(gmp_root(1000, 3));
-var_dump(gmp_root(100, 3));
-var_dump(gmp_root(-100, 3));
-
-var_dump(gmp_root(1000, 4));
-var_dump(gmp_root(100, 4));
-var_dump(gmp_root(-100, 4));
-
-var_dump(gmp_root(0, 3));
-var_dump(gmp_root(100, 0));
-var_dump(gmp_root(100, -3));
-
 var_dump(gmp_rootrem(1000, 3));
 var_dump(gmp_rootrem(100, 3));
 var_dump(gmp_rootrem(-100, 3));
@@ -34,44 +21,8 @@ var_dump(gmp_rootrem(100, -3));
 
 ?>
 --EXPECTF--    
-Warning: gmp_root() expects exactly 2 parameters, 0 given in %s on line %d
-NULL
-
 Warning: gmp_rootrem() expects exactly 2 parameters, 0 given in %s on line %d
 NULL
-object(GMP)#%d (1) {
-  ["num"]=>
-  string(2) "10"
-}
-object(GMP)#%d (1) {
-  ["num"]=>
-  string(1) "4"
-}
-object(GMP)#%d (1) {
-  ["num"]=>
-  string(2) "-4"
-}
-object(GMP)#%d (1) {
-  ["num"]=>
-  string(1) "5"
-}
-object(GMP)#%d (1) {
-  ["num"]=>
-  string(1) "3"
-}
-
-Warning: gmp_root(): Can't take even root of negative number in %s on line %d
-bool(false)
-object(GMP)#%d (1) {
-  ["num"]=>
-  string(1) "0"
-}
-
-Warning: gmp_root(): The root must be positive in %s on line %d
-bool(false)
-
-Warning: gmp_root(): The root must be positive in %s on line %d
-bool(false)
 array(2) {
   [0]=>
   object(GMP)#%d (1) {
diff --git a/ext/gmp/tests/gmp_root.phpt b/ext/gmp/tests/gmp_root.phpt
new file mode 100644 (file)
index 0000000..70faf27
--- /dev/null
@@ -0,0 +1,58 @@
+--TEST--
+gmp_root() basic tests
+--SKIPIF--
+<?php if (!extension_loaded("gmp")) print "skip"; ?>
+--FILE--
+<?php
+
+var_dump(gmp_root());
+
+var_dump(gmp_root(1000, 3));
+var_dump(gmp_root(100, 3));
+var_dump(gmp_root(-100, 3));
+
+var_dump(gmp_root(1000, 4));
+var_dump(gmp_root(100, 4));
+var_dump(gmp_root(-100, 4));
+
+var_dump(gmp_root(0, 3));
+var_dump(gmp_root(100, 0));
+var_dump(gmp_root(100, -3));
+
+?>
+--EXPECTF--    
+Warning: gmp_root() expects exactly 2 parameters, 0 given in %s on line %d
+NULL
+object(GMP)#%d (1) {
+  ["num"]=>
+  string(2) "10"
+}
+object(GMP)#%d (1) {
+  ["num"]=>
+  string(1) "4"
+}
+object(GMP)#%d (1) {
+  ["num"]=>
+  string(2) "-4"
+}
+object(GMP)#%d (1) {
+  ["num"]=>
+  string(1) "5"
+}
+object(GMP)#%d (1) {
+  ["num"]=>
+  string(1) "3"
+}
+
+Warning: gmp_root(): Can't take even root of negative number in %s on line %d
+bool(false)
+object(GMP)#%d (1) {
+  ["num"]=>
+  string(1) "0"
+}
+
+Warning: gmp_root(): The root must be positive in %s on line %d
+bool(false)
+
+Warning: gmp_root(): The root must be positive in %s on line %d
+bool(false)