diff options
Diffstat (limited to 'ext/sockets/tests')
| -rw-r--r-- | ext/sockets/tests/socket_export_stream-1.phpt | 27 | ||||
| -rw-r--r-- | ext/sockets/tests/socket_export_stream-2.phpt | 48 | ||||
| -rw-r--r-- | ext/sockets/tests/socket_export_stream-3.phpt | 47 | ||||
| -rw-r--r-- | ext/sockets/tests/socket_export_stream-4-win.phpt | 108 | ||||
| -rw-r--r-- | ext/sockets/tests/socket_export_stream-4.phpt | 105 | ||||
| -rw-r--r-- | ext/sockets/tests/socket_export_stream-5.phpt | 25 |
6 files changed, 360 insertions, 0 deletions
diff --git a/ext/sockets/tests/socket_export_stream-1.phpt b/ext/sockets/tests/socket_export_stream-1.phpt new file mode 100644 index 0000000000..498e0a277c --- /dev/null +++ b/ext/sockets/tests/socket_export_stream-1.phpt @@ -0,0 +1,27 @@ +--TEST-- +socket_export_stream: Basic test +--SKIPIF-- +<?php +if (!extension_loaded('sockets')) { + die('SKIP sockets extension not available.'); +} + +--FILE-- +<?php + +$domain = (strtoupper(substr(PHP_OS, 0, 3) == 'WIN') ? AF_INET : AF_UNIX); +socket_create_pair($domain, SOCK_STREAM, 0, $s); + +$s0 = reset($s); +$s1 = next($s); + +$stream = socket_export_stream($s0); +var_dump($stream); + +socket_write($s1, "test message"); +socket_close($s1); + +var_dump(stream_get_contents($stream)); +--EXPECTF-- +resource(%d) of type (stream) +string(12) "test message" diff --git a/ext/sockets/tests/socket_export_stream-2.phpt b/ext/sockets/tests/socket_export_stream-2.phpt new file mode 100644 index 0000000000..98528420fa --- /dev/null +++ b/ext/sockets/tests/socket_export_stream-2.phpt @@ -0,0 +1,48 @@ +--TEST-- +socket_export_stream: Bad arguments +--SKIPIF-- +<?php +if (!extension_loaded('sockets')) { + die('SKIP sockets extension not available.'); +} + +--FILE-- +<?php + +var_dump(socket_export_stream()); +var_dump(socket_export_stream(1, 2)); +var_dump(socket_export_stream(1)); +var_dump(socket_export_stream(new stdclass)); +var_dump(socket_export_stream(fopen(__FILE__, "rb"))); +var_dump(socket_export_stream(stream_socket_server("udp://127.0.0.1:58392", $errno, $errstr, STREAM_SERVER_BIND))); +$s = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); +var_dump($s); +socket_close($s); +var_dump(socket_export_stream($s)); + + +echo "Done."; +--EXPECTF-- +Warning: socket_export_stream() expects exactly 1 parameter, 0 given in %s on line %d +NULL + +Warning: socket_export_stream() expects exactly 1 parameter, 2 given in %s on line %d +NULL + +Warning: socket_export_stream() expects parameter 1 to be resource, integer given in %s on line %d +NULL + +Warning: socket_export_stream() expects parameter 1 to be resource, object given in %s on line %d +NULL + +Warning: socket_export_stream(): supplied resource is not a valid Socket resource in %s on line %d +bool(false) + +Warning: socket_export_stream(): supplied resource is not a valid Socket resource in %s on line %d +bool(false) +resource(%d) of type (Socket) + +Warning: socket_export_stream(): supplied resource is not a valid Socket resource in %s on line %d +bool(false) +Done. + diff --git a/ext/sockets/tests/socket_export_stream-3.phpt b/ext/sockets/tests/socket_export_stream-3.phpt new file mode 100644 index 0000000000..b13bb34739 --- /dev/null +++ b/ext/sockets/tests/socket_export_stream-3.phpt @@ -0,0 +1,47 @@ +--TEST-- +socket_export_stream: Test with multicasting +--SKIPIF-- +<?php +if (!extension_loaded('sockets')) { + die('SKIP sockets extension not available.'); +} +$s = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); +$br = socket_bind($s, '0.0.0.0', 58381); +if ($br === false) + die("SKIP IPv4/port 58381 not available"); +$so = socket_set_option($s, IPPROTO_IP, MCAST_JOIN_GROUP, array( + "group" => '224.0.0.23', + "interface" => "lo", +)); +if ($so === false) + die("SKIP joining group 224.0.0.23 on interface lo failed"); +--FILE-- +<?php + +$sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); +socket_bind($sock, '0.0.0.0', 58381); +$stream = socket_export_stream($sock); +var_dump($stream); +$so = socket_set_option($sock, IPPROTO_IP, MCAST_JOIN_GROUP, array( + "group" => '224.0.0.23', + "interface" => "lo", +)); +var_dump($so); + +$sendsock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); +var_dump($sendsock); +$br = socket_bind($sendsock, '127.0.0.1'); +$so = socket_sendto($sendsock, $m = "my message", strlen($m), 0, "224.0.0.23", 58381); +var_dump($so); + +stream_set_blocking($stream, 0); +var_dump(fread($stream, strlen($m))); +echo "Done.\n"; +--EXPECTF-- +resource(%d) of type (stream) +bool(true) +resource(%d) of type (Socket) +int(10) +string(10) "my message" +Done. + diff --git a/ext/sockets/tests/socket_export_stream-4-win.phpt b/ext/sockets/tests/socket_export_stream-4-win.phpt new file mode 100644 index 0000000000..e38db7bd08 --- /dev/null +++ b/ext/sockets/tests/socket_export_stream-4-win.phpt @@ -0,0 +1,108 @@ +--TEST-- +socket_export_stream: effects of closing +--SKIPIF-- +<?php +if (!extension_loaded('sockets')) { + die('SKIP sockets extension not available.'); +} +if(substr(PHP_OS, 0, 3) != 'WIN' ) { + die("skip Not Valid for Linux"); +} + +--FILE-- +<?php + +function test($stream, $sock) { + if ($stream !== null) { + echo "stream_set_blocking "; + print_r(stream_set_blocking($stream, 0)); + echo "\n"; + } + if ($sock !== null) { + echo "socket_set_block "; + print_r(socket_set_block($sock)); + echo "\n"; + echo "socket_get_option "; + print_r(socket_get_option($sock, SOL_SOCKET, SO_TYPE)); + echo "\n"; + } + echo "\n"; +} + +echo "normal\n"; +$sock0 = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); +socket_bind($sock0, '0.0.0.0', 58380); +$stream0 = socket_export_stream($sock0); +test($stream0, $sock0); + +echo "\nunset stream\n"; +$sock1 = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); +socket_bind($sock1, '0.0.0.0', 58381); +$stream1 = socket_export_stream($sock1); +unset($stream1); +test(null, $sock1); + +echo "\nunset socket\n"; +$sock2 = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); +socket_bind($sock2, '0.0.0.0', 58382); +$stream2 = socket_export_stream($sock2); +unset($sock2); +test($stream2, null); + +echo "\nclose stream\n"; +$sock3 = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); +socket_bind($sock3, '0.0.0.0', 58383); +$stream3 = socket_export_stream($sock3); +fclose($stream3); +test($stream3, $sock3); + +echo "\nclose socket\n"; +$sock4 = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); +socket_bind($sock4, '0.0.0.0', 58484); +$stream4 = socket_export_stream($sock4); +socket_close($sock4); +test($stream4, $sock4); + +echo "Done.\n"; +--EXPECTF-- +normal +stream_set_blocking 1 +socket_set_block 1 +socket_get_option 2 + + +unset stream +socket_set_block 1 +socket_get_option 2 + + +unset socket +stream_set_blocking 1 + + +close stream +stream_set_blocking +Warning: stream_set_blocking(): supplied resource is not a valid stream resource in %s on line %d + +socket_set_block +Warning: socket_set_block(): unable to set blocking mode [%d]: An operation was attempted on something that is not a socket. + in %s on line %d + +socket_get_option +Warning: socket_get_option(): unable to retrieve socket option [%d]: An operation was attempted on something that is not a socket. + in %s on line %d + + + +close socket +stream_set_blocking +Warning: stream_set_blocking(): supplied resource is not a valid stream resource in %s on line %d + +socket_set_block +Warning: socket_set_block(): supplied resource is not a valid Socket resource in %s on line %d + +socket_get_option +Warning: socket_get_option(): supplied resource is not a valid Socket resource in %s on line %d + + +Done. diff --git a/ext/sockets/tests/socket_export_stream-4.phpt b/ext/sockets/tests/socket_export_stream-4.phpt new file mode 100644 index 0000000000..ff329ec795 --- /dev/null +++ b/ext/sockets/tests/socket_export_stream-4.phpt @@ -0,0 +1,105 @@ +--TEST-- +socket_export_stream: effects of closing +--SKIPIF-- +<?php +if (!extension_loaded('sockets')) { + die('SKIP sockets extension not available.'); +} +if(substr(PHP_OS, 0, 3) == 'WIN' ) { + die("skip Not Valid for Windows"); +} +--FILE-- +<?php + +function test($stream, $sock) { + if ($stream !== null) { + echo "stream_set_blocking "; + print_r(stream_set_blocking($stream, 0)); + echo "\n"; + } + if ($sock !== null) { + echo "socket_set_block "; + print_r(socket_set_block($sock)); + echo "\n"; + echo "socket_get_option "; + print_r(socket_get_option($sock, SOL_SOCKET, SO_TYPE)); + echo "\n"; + } + echo "\n"; +} + +echo "normal\n"; +$sock0 = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); +socket_bind($sock0, '0.0.0.0', 58380); +$stream0 = socket_export_stream($sock0); +test($stream0, $sock0); + +echo "\nunset stream\n"; +$sock1 = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); +socket_bind($sock1, '0.0.0.0', 58381); +$stream1 = socket_export_stream($sock1); +unset($stream1); +test(null, $sock1); + +echo "\nunset socket\n"; +$sock2 = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); +socket_bind($sock2, '0.0.0.0', 58382); +$stream2 = socket_export_stream($sock2); +unset($sock2); +test($stream2, null); + +echo "\nclose stream\n"; +$sock3 = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); +socket_bind($sock3, '0.0.0.0', 58383); +$stream3 = socket_export_stream($sock3); +fclose($stream3); +test($stream3, $sock3); + +echo "\nclose socket\n"; +$sock4 = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); +socket_bind($sock4, '0.0.0.0', 58484); +$stream4 = socket_export_stream($sock4); +socket_close($sock4); +test($stream4, $sock4); + +echo "Done.\n"; +--EXPECTF-- +normal +stream_set_blocking 1 +socket_set_block 1 +socket_get_option 2 + + +unset stream +socket_set_block 1 +socket_get_option 2 + + +unset socket +stream_set_blocking 1 + + +close stream +stream_set_blocking +Warning: stream_set_blocking(): supplied resource is not a valid stream resource in %s on line %d + +socket_set_block +Warning: socket_set_block(): unable to set blocking mode [%d]: %s in %s on line %d + +socket_get_option +Warning: socket_get_option(): unable to retrieve socket option [%d]: %s in %s on line %d + + + +close socket +stream_set_blocking +Warning: stream_set_blocking(): supplied resource is not a valid stream resource in %s on line %d + +socket_set_block +Warning: socket_set_block(): supplied resource is not a valid Socket resource in %s on line %d + +socket_get_option +Warning: socket_get_option(): supplied resource is not a valid Socket resource in %s on line %d + + +Done. diff --git a/ext/sockets/tests/socket_export_stream-5.phpt b/ext/sockets/tests/socket_export_stream-5.phpt new file mode 100644 index 0000000000..732b2072d0 --- /dev/null +++ b/ext/sockets/tests/socket_export_stream-5.phpt @@ -0,0 +1,25 @@ +--TEST-- +socket_export_stream: effects of leaked handles +--SKIPIF-- +<?php +if (!extension_loaded('sockets')) { + die('SKIP sockets extension not available.'); +} +if (!function_exists('leak_variable')) + die('SKIP only for debug builds'); +--FILE-- +<?php + +$sock0 = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); +socket_bind($sock0, '0.0.0.0', 58380); +$stream0 = socket_export_stream($sock0); +leak_variable($stream0, true); + +$sock1 = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); +socket_bind($sock1, '0.0.0.0', 58381); +$stream1 = socket_export_stream($sock1); +leak_variable($sock1, true); + +echo "Done.\n"; +--EXPECT-- +Done. |
