cvs: php-src /ext/standard/tests/strings substr_replace_error.phpt unpack_error.phpt
| From: | andy wharmby | Date: | Mon, 19 Jan 2009 17:13:17 +0000 |
| Subject: | cvs: php-src /ext/standard/tests/strings substr_replace_error.phpt unpack_error.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-55764@lists.php.net to get a copy of this message | ||
wharmby Mon Jan 19 17:13:17 2009 UTC
Modified files:
/php-src/ext/standard/tests/strings substr_replace_error.phpt
unpack_error.phpt
Log:
New substr_replace() and unpack() error tests. Tested on Windows, Linux and Linux 64 bit.
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/strings/substr_replace_error.phpt?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/standard/tests/strings/substr_replace_error.phpt
diff -u /dev/null php-src/ext/standard/tests/strings/substr_replace_error.phpt:1.2
--- /dev/null Mon Jan 19 17:13:17 2009
+++ php-src/ext/standard/tests/strings/substr_replace_error.phpt Mon Jan 19 17:13:17 2009
@@ -0,0 +1,70 @@
+--TEST--
+Test substr_replace() function : error conditions
+--FILE--
+<?php
+/* Prototype : mixed substr_replace ( mixed $string , string $replacement , int $start [, int
$length ] )
+ * Description: Replace text within a portion of a string
+ * Source code: ext/standard/string.c
+*/
+
+/*
+ * Testing substr_replace() for error conditions
+*/
+
+echo "*** Testing substr_replace() : error conditions ***\n";
+
+$s1 = "Good morning";
+
+echo "\n-- Testing substr_replace() function with less than expected no. of arguments
--\n";
+var_dump(substr_replace());
+var_dump(substr_replace($s1, "evening"));
+
+echo "\n-- Testing substr_replace() function with more than expected no. of arguments
--\n";
+var_dump(substr_replace($s1, "evening", 5, 7, true));
+
+echo "\n-- Testing substr_replace() function with start and length different types --\n";
+var_dump(substr_replace($s1, "evening", array(5)));
+var_dump(substr_replace($s1, "evening", 5, array(8)));
+
+echo "\n-- Testing substr_replace() function with start and length with a different number of
elments --\n";
+var_dump(substr_replace($s1, "evening", array(5, 1), array(8)));
+
+echo "\n-- Testing substr_replace() function with start and length as arrays but string
not--\n";
+var_dump(substr_replace($s1, "evening", array(5), array(8)));
+
+?>
+===DONE===
+--EXPECTF--
+*** Testing substr_replace() : error conditions ***
+
+-- Testing substr_replace() function with less than expected no. of arguments --
+
+Warning: substr_replace() expects at least 3 parameters, 0 given in %s on line %d
+NULL
+
+Warning: substr_replace() expects at least 3 parameters, 2 given in %s on line %d
+NULL
+
+-- Testing substr_replace() function with more than expected no. of arguments --
+
+Warning: substr_replace() expects at most 4 parameters, 5 given in %s on line %d
+NULL
+
+-- Testing substr_replace() function with start and length different types --
+
+Warning: substr_replace(): 'from' and 'len' should be of same type - numerical
or array in %s on line %d
+unicode(12) "Good morning"
+
+Warning: substr_replace(): 'from' and 'len' should be of same type - numerical
or array in %s on line %d
+unicode(12) "Good morning"
+
+-- Testing substr_replace() function with start and length with a different number of elments --
+
+Warning: substr_replace(): 'from' and 'len' should have the same number of
elements in %s on line %d
+unicode(12) "Good morning"
+
+-- Testing substr_replace() function with start and length as arrays but string not--
+
+Warning: substr_replace(): Functionality of 'from' and 'len' as arrays is not
implemented in %s on line %d
+unicode(12) "Good morning"
+===DONE===
\ No newline at end of file
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/strings/unpack_error.phpt?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/standard/tests/strings/unpack_error.phpt
diff -u /dev/null php-src/ext/standard/tests/strings/unpack_error.phpt:1.2
--- /dev/null Mon Jan 19 17:13:17 2009
+++ php-src/ext/standard/tests/strings/unpack_error.phpt Mon Jan 19 17:13:17 2009
@@ -0,0 +1,42 @@
+--TEST--
+Test unpack() function : error conditions
+--FILE--
+<?php
+
+/* Prototype : array unpack ( string $format , string $data )
+ * Description: Unpack data from binary string
+ * Source code: ext/standard/pack.c
+*/
+
+echo "*** Testing unpack() : error conditions ***\n";
+
+echo "\n-- Testing unpack() function with no arguments --\n";
+var_dump( unpack() );
+
+echo "\n-- Testing unpack() function with more than expected no. of arguments --\n";
+$extra_arg = 10;
+var_dump(unpack("I", pack("I", 65534), $extra_arg));
+
+echo "\n-- Testing unpack() function with invalid format character --\n";
+$extra_arg = 10;
+var_dump(unpack("Z", pack("I", 65534)));
+?>
+===DONE===
+--EXPECTF--
+*** Testing unpack() : error conditions ***
+
+-- Testing unpack() function with no arguments --
+
+Warning: unpack() expects exactly 2 parameters, 0 given in %s on line %d
+NULL
+
+-- Testing unpack() function with more than expected no. of arguments --
+
+Warning: unpack() expects exactly 2 parameters, 3 given in %s on line %d
+NULL
+
+-- Testing unpack() function with invalid format character --
+
+Warning: unpack(): Invalid format type Z in %s on line %d
+bool(false)
+===DONE===