New tests for str_pad(), str_shuffle(), stristr() and strlen(). Tested on WIndows, Linux and Linux 64 bit

This commit is contained in:
andy wharmby 2009-01-19 15:46:36 +00:00
parent a98959be35
commit 8be7bef0a6
19 changed files with 1576 additions and 163 deletions

View File

@ -0,0 +1,140 @@
--TEST--
Test str_pad() function : usage variations - unexpected inputs for '$input' argument
--FILE--
<?php
/* Prototype : string str_pad ( string $input , int $pad_length [, string $pad_string [, int $pad_type ]] )
* Description: Pad a string to a certain length with another string
* Source code: ext/standard/string.c
*/
/* Test str_pad() function: with unexpected inputs for '$input'
* and expected type for '$pad_length'
*/
echo "*** Testing str_pad() function: with unexpected inputs for 'input' argument ***\n";
//get an unset variable
$unset_var = 'string_val';
unset($unset_var);
//defining a class
class sample {
public function __toString() {
return "sample object";
}
}
//getting the resource
$file_handle = fopen(__FILE__, "r");
// array with different values for $input
$inputs = array (
// integer values
/*1*/ 0,
1,
-2,
2147483647,
-2147483648,
// float values
/*6*/ 10.5,
-20.5,
10.1234567e10,
// array values
/*9*/ array(),
array(0),
array(1, 2),
// boolean values
/*12*/ true,
false,
TRUE,
FALSE,
// null vlaues
/*16*/ NULL,
null,
// objects
/*18*/ new sample(),
// resource
/*19*/ $file_handle,
// undefined variable
/*20*/ @$undefined_var,
// unset variable
/*21*/ @$unset_var
);
//defining '$pad_length' argument
$pad_length = "20";
// loop through with each element of the $inputs array to test str_pad() function
$count = 1;
foreach($inputs as $input) {
echo "-- Iteration $count --\n";
var_dump( str_pad($input, $pad_length) );
$count ++;
}
fclose($file_handle); //closing the file handle
?>
===DONE===
--EXPECTF--
*** Testing str_pad() function: with unexpected inputs for 'input' argument ***
-- Iteration 1 --
unicode(20) "0 "
-- Iteration 2 --
unicode(20) "1 "
-- Iteration 3 --
unicode(20) "-2 "
-- Iteration 4 --
unicode(20) "2147483647 "
-- Iteration 5 --
unicode(20) "-2147483648 "
-- Iteration 6 --
unicode(20) "10.5 "
-- Iteration 7 --
unicode(20) "-20.5 "
-- Iteration 8 --
unicode(20) "101234567000 "
-- Iteration 9 --
Warning: str_pad() expects parameter 1 to be string (Unicode or binary), array given in %s on line %d
NULL
-- Iteration 10 --
Warning: str_pad() expects parameter 1 to be string (Unicode or binary), array given in %s on line %d
NULL
-- Iteration 11 --
Warning: str_pad() expects parameter 1 to be string (Unicode or binary), array given in %s on line %d
NULL
-- Iteration 12 --
unicode(20) "1 "
-- Iteration 13 --
unicode(20) " "
-- Iteration 14 --
unicode(20) "1 "
-- Iteration 15 --
unicode(20) " "
-- Iteration 16 --
unicode(20) " "
-- Iteration 17 --
unicode(20) " "
-- Iteration 18 --
unicode(20) "sample object "
-- Iteration 19 --
Warning: str_pad() expects parameter 1 to be string (Unicode or binary), resource given in %s on line %d
NULL
-- Iteration 20 --
unicode(20) " "
-- Iteration 21 --
unicode(20) " "
===DONE===

View File

@ -0,0 +1,139 @@
--TEST--
Test str_pad() function : usage variations - unexpected inputs for '$pad_length' argument
--FILE--
<?php
/* Prototype : string str_pad ( string $input , int $pad_length [, string $pad_string [, int $pad_type ]] )
* Description: Pad a string to a certain length with another string
* Source code: ext/standard/string.c
*/
/* Test str_pad() function: with unexpected inputs for '$pad_length'
* and expected type for '$input'
*/
echo "*** Testing str_pad() function: with unexpected inputs for 'pad_length' argument ***\n";
//get an unset variable
$unset_var = 'string_val';
unset($unset_var);
//defining a class
class sample {
public function __toString() {
return "sample object";
}
}
//getting the resource
$file_handle = fopen(__FILE__, "r");
// array with different values for $input
$pad_lengths = array (
// integer values
/*1*/ 0,
1,
-2,
255,
// float values
/*5*/ 10.5,
-20.5,
10.12345e2,
// array values
/*8*/ array(),
array(0),
array(1, 2),
// boolean values
/*11*/ true,
false,
TRUE,
FALSE,
// null vlaues
/*15*/ NULL,
null,
// objects
/*17*/ new sample(),
// resource
/*18*/ $file_handle,
// undefined variable
/*19*/ @$undefined_var,
// unset variable
/*20*/ @$unset_var
);
//defining '$input' argument
$input = "Test string";
// loop through with each element of the $pad_lengths array to test str_pad() function
$count = 1;
foreach($pad_lengths as $pad_length) {
echo "-- Iteration $count --\n";
var_dump( str_pad($input, $pad_length) );
$count ++;
}
fclose($file_handle); //closing the file handle
?>
===DONE===
--EXPECTF--
*** Testing str_pad() function: with unexpected inputs for 'pad_length' argument ***
-- Iteration 1 --
unicode(11) "Test string"
-- Iteration 2 --
unicode(11) "Test string"
-- Iteration 3 --
unicode(11) "Test string"
-- Iteration 4 --
unicode(255) "Test string "
-- Iteration 5 --
unicode(11) "Test string"
-- Iteration 6 --
unicode(11) "Test string"
-- Iteration 7 --
unicode(1012) "Test string "
-- Iteration 8 --
Warning: str_pad() expects parameter 2 to be long, array given in %s on line %d
NULL
-- Iteration 9 --
Warning: str_pad() expects parameter 2 to be long, array given in %s on line %d
NULL
-- Iteration 10 --
Warning: str_pad() expects parameter 2 to be long, array given in %s on line %d
NULL
-- Iteration 11 --
unicode(11) "Test string"
-- Iteration 12 --
unicode(11) "Test string"
-- Iteration 13 --
unicode(11) "Test string"
-- Iteration 14 --
unicode(11) "Test string"
-- Iteration 15 --
unicode(11) "Test string"
-- Iteration 16 --
unicode(11) "Test string"
-- Iteration 17 --
Warning: str_pad() expects parameter 2 to be long, object given in %s on line %d
NULL
-- Iteration 18 --
Warning: str_pad() expects parameter 2 to be long, resource given in %s on line %d
NULL
-- Iteration 19 --
unicode(11) "Test string"
-- Iteration 20 --
unicode(11) "Test string"
===DONE===

View File

@ -0,0 +1,153 @@
--TEST--
Test str_pad() function : usage variations - unexpected inputs for '$pad_string' argument
--FILE--
<?php
/* Prototype : string str_pad ( string $input , int $pad_length [, string $pad_string [, int $pad_type ]] )
* Description: Pad a string to a certain length with another string
* Source code: ext/standard/string.c
*/
/* Test str_pad() function: with unexpected inputs for '$pad_string'
* and expected type for '$input' and '$pad_length'
*/
echo "*** Testing str_pad() function: with unexpected inputs for 'pad_string' argument ***\n";
//get an unset variable
$unset_var = 'string_val';
unset($unset_var);
//defining a class
class sample {
public function __toString() {
return "sample object";
}
}
//getting the resource
$file_handle = fopen(__FILE__, "r");
// array with different values for $input
$pad_strings = array (
// integer values
/*1*/ 0,
1,
-2,
2147483647,
-2147483648,
// float values
/*6*/ 10.5,
-20.5,
10.1234567e10,
// array values
/*9*/ array(),
array(0),
array(1, 2),
// boolean values
/*12*/ true,
false,
TRUE,
FALSE,
// null vlaues
/*16*/ NULL,
null,
// objects
/*18*/ new sample(),
// resource
/*19*/ $file_handle,
// undefined variable
/*20*/ @$undefined_var,
// unset variable
/*21*/ @$unset_var
);
//defining '$input' argument
$input = "Test string";
$pad_length = 20;
// loop through with each element of the $pad_strings array to test str_pad() function
$count = 1;
foreach($pad_strings as $pad_string) {
echo "-- Iteration $count --\n";
var_dump( str_pad($input, $pad_length, $pad_string) );
$count ++;
}
fclose($file_handle); //closing the file handle
?>
===DONE===
--EXPECTF--
*** Testing str_pad() function: with unexpected inputs for 'pad_string' argument ***
-- Iteration 1 --
unicode(20) "Test string000000000"
-- Iteration 2 --
unicode(20) "Test string111111111"
-- Iteration 3 --
unicode(20) "Test string-2-2-2-2-"
-- Iteration 4 --
unicode(20) "Test string214748364"
-- Iteration 5 --
unicode(20) "Test string-21474836"
-- Iteration 6 --
unicode(20) "Test string10.510.51"
-- Iteration 7 --
unicode(20) "Test string-20.5-20."
-- Iteration 8 --
unicode(20) "Test string101234567"
-- Iteration 9 --
Warning: str_pad() expects parameter 3 to be string (Unicode or binary), array given in %s on line %d
NULL
-- Iteration 10 --
Warning: str_pad() expects parameter 3 to be string (Unicode or binary), array given in %s on line %d
NULL
-- Iteration 11 --
Warning: str_pad() expects parameter 3 to be string (Unicode or binary), array given in %s on line %d
NULL
-- Iteration 12 --
unicode(20) "Test string111111111"
-- Iteration 13 --
Warning: str_pad(): Padding string cannot be empty in %s on line %d
NULL
-- Iteration 14 --
unicode(20) "Test string111111111"
-- Iteration 15 --
Warning: str_pad(): Padding string cannot be empty in %s on line %d
NULL
-- Iteration 16 --
Warning: str_pad(): Padding string cannot be empty in %s on line %d
NULL
-- Iteration 17 --
Warning: str_pad(): Padding string cannot be empty in %s on line %d
NULL
-- Iteration 18 --
unicode(20) "Test stringsample ob"
-- Iteration 19 --
Warning: str_pad() expects parameter 3 to be string (Unicode or binary), resource given in %s on line %d
NULL
-- Iteration 20 --
Warning: str_pad(): Padding string cannot be empty in %s on line %d
NULL
-- Iteration 21 --
Warning: str_pad(): Padding string cannot be empty in %s on line %d
NULL
===DONE===

View File

@ -0,0 +1,168 @@
--TEST--
Test str_pad() function : usage variations - unexpected inputs for '$pad_type' argument
--FILE--
<?php
/* Prototype : string str_pad ( string $input , int $pad_length [, string $pad_string [, int $pad_type ]] )
* Description: Pad a string to a certain length with another string
* Source code: ext/standard/string.c
*/
/* Test str_pad() function: with unexpected inputs for '$pad_type'
* and expected type for '$input', '$pad_length' and '$pad_string'
*/
echo "*** Testing str_pad() function: with unexpected inputs for 'pad_type' argument ***\n";
//get an unset variable
$unset_var = 'string_val';
unset($unset_var);
//defining a class
class sample {
public function __toString() {
return "sample object";
}
}
// array with different values for $input
$pad_types = array (
// integer values
/*1*/ 0, // == STR_PAD_LEFT
1, // == STR_PAD_RIGHT
2, // == STR_PAD_BOTH
-2,
2147483647,
-2147483648,
// float values
/*7*/ 10.5,
-20.5,
10.1234567e10,
// string data
/*10*/ "abc",
"STR_PAD_LEFT",
"2",
"0x2",
"02",
// array values
/*15*/ array(),
array(0),
array(1, 2),
// boolean values
/*18*/ true,
false,
TRUE,
FALSE,
// null vlaues
/*22*/ NULL,
null,
// objects
/*24*/ new sample(),
// undefined variable
/*25*/ @$undefined_var,
// unset variable
/*26*/ @$unset_var
);
//defining '$input' argument
$input = "Test string";
$pad_length = 20;
$pad_string = "*";
// loop through with each element of the $pad_types array to test str_pad() function
$count = 1;
foreach($pad_types as $pad_type) {
echo "-- Iteration $count --\n";
var_dump( str_pad($input, $pad_length, $pad_string, $pad_type) );
$count ++;
}
?>
===DONE===
--EXPECTF--
*** Testing str_pad() function: with unexpected inputs for 'pad_type' argument ***
-- Iteration 1 --
unicode(20) "*********Test string"
-- Iteration 2 --
unicode(20) "Test string*********"
-- Iteration 3 --
unicode(20) "****Test string*****"
-- Iteration 4 --
Warning: str_pad(): Padding type has to be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH in %s on line %d
NULL
-- Iteration 5 --
Warning: str_pad(): Padding type has to be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH in %s on line %d
NULL
-- Iteration 6 --
Warning: str_pad(): Padding type has to be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH in %s on line %d
NULL
-- Iteration 7 --
Warning: str_pad(): Padding type has to be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH in %s on line %d
NULL
-- Iteration 8 --
Warning: str_pad(): Padding type has to be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH in %s on line %d
NULL
-- Iteration 9 --
Warning: str_pad(): Padding type has to be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH in %s on line %d
NULL
-- Iteration 10 --
Warning: str_pad() expects parameter 4 to be long, Unicode string given in %s on line %d
NULL
-- Iteration 11 --
Warning: str_pad() expects parameter 4 to be long, Unicode string given in %s on line %d
NULL
-- Iteration 12 --
unicode(20) "****Test string*****"
-- Iteration 13 --
unicode(20) "****Test string*****"
-- Iteration 14 --
unicode(20) "****Test string*****"
-- Iteration 15 --
Warning: str_pad() expects parameter 4 to be long, array given in %s on line %d
NULL
-- Iteration 16 --
Warning: str_pad() expects parameter 4 to be long, array given in %s on line %d
NULL
-- Iteration 17 --
Warning: str_pad() expects parameter 4 to be long, array given in %s on line %d
NULL
-- Iteration 18 --
unicode(20) "Test string*********"
-- Iteration 19 --
unicode(20) "*********Test string"
-- Iteration 20 --
unicode(20) "Test string*********"
-- Iteration 21 --
unicode(20) "*********Test string"
-- Iteration 22 --
unicode(20) "*********Test string"
-- Iteration 23 --
unicode(20) "*********Test string"
-- Iteration 24 --
Warning: str_pad() expects parameter 4 to be long, object given in %s on line %d
NULL
-- Iteration 25 --
unicode(20) "*********Test string"
-- Iteration 26 --
unicode(20) "*********Test string"
===DONE===

View File

@ -0,0 +1,31 @@
--TEST--
Test str_pad() function : usage variations - unexpected large value for '$pad_length' argument
--INI--
memory_limit=128M
--SKIPIF--
<?php
if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only");
?>
--FILE--
<?php
/* Prototype : string str_pad ( string $input , int $pad_length [, string $pad_string [, int $pad_type ]] )
* Description: Pad a string to a certain length with another string
* Source code: ext/standard/string.c
*/
/* Test str_pad() function: with unexpected inputs for '$pad_length'
* and expected type for '$input'
*/
echo "*** Testing str_pad() function: with large value for for 'pad_length' argument ***\n";
//defining '$input' argument
$input = "Test string";
$pad_length = PHP_INT_MAX;
var_dump( str_pad($input, $pad_length) );
?>
--EXPECTF--
*** Testing str_pad() function: with large value for for 'pad_length' argument ***
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 4294967272 bytes) in %s on line %d

View File

@ -0,0 +1,59 @@
--TEST--
Test str_shuffle() function : basic functionality
--FILE--
<?php
/* Prototype : string str_shuffle ( string $str )
* Description: Randomly shuffles a string
* Source code: ext/standard/string.c
*/
/*
* Testing str_shuffle() : basic functionality
*/
echo "*** Testing str_shuffle() : basic functionality ***\n";
// Initialize all required variables
$str = 'This testcase tests the str_shuffle() function.';
var_dump(str_shuffle($str));
// For a given i/p string ensure that all combinations are
// generated given a reasonable sample of calls
$a = array();
$trys = 1000;
$ip = 'abcd';
$len_ip = strlen($ip);
for ($i = 0; $i < $trys; $i++) {
$op = str_shuffle($ip);
if (!is_string($op) || strlen($op) != $len_ip) {
echo "TEST FAILED\n";
}
// Combination already hit ?
if (empty($a[$op])) {
// No first time init
$a[$op] = 0;
}
// Increment count for this combination
$a[$op]++;
}
$combinations = count($a);
if ($combinations != 24) {
echo "TEST FAILED.. Only $combinations out of a possible 24 combinations used\n";
} else {
echo "TEST PASSED\n";
}
?>
===DONE===
--EXPECTF--
*** Testing str_shuffle() : basic functionality ***
unicode(47) "%s"
TEST PASSED
===DONE===

View File

@ -0,0 +1,33 @@
--TEST--
Test str_shuffle() function : error conditions
--FILE--
<?php
/* Prototype : string str_shuffle ( string $str )
* Description: Randomly shuffles a string
* Source code: ext/standard/string.c
*/
echo "*** Testing str_shuffle() : error conditions ***\n";
echo "\n-- Testing str_shuffle() function with no arguments --\n";
var_dump( str_shuffle() );
echo "\n-- Testing str_shuffle() function with more than expected no. of arguments --\n";
$extra_arg = 10;
var_dump( str_shuffle("Hello World", $extra_arg) );
?>
===DONE===
--EXPECTF--
*** Testing str_shuffle() : error conditions ***
-- Testing str_shuffle() function with no arguments --
Warning: str_shuffle() expects exactly 1 parameter, 0 given in %s on line %d
NULL
-- Testing str_shuffle() function with more than expected no. of arguments --
Warning: str_shuffle() expects exactly 1 parameter, 2 given in %s on line %d
NULL
===DONE===

View File

@ -0,0 +1,135 @@
--TEST--
Test str_shuffle() function : usage variations - test values for $haystack argument
--FILE--
<?php
/* Prototype : string str_shuffle ( string $str )
* Description: Randomly shuffles a string
* Source code: ext/standard/string.c
*/
echo "*** Testing str_shuffle() function: with unexpected inputs for 'string' argument ***\n";
//get an unset variable
$unset_var = 'string_val';
unset($unset_var);
//defining a class
class sample {
public function __toString() {
return "sample object";
}
}
//getting the resource
$file_handle = fopen(__FILE__, "r");
// array with different values for $input
$inputs = array (
// integer values
/*1*/ 0,
1,
-2,
2147483647,
-2147483648,
// float values
/*6*/ 10.5,
-20.5,
10.1234567e10,
// array values
/*9*/ array(),
array(0),
array(1, 2),
// boolean values
/*12*/ true,
false,
TRUE,
FALSE,
// null vlaues
/*16*/ NULL,
null,
// objects
/*18*/ new sample(),
// resource
/*19*/ $file_handle,
// undefined variable
/*20*/ @$undefined_var,
// unset variable
/*21*/ @$unset_var
);
// loop through with each element of the $inputs array to test str_shuffle() function
$count = 1;
foreach($inputs as $input) {
echo "-- Iteration $count --\n";
var_dump( str_shuffle($input) );
$count ++;
}
fclose($file_handle); //closing the file handle
?>
===DONE===
--EXPECTF--
*** Testing str_shuffle() function: with unexpected inputs for 'string' argument ***
-- Iteration 1 --
unicode(1) "0"
-- Iteration 2 --
unicode(1) "1"
-- Iteration 3 --
unicode(2) "%s"
-- Iteration 4 --
unicode(10) "%s"
-- Iteration 5 --
unicode(11) "%s"
-- Iteration 6 --
unicode(4) "%s"
-- Iteration 7 --
unicode(5) "%s"
-- Iteration 8 --
unicode(12) "%s"
-- Iteration 9 --
Warning: str_shuffle() expects parameter 1 to be string (Unicode or binary), array given in %s on line %d
NULL
-- Iteration 10 --
Warning: str_shuffle() expects parameter 1 to be string (Unicode or binary), array given in %s on line %d
NULL
-- Iteration 11 --
Warning: str_shuffle() expects parameter 1 to be string (Unicode or binary), array given in %s on line %d
NULL
-- Iteration 12 --
unicode(1) "1"
-- Iteration 13 --
unicode(0) ""
-- Iteration 14 --
unicode(1) "1"
-- Iteration 15 --
unicode(0) ""
-- Iteration 16 --
unicode(0) ""
-- Iteration 17 --
unicode(0) ""
-- Iteration 18 --
unicode(13) "%s"
-- Iteration 19 --
Warning: str_shuffle() expects parameter 1 to be string (Unicode or binary), resource given in %s on line %d
NULL
-- Iteration 20 --
unicode(0) ""
-- Iteration 21 --
unicode(0) ""
===DONE===

View File

@ -0,0 +1,36 @@
--TEST--
Test stristr() function : basic functionality
--FILE--
<?php
/* Prototype: string stristr ( string $haystack , mixed $needle [, bool $before_needle ] )
Description: Case-insensitive strstr().
*/
echo "*** Testing stristr() : basic functionality ***\n";
var_dump( stristr("Test string", "teSt") );
var_dump( stristr("test stRIng", "striNG") );
var_dump( stristr("teST StrinG", "stRIn") );
var_dump( stristr("tesT string", "t S") );
var_dump( stristr("test strinG", "g") );
var_dump( bin2hex((binary)stristr(b"te".chr(0).b"St", chr(0))) );
var_dump( stristr("tEst", "test") );
var_dump( stristr("teSt", "test") );
var_dump( stristr("Test String", "String", false) );
var_dump( stristr("Test String", "String", true) );
?>
===DONE===
--EXPECTF--
*** Testing stristr() : basic functionality ***
unicode(11) "Test string"
unicode(6) "stRIng"
unicode(6) "StrinG"
unicode(8) "T string"
unicode(1) "G"
unicode(6) "005374"
unicode(4) "tEst"
unicode(4) "teSt"
unicode(6) "String"
unicode(5) "Test "
===DONE===

View File

@ -0,0 +1,60 @@
--TEST--
Test stristr() function : error conditions
--FILE--
<?php
/* Prototype: string stristr ( string $haystack , mixed $needle [, bool $before_needle ] )
Description: Case-insensitive strstr()
*/
echo "*** Testing stristr() : error conditions ***\n";
echo "\n-- Testing stristr() function with no arguments --\n";
var_dump( stristr() );
var_dump( stristr("") );
echo "\n-- Testing stristr() function with no needle --\n";
var_dump( stristr("Hello World") ); // without "needle"
echo "\n-- Testing stristr() function with more than expected no. of arguments --\n";
$extra_arg = 10;
var_dump( stristr("Hello World", "World", true, $extra_arg) );
echo "\n-- Testing stristr() function with empty haystack --\n";
var_dump( stristr(NULL, "") );
echo "\n-- Testing stristr() function with empty needle --\n";
var_dump( stristr("Hello World", "") );
?>
===DONE===
--EXPECTF--
*** Testing stristr() : error conditions ***
-- Testing stristr() function with no arguments --
Warning: stristr() expects at least 2 parameters, 0 given in %s on line %d
NULL
Warning: stristr() expects at least 2 parameters, 1 given in %s on line %d
NULL
-- Testing stristr() function with no needle --
Warning: stristr() expects at least 2 parameters, 1 given in %s on line %d
NULL
-- Testing stristr() function with more than expected no. of arguments --
Warning: stristr() expects at most 3 parameters, 4 given in %s on line %d
NULL
-- Testing stristr() function with empty haystack --
Warning: stristr(): Empty delimiter in %s on line %d
bool(false)
-- Testing stristr() function with empty needle --
Warning: stristr(): Empty delimiter in %s on line %d
bool(false)
===DONE===

View File

@ -0,0 +1,131 @@
--TEST--
Test stristr() function : usage variations - test values for $haystack argument
--FILE--
<?php
/* Prototype: string stristr ( string $haystack, string $needle );
Description: Case-insensitive strstr().
*/
echo "*** Testing stristr() function: with unexpected inputs for 'string' argument ***\n";
//get an unset variable
$unset_var = 'string_val';
unset($unset_var);
//defining a class
class sample {
public function __toString() {
return "sample object";
}
}
//getting the resource
$file_handle = fopen(__FILE__, "r");
// array with different values for $input
$inputs = array (
// integer values
/*1*/ 0,
1,
-2,
-PHP_INT_MAX,
// float values
/*5*/ 10.5,
-20.5,
10.1234567e10,
// array values
/*8*/ array(),
array(0),
array(1, 2),
// boolean values
/*11*/ true,
false,
TRUE,
FALSE,
// null vlaues
/*15*/ NULL,
null,
// objects
/*17*/ new sample(),
// resource
/*18*/ $file_handle,
// undefined variable
/*19*/ @$undefined_var,
// unset variable
/*20*/ @$unset_var
);
//defining '$pad_length' argument
$pad_length = "20";
// loop through with each element of the $inputs array to test stristr() function
$count = 1;
foreach($inputs as $input) {
echo "-- Iteration $count --\n";
var_dump( stristr($input, " ") );
$count ++;
}
fclose($file_handle); //closing the file handle
?>
===DONE===
--EXPECTF--
*** Testing stristr() function: with unexpected inputs for 'string' argument ***
-- Iteration 1 --
bool(false)
-- Iteration 2 --
bool(false)
-- Iteration 3 --
bool(false)
-- Iteration 4 --
bool(false)
-- Iteration 5 --
bool(false)
-- Iteration 6 --
bool(false)
-- Iteration 7 --
bool(false)
-- Iteration 8 --
Notice: Array to string conversion in %s on line %d2
bool(false)
-- Iteration 9 --
Notice: Array to string conversion in %s on line %d2
bool(false)
-- Iteration 10 --
Notice: Array to string conversion in %s on line %d2
bool(false)
-- Iteration 11 --
bool(false)
-- Iteration 12 --
bool(false)
-- Iteration 13 --
bool(false)
-- Iteration 14 --
bool(false)
-- Iteration 15 --
bool(false)
-- Iteration 16 --
bool(false)
-- Iteration 17 --
unicode(7) " object"
-- Iteration 18 --
unicode(%d) " id #%d"
-- Iteration 19 --
bool(false)
-- Iteration 20 --
bool(false)
===DONE===

View File

@ -0,0 +1,135 @@
--TEST--
Test stristr() function : usage variations - test values for $needle argument
--FILE--
<?php
/* Prototype: string stristr ( string $haystack, string $needle );
Description: Case-insensitive strstr().
*/
echo "*** Testing stristr() function: with unexpected inputs for 'needle' argument ***\n";
//get an unset variable
$unset_var = 'string_val';
unset($unset_var);
//defining a class
class sample {
public function __toString() {
return "sample object";
}
}
//getting the resource
$file_handle = fopen(__FILE__, "r");
// array with different values for $input
$inputs = array (
// integer values
/*1*/ 0,
1,
-2,
-PHP_INT_MAX,
// float values
/*5*/ 10.5,
-20.5,
10.1234567e10,
// array values
/*8*/ array(),
array(0),
array(1, 2),
// boolean values
/*11*/ true,
false,
TRUE,
FALSE,
// null vlaues
/*15*/ NULL,
null,
// objects
/*17*/ new sample(),
// resource
/*18*/ $file_handle,
// undefined variable
/*19*/ @$undefined_var,
// unset variable
/*20*/ @$unset_var
);
//defining '$pad_length' argument
$pad_length = "20";
// loop through with each element of the $inputs array to test stristr() function
$count = 1;
foreach($inputs as $input) {
echo "-- Iteration $count --\n";
var_dump( stristr("Hello World", $input) );
$count ++;
}
fclose($file_handle); //closing the file handle
?>
===DONE===
--EXPECTF--
*** Testing stristr() function: with unexpected inputs for 'needle' argument ***
-- Iteration 1 --
bool(false)
-- Iteration 2 --
bool(false)
-- Iteration 3 --
Warning: Needle argument codepoint value out of range (0 - 0x10FFFF) in %s on line %d
bool(false)
-- Iteration 4 --
Warning: Needle argument codepoint value out of range (0 - 0x10FFFF) in %s on line %d
bool(false)
-- Iteration 5 --
bool(false)
-- Iteration 6 --
Warning: Needle argument codepoint value out of range (0 - 0x10FFFF) in %s on line %d
bool(false)
-- Iteration 7 --
Warning: Needle argument codepoint value out of range (0 - 0x10FFFF) in %s on line %d
bool(false)
-- Iteration 8 --
bool(false)
-- Iteration 9 --
bool(false)
-- Iteration 10 --
bool(false)
-- Iteration 11 --
bool(false)
-- Iteration 12 --
bool(false)
-- Iteration 13 --
bool(false)
-- Iteration 14 --
bool(false)
-- Iteration 15 --
bool(false)
-- Iteration 16 --
bool(false)
-- Iteration 17 --
Notice: Object of class sample could not be converted to int in %s on line %d
bool(false)
-- Iteration 18 --
bool(false)
-- Iteration 19 --
bool(false)
-- Iteration 20 --
bool(false)
===DONE===

View File

@ -0,0 +1,24 @@
--TEST--
Test strlen() function : basic functionality
--FILE--
<?php
/* Prototype : int strlen ( string $string )
* Description: Get string length
* Source code: ext/standard/string.c
*/
echo "*** Testing strlen() : basic functionality ***\n";
var_dump(strlen("abcdef"));
var_dump(strlen(" ab de "));
var_dump(strlen(""));
var_dump(strlen("\x90\x91\x00\x93\x94\x90\x91\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f"));
?>
===DONE===
--EXPECTF--
*** Testing strlen() : basic functionality ***
int(6)
int(7)
int(0)
int(18)
===DONE===

View File

@ -0,0 +1,33 @@
--TEST--
Test strlen() function : error conditions
--FILE--
<?php
/* Prototype : int strlen ( string $string )
* Description: Get string length
* Source code: ext/standard/string.c
*/
echo "*** Testing strlen() : unexpected number of arguments ***";
echo "\n-- Testing strlen() function with no arguments --\n";
var_dump( strlen() );
echo "\n-- Testing strlen() function with more than expected no. of arguments --\n";
$extra_arg = 10;
var_dump( strlen("abc def", $extra_arg) );
?>
===DONE===
--EXPECTF--
*** Testing strlen() : unexpected number of arguments ***
-- Testing strlen() function with no arguments --
Warning: strlen() expects exactly 1 parameter, 0 given in %s on line %d
NULL
-- Testing strlen() function with more than expected no. of arguments --
Warning: strlen() expects exactly 1 parameter, 2 given in %s on line %d
NULL
===DONE===

View File

@ -0,0 +1,137 @@
--TEST--
Test strlen() function : usage variations - unexpected input for '$string' argument
--FILE--
<?php
/* Prototype : int strlen ( string $string )
* Description: Get string length
* Source code: ext/standard/string.c
*/
echo "*** Testing strlen() : with unexpected input for 'string' argument ***\n";
//get an unset variable
$unset_var = 'string_val';
unset($unset_var);
//defining a class
class sample {
public function __toString() {
return "sample object";
}
}
//getting the resource
$file_handle = fopen(__FILE__, "r");
// array with different values for $input
$inputs = array (
// integer values
/*1*/ 0,
1,
-2,
2147483647,
-2147483648,
// float values
/*6*/ 10.5,
-20.5,
10.1234567e10,
// array values
/*9*/ array(),
array(0),
array(1, 2),
// boolean values
/*12*/ true,
false,
TRUE,
FALSE,
// null values
/*16*/ NULL,
null,
// objects
/*18*/ new sample(),
// resource
/*19*/ $file_handle,
// undefined variable
/*20*/ @$undefined_var,
// unset variable
/*21*/ @$unset_var
);
//defining '$pad_length' argument
$pad_length = "20";
// loop through with each element of the $inputs array to test strlen() function
$count = 1;
foreach($inputs as $input) {
echo "-- Iteration $count --\n";
var_dump( strlen($input) );
$count ++;
}
fclose($file_handle); //closing the file handle
?>
===Done===
--EXPECTF--
*** Testing strlen() : with unexpected input for 'string' argument ***
-- Iteration 1 --
int(1)
-- Iteration 2 --
int(1)
-- Iteration 3 --
int(2)
-- Iteration 4 --
int(10)
-- Iteration 5 --
int(11)
-- Iteration 6 --
int(4)
-- Iteration 7 --
int(5)
-- Iteration 8 --
int(12)
-- Iteration 9 --
Warning: strlen() expects parameter 1 to be string (Unicode or binary), array given in %s on line %d
NULL
-- Iteration 10 --
Warning: strlen() expects parameter 1 to be string (Unicode or binary), array given in %s on line %d
NULL
-- Iteration 11 --
Warning: strlen() expects parameter 1 to be string (Unicode or binary), array given in %s on line %d
NULL
-- Iteration 12 --
int(1)
-- Iteration 13 --
int(0)
-- Iteration 14 --
int(1)
-- Iteration 15 --
int(0)
-- Iteration 16 --
int(0)
-- Iteration 17 --
int(0)
-- Iteration 18 --
int(13)
-- Iteration 19 --
Warning: strlen() expects parameter 1 to be string (Unicode or binary), resource given in %s on line %d
NULL
-- Iteration 20 --
int(0)
-- Iteration 21 --
int(0)
===Done===

View File

@ -31,42 +31,42 @@ $file_handle = fopen(__FILE__, "r");
// array with different values
$strings = array (
// integer values
0,
1,
-2,
// float values
10.5,
-20.5,
10.5e10,
// array values
array(),
array(0),
array(1, 2),
// boolean values
true,
false,
TRUE,
FALSE,
// null vlaues
NULL,
null,
// objects
new sample(),
// resource
$file_handle,
// undefined variable
@$undefined_var,
// unset variable
@$unset_var
// integer values
/*1*/ 0,
1,
-2,
// float values
/*4*/ 10.5,
-20.5,
10.1234567e10,
// array values
/*7*/ array(),
array(0),
array(1, 2),
// boolean values
/*10*/ true,
false,
TRUE,
FALSE,
// null vlaues
/*14*/ NULL,
null,
// objects
/*16*/ new sample(),
// resource
/*17*/ $file_handle,
// undefined variable
/*18*/ @$undefined_var,
// unset variable
/*19*/ @$unset_var
);
//defining 'from' argument
@ -86,8 +86,8 @@ for($index = 0; $index < count($strings); $index++) {
fclose($file_handle); //closing the file handle
echo "*** Done ***";
?>
===DONE===
--EXPECTF--
*** Testing strtr() function: with unexpected inputs for 'str' ***
-- Iteration 1 --
@ -101,7 +101,7 @@ unicode(4) "ta.5"
-- Iteration 5 --
unicode(5) "-ma.5"
-- Iteration 6 --
unicode(12) "ta5aaaaaaaaa"
unicode(12) "tatm34567aaa"
-- Iteration 7 --
Warning: strtr() expects parameter 1 to be string (Unicode or binary), array given in %s on line %d
@ -136,4 +136,4 @@ NULL
unicode(0) ""
-- Iteration 19 --
unicode(0) ""
*** Done ***
===DONE===

View File

@ -1,5 +1,5 @@
--TEST--
Test strtr() function : usage variations - unexpected inputs for 'from' argument(Bug #42861)
Test strtr() function : usage variations - unexpected inputs for 'from' argument
--FILE--
<?php
/* Prototype : string strtr(string $str, string $from[, string $to]);
@ -34,42 +34,42 @@ $str = "012atm";
// array of values for 'from'
$from_arr = array (
// integer values
0,
1,
-2,
// float values
10.5,
-20.5,
10.5e10,
// array values
array(),
array(0),
array(1, 2),
// boolean values
true,
false,
TRUE,
FALSE,
// null vlaues
NULL,
null,
// objects
new sample(),
// resource
$file_handle,
// undefined variable
@$undefined_var,
// unset variable
@$unset_var
// integer values
/*1*/ 0,
1,
-2,
// float values
/*4*/ 10.5,
-20.5,
10.1234567e10,
// array values
/*7*/ array(),
array(0),
array(1, 2),
// boolean values
/*10*/ true,
false,
TRUE,
FALSE,
// null vlaues
/*14*/ NULL,
null,
// objects
/*16*/ new sample(),
// resource
/*17*/ $file_handle,
// undefined variable
/*18*/ @$undefined_var,
// unset variable
/*19*/ @$unset_var
);
//defining 'to' argument
@ -85,9 +85,8 @@ for($index = 0; $index < count($from_arr); $index++) {
}
fclose($file_handle); //closing the file handle
echo "*** Done ***";
?>
===DONE===
--EXPECTF--
*** Testing strtr() function: with unexpected inputs for 'from' ***
-- Iteration 1 --
@ -101,7 +100,7 @@ unicode(6) "ta2atm"
-- Iteration 5 --
unicode(6) "m1tatm"
-- Iteration 6 --
unicode(6) "2a2atm"
unicode(6) "tm0atm"
-- Iteration 7 --
Notice: Array to string conversion in %s on line %d
@ -134,4 +133,4 @@ unicode(6) "012atm"
unicode(6) "012atm"
-- Iteration 19 --
unicode(6) "012atm"
*** Done ***
===DONE===

View File

@ -1,5 +1,5 @@
--TEST--
Test strtr() function : usage variations - unexpected inputs for 'to' argument(Bug #42861)
Test strtr() function : usage variations - unexpected inputs for 'to' argument
--FILE--
<?php
/* Prototype : string strtr(string $str, string $from[, string $to]);
@ -37,42 +37,42 @@ $from = "atm012";
// array of values for 'to' argument
$to_arr = array (
// integer values
0,
1,
-2,
// float values
10.5,
-20.5,
10.5e10,
// array values
array(),
array(0),
array(1, 2),
// boolean values
true,
false,
TRUE,
FALSE,
// null vlaues
NULL,
null,
// objects
new sample(),
// resource
$file_handle,
// undefined variable
@$undefined_var,
// unset variable
@$unset_var
// integer values
/*1*/ 0,
1,
-2,
// float values
/*4*/ 10.5,
-20.5,
10.12345675e10,
// array values
/*7*/ array(),
array(0),
array(1, 2),
// boolean values
/*10*/ true,
false,
TRUE,
FALSE,
// null vlaues
/*14*/ NULL,
null,
// objects
/*16*/ new sample(),
// resource
/*17*/ $file_handle,
// undefined variable
/*18*/ @$undefined_var,
// unset variable
/*19*/ @$unset_var
);
// loop through with each element of the $to array to test strtr() function
@ -86,8 +86,8 @@ for($index = 0; $index < count($to_arr); $index++) {
fclose($file_handle); //closing the file handle
echo "*** Done ***";
?>
===DONE===
--EXPECTF--
*** Testing strtr() function: with unexpected inputs for 'to' ***
@ -107,7 +107,7 @@ unicode(6) "51210."
unicode(6) ".52-20"
-- Iteration 6 --
unicode(6) "000105"
unicode(6) "234101"
-- Iteration 7 --
@ -155,4 +155,4 @@ unicode(6) "012atm"
-- Iteration 19 --
unicode(6) "012atm"
*** Done ***
===DONE===

View File

@ -19,7 +19,7 @@ unset($unset_var);
//defining a class
class sample {
public function __toString() {
return "My String";
return "sample object";
}
}
@ -29,44 +29,44 @@ $file_handle = fopen(__FILE__, "r");
// array with different values
$values = array (
// integer values
0,
1,
-2,
// float values
10.5,
-20.5,
10.5e10,
// array values
array(),
array(0),
array(1),
array(1, 2),
array('color' => 'red', 'item' => 'pen'),
// boolean values
true,
false,
TRUE,
FALSE,
// null vlaues
NULL,
null,
// objects
new sample(),
// resource
$file_handle,
// undefined variable
@$undefined_var,
// unset variable
@$unset_var
// integer values
/*1*/ 0,
1,
-2,
// float values
/*4*/ 10.5,
-20.5,
10.1234567e10,
// array values
/*7*/ array(),
array(0),
array(1),
array(1, 2),
array('color' => 'red', 'item' => 'pen'),
// boolean values
/*12*/ true,
false,
TRUE,
FALSE,
// null vlaues
/*16*/ NULL,
null,
// objects
/*18*/ new sample(),
// resource
/*19*/ $file_handle,
// undefined variable
/*20*/ @$undefined_var,
// unset variable
/*21*/ @$unset_var
);
// loop through with each element of the $values array to test strtr() function
@ -80,8 +80,8 @@ for($index = 0; $index < count($values); $index++) {
fclose($file_handle); //closing the file handle
echo "*** Done ***";
?>
===DONE===
--EXPECTF--
*** Testing strtr() function: with unexpected inputs for all arguments ***
@ -116,7 +116,7 @@ Warning: strtr(): The second argument is not an array in %s on line %d
bool(false)
-- Iteration 6 --
unicode(12) "105000000000"
unicode(12) "101234567000"
Warning: strtr(): The second argument is not an array in %s on line %d
bool(false)
@ -198,7 +198,7 @@ Warning: strtr(): The second argument is not an array in %s on line %d
bool(false)
-- Iteration 18 --
unicode(9) "My String"
unicode(13) "sample object"
Warning: strtr(): The second argument is not an array in %s on line %d
bool(false)
@ -222,4 +222,4 @@ unicode(0) ""
Warning: strtr(): The second argument is not an array in %s on line %d
bool(false)
*** Done ***
===DONE===