dkelsey Fri Jan 23 15:34:22 2009 UTC Modified files: /php-src/ext/standard/tests/network fsockopen_variation1.phpt socket_get_status_basic.phpt closelog_basic.phpt long2ip_error.phpt syslog_basic-win32.phpt closelog_error.phpt syslog_error.phpt long2ip_variation1.phpt fsockopen_variation2.phpt fsockopen_basic.phpt ip2long_error.phpt fsockopen_error.phpt ip2long_variation1.phpt Log: various network tests. tested on windows, linux, linux 64 bit
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/network/fsockopen_variation1.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/standard/tests/network/fsockopen_variation1.phpt diff -u /dev/null php-src/ext/standard/tests/network/fsockopen_variation1.phpt:1.2 --- /dev/null Fri Jan 23 15:34:22 2009 +++ php-src/ext/standard/tests/network/fsockopen_variation1.phpt Fri Jan 23 15:34:21 2009 @@ -0,0 +1,32 @@ +--TEST-- +testing fsockopen without a protocol string +--FILE-- +<?php + +echo "Open a server socket\n"; +$server = stream_socket_server('tcp://127.0.0.1:31337'); + +echo "\nCalling fsockopen() without a protocol in the hostname string:\n"; +$hostname = '127.0.0.1'; +$port = '31337'; +$client = fsockopen($hostname, $port); +var_dump($client); +fclose($client); + +echo "\nCalling fsockopen() with address and port in same string, without a protocol:\n"; +$address = $hostname . ':' . $port; +$second_client = fsockopen($address); +var_dump($second_client); +fclose($second_client); + +echo "Done"; +?> +--EXPECTF-- +Open a server socket + +Calling fsockopen() without a protocol in the hostname string: +resource(%d) of type (stream) + +Calling fsockopen() with address and port in same string, without a protocol: +resource(%d) of type (stream) +Done http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/network/socket_get_status_basic.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/standard/tests/network/socket_get_status_basic.phpt diff -u /dev/null php-src/ext/standard/tests/network/socket_get_status_basic.phpt:1.2 --- /dev/null Fri Jan 23 15:34:22 2009 +++ php-src/ext/standard/tests/network/socket_get_status_basic.phpt Fri Jan 23 15:34:22 2009 @@ -0,0 +1,29 @@ +--TEST-- +Testing socket_get_status() +--FILE-- +<?php + +$tcp_socket = stream_socket_server('tcp://127.0.0.1:31337'); +var_dump(socket_get_status($tcp_socket)); +fclose($tcp_socket); + +?> +--EXPECT-- +array(8) { + [u"stream_type"]=> + unicode(10) "tcp_socket" + [u"mode"]=> + unicode(2) "r+" + [u"unread_bytes"]=> + int(0) + [u"unread_chars"]=> + int(0) + [u"seekable"]=> + bool(false) + [u"timed_out"]=> + bool(false) + [u"blocked"]=> + bool(true) + [u"eof"]=> + bool(false) +} http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/network/closelog_basic.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/standard/tests/network/closelog_basic.phpt diff -u /dev/null php-src/ext/standard/tests/network/closelog_basic.phpt:1.2 --- /dev/null Fri Jan 23 15:34:22 2009 +++ php-src/ext/standard/tests/network/closelog_basic.phpt Fri Jan 23 15:34:22 2009 @@ -0,0 +1,23 @@ +--TEST-- +Test closelog() function : basic functionality +--FILE-- +<?php +/* Prototype : bool closelog(void) + * Description: Close connection to system logger + * Source code: ext/standard/syslog.c + * Alias to functions: + */ + +echo "*** Testing closelog() : basic functionality ***\n"; + +// Zero arguments +echo "\n-- Testing closelog() function with Zero arguments --\n"; +var_dump( closelog() ); +?> +===DONE=== +--EXPECT-- +*** Testing closelog() : basic functionality *** + +-- Testing closelog() function with Zero arguments -- +bool(true) +===DONE=== http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/network/long2ip_error.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/standard/tests/network/long2ip_error.phpt diff -u /dev/null php-src/ext/standard/tests/network/long2ip_error.phpt:1.2 --- /dev/null Fri Jan 23 15:34:22 2009 +++ php-src/ext/standard/tests/network/long2ip_error.phpt Fri Jan 23 15:34:22 2009 @@ -0,0 +1,37 @@ +--TEST-- +Test long2ip() function : error conditions +--FILE-- +<?php +/* Prototype : string long2ip(int proper_address) + * Description: Converts an (IPv4) Internet network address into a string in Internet standard dotted format + * Source code: ext/standard/basic_functions.c + * Alias to functions: + */ + +echo "*** Testing long2ip() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing long2ip() function with Zero arguments --\n"; +var_dump( long2ip() ); + +//Test long2ip with one more than the expected number of arguments +echo "\n-- Testing long2ip() function with more than expected no. of arguments --\n"; +$proper_address = 10; +$extra_arg = 10; +var_dump( long2ip($proper_address, $extra_arg) ); + +?> +===DONE=== +--EXPECTF-- +*** Testing long2ip() : error conditions *** + +-- Testing long2ip() function with Zero arguments -- + +Warning: long2ip() expects exactly 1 parameter, 0 given in %s on line %d +NULL + +-- Testing long2ip() function with more than expected no. of arguments -- + +Warning: long2ip() expects exactly 1 parameter, 2 given in %s on line %d +NULL +===DONE=== \ No newline at end of file http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/network/syslog_basic-win32.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/standard/tests/network/syslog_basic-win32.phpt diff -u /dev/null php-src/ext/standard/tests/network/syslog_basic-win32.phpt:1.2 --- /dev/null Fri Jan 23 15:34:22 2009 +++ php-src/ext/standard/tests/network/syslog_basic-win32.phpt Fri Jan 23 15:34:22 2009 @@ -0,0 +1,31 @@ +--TEST-- +Test syslog() function : basic functionality +--SKIPIF-- +<?php +if(substr(PHP_OS, 0, 3) != "WIN") + die("skip Only run on Windows"); +?> +--FILE-- +<?php +/* Prototype : bool syslog(int priority, string message) + * Description: Generate a system log message + * Source code: ext/standard/syslog.c + * Alias to functions: + */ + +echo "*** Testing syslog() : basic functionality ***\n"; + + +// Initialise all required variables +$priority = LOG_WARNING; +$message = 'A test syslog call invocation'; + +// Calling syslog() with all possible arguments +var_dump( syslog($priority, $message) ); + +?> +===DONE=== +--EXPECT-- +*** Testing syslog() : basic functionality *** +bool(true) +===DONE=== http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/network/closelog_error.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/standard/tests/network/closelog_error.phpt diff -u /dev/null php-src/ext/standard/tests/network/closelog_error.phpt:1.2 --- /dev/null Fri Jan 23 15:34:22 2009 +++ php-src/ext/standard/tests/network/closelog_error.phpt Fri Jan 23 15:34:22 2009 @@ -0,0 +1,27 @@ +--TEST-- +Test closelog() function : error conditions +--FILE-- +<?php +/* Prototype : bool closelog(void) + * Description: Close connection to system logger + * Source code: ext/standard/syslog.c + * Alias to functions: + */ + +echo "*** Testing closelog() : error conditions ***\n"; + +// One argument +echo "\n-- Testing closelog() function with one argument --\n"; +$extra_arg = 10;; +var_dump( closelog($extra_arg) ); + +?> +===DONE=== +--EXPECTF-- +*** Testing closelog() : error conditions *** + +-- Testing closelog() function with one argument -- + +Warning: closelog() expects exactly 0 parameters, 1 given in %s on line %d +NULL +===DONE=== http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/network/syslog_error.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/standard/tests/network/syslog_error.phpt diff -u /dev/null php-src/ext/standard/tests/network/syslog_error.phpt:1.2 --- /dev/null Fri Jan 23 15:34:22 2009 +++ php-src/ext/standard/tests/network/syslog_error.phpt Fri Jan 23 15:34:22 2009 @@ -0,0 +1,40 @@ +--TEST-- +Test syslog() function : error conditions +--FILE-- +<?php +/* Prototype : bool syslog(int priority, string message) + * Description: Generate a system log message + * Source code: ext/standard/syslog.c + * Alias to functions: + */ + +echo "*** Testing syslog() : error conditions ***\n"; + + +//Test syslog with one more than the expected number of arguments +echo "\n-- Testing syslog() function with more than expected no. of arguments --\n"; +$priority = 10; +$message = 'string_val'; +$extra_arg = 10; +var_dump( syslog($priority, $message, $extra_arg) ); + +// Testing syslog with one less than the expected number of arguments +echo "\n-- Testing syslog() function with less than expected no. of arguments --\n"; +$priority = 10; +var_dump( syslog($priority) ); + +?> +===DONE=== +--EXPECTF-- +*** Testing syslog() : error conditions *** + +-- Testing syslog() function with more than expected no. of arguments -- + +Warning: syslog() expects exactly 2 parameters, 3 given in %s on line %d +NULL + +-- Testing syslog() function with less than expected no. of arguments -- + +Warning: syslog() expects exactly 2 parameters, 1 given in %s on line %d +NULL +===DONE=== http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/network/long2ip_variation1.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/standard/tests/network/long2ip_variation1.phpt diff -u /dev/null php-src/ext/standard/tests/network/long2ip_variation1.phpt:1.2 --- /dev/null Fri Jan 23 15:34:22 2009 +++ php-src/ext/standard/tests/network/long2ip_variation1.phpt Fri Jan 23 15:34:22 2009 @@ -0,0 +1,196 @@ +--TEST-- +Test long2ip() function : usage variation +--SKIPIF-- +<?php +if(substr(PHP_OS, 0, 3) == "WIN") + die("skip don't run on Windows"); +?> +--FILE-- +<?php +/* Prototype : string long2ip(int proper_address) + * Description: Converts an (IPv4) Internet network address into a string in Internet standard dotted format + * Source code: ext/standard/basic_functions.c + * Alias to functions: + */ + +echo "*** Testing long2ip() : usage variation ***\n"; + +// Define error handler +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + if (error_reporting() != 0) { + // report non-silenced errors + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; + } +} +set_error_handler('test_error_handler'); + +// Initialise function arguments not being substituted (if any) + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +// resource +$res = fopen(__FILE__,'r'); + +//array of values to iterate over +$inputs = array( + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float .5' => .5, + + // array data + 'empty array' => array(), + 'int indexed array' => $index_array, + 'associative array' => $assoc_array, + 'nested arrays' => array('foo', $index_array, $assoc_array), + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, + + // resource + 'resource' => $res, +); + +// loop through each element of the array for proper_address + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( long2ip($value) ); +}; + +fclose($res); + +?> +===DONE=== +--EXPECTF-- +*** Testing long2ip() : usage variation *** + +--float 10.5-- +unicode(8) "0.0.0.10" + +--float -10.5-- +unicode(15) "255.255.255.246" + +--float .5-- +unicode(7) "0.0.0.0" + +--empty array-- +Error: 2 - long2ip() expects parameter 1 to be binary string, array given, %s(%d) +NULL + +--int indexed array-- +Error: 2 - long2ip() expects parameter 1 to be binary string, array given, %s(%d) +NULL + +--associative array-- +Error: 2 - long2ip() expects parameter 1 to be binary string, array given, %s(%d) +NULL + +--nested arrays-- +Error: 2 - long2ip() expects parameter 1 to be binary string, array given, %s(%d) +NULL + +--uppercase NULL-- +unicode(7) "0.0.0.0" + +--lowercase null-- +unicode(7) "0.0.0.0" + +--lowercase true-- +unicode(7) "0.0.0.1" + +--lowercase false-- +unicode(7) "0.0.0.0" + +--uppercase TRUE-- +unicode(7) "0.0.0.1" + +--uppercase FALSE-- +unicode(7) "0.0.0.0" + +--empty string DQ-- +unicode(7) "0.0.0.0" + +--empty string SQ-- +unicode(7) "0.0.0.0" + +--string DQ-- +unicode(7) "0.0.0.0" + +--string SQ-- +unicode(7) "0.0.0.0" + +--mixed case string-- +unicode(7) "0.0.0.0" + +--heredoc-- +unicode(7) "0.0.0.0" + +--instance of classWithToString-- +unicode(7) "0.0.0.0" + +--instance of classWithoutToString-- +Error: 2 - long2ip() expects parameter 1 to be binary string, object given, %s(%d) +NULL + +--undefined var-- +unicode(7) "0.0.0.0" + +--unset var-- +unicode(7) "0.0.0.0" + +--resource-- +Error: 2 - long2ip() expects parameter 1 to be binary string, resource given, %s(%d) +NULL +===DONE=== http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/network/fsockopen_variation2.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/standard/tests/network/fsockopen_variation2.phpt diff -u /dev/null php-src/ext/standard/tests/network/fsockopen_variation2.phpt:1.2 --- /dev/null Fri Jan 23 15:34:22 2009 +++ php-src/ext/standard/tests/network/fsockopen_variation2.phpt Fri Jan 23 15:34:22 2009 @@ -0,0 +1,48 @@ +--TEST-- +testing fsockopen() with udp sockets +--FILE-- +<?php + +$hostname = 'udp://127.0.0.1'; +$port = '31337'; + +echo "Open a server socket\n"; +$server = stream_socket_server($hostname . ':' . $port, $errno, $errstr, STREAM_SERVER_BIND); + +echo "\nCalling fsockopen():\n"; +$client = fsockopen($hostname, $port); +var_dump($client); + +echo "\nPass some data between the sockets:\n"; +fwrite($client, b"0123456789"); +var_dump(fread($server, 10)); +fclose($client); + +echo "\nCalling fsockopen() with address and port in same string:\n"; +$address = $hostname . ':' . $port; +$second_client = fsockopen($address); +var_dump($second_client); + +echo "\nPass some data between the sockets:\n"; +fwrite($second_client, b"0123456789"); +var_dump(fread($server, 10)); +fclose($second_client); + +echo "Done"; + +?> +--EXPECTF-- +Open a server socket + +Calling fsockopen(): +resource(%d) of type (stream) + +Pass some data between the sockets: +string(10) "0123456789" + +Calling fsockopen() with address and port in same string: +resource(%d) of type (stream) + +Pass some data between the sockets: +string(10) "0123456789" +Done http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/network/fsockopen_basic.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/standard/tests/network/fsockopen_basic.phpt diff -u /dev/null php-src/ext/standard/tests/network/fsockopen_basic.phpt:1.2 --- /dev/null Fri Jan 23 15:34:22 2009 +++ php-src/ext/standard/tests/network/fsockopen_basic.phpt Fri Jan 23 15:34:22 2009 @@ -0,0 +1,54 @@ +--TEST-- +Test fsockopen() function : basic functionality +--FILE-- +<?php +/* Prototype : proto resource fsockopen(string hostname, int port [, int errno [, string errstr [, float timeout]]]) + * Description: Open Internet or Unix domain socket connection + * Source code: ext/standard/fsock.c + * Alias to functions: + */ + +echo "*** Testing fsockopen() : basic functionality ***\n"; + +echo "Open a server socket\n"; +$server = stream_socket_server('tcp://127.0.0.1:31337'); + + +// Initialise all required variables +$hostname = 'tcp://127.0.0.1'; // loopback address +$port = 31337; +$errno = null; +$errstr = null; +$timeout = 1.5; + +echo "\nCalling fsockopen() with all possible arguments:\n"; +$client = fsockopen($hostname, $port, $errno, $errstr, $timeout); +var_dump($client); +fclose($client); + +echo "\nCalling fsockopen() with mandatory arguments:\n"; +$second_client = fsockopen($hostname, $port); +var_dump($second_client); +fclose($second_client); + +echo "\nCalling fsockopen() with address and port in same string:\n"; +$address = $hostname . ':' . $port; +$third_client = fsockopen($address); +var_dump($third_client); +fclose($third_client); + +echo "Done"; +?> +--EXPECTF-- +*** Testing fsockopen() : basic functionality *** +Open a server socket + +Calling fsockopen() with all possible arguments: +resource(%d) of type (stream) + +Calling fsockopen() with mandatory arguments: +resource(%d) of type (stream) + +Calling fsockopen() with address and port in same string: +resource(%d) of type (stream) +Done http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/network/ip2long_error.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/standard/tests/network/ip2long_error.phpt diff -u /dev/null php-src/ext/standard/tests/network/ip2long_error.phpt:1.2 --- /dev/null Fri Jan 23 15:34:22 2009 +++ php-src/ext/standard/tests/network/ip2long_error.phpt Fri Jan 23 15:34:22 2009 @@ -0,0 +1,37 @@ +--TEST-- +Test ip2long() function : error conditions +--FILE-- +<?php +/* Prototype : int ip2long(string ip_address) + * Description: Converts a string containing an (IPv4) Internet Protocol dotted address into a proper address + * Source code: ext/standard/basic_functions.c + * Alias to functions: + */ + +echo "*** Testing ip2long() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing ip2long() function with Zero arguments --\n"; +var_dump( ip2long() ); + +//Test ip2long with one more than the expected number of arguments +echo "\n-- Testing ip2long() function with more than expected no. of arguments --\n"; +$ip_address = '127.0.0.1'; +$extra_arg = 10; +var_dump( ip2long($ip_address, $extra_arg) ); + +?> +===DONE=== +--EXPECTF-- +*** Testing ip2long() : error conditions *** + +-- Testing ip2long() function with Zero arguments -- + +Warning: ip2long() expects exactly 1 parameter, 0 given in %s on line %d +NULL + +-- Testing ip2long() function with more than expected no. of arguments -- + +Warning: ip2long() expects exactly 1 parameter, 2 given in %s on line %d +NULL +===DONE=== http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/network/fsockopen_error.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/standard/tests/network/fsockopen_error.phpt diff -u /dev/null php-src/ext/standard/tests/network/fsockopen_error.phpt:1.2 --- /dev/null Fri Jan 23 15:34:22 2009 +++ php-src/ext/standard/tests/network/fsockopen_error.phpt Fri Jan 23 15:34:22 2009 @@ -0,0 +1,75 @@ +--TEST-- +Test fsockopen() function : error conditions +--FILE-- +<?php +/* Prototype : proto resource fsockopen(string hostname, int port [, int errno [, string errstr [, float timeout]]]) + * Description: Open Internet or Unix domain socket connection + * Source code: ext/standard/fsock.c + * Alias to functions: + */ + + +echo "*** Testing fsockopen() : basic error conditions ***\n"; + + +echo "\n-- Testing fsockopen() function with more than expected no. of arguments --\n"; +$hostname = 'string_val'; +$port = 10; +$errno = 10; +$errstr = 'string_val'; +$timeout = 10.5; +$extra_arg = 10; +var_dump( fsockopen($hostname, $port, $errno, $errstr, $timeout, $extra_arg) ); +var_dump($errstr); +var_dump($errno); + +echo "\n-- Testing fsockopen() function with less than expected no. of arguments --\n"; +var_dump( fsockopen() ); + +echo "\n-- Attempting to connect to a non-existent socket --\n"; +$hostname = 'tcp://127.0.0.1'; // loopback address +$port = 31337; +$errno = null; +$errstr = null; +$timeout = 1.5; +var_dump( fsockopen($hostname, $port, $errno, $errstr, $timeout) ); +var_dump($errstr); + +echo "\n-- Attempting to connect using an invalid protocol --\n"; +$hostname = 'invalid://127.0.0.1'; // loopback address +$port = 31337; +$errno = null; +$errstr = null; +$timeout = 1.5; +var_dump( fsockopen($hostname, $port, $errno, $errstr, $timeout) ); +var_dump($errstr); + +echo "Done"; +?> +--EXPECTF-- +*** Testing fsockopen() : basic error conditions *** + +-- Testing fsockopen() function with more than expected no. of arguments -- + +Warning: fsockopen() expects at most 5 parameters, 6 given in %s on line %d +bool(false) +unicode(10) "string_val" +int(10) + +-- Testing fsockopen() function with less than expected no. of arguments -- + +Warning: fsockopen() expects at least 1 parameter, 0 given in %s on line %d +bool(false) + +-- Attempting to connect to a non-existent socket -- + +Warning: fsockopen(): unable to connect to tcp://127.0.0.1:31337 (%a) in %s on line %d +bool(false) +unicode(%d) "%a" + +-- Attempting to connect using an invalid protocol -- + +Warning: fsockopen(): unable to connect to invalid://127.0.0.1:31337 (Unable to find the socket transport "invalid" - did you forget to enable it when you configured PHP?) in %s on line %d +bool(false) +unicode(100) "Unable to find the socket transport "invalid" - did you forget to enable it when you configured PHP?" +Done http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/network/ip2long_variation1.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/standard/tests/network/ip2long_variation1.phpt diff -u /dev/null php-src/ext/standard/tests/network/ip2long_variation1.phpt:1.2 --- /dev/null Fri Jan 23 15:34:22 2009 +++ php-src/ext/standard/tests/network/ip2long_variation1.phpt Fri Jan 23 15:34:22 2009 @@ -0,0 +1,199 @@ +--TEST-- +Test ip2long() function : usage variation +--FILE-- +<?php +/* Prototype : int ip2long(string ip_address) + * Description: Converts a string containing an (IPv4) Internet Protocol dotted address into a proper address + * Source code: ext/standard/basic_functions.c + * Alias to functions: + */ + +echo "*** Testing ip2long() : usage variation ***\n"; + +// Define error handler +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + if (error_reporting() != 0) { + // report non-silenced errors + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; + } +} +set_error_handler('test_error_handler'); + +// Initialise function arguments not being substituted (if any) + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +// resource +$res = fopen(__FILE__,'r'); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // array data + 'empty array' => array(), + 'int indexed array' => $index_array, + 'associative array' => $assoc_array, + 'nested arrays' => array('foo', $index_array, $assoc_array), + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, + + // resource + 'resource' => $res, +); + +// loop through each element of the array for ip_address + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( ip2long($value) ); +}; + +fclose($res); + +?> +===DONE=== +--EXPECTF-- +*** Testing ip2long() : usage variation *** + +--int 0-- +int(0) + +--int 1-- +int(1) + +--int 12345-- +int(12345) + +--int -12345-- +bool(false) + +--float 10.5-- +int(167772165) + +--float -10.5-- +bool(false) + +--float 12.3456789000e10-- +bool(false) + +--float -12.3456789000e10-- +bool(false) + +--float .5-- +int(5) + +--empty array-- +Error: 2 - ip2long() expects parameter 1 to be binary string, array given, %s(%d) +NULL + +--int indexed array-- +Error: 2 - ip2long() expects parameter 1 to be binary string, array given, %s(%d) +NULL + +--associative array-- +Error: 2 - ip2long() expects parameter 1 to be binary string, array given, %s(%d) +NULL + +--nested arrays-- +Error: 2 - ip2long() expects parameter 1 to be binary string, array given, %s(%d) +NULL + +--uppercase NULL-- +bool(false) + +--lowercase null-- +bool(false) + +--lowercase true-- +int(1) + +--lowercase false-- +bool(false) + +--uppercase TRUE-- +int(1) + +--uppercase FALSE-- +bool(false) + +--empty string DQ-- +bool(false) + +--empty string SQ-- +bool(false) + +--instance of classWithToString-- +bool(false) + +--instance of classWithoutToString-- +Error: 2 - ip2long() expects parameter 1 to be binary string, object given, %s(%d) +NULL + +--undefined var-- +bool(false) + +--unset var-- +bool(false) + +--resource-- +Error: 2 - ip2long() expects parameter 1 to be binary string, resource given, %s(%d) +NULL +===DONE=== \ No newline at end of file
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php