New testcases for crc32() function

This commit is contained in:
Raghubansh Kumar 2007-09-26 06:03:55 +00:00
parent d0796d9d68
commit 433d1a5d02
6 changed files with 711 additions and 0 deletions

View File

@ -0,0 +1,41 @@
--TEST--
Test crc32() function : basic functionality
--SKIPIF--
<?php
if (PHP_INT_SIZE != 4)
die("skip this test is for 32bit platform only");
?>
--FILE--
<?php
/* Prototype : string crc32(string $str)
* Description: Calculate the crc32 polynomial of a string
* Source code: ext/standard/crc32.c
* Alias to functions: none
*/
/*
* Testing crc32() : basic functionality
*/
echo "*** Testing crc32() : basic functionality ***\n";
// Initialise all required variables
$str = 'string_val1234';
// Calling crc32() with all possible arguments
// checking for the return type of the function
var_dump( is_int(crc32($str)) );
// Printing the returned value from the function
printf("%u\n", crc32($str) );
echo "Done";
?>
--EXPECTF--
*** Testing crc32() : basic functionality ***
bool(true)
256895812
Done

View File

@ -0,0 +1,47 @@
--TEST--
Test crc32() function : error conditions
--SKIPIF--
<?php
if (PHP_INT_SIZE != 4)
die("skip this test is for 32bit platform only");
?>
--FILE--
<?php
/* Prototype : string crc32(string $str)
* Description: Calculate the crc32 polynomial of a string
* Source code: ext/standard/crc32.c
* Alias to functions: none
*/
/*
* Testing crc32() : error conditions
*/
echo "*** Testing crc32() : error conditions ***\n";
// Zero arguments
echo "\n-- Testing crc32() function with Zero arguments --\n";
var_dump( crc32() );
//Test crc32 with one more than the expected number of arguments
echo "\n-- Testing crc32() function with more than expected no. of arguments --\n";
$str = 'string_val';
$extra_arg = 10;
var_dump( crc32($str, $extra_arg) );
echo "Done";
?>
--EXPECTF--
*** Testing crc32() : error conditions ***
-- Testing crc32() function with Zero arguments --
Warning: crc32() expects exactly 1 parameter, 0 given in %s on line %d
NULL
-- Testing crc32() function with more than expected no. of arguments --
Warning: crc32() expects exactly 1 parameter, 2 given in %s on line %d
NULL
Done

View File

@ -0,0 +1,196 @@
--TEST--
Test crc32() function : usage variations - unexpected values
--SKIPIF--
<?php
if (PHP_INT_SIZE != 4)
die("skip this test is for 32bit platform only");
?>
--FILE--
<?php
/* Prototype : string crc32(string $str)
* Description: Calculate the crc32 polynomial of a string
* Source code: ext/standard/crc32.c
* Alias to functions: none
*/
/*
* Testing crc32() : with unexpected values for str argument
*/
echo "*** Testing crc32() : with unexpected values for str argument ***\n";
//get an unset variable
$unset_var = 10;
unset ($unset_var);
// declaring class
class sample {
public function __toString() {
return "object";
}
}
// creating a file resource
$file_handle = fopen(__FILE__, 'r');
//array of values to iterate over
$values = array(
// int data
0,
1,
12345,
-2345,
// float data
10.5,
-10.5,
10.5e10,
10.6E-10,
.5,
// array data
array(),
array(0),
array(1),
array(1, 2),
array('color' => 'red', 'item' => 'pen'),
// null data
NULL,
null,
// boolean data
true,
false,
TRUE,
FALSE,
// empty data
"",
'',
// object data
new sample(),
// undefined data
$undefined_var,
// unset data
$unset_var,
// resource
$file_handle
);
// loop through each element of the array for str
$count = 1;
foreach($values as $value) {
echo "\n-- Iteration $count --\n";
var_dump( crc32($value) );
};
// closing the resource
fclose($file_handle);
echo "Done";
?>
--EXPECTF--
*** Testing crc32() : with unexpected values for str argument ***
Notice: Undefined variable: undefined_var in %s on line %d
Notice: Undefined variable: unset_var in %s on line %d
-- Iteration 1 --
int(-186917087)
-- Iteration 1 --
int(-2082672713)
-- Iteration 1 --
int(-873121252)
-- Iteration 1 --
int(1860518047)
-- Iteration 1 --
int(269248583)
-- Iteration 1 --
int(-834950157)
-- Iteration 1 --
int(-638440228)
-- Iteration 1 --
int(-742287383)
-- Iteration 1 --
int(-2036403827)
-- Iteration 1 --
Warning: crc32() expects parameter 1 to be string, array given in %s on line %d
NULL
-- Iteration 1 --
Warning: crc32() expects parameter 1 to be string, array given in %s on line %d
NULL
-- Iteration 1 --
Warning: crc32() expects parameter 1 to be string, array given in %s on line %d
NULL
-- Iteration 1 --
Warning: crc32() expects parameter 1 to be string, array given in %s on line %d
NULL
-- Iteration 1 --
Warning: crc32() expects parameter 1 to be string, array given in %s on line %d
NULL
-- Iteration 1 --
int(0)
-- Iteration 1 --
int(0)
-- Iteration 1 --
int(-2082672713)
-- Iteration 1 --
int(0)
-- Iteration 1 --
int(-2082672713)
-- Iteration 1 --
int(0)
-- Iteration 1 --
int(0)
-- Iteration 1 --
int(0)
-- Iteration 1 --
int(-1465013268)
-- Iteration 1 --
int(0)
-- Iteration 1 --
int(0)
-- Iteration 1 --
Warning: crc32() expects parameter 1 to be string, resource given in %s on line %d
NULL
Done

View File

@ -0,0 +1,149 @@
--TEST--
Test crc32() function : usage variations - single quoted strings
--SKIPIF--
<?php
if (PHP_INT_SIZE != 4)
die("skip this test is for 32bit platform only");
?>
--FILE--
<?php
/* Prototype : string crc32(string $str)
* Description: Calculate the crc32 polynomial of a string
* Source code: ext/standard/crc32.c
* Alias to functions: none
*/
/*
* Testing crc32() : with different strings in single quotes passed to the function
*/
echo "*** Testing crc32() : with different strings in single quotes ***\n";
// defining an array of strings
$string_array = array(
'',
' ',
'hello world',
'HELLO WORLD',
' helloworld ',
'(hello world)',
'hello(world)',
'helloworld()',
'hello()(world',
'"hello" world',
'hello "world"',
'hello""world',
'hello\tworld',
'hellowor\\tld',
'\thello world\t',
'hello\nworld',
'hellowor\\nld',
'\nhello world\n',
'\n\thelloworld',
'hel\tlo\n world',
'!@#$%&',
'#hello@world.com',
'$hello$world',
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbb
cccccccccccccccccccccccccccccccccddddddddddddddddddddddddddddddddd
eeeeeeeeeeeeeeeeeeeeeeeeeeeeffffffffffffffffffffffffffffffffffffff
gggggggggggggggggggggggggggggggggggggggggghhhhhhhhhhhhhhhhhhhhhhhh
111111111111111111111122222222222222222222222222222222222222222222
333333333333333333333333333333333334444444444444444444444444444444
555555555555555555555555555555555555555555556666666666666666666666
777777777777777777777777777777777777777777777777777777777777777777
/t/t/t/t/t/t/t/t/t/t/t/t/t/t/t/t/t/t/t/t/t/t/t/t/t/t/t/t/t/t/t/t/t
/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n'
);
// looping to check the behaviour of the function for each string in the array
$count = 1;
foreach($string_array as $str) {
echo "\n-- Iteration $count --\n";
var_dump( crc32($str) );
$count++;
}
echo "Done";
?>
--EXPECTF--
*** Testing crc32() : with different strings in single quotes ***
-- Iteration 1 --
int(0)
-- Iteration 2 --
int(-378745019)
-- Iteration 3 --
int(222957957)
-- Iteration 4 --
int(-2015000997)
-- Iteration 5 --
int(1234261835)
-- Iteration 6 --
int(-1867296214)
-- Iteration 7 --
int(1048577080)
-- Iteration 8 --
int(2129739710)
-- Iteration 9 --
int(-1633247628)
-- Iteration 10 --
int(135755572)
-- Iteration 11 --
int(27384015)
-- Iteration 12 --
int(-497244052)
-- Iteration 13 --
int(-2065897232)
-- Iteration 14 --
int(243585859)
-- Iteration 15 --
int(-856440615)
-- Iteration 16 --
int(647088397)
-- Iteration 17 --
int(523630053)
-- Iteration 18 --
int(-2062229676)
-- Iteration 19 --
int(1169918910)
-- Iteration 20 --
int(-618551732)
-- Iteration 21 --
int(-1828940657)
-- Iteration 22 --
int(-1654468652)
-- Iteration 23 --
int(-1648442217)
-- Iteration 24 --
int(1431761713)
Done

View File

@ -0,0 +1,161 @@
--TEST--
Test crc32() function : usage variations - double quoted strings
--SKIPIF--
<?php
if (PHP_INT_SIZE != 4)
die("skip this test is for 32bit platform only");
?>
--FILE--
<?php
/* Prototype : string crc32(string $str)
* Description: Calculate the crc32 polynomial of a string
* Source code: ext/standard/crc32.c
* Alias to functions: none
*/
/*
* Testing crc32() : with different strings in double quotes passed to the function
*/
echo "*** Testing crc32() : with different strings in double quotes ***\n";
// defining an array of strings
$string_array = array(
"",
" ",
"hello world",
"HELLO WORLD",
" helloworld ",
"(hello world)",
"hello(world)",
"helloworld()",
"hello()(world",
"'hello' world",
"hello 'world'",
"hello''world",
"hello\tworld",
"hellowor\\tld",
"\thello world\t",
"helloworld",
"hellowor\\ld",
"hello\nworld",
"hellowor\\nld",
"\nhello world\n",
"\n\thelloworld",
"hel\tlo\n world",
"!@#$%&",
"#hello@world.com",
"$hello$world",
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbb
cccccccccccccccccccccccccccccccccddddddddddddddddddddddddddddddddd
eeeeeeeeeeeeeeeeeeeeeeeeeeeeffffffffffffffffffffffffffffffffffffff
gggggggggggggggggggggggggggggggggggggggggghhhhhhhhhhhhhhhhhhhhhhhh
111111111111111111111122222222222222222222222222222222222222222222
333333333333333333333333333333333334444444444444444444444444444444
555555555555555555555555555555555555555555556666666666666666666666
777777777777777777777777777777777777777777777777777777777777777777
/t/t/t/t/t/t/t/t/t/t/t/t/t/t/t/t/t/t/t/t/t/t/t/t/t/t/t/t/t/t/t/t/t
/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n"
);
// looping to check the behaviour of the function for each string in the array
$count = 1;
foreach($string_array as $str) {
echo "\n-- Iteration $count --\n";
var_dump( crc32($str) );
$count++;
}
echo "Done";
?>
--EXPECTF--
*** Testing crc32() : with different strings in double quotes ***
Notice: Undefined variable: hello in %s on line %d
Notice: Undefined variable: world in %s on line %d
-- Iteration 1 --
int(0)
-- Iteration 2 --
int(-378745019)
-- Iteration 3 --
int(222957957)
-- Iteration 4 --
int(-2015000997)
-- Iteration 5 --
int(1234261835)
-- Iteration 6 --
int(-1867296214)
-- Iteration 7 --
int(1048577080)
-- Iteration 8 --
int(2129739710)
-- Iteration 9 --
int(-1633247628)
-- Iteration 10 --
int(1191242624)
-- Iteration 11 --
int(603128807)
-- Iteration 12 --
int(-525789576)
-- Iteration 13 --
int(770262395)
-- Iteration 14 --
int(243585859)
-- Iteration 15 --
int(-986324846)
-- Iteration 16 --
int(-102031187)
-- Iteration 17 --
int(-588181215)
-- Iteration 18 --
int(-1417857067)
-- Iteration 19 --
int(523630053)
-- Iteration 20 --
int(-503915034)
-- Iteration 21 --
int(-254912432)
-- Iteration 22 --
int(-1581578467)
-- Iteration 23 --
int(-1828940657)
-- Iteration 24 --
int(-1654468652)
-- Iteration 25 --
int(0)
-- Iteration 26 --
int(1431761713)
Done

View File

@ -0,0 +1,117 @@
--TEST--
Test crc32() function : usage variations - heredoc strings
--SKIPIF--
<?php
if (PHP_INT_SIZE != 4)
die("skip this test is for 32bit platform only");
?>
--FILE--
<?php
/* Prototype : string crc32(string $str)
* Description: Calculate the crc32 polynomial of a string
* Source code: ext/standard/crc32.c
* Alias to functions: none
*/
/*
* Testing crc32() : with different heredoc strings passed to the str argument
*/
echo "*** Testing crc32() : with different heredoc strings ***\n";
// defining different heredoc strings
$empty_heredoc = <<<EOT
EOT;
$heredoc_with_newline = <<<EOT
\n
EOT;
$heredoc_with_characters = <<<EOT
first line of heredoc string
second line of heredoc string
third line of heredocstring
EOT;
$heredoc_with_newline_and_tabs = <<<EOT
hello\tworld\nhello\nworld\n
EOT;
$heredoc_with_alphanumerics = <<<EOT
hello123world456
1234hello\t1234
EOT;
$heredoc_with_embedded_nulls = <<<EOT
hello\0world\0hello
\0hello\0
EOT;
$heredoc_with_hexa_octal = <<<EOT
hello\0\100\xaaworld\0hello
\0hello\0
EOT;
$heredoc_with_long_string = <<<EOT
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbb
cccccccccccccccccccccccccccccccccddddddddddddddddddddddddddddddddd
eeeeeeeeeeeeeeeeeeeeeeeeeeeeffffffffffffffffffffffffffffffffffffff
gggggggggggggggggggggggggggggggggggggggggghhhhhhhhhhhhhhhhhhhhhhhh
111111111111111111111122222222222222222222222222222222222222222222
333333333333333333333333333333333334444444444444444444444444444444
555555555555555555555555555555555555555555556666666666666666666666
777777777777777777777777777777777777777777777777777777777777777777
/t/t/t/t/t/t/t/t/t/t/t/t/t/t/t/t/t/t/t/t/t/t/t/t/t/t/t/t/t/t/t/t/t
/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n
EOT;
$heredoc_strings = array(
$empty_heredoc,
$heredoc_with_newline,
$heredoc_with_characters,
$heredoc_with_newline_and_tabs,
$heredoc_with_alphanumerics,
$heredoc_with_embedded_nulls,
$heredoc_with_hexa_octal,
$heredoc_with_long_string
);
// loop to test the function with each heredoc string in the array
$count = 1;
foreach($heredoc_strings as $str) {
echo "\n-- Iteration $count --\n";
var_dump( crc32($str) );
$count++;
}
echo "Done";
?>
--EXPECTF--
*** Testing crc32() : with different heredoc strings ***
-- Iteration 1 --
int(0)
-- Iteration 2 --
int(1541608299)
-- Iteration 3 --
int(1588851550)
-- Iteration 4 --
int(-1726108239)
-- Iteration 5 --
int(-1847303891)
-- Iteration 6 --
int(-1260053120)
-- Iteration 7 --
int(-1718044186)
-- Iteration 8 --
int(1646793751)
Done