diff options
author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2013-03-14 05:42:27 +0000 |
---|---|---|
committer | <> | 2013-04-03 16:25:08 +0000 |
commit | c4dd7a1a684490673e25aaf4fabec5df138854c4 (patch) | |
tree | 4d57c44caae4480efff02b90b9be86f44bf25409 /ext/standard/tests/network | |
download | php2-master.tar.gz |
Imported from /home/lorry/working-area/delta_php2/php-5.4.13.tar.bz2.HEADphp-5.4.13master
Diffstat (limited to 'ext/standard/tests/network')
40 files changed, 1689 insertions, 0 deletions
diff --git a/ext/standard/tests/network/bug20134.phpt b/ext/standard/tests/network/bug20134.phpt new file mode 100644 index 0000000..400e3fb --- /dev/null +++ b/ext/standard/tests/network/bug20134.phpt @@ -0,0 +1,24 @@ +--TEST-- +Bug #20134 (UDP reads from invalid ports) +--FILE-- +<?php +# vim600:syn=php: +$fp = fsockopen("udp://localhost", 65534, $errno, $errstr); +if (!$fp) { + /* UDP will never cause a connection error, as it is + * a connection-LESS protocol */ + echo "ERROR: $errno - $errstr<br>\n"; +} +else { + /* Likewise, writes will always appear to succeed */ + $x = fwrite($fp,b"\n"); + var_dump($x); + /* But reads should always fail */ + $content = fread($fp, 40); + var_dump($content); + fclose($fp); +} +?> +--EXPECT-- +int(1) +string(0) "" diff --git a/ext/standard/tests/network/bug41347.phpt b/ext/standard/tests/network/bug41347.phpt new file mode 100644 index 0000000..6ece098 --- /dev/null +++ b/ext/standard/tests/network/bug41347.phpt @@ -0,0 +1,9 @@ +--TEST-- +dns_check_record() segfault with empty host +--FILE-- +<?php +var_dump(dns_check_record('')); +?> +--EXPECTF-- +Warning: dns_check_record(): Host cannot be empty in %s on line %d +bool(false) diff --git a/ext/standard/tests/network/closelog_basic.phpt b/ext/standard/tests/network/closelog_basic.phpt new file mode 100644 index 0000000..06798a5 --- /dev/null +++ b/ext/standard/tests/network/closelog_basic.phpt @@ -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=== diff --git a/ext/standard/tests/network/closelog_error.phpt b/ext/standard/tests/network/closelog_error.phpt new file mode 100644 index 0000000..ad3fdf5 --- /dev/null +++ b/ext/standard/tests/network/closelog_error.phpt @@ -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=== diff --git a/ext/standard/tests/network/fsockopen_basic.phpt b/ext/standard/tests/network/fsockopen_basic.phpt new file mode 100644 index 0000000..3ec9366 --- /dev/null +++ b/ext/standard/tests/network/fsockopen_basic.phpt @@ -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 diff --git a/ext/standard/tests/network/fsockopen_error.phpt b/ext/standard/tests/network/fsockopen_error.phpt new file mode 100644 index 0000000..3b13b8c --- /dev/null +++ b/ext/standard/tests/network/fsockopen_error.phpt @@ -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) +string(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) +string(%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) +string(100) "Unable to find the socket transport "invalid" - did you forget to enable it when you configured PHP?" +Done diff --git a/ext/standard/tests/network/fsockopen_variation1.phpt b/ext/standard/tests/network/fsockopen_variation1.phpt new file mode 100644 index 0000000..2e5f8d9 --- /dev/null +++ b/ext/standard/tests/network/fsockopen_variation1.phpt @@ -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 diff --git a/ext/standard/tests/network/fsockopen_variation2.phpt b/ext/standard/tests/network/fsockopen_variation2.phpt new file mode 100644 index 0000000..262ae0b --- /dev/null +++ b/ext/standard/tests/network/fsockopen_variation2.phpt @@ -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, "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, "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 diff --git a/ext/standard/tests/network/gethostbyaddr_basic1.phpt b/ext/standard/tests/network/gethostbyaddr_basic1.phpt new file mode 100644 index 0000000..a20b475 --- /dev/null +++ b/ext/standard/tests/network/gethostbyaddr_basic1.phpt @@ -0,0 +1,18 @@ +--TEST-- +Test gethostbyaddr() function : basic functionality +--FILE-- +<?php +/* Prototype : string gethostbyaddr ( string $ip_address ) + * Description: Get the Internet host name corresponding to a given IP address + * Source code: ext/standard/dns.c +*/ + +echo "*** Testing gethostbyaddr() : basic functionality ***\n"; +echo gethostbyaddr("127.0.0.1")."\n"; + +?> +===DONE=== +--EXPECTF-- +*** Testing gethostbyaddr() : basic functionality *** +%rloopback|localhost(\.localdomain)?|%s%r +===DONE=== diff --git a/ext/standard/tests/network/gethostbyaddr_error.phpt b/ext/standard/tests/network/gethostbyaddr_error.phpt new file mode 100644 index 0000000..8909a30 --- /dev/null +++ b/ext/standard/tests/network/gethostbyaddr_error.phpt @@ -0,0 +1,60 @@ +--TEST-- +Test gethostbyaddr() function : error conditions +--FILE-- +<?php +/* Prototype : proto string gethostbyaddr(string ip_address) + * Description: Get the Internet host name corresponding to a given IP address + * Source code: ext/standard/dns.c + * Alias to functions: + */ + + +echo "Testing gethostbyaddr : error conditions\n"; + +// Zero arguments +echo "\n-- Testing gethostbyaddr function with Zero arguments --\n"; +var_dump( gethostbyaddr() ); + +//Test gethostbyaddr with one more than the expected number of arguments +echo "\n-- Testing gethostbyaddr function with more than expected no. of arguments --\n"; +$ip_address = 'string_val'; +$extra_arg = 10; +var_dump( gethostbyaddr($ip_address, $extra_arg) ); + +echo "\n-- Testing gethostbyaddr function with invalid addresses --\n"; + +$ip_address = 'invalid'; +var_dump( gethostbyaddr($ip_address) ); + +$ip_address = '300.1.2.3'; +var_dump( gethostbyaddr($ip_address) ); + +$ip_address = '256.1.2.3'; +var_dump( gethostbyaddr($ip_address) ); + +echo "Done"; +?> +--EXPECTREGEX-- +Testing gethostbyaddr : error conditions + +-- Testing gethostbyaddr function with Zero arguments -- + +Warning: gethostbyaddr\(\) expects exactly 1 parameter, 0 given in .* on line \d+ +NULL + +-- Testing gethostbyaddr function with more than expected no. of arguments -- + +Warning: gethostbyaddr\(\) expects exactly 1 parameter, 2 given in .* on line \d+ +NULL + +-- Testing gethostbyaddr function with invalid addresses -- + +Warning: gethostbyaddr\(\): Address is not (in a.b.c.d form|a valid IPv4 or IPv6 address) in .* on line \d+ +bool\(false\) + +Warning: gethostbyaddr\(\): Address is not (in a.b.c.d form|a valid IPv4 or IPv6 address) in .* on line \d+ +bool\(false\) + +Warning: gethostbyaddr\(\): Address is not (in a.b.c.d form|a valid IPv4 or IPv6 address) in .* on line \d+ +bool\(false\) +Done diff --git a/ext/standard/tests/network/gethostbyname_basic001.phpt b/ext/standard/tests/network/gethostbyname_basic001.phpt new file mode 100644 index 0000000..9171e22 --- /dev/null +++ b/ext/standard/tests/network/gethostbyname_basic001.phpt @@ -0,0 +1,15 @@ +--TEST-- +gethostbyname() function - basic type return test +--CREDITS-- +"Sylvain R." <sracine@phpquebec.org> +--SKIPIF-- +<?php +if (getenv("SKIP_SLOW_TESTS")) die("skip slow test"); +if (getenv("SKIP_ONLINE_TESTS")) die("skip test requiring internet connection"); +?> +--FILE-- +<?php + var_dump(is_string(gethostbyname("www.php.net"))); +?> +--EXPECT-- +bool(true) diff --git a/ext/standard/tests/network/gethostbyname_basic003.phpt b/ext/standard/tests/network/gethostbyname_basic003.phpt new file mode 100644 index 0000000..711490c --- /dev/null +++ b/ext/standard/tests/network/gethostbyname_basic003.phpt @@ -0,0 +1,18 @@ +--TEST--
+Test gethostbyname() function : basic functionality
+--FILE--
+<?php
+/* Prototype : string gethostbyname ( string $hostname )
+ * Description: Get the IPv4 address corresponding to a given Internet host name
+ * Source code: ext/standard/dns.c
+*/
+
+echo "*** Testing gethostbyname() : basic functionality ***\n";
+
+echo gethostbyname("localhost")."\n";
+?>
+===DONE===
+--EXPECT--
+*** Testing gethostbyname() : basic functionality ***
+127.0.0.1
+===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/network/gethostbyname_error001.phpt b/ext/standard/tests/network/gethostbyname_error001.phpt new file mode 100644 index 0000000..f141be8 --- /dev/null +++ b/ext/standard/tests/network/gethostbyname_error001.phpt @@ -0,0 +1,10 @@ +--TEST-- +gethostbyname() function - basic type return error test +--CREDITS-- +"Sylvain R." <sracine@phpquebec.org> +--FILE-- +<?php + var_dump(is_string(gethostbyname("192.168.0.101"))); +?> +--EXPECT-- +bool(true) diff --git a/ext/standard/tests/network/gethostbyname_error002.phpt b/ext/standard/tests/network/gethostbyname_error002.phpt new file mode 100644 index 0000000..2430a7f --- /dev/null +++ b/ext/standard/tests/network/gethostbyname_error002.phpt @@ -0,0 +1,10 @@ +--TEST-- +gethostbyname() function - basic type return error test +--CREDITS-- +"Sylvain R." <sracine@phpquebec.org> +--FILE-- +<?php + var_dump(is_string(gethostbyname("1234567890"))); +?> +--EXPECT-- +bool(true) diff --git a/ext/standard/tests/network/gethostbyname_error003.phpt b/ext/standard/tests/network/gethostbyname_error003.phpt new file mode 100644 index 0000000..3d4bb7a --- /dev/null +++ b/ext/standard/tests/network/gethostbyname_error003.phpt @@ -0,0 +1,10 @@ +--TEST-- +gethostbyname() function - basic type return error test +--CREDITS-- +"Sylvain R." <sracine@phpquebec.org> +--FILE-- +<?php + var_dump(is_string(gethostbyname("asdfasdf"))); +?> +--EXPECT-- +bool(true) diff --git a/ext/standard/tests/network/gethostbyname_error004.phpt b/ext/standard/tests/network/gethostbyname_error004.phpt new file mode 100644 index 0000000..274301a --- /dev/null +++ b/ext/standard/tests/network/gethostbyname_error004.phpt @@ -0,0 +1,16 @@ +--TEST-- +gethostbyname() function - basic return valid ip address test +--CREDITS-- +"Sylvain R." <sracine@phpquebec.org> +--SKIPIF-- +<?php +if (getenv("SKIP_SLOW_TESTS")) die("skip slow test"); +if (getenv("SKIP_ONLINE_TESTS")) die("skip test requiring internet connection"); +?> +--FILE-- +<?php + $ip = gethostbyname("www.php.net"); + var_dump((bool) ip2long($ip)); +?> +--EXPECT-- +bool(true) diff --git a/ext/standard/tests/network/gethostbyname_error005.phpt b/ext/standard/tests/network/gethostbyname_error005.phpt new file mode 100644 index 0000000..be4b159 --- /dev/null +++ b/ext/standard/tests/network/gethostbyname_error005.phpt @@ -0,0 +1,12 @@ +--TEST-- +gethostbyname() function - basic invalid parameter test +--CREDITS-- +"Sylvain R." <sracine@phpquebec.org> +--INI-- +display_errors=false +--FILE-- +<?php + var_dump(gethostbyname()); +?> +--EXPECT-- +NULL diff --git a/ext/standard/tests/network/gethostbyname_error006.phpt b/ext/standard/tests/network/gethostbyname_error006.phpt new file mode 100644 index 0000000..dc509a1 --- /dev/null +++ b/ext/standard/tests/network/gethostbyname_error006.phpt @@ -0,0 +1,10 @@ +--TEST-- +gethostbyname() function - basic invalid parameter test +--CREDITS-- +"Sylvain R." <sracine@phpquebec.org> +--FILE-- +<?php + var_dump(gethostbyname(".toto.toto.toto")); +?> +--EXPECTF-- +%string|unicode%(15) ".toto.toto.toto" diff --git a/ext/standard/tests/network/gethostbynamel_basic1.phpt b/ext/standard/tests/network/gethostbynamel_basic1.phpt new file mode 100644 index 0000000..5ce7c42 --- /dev/null +++ b/ext/standard/tests/network/gethostbynamel_basic1.phpt @@ -0,0 +1,19 @@ +--TEST--
+Test gethostbynamel() function : basic functionality
+--FILE--
+<?php
+/* Prototype : array gethostbynamel ( string $hostname )
+ * Description: Get a list of IPv4 addresses corresponding to a given Internet host name
+ * Source code: ext/standard/dns.c
+*/
+
+echo "*** Testing gethostbynamel() : basic functionality ***\n";
+var_dump(gethostbynamel("localhost"));
+?>
+===DONE===
+--EXPECTF--
+*** Testing gethostbynamel() : basic functionality ***
+array(%d) {
+ %a
+}
+===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/network/gethostbynamel_error.phpt b/ext/standard/tests/network/gethostbynamel_error.phpt new file mode 100644 index 0000000..7aa00e5 --- /dev/null +++ b/ext/standard/tests/network/gethostbynamel_error.phpt @@ -0,0 +1,36 @@ +--TEST-- +Test gethostbynamel() function : error conditions +--FILE-- +<?php +/* Prototype : proto array gethostbynamel(string hostname) + * Description: Return a list of IP addresses that a given hostname resolves to. + * Source code: ext/standard/dns.c + * Alias to functions: + */ + +echo "*** Testing gethostbynamel() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing gethostbynamel() function with Zero arguments --\n"; +var_dump( gethostbynamel() ); + +//Test gethostbynamel with one more than the expected number of arguments +echo "\n-- Testing gethostbynamel() function with more than expected no. of arguments --\n"; +$hostname = 'string_val'; +$extra_arg = 10; +var_dump( gethostbynamel($hostname, $extra_arg) ); +echo "Done"; +?> +--EXPECTF-- +*** Testing gethostbynamel() : error conditions *** + +-- Testing gethostbynamel() function with Zero arguments -- + +Warning: gethostbynamel() expects exactly 1 parameter, 0 given in %s on line %d +NULL + +-- Testing gethostbynamel() function with more than expected no. of arguments -- + +Warning: gethostbynamel() expects exactly 1 parameter, 2 given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/network/getmxrr.phpt b/ext/standard/tests/network/getmxrr.phpt new file mode 100644 index 0000000..c4a15c5 --- /dev/null +++ b/ext/standard/tests/network/getmxrr.phpt @@ -0,0 +1,24 @@ +--TEST-- +getmxrr() test +--SKIPIF-- +<?php +if (getenv("SKIP_SLOW_TESTS")) die("skip slow test"); +if (getenv("SKIP_ONLINE_TESTS")) die("skip test requiring internet connection"); +if (substr(PHP_OS, 0, 3) == 'WIN') { + die('skip: no Windows support'); +} +?> +--FILE-- +<?php +$domains = array( 'mx1.tests.php.net', 'mx2.tests.php.net' ); +foreach ( $domains as $domain ) +{ + if ( getmxrr( $domain, $hosts, $weights ) ) + { + echo "Hosts: " . count( $hosts ) . ", weights: " . count( $weights ) . "\n"; + } +} +?> +--EXPECT-- +Hosts: 1, weights: 1 +Hosts: 2, weights: 2 diff --git a/ext/standard/tests/network/http-stream.phpt b/ext/standard/tests/network/http-stream.phpt new file mode 100644 index 0000000..99245f7 --- /dev/null +++ b/ext/standard/tests/network/http-stream.phpt @@ -0,0 +1,18 @@ +--TEST-- +http-stream test +--SKIPIF-- +<?php +if (getenv("SKIP_SLOW_TESTS")) die("skip slow test"); +if (getenv("SKIP_ONLINE_TESTS")) die("skip online test"); +if (!extension_loaded("dom")) die("skip dom extension is not present"); +?> +--INI-- +allow_url_fopen=1 +--FILE-- +<?php +$d = new DomDocument; +$e = $d->load("http://php.net/news.rss"); +echo "ALIVE\n"; +?> +--EXPECTF-- +ALIVE diff --git a/ext/standard/tests/network/inet.phpt b/ext/standard/tests/network/inet.phpt new file mode 100644 index 0000000..851e1ba --- /dev/null +++ b/ext/standard/tests/network/inet.phpt @@ -0,0 +1,75 @@ +--TEST-- +inet_ntop() & inet_pton() tests +--SKIPIF-- +<?php +if (!function_exists("inet_ntop")) die("skip no inet_ntop()"); +if (!function_exists("inet_pton")) die("skip no inet_pton()"); +?> +--FILE-- +<?php + +$packed = chr(127) . chr(0) . chr(0) . chr(1); +var_dump(inet_ntop((binary)$packed)); + +$packed = chr(255) . chr(255) . chr(255) . chr(0); +var_dump(inet_ntop((binary)$packed)); + +var_dump(inet_ntop()); +var_dump(inet_ntop(-1)); +var_dump(inet_ntop(b"")); +var_dump(inet_ntop(b"blah-blah")); + +var_dump(inet_pton()); +var_dump(inet_pton(b"")); +var_dump(inet_pton(-1)); +var_dump(inet_pton(b"abra")); + +$array = array( + b"127.0.0.1", + b"66.163.161.116", + b"255.255.255.255", + b"0.0.0.0", + ); +foreach ($array as $val) { + var_dump(bin2hex($packed = inet_pton($val))); + var_dump(inet_ntop($packed)); +} + +echo "Done\n"; +?> +--EXPECTF-- +%unicode|string%(9) "127.0.0.1" +%unicode|string%(13) "255.255.255.0" + +Warning: inet_ntop() expects exactly 1 parameter, 0 given in %s on line %d +bool(false) + +Warning: inet_ntop(): Invalid in_addr value in %s on line %d +bool(false) + +Warning: inet_ntop(): Invalid in_addr value in %s on line %d +bool(false) + +Warning: inet_ntop(): Invalid in_addr value in %s on line %d +bool(false) + +Warning: inet_pton() expects exactly 1 parameter, 0 given in %s on line %d +bool(false) + +Warning: inet_pton(): Unrecognized address in %s on line %d +bool(false) + +Warning: inet_pton(): Unrecognized address -1 in %s on line %d +bool(false) + +Warning: inet_pton(): Unrecognized address abra in %s on line %d +bool(false) +%unicode|string%(%d) "7f000001" +%unicode|string%(9) "127.0.0.1" +%unicode|string%(%d) "42a3a174" +%unicode|string%(14) "66.163.161.116" +%unicode|string%(%d) "ffffffff" +%unicode|string%(15) "255.255.255.255" +%unicode|string%(%d) "00000000" +%unicode|string%(7) "0.0.0.0" +Done diff --git a/ext/standard/tests/network/inet_ipv6.phpt b/ext/standard/tests/network/inet_ipv6.phpt new file mode 100644 index 0000000..3b280df --- /dev/null +++ b/ext/standard/tests/network/inet_ipv6.phpt @@ -0,0 +1,50 @@ +--TEST-- +inet_ntop() & inet_pton() IPv6 tests +--SKIPIF-- +<?php +if (!function_exists("inet_ntop")) die("skip no inet_ntop()"); +if (!function_exists("inet_pton")) die("skip no inet_pton()"); + +$packed = str_repeat(chr(0), 15) . chr(1); +if (@inet_ntop($packed) === false) { + die("skip no IPv6 support"); +} +if (stristr(PHP_OS, "darwin") !== false) die("skip MacOS has broken inet_*() funcs"); +?> +--FILE-- +<?php + +$a = array( + '::1', + '::2', + '::35', + '::255', + '::1024', + '', + '2001:0db8:85a3:08d3:1319:8a2e:0370:7344', + '2001:0db8:1234:0000:0000:0000:0000:0000', + '2001:0db8:1234:FFFF:FFFF:FFFF:FFFF:FFFF', +); + +foreach ($a as $address) { + $packed = inet_pton($address); + var_dump(inet_ntop($packed)); +} + +echo "Done\n"; +?> +--EXPECTF-- +string(3) "::1" +string(3) "::2" +string(4) "::35" +string(5) "::255" +string(6) "::1024" + +Warning: inet_pton(): Unrecognized address in %s on line %d + +Warning: inet_ntop(): Invalid in_addr value in %s on line %d +bool(false) +string(36) "2001:db8:85a3:8d3:1319:8a2e:370:7344" +string(15) "2001:db8:1234::" +string(38) "2001:db8:1234:ffff:ffff:ffff:ffff:ffff" +Done diff --git a/ext/standard/tests/network/ip.phpt b/ext/standard/tests/network/ip.phpt new file mode 100644 index 0000000..3fc1b9d --- /dev/null +++ b/ext/standard/tests/network/ip.phpt @@ -0,0 +1,67 @@ +--TEST-- +ip2long() & long2ip() tests +--SKIPIF-- +<?php +if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only"); +?> +--FILE-- +<?php + +$array = array( + "127.0.0.1", + "10.0.0.1", + "255.255.255.255", + "255.255.255.0", + "0.0.0.0", + "66.163.161.116", +); + +foreach ($array as $ip) { + var_dump($long = ip2long($ip)); + var_dump(long2ip($long)); +} + +var_dump(ip2long()); +var_dump(ip2long("")); +var_dump(ip2long("777.777.777.777")); +var_dump(ip2long("111.111.111.111")); +var_dump(ip2long(array())); + +var_dump(long2ip()); +var_dump(long2ip(-110000)); +var_dump(long2ip("")); +var_dump(long2ip(array())); + +echo "Done\n"; +?> +--EXPECTF-- +int(2130706433) +string(9) "127.0.0.1" +int(167772161) +string(8) "10.0.0.1" +int(-1) +string(15) "255.255.255.255" +int(-256) +string(13) "255.255.255.0" +int(0) +string(7) "0.0.0.0" +int(1118019956) +string(14) "66.163.161.116" + +Warning: ip2long() expects exactly 1 parameter, 0 given in %s on line %d +NULL +bool(false) +bool(false) +int(1869573999) + +Warning: ip2long() expects parameter 1 to be string, array given in %s on line %d +NULL + +Warning: long2ip() expects exactly 1 parameter, 0 given in %s on line %d +NULL +string(13) "255.254.82.80" +string(7) "0.0.0.0" + +Warning: long2ip() expects parameter 1 to be string, array given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/network/ip2long_error.phpt b/ext/standard/tests/network/ip2long_error.phpt new file mode 100644 index 0000000..65e7315 --- /dev/null +++ b/ext/standard/tests/network/ip2long_error.phpt @@ -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=== diff --git a/ext/standard/tests/network/ip2long_variation1.phpt b/ext/standard/tests/network/ip2long_variation1.phpt new file mode 100644 index 0000000..f87282a --- /dev/null +++ b/ext/standard/tests/network/ip2long_variation1.phpt @@ -0,0 +1,204 @@ +--TEST-- +Test ip2long() function : usage variation +--SKIPIF-- +<?php +if(substr(PHP_OS, 0, 3) == "WIN") + die("skip. Windows is more compliant (like 0 for localhost, etc.)"); +?> +--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-- +bool(false) + +--int 1-- +bool(false) + +--int 12345-- +bool(false) + +--int -12345-- +bool(false) + +--float 10.5-- +bool(false) + +--float -10.5-- +bool(false) + +--float 12.3456789000e10-- +bool(false) + +--float -12.3456789000e10-- +bool(false) + +--float .5-- +bool(false) + +--empty array-- +Error: 2 - ip2long() expects parameter 1 to be string, array given, %s(%d) +NULL + +--int indexed array-- +Error: 2 - ip2long() expects parameter 1 to be string, array given, %s(%d) +NULL + +--associative array-- +Error: 2 - ip2long() expects parameter 1 to be string, array given, %s(%d) +NULL + +--nested arrays-- +Error: 2 - ip2long() expects parameter 1 to be string, array given, %s(%d) +NULL + +--uppercase NULL-- +bool(false) + +--lowercase null-- +bool(false) + +--lowercase true-- +bool(false) + +--lowercase false-- +bool(false) + +--uppercase TRUE-- +bool(false) + +--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 string, object given, %s(%d) +NULL + +--undefined var-- +bool(false) + +--unset var-- +bool(false) + +--resource-- +Error: 2 - ip2long() expects parameter 1 to be string, resource given, %s(%d) +NULL +===DONE=== diff --git a/ext/standard/tests/network/ip_x86_64.phpt b/ext/standard/tests/network/ip_x86_64.phpt new file mode 100644 index 0000000..1fcb8b2 --- /dev/null +++ b/ext/standard/tests/network/ip_x86_64.phpt @@ -0,0 +1,67 @@ +--TEST-- +ip2long() & long2ip() tests +--SKIPIF-- +<?php +if (PHP_INT_SIZE == 4) die("skip this test is for >32bit platform only"); +?> +--FILE-- +<?php + +$array = array( + "127.0.0.1", + "10.0.0.1", + "255.255.255.255", + "255.255.255.0", + "0.0.0.0", + "66.163.161.116", +); + +foreach ($array as $ip) { + var_dump($long = ip2long($ip)); + var_dump(long2ip($long)); +} + +var_dump(ip2long()); +var_dump(ip2long("")); +var_dump(ip2long("777.777.777.777")); +var_dump(ip2long("111.111.111.111")); +var_dump(ip2long(array())); + +var_dump(long2ip()); +var_dump(long2ip(-110000)); +var_dump(long2ip("")); +var_dump(long2ip(array())); + +echo "Done\n"; +?> +--EXPECTF-- +int(2130706433) +string(9) "127.0.0.1" +int(167772161) +string(8) "10.0.0.1" +int(4294967295) +string(15) "255.255.255.255" +int(4294967040) +string(13) "255.255.255.0" +int(0) +string(7) "0.0.0.0" +int(1118019956) +string(14) "66.163.161.116" + +Warning: ip2long() expects exactly 1 parameter, 0 given in %s on line %d +NULL +bool(false) +bool(false) +int(1869573999) + +Warning: ip2long() expects parameter 1 to be string, array given in %s on line %d +NULL + +Warning: long2ip() expects exactly 1 parameter, 0 given in %s on line %d +NULL +string(13) "255.254.82.80" +string(7) "0.0.0.0" + +Warning: long2ip() expects parameter 1 to be string, array given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/network/long2ip_error.phpt b/ext/standard/tests/network/long2ip_error.phpt new file mode 100644 index 0000000..d56397c --- /dev/null +++ b/ext/standard/tests/network/long2ip_error.phpt @@ -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 diff --git a/ext/standard/tests/network/long2ip_variation1.phpt b/ext/standard/tests/network/long2ip_variation1.phpt new file mode 100644 index 0000000..2dc6fb1 --- /dev/null +++ b/ext/standard/tests/network/long2ip_variation1.phpt @@ -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-- +string(8) "0.0.0.10" + +--float -10.5-- +string(15) "255.255.255.246" + +--float .5-- +string(7) "0.0.0.0" + +--empty array-- +Error: 2 - long2ip() expects parameter 1 to be string, array given, %s(%d) +NULL + +--int indexed array-- +Error: 2 - long2ip() expects parameter 1 to be string, array given, %s(%d) +NULL + +--associative array-- +Error: 2 - long2ip() expects parameter 1 to be string, array given, %s(%d) +NULL + +--nested arrays-- +Error: 2 - long2ip() expects parameter 1 to be string, array given, %s(%d) +NULL + +--uppercase NULL-- +string(7) "0.0.0.0" + +--lowercase null-- +string(7) "0.0.0.0" + +--lowercase true-- +string(7) "0.0.0.1" + +--lowercase false-- +string(7) "0.0.0.0" + +--uppercase TRUE-- +string(7) "0.0.0.1" + +--uppercase FALSE-- +string(7) "0.0.0.0" + +--empty string DQ-- +string(7) "0.0.0.0" + +--empty string SQ-- +string(7) "0.0.0.0" + +--string DQ-- +string(7) "0.0.0.0" + +--string SQ-- +string(7) "0.0.0.0" + +--mixed case string-- +string(7) "0.0.0.0" + +--heredoc-- +string(7) "0.0.0.0" + +--instance of classWithToString-- +string(7) "0.0.0.0" + +--instance of classWithoutToString-- +Error: 2 - long2ip() expects parameter 1 to be string, object given, %s(%d) +NULL + +--undefined var-- +string(7) "0.0.0.0" + +--unset var-- +string(7) "0.0.0.0" + +--resource-- +Error: 2 - long2ip() expects parameter 1 to be string, resource given, %s(%d) +NULL +===DONE=== diff --git a/ext/standard/tests/network/shutdown.phpt b/ext/standard/tests/network/shutdown.phpt new file mode 100644 index 0000000..f9ab664 --- /dev/null +++ b/ext/standard/tests/network/shutdown.phpt @@ -0,0 +1,65 @@ +--TEST-- +stream_socket_shutdown() test on IPv4 TCP Loopback +--SKIPIF-- +<?php + function_exists('stream_socket_shutdown') or die('skip stream_socket_shutdown() is not supported.'); +?> +--FILE-- +<?php + /* Setup socket server */ + $server = stream_socket_server('tcp://127.0.0.1:31337'); + if (!$server) { + die('Unable to create AF_INET socket [server]'); + } + + /* Connect and send request 1 */ + $client1 = stream_socket_client('tcp://127.0.0.1:31337'); + if (!$client1) { + die('Unable to create AF_INET socket [client]'); + } + @fwrite($client1, "Client 1\n"); + stream_socket_shutdown($client1, STREAM_SHUT_WR); + @fwrite($client1, "Error 1\n"); + + /* Connect and send request 2 */ + $client2 = stream_socket_client('tcp://127.0.0.1:31337'); + if (!$client2) { + die('Unable to create AF_INET socket [client]'); + } + @fwrite($client2, "Client 2\n"); + stream_socket_shutdown($client2, STREAM_SHUT_WR); + @fwrite($client2, "Error 2\n"); + + /* Accept connection 1 */ + $socket = stream_socket_accept($server); + if (!$socket) { + die('Unable to accept connection'); + } + @fwrite($socket, fgets($socket)); + @fwrite($socket, fgets($socket)); + fclose($socket); + + /* Read Response 1 */ + echo fgets($client1); + echo fgets($client1); + + /* Accept connection 2 */ + $socket = stream_socket_accept($server); + if (!$socket) { + die('Unable to accept connection'); + } + @fwrite($socket, fgets($socket)); + @fwrite($socket, fgets($socket)); + fclose($socket); + + /* Read Response 2 */ + echo fgets($client2); + echo fgets($client2); + + fclose($client1); + fclose($client2); + fclose($server); +?> +--EXPECT-- +Client 1 +Client 2 diff --git a/ext/standard/tests/network/socket_get_status_basic.phpt b/ext/standard/tests/network/socket_get_status_basic.phpt new file mode 100644 index 0000000..f72662b --- /dev/null +++ b/ext/standard/tests/network/socket_get_status_basic.phpt @@ -0,0 +1,27 @@ +--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); + +?> +--EXPECTF-- +array(7) { + ["stream_type"]=> + string(%d) "tcp_socket%S" + ["mode"]=> + string(2) "r+" + ["unread_bytes"]=> + int(0) + ["seekable"]=> + bool(false) + ["timed_out"]=> + bool(false) + ["blocked"]=> + bool(true) + ["eof"]=> + bool(false) +} diff --git a/ext/standard/tests/network/syslog_basic-win32.phpt b/ext/standard/tests/network/syslog_basic-win32.phpt new file mode 100644 index 0000000..88d3c5a --- /dev/null +++ b/ext/standard/tests/network/syslog_basic-win32.phpt @@ -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=== diff --git a/ext/standard/tests/network/syslog_error.phpt b/ext/standard/tests/network/syslog_error.phpt new file mode 100644 index 0000000..a99fd53 --- /dev/null +++ b/ext/standard/tests/network/syslog_error.phpt @@ -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=== diff --git a/ext/standard/tests/network/tcp4loop.phpt b/ext/standard/tests/network/tcp4loop.phpt new file mode 100644 index 0000000..afd9559 --- /dev/null +++ b/ext/standard/tests/network/tcp4loop.phpt @@ -0,0 +1,34 @@ +--TEST-- +Streams Based IPv4 TCP Loopback test +--FILE-- +<?php # vim:ft=php: + /* Setup socket server */ + $server = stream_socket_server('tcp://127.0.0.1:31337'); + if (!$server) { + die('Unable to create AF_INET socket [server]'); + } + + /* Connect to it */ + $client = stream_socket_client('tcp://127.0.0.1:31337'); + if (!$client) { + die('Unable to create AF_INET socket [client]'); + } + + /* Accept that connection */ + $socket = stream_socket_accept($server); + if (!$socket) { + die('Unable to accept connection'); + } + + fwrite($client, "ABCdef123\n"); + + $data = fread($socket, 10); + var_dump($data); + + fclose($client); + fclose($socket); + fclose($server); +?> +--EXPECT-- +string(10) "ABCdef123 +" diff --git a/ext/standard/tests/network/tcp6loop.phpt b/ext/standard/tests/network/tcp6loop.phpt new file mode 100644 index 0000000..3f28cd4 --- /dev/null +++ b/ext/standard/tests/network/tcp6loop.phpt @@ -0,0 +1,42 @@ +--TEST-- +Streams Based IPv6 TCP Loopback test +--SKIPIF-- +<?php + /* If IPv6 is supported on the platform this will error out with code 111 - Connection refused. + If IPv6 is NOT supported, $errno will be set to something else (indicating parse/getaddrinfo error) + Note: Might be a good idea to export an IPv6 support indicator (such as AF_INET6 exported by ext/sockets) */ + @stream_socket_client('tcp://[::1]:0', $errno); + if ($errno != 111) die('skip IPv6 not supported.'); +?> +--FILE-- +<?php + /* Setup socket server */ + $server = stream_socket_server('tcp://[::1]:31337'); + if (!$server) { + die('Unable to create AF_INET6 socket [server]'); + } + + /* Connect to it */ + $client = stream_socket_client('tcp://[::1]:31337'); + if (!$client) { + die('Unable to create AF_INET6 socket [client]'); + } + + /* Accept that connection */ + $socket = stream_socket_accept($server); + if (!$socket) { + die('Unable to accept connection'); + } + + fwrite($client, "ABCdef123\n"); + + $data = fread($socket, 10); + var_dump($data); + + fclose($client); + fclose($socket); + fclose($server); +?> +--EXPECT-- +string(10) "ABCdef123 +" diff --git a/ext/standard/tests/network/udgloop.phpt b/ext/standard/tests/network/udgloop.phpt new file mode 100644 index 0000000..a61d082 --- /dev/null +++ b/ext/standard/tests/network/udgloop.phpt @@ -0,0 +1,37 @@ +--TEST-- +Streams Based Unix Domain Datagram Loopback test +--SKIPIF-- +<?php # vim:ft=php: + if (array_search("udg",stream_get_transports()) === false) + die('SKIP No support for UNIX domain sockets.'); +?> +--FILE-- +<?php + $uniqid = uniqid(); + if (file_exists("/tmp/$uniqid.sock")) + die('Temporary socket /tmp/$uniqid.sock already exists.'); + + /* Setup socket server */ + $server = stream_socket_server("udg:///tmp/$uniqid.sock", $errno, $errstr, STREAM_SERVER_BIND); + if (!$server) { + die('Unable to create AF_UNIX socket [server]'); + } + + /* Connect to it */ + $client = stream_socket_client("udg:///tmp/$uniqid.sock"); + if (!$client) { + die('Unable to create AF_UNIX socket [client]'); + } + + fwrite($client, "ABCdef123\n"); + + $data = fread($server, 10); + var_dump($data); + + fclose($client); + fclose($server); + unlink("/tmp/$uniqid.sock"); +?> +--EXPECT-- +string(10) "ABCdef123 +" diff --git a/ext/standard/tests/network/udp4loop.phpt b/ext/standard/tests/network/udp4loop.phpt new file mode 100644 index 0000000..10d36ed --- /dev/null +++ b/ext/standard/tests/network/udp4loop.phpt @@ -0,0 +1,27 @@ +--TEST-- +Streams Based IPv4 UDP Loopback test +--FILE-- +<?php + /* Setup socket server */ + $server = stream_socket_server('udp://127.0.0.1:31338', $errno, $errstr, STREAM_SERVER_BIND); + if (!$server) { + die('Unable to create AF_INET socket [server]'); + } + + /* Connect to it */ + $client = stream_socket_client('udp://127.0.0.1:31338'); + if (!$client) { + die('Unable to create AF_INET socket [client]'); + } + + fwrite($client, "ABCdef123\n"); + + $data = fread($server, 10); + var_dump($data); + + fclose($client); + fclose($server); +?> +--EXPECT-- +string(10) "ABCdef123 +" diff --git a/ext/standard/tests/network/udp6loop.phpt b/ext/standard/tests/network/udp6loop.phpt new file mode 100644 index 0000000..5fcf7a7 --- /dev/null +++ b/ext/standard/tests/network/udp6loop.phpt @@ -0,0 +1,41 @@ +--TEST-- +Streams Based IPv6 UDP Loopback test +--SKIPIF-- +<?php # vim:ft=php: + /* If IPv6 is supported on the platform this will error out with code 111 - + * Connection refused. If IPv6 is NOT supported, $errno will be set to + * something else (indicating parse/getaddrinfo error) + * Note: Might be a good idea to export an IPv6 support indicator + * (such as AF_INET6 exported by ext/sockets), however, since we + * cannot tell for sure if IPv6 works until we probe it at run time, + * this isn't really practical. + */ + + @stream_socket_client('tcp://[::1]:0', $errno); + if ($errno != 111) die('skip IPv6 not supported.'); +?> +--FILE-- +<?php + /* Setup socket server */ + $server = stream_socket_server('udp://[::1]:31337', $errno, $errstr, STREAM_SERVER_BIND); + if (!$server) { + die('Unable to create AF_INET6 socket [server]'); + } + + /* Connect to it */ + $client = stream_socket_client('udp://[::1]:31337'); + if (!$client) { + die('Unable to create AF_INET6 socket [client]'); + } + + fwrite($client, "ABCdef123\n"); + + $data = fread($server, 10); + var_dump($data); + + fclose($client); + fclose($server); +?> +--EXPECT-- +string(10) "ABCdef123 +" diff --git a/ext/standard/tests/network/unixloop.phpt b/ext/standard/tests/network/unixloop.phpt new file mode 100644 index 0000000..abb103b --- /dev/null +++ b/ext/standard/tests/network/unixloop.phpt @@ -0,0 +1,44 @@ +--TEST-- +Streams Based Unix Domain Loopback test +--SKIPIF-- +<?php # vim:ft=php: + if (array_search("unix",stream_get_transports()) === false) + die('SKIP No support for UNIX domain sockets.'); +?> +--FILE-- +<?php + $uniqid = uniqid(); + if (file_exists("/tmp/$uniqid.sock")) + die('Temporary socket already exists.'); + + /* Setup socket server */ + $server = stream_socket_server("unix:///tmp/$uniqid.sock"); + if (!$server) { + die('Unable to create AF_UNIX socket [server]'); + } + + /* Connect to it */ + $client = stream_socket_client("unix:///tmp/$uniqid.sock"); + if (!$client) { + die('Unable to create AF_UNIX socket [client]'); + } + + /* Accept that connection */ + $socket = stream_socket_accept($server); + if (!$socket) { + die('Unable to accept connection'); + } + + fwrite($client, "ABCdef123\n"); + + $data = fread($socket, 10); + var_dump($data); + + fclose($client); + fclose($socket); + fclose($server); + unlink("/tmp/$uniqid.sock"); +?> +--EXPECT-- +string(10) "ABCdef123 +" |