]> granicus.if.org Git - php/commitdiff
New basic test for md5(). Tested on Windows, Linux and Linux 64 bit
authorandy wharmby <wharmby@php.net>
Wed, 19 Aug 2009 08:39:33 +0000 (08:39 +0000)
committerandy wharmby <wharmby@php.net>
Wed, 19 Aug 2009 08:39:33 +0000 (08:39 +0000)
ext/standard/tests/strings/md5_basic1.phpt [new file with mode: 0644]
ext/standard/tests/strings/md5_basic2.phpt [new file with mode: 0644]
ext/standard/tests/strings/md5_error.phpt [new file with mode: 0644]

diff --git a/ext/standard/tests/strings/md5_basic1.phpt b/ext/standard/tests/strings/md5_basic1.phpt
new file mode 100644 (file)
index 0000000..eda414b
--- /dev/null
@@ -0,0 +1,17 @@
+--TEST--\r
+Test md5() function : basic functionality \r
+--FILE--\r
+<?php\r
+/* Prototype  : string md5  ( string $str  [, bool $raw_output= false  ] )\r
+ * Description: Calculate the md5 hash of a string\r
+ * Source code: ext/standard/md5.c\r
+*/\r
+\r
+echo "*** Testing md5() : basic functionality ***\n";\r
+var_dump(md5(b"apple"));\r
+?>\r
+===DONE===\r
+--EXPECTF--\r
+*** Testing md5() : basic functionality ***\r
+string(32) "1f3870be274f6c49b3e31a0c6728957f"\r
+===DONE===\r
diff --git a/ext/standard/tests/strings/md5_basic2.phpt b/ext/standard/tests/strings/md5_basic2.phpt
new file mode 100644 (file)
index 0000000..1f89ba8
--- /dev/null
@@ -0,0 +1,30 @@
+--TEST--\r
+Test md5() function : basic functionality - with raw output\r
+--FILE--\r
+<?php\r
+/* Prototype  : string md5  ( string $str  [, bool $raw_output= false  ] )\r
+ * Description: Calculate the md5 hash of a string\r
+ * Source code: ext/standard/md5.c\r
+*/\r
+\r
+echo "*** Testing md5() : basic functionality - with raw output***\n";\r
+$str = b"Hello World";\r
+$md5_raw = md5($str, true);\r
+var_dump(bin2hex($md5_raw));\r
+\r
+$md5 = md5($str, false);\r
+       \r
+if (strcmp(bin2hex($md5_raw), $md5) == 0 ) {\r
+       echo "TEST PASSED\n";\r
+} else {\r
+       echo "TEST FAILED\n";\r
+       var_dump($md5_raw, $md5);\r
+}\r
+\r
+?>\r
+===DONE===\r
+--EXPECT--\r
+*** Testing md5() : basic functionality - with raw output***\r
+string(32) "b10a8db164e0754105b7a99be72e3fe5"\r
+TEST PASSED\r
+===DONE===
\ No newline at end of file
diff --git a/ext/standard/tests/strings/md5_error.phpt b/ext/standard/tests/strings/md5_error.phpt
new file mode 100644 (file)
index 0000000..190b09c
--- /dev/null
@@ -0,0 +1,35 @@
+--TEST--\r
+Test md5() function : error conditions\r
+--FILE--\r
+<?php\r
+/* Prototype  : string md5  ( string $str  [, bool $raw_output= false  ] )\r
+ * Description: Calculate the md5 hash of a string\r
+ * Source code: ext/standard/md5.c\r
+*/\r
+\r
+echo "*** Testing md5() : error conditions ***\n";\r
+\r
+echo "\n-- Testing md5() function with no arguments --\n";\r
+var_dump( md5());\r
+\r
+echo "\n-- Testing md5() function with more than expected no. of arguments --\n";\r
+$str = "Hello World";\r
+$raw_output = true;\r
+$extra_arg = 10;\r
+\r
+var_dump(md5($str, $raw_output, $extra_arg));\r
+?>\r
+===DONE==\r
+--EXPECTF--\r
+*** Testing md5() : error conditions ***\r
+\r
+-- Testing md5() function with no arguments --\r
+\r
+Warning: md5() expects at least 1 parameter, 0 given in %s on line %d\r
+NULL\r
+\r
+-- Testing md5() function with more than expected no. of arguments --\r
+\r
+Warning: md5() expects at most 2 parameters, 3 given in %s on line %d\r
+NULL\r
+===DONE==
\ No newline at end of file