Browse Source

Tests for bug #43841 and #45923

PHP-5.2.1RC1
Ant Phillips 18 years ago
parent
commit
0397dd836b
  1. 86
      ext/mbstring/tests/bug43841.phpt
  2. 119
      ext/mbstring/tests/mb_stripos_variation5_Bug45923.phpt
  3. 206
      ext/mbstring/tests/mb_strripos_variation3_Bug45923.phpt
  4. 115
      ext/mbstring/tests/mb_strripos_variation5_Bug45923.phpt

86
ext/mbstring/tests/bug43841.phpt

@ -0,0 +1,86 @@
--TEST--
Test mb_strrpos() function : mb_strrpos offset is byte count for negative values
--XFAIL--
--SKIPIF--
<?php
extension_loaded('mbstring') or die('skip');
function_exists('mb_strrpos') or die("skip mb_strrpos() is not available in this build");
?>
--FILE--
<?php
/* Prototype : int mb_strrpos(string $haystack, string $needle [, int $offset [, string $encoding]])
* Description: Find position of last occurrence of a string within another
* Source code: ext/mbstring/mbstring.c
*/
/*
* Test that mb_strrpos offset is byte count for negative values (should be character count)
*/
$offsets = array(-25, -24, -13, -12);
$string_mb =
base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvv
JfvvJjvvJnjgII=');
$needle = base64_decode('44CC');
foreach ($offsets as $i) {
echo "\n-- Offset is $i --\n";
echo "Multibyte String:\n";
var_dump( mb_strrpos($string_mb, $needle, $i, 'UTF-8') );
echo "ASCII String:\n";
echo "mb_strrpos:\n";
var_dump(mb_strrpos(b'This is na English ta', b'a', $i));
echo "strrpos:\n";
var_dump(strrpos(b'This is na English ta', b'a', $i));
}
?>
--EXPECTF--
-- Offset is -25 --
Multibyte String:
Notice: mb_strrpos(): Offset is greater than the length of haystack string in %s on line %d
bool(false)
ASCII String:
mb_strrpos:
Notice: mb_strrpos(): Offset is greater than the length of haystack string in %s on line %d
bool(false)
strrpos:
Notice: strrpos(): Offset is greater than the length of haystack string in %s on line %d
bool(false)
-- Offset is -24 --
Multibyte String:
Notice: mb_strrpos(): Offset is greater than the length of haystack string in %s on line %d
bool(false)
ASCII String:
mb_strrpos:
Notice: mb_strrpos(): Offset is greater than the length of haystack string in %s on line %d
bool(false)
strrpos:
Notice: strrpos(): Offset is greater than the length of haystack string in %s on line %d
bool(false)
-- Offset is -13 --
Multibyte String:
bool(false)
ASCII String:
mb_strrpos:
bool(false)
strrpos:
bool(false)
-- Offset is -12 --
Multibyte String:
int(9)
ASCII String:
mb_strrpos:
int(9)
strrpos:
int(9)

119
ext/mbstring/tests/mb_stripos_variation5_Bug45923.phpt

@ -0,0 +1,119 @@
--TEST--
Test mb_stripos() function : usage variations - Pass different integers as $offset argument
--XFAIL--
--SKIPIF--
<?php
extension_loaded('mbstring') or die('skip');
function_exists('mb_stripos') or die("skip mb_stripos() is not available in this build");
?>
--FILE--
<?php
/* Prototype : int mb_stripos(string haystack, string needle [, int offset [, string encoding]])
* Description: Finds position of first occurrence of a string within another, case insensitive
* Source code: ext/mbstring/mbstring.c
* Alias to functions:
*/
/*
* Test how mb_stripos() behaves when passed different integers as $offset argument
* The character length of $string_ascii and $string_mb is the same,
* and the needle appears at the same positions in both strings
*/
mb_internal_encoding('UTF-8');
echo "*** Testing mb_stripos() : usage variations ***\n";
$string_ascii = b'+Is an English string'; //21 chars
$needle_ascii = b'G';
$string_mb = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII='); //21 chars
$needle_mb = base64_decode('44CC');
/*
* Loop through integers as multiples of ten for $offset argument
* mb_stripos should not be able to accept negative values as $offset.
* 60 is larger than *BYTE* count for $string_mb
*/
for ($i = -10; $i <= 60; $i += 10) {
echo "\n**-- Offset is: $i --**\n";
echo "-- ASCII String --\n";
var_dump(mb_stripos($string_ascii, $needle_ascii, $i));
echo "--Multibyte String --\n";
var_dump(mb_stripos($string_mb, $needle_mb, $i, 'UTF-8'));
}
echo "Done";
?>
--EXPECTF--
*** Testing mb_stripos() : usage variations ***
**-- Offset is: -10 --**
-- ASCII String --
Warning: mb_stripos(): Offset not contained in string. in %s on line %d
bool(false)
--Multibyte String --
Warning: mb_stripos(): Offset not contained in string. in %s on line %d
bool(false)
**-- Offset is: 0 --**
-- ASCII String --
int(9)
--Multibyte String --
int(9)
**-- Offset is: 10 --**
-- ASCII String --
int(20)
--Multibyte String --
int(20)
**-- Offset is: 20 --**
-- ASCII String --
int(20)
--Multibyte String --
int(20)
**-- Offset is: 30 --**
-- ASCII String --
Warning: mb_stripos(): Offset not contained in string. in %s on line %d
bool(false)
--Multibyte String --
Warning: mb_stripos(): Offset not contained in string. in %s on line %d
bool(false)
**-- Offset is: 40 --**
-- ASCII String --
Warning: mb_stripos(): Offset not contained in string. in %s on line %d
bool(false)
--Multibyte String --
Warning: mb_stripos(): Offset not contained in string. in %s on line %d
bool(false)
**-- Offset is: 50 --**
-- ASCII String --
Warning: mb_stripos(): Offset not contained in string. in %s on line %d
bool(false)
--Multibyte String --
Warning: mb_stripos(): Offset not contained in string. in %s on line %d
bool(false)
**-- Offset is: 60 --**
-- ASCII String --
Warning: mb_stripos(): Offset not contained in string. in %s on line %d
bool(false)
--Multibyte String --
Warning: mb_stripos(): Offset not contained in string. in %s on line %d
bool(false)
Done

206
ext/mbstring/tests/mb_strripos_variation3_Bug45923.phpt

@ -0,0 +1,206 @@
--TEST--
Test mb_strripos() function : usage variations - pass different data types as $offset arg
--XFAIL--
--SKIPIF--
<?php
extension_loaded('mbstring') or die('skip');
function_exists('mb_strripos') or die("skip mb_strripos() is not available in this build");
?>
--FILE--
<?php
/* Prototype : int mb_strripos(string haystack, string needle [, int offset [, string encoding]])
* Description: Finds position of last occurrence of a string within another, case insensitive
* Source code: ext/mbstring/mbstring.c
* Alias to functions:
*/
/*
* Pass mb_strripos different data types as $offset arg to test behaviour
*/
echo "*** Testing mb_strripos() : usage variations ***\n";
// Initialise function arguments not being substituted
$needle = b'A';
$haystack = b'string_val';
$encoding = 'utf-8';
//get an unset variable
$unset_var = 10;
unset ($unset_var);
// get a class
class classA
{
public function __toString() {
return b"Class A object";
}
}
// heredoc string
$heredoc = b<<<EOT
hello world
EOT;
// get a resource variable
$fp = fopen(__FILE__, "r");
// unexpected values to be passed to $offest argument
$inputs = array(
// int data
/*1*/ 0,
1,
12345,
-2345,
// float data
/*5*/ 12.5,
-12.5,
12.3456789000e10,
12.3456789000E-10,
.5,
// null data
/*10*/ NULL,
null,
// boolean data
/*12*/ true,
false,
TRUE,
FALSE,
// empty data
/*16*/ "",
'',
// string data
/*18*/ b"string",
b'string',
$heredoc,
// object data
/*21*/ new classA(),
// undefined data
/*22*/ @$undefined_var,
// unset data
/*23*/ @$unset_var,
// resource variable
/*24*/ $fp
);
// loop through each element of $inputs to check the behavior of mb_strripos()
$iterator = 1;
foreach($inputs as $input) {
echo "\n-- Iteration $iterator --\n";
var_dump( mb_strripos($haystack, $needle, $input, $encoding));
$iterator++;
};
fclose($fp);
echo "Done";
?>
--EXPECTF--
*** Testing mb_strripos() : usage variations ***
-- Iteration 1 --
int(8)
-- Iteration 2 --
int(8)
-- Iteration 3 --
Notice: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
bool(false)
-- Iteration 4 --
Notice: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
bool(false)
-- Iteration 5 --
Notice: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
bool(false)
-- Iteration 6 --
Notice: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
bool(false)
-- Iteration 7 --
Notice: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
bool(false)
-- Iteration 8 --
int(8)
-- Iteration 9 --
int(8)
-- Iteration 10 --
int(8)
-- Iteration 11 --
int(8)
-- Iteration 12 --
int(8)
-- Iteration 13 --
int(8)
-- Iteration 14 --
int(8)
-- Iteration 15 --
int(8)
-- Iteration 16 --
Warning: mb_strripos() expects parameter 3 to be long, string given in %s on line %d
bool(false)
-- Iteration 17 --
Warning: mb_strripos() expects parameter 3 to be long, string given in %s on line %d
bool(false)
-- Iteration 18 --
Warning: mb_strripos() expects parameter 3 to be long, string given in %s on line %d
bool(false)
-- Iteration 19 --
Warning: mb_strripos() expects parameter 3 to be long, string given in %s on line %d
bool(false)
-- Iteration 20 --
Warning: mb_strripos() expects parameter 3 to be long, string given in %s on line %d
bool(false)
-- Iteration 21 --
Warning: mb_strripos() expects parameter 3 to be long, object given in %s on line %d
bool(false)
-- Iteration 22 --
int(8)
-- Iteration 23 --
int(8)
-- Iteration 24 --
Warning: mb_strripos() expects parameter 3 to be long, resource given in %s on line %d
bool(false)
Done

115
ext/mbstring/tests/mb_strripos_variation5_Bug45923.phpt

@ -0,0 +1,115 @@
--TEST--
Test mb_strripos() function : usage variations - Pass different integers as $offset argument
--XFAIL--
--SKIPIF--
<?php
extension_loaded('mbstring') or die('skip');
function_exists('mb_strripos') or die("skip mb_strripos() is not available in this build");
?>
--FILE--
<?php
/* Prototype : int mb_strripos(string haystack, string needle [, int offset [, string encoding]])
* Description: Finds position of last occurrence of a string within another, case insensitive
* Source code: ext/mbstring/mbstring.c
* Alias to functions:
*/
/*
* Test how mb_strripos() behaves when passed different integers as $offset argument
* The character length of $string_ascii and $string_mb is the same,
* and the needle appears at the same positions in both strings
*/
mb_internal_encoding('UTF-8');
echo "*** Testing mb_strripos() : usage variations ***\n";
$string_ascii = b'+Is an English string'; //21 chars
$needle_ascii = b'G';
$string_mb = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII='); //21 chars
$needle_mb = base64_decode('44CC');
/*
* Loop through integers as multiples of ten for $offset argument
* mb_strripos should not be able to accept negative values as $offset.
* 60 is larger than *BYTE* count for $string_mb
*/
for ($i = -10; $i <= 60; $i += 10) {
echo "\n**-- Offset is: $i --**\n";
echo "-- ASCII String --\n";
var_dump(mb_strripos($string_ascii, $needle_ascii, $i));
echo "--Multibyte String --\n";
var_dump(mb_strripos($string_mb, $needle_mb, $i, 'UTF-8'));
}
echo "Done";
?>
--EXPECTF--
*** Testing mb_strripos() : usage variations ***
**-- Offset is: -10 --**
-- ASCII String --
int(9)
--Multibyte String --
int(9)
**-- Offset is: 0 --**
-- ASCII String --
int(20)
--Multibyte String --
int(20)
**-- Offset is: 10 --**
-- ASCII String --
int(20)
--Multibyte String --
int(20)
**-- Offset is: 20 --**
-- ASCII String --
int(20)
--Multibyte String --
int(20)
**-- Offset is: 30 --**
-- ASCII String --
Notice: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
bool(false)
--Multibyte String --
Notice: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
bool(false)
**-- Offset is: 40 --**
-- ASCII String --
Notice: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
bool(false)
--Multibyte String --
Notice: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
bool(false)
**-- Offset is: 50 --**
-- ASCII String --
Notice: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
bool(false)
--Multibyte String --
Notice: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
bool(false)
**-- Offset is: 60 --**
-- ASCII String --
Notice: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
bool(false)
--Multibyte String --
Notice: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
bool(false)
Done
Loading…
Cancel
Save