]> granicus.if.org Git - php/commitdiff
- New tests (testfest BerlinUG)
authorFelipe Pena <felipe@php.net>
Sun, 17 May 2009 18:07:36 +0000 (18:07 +0000)
committerFelipe Pena <felipe@php.net>
Sun, 17 May 2009 18:07:36 +0000 (18:07 +0000)
23 files changed:
ext/sockets/tests/socket_accept-wrongparams.phpt [new file with mode: 0644]
ext/sockets/tests/socket_create_listen-nobind.phpt [new file with mode: 0644]
ext/sockets/tests/socket_create_listen-wrongparams.phpt [new file with mode: 0644]
ext/sockets/tests/socket_create_listen.phpt [new file with mode: 0644]
ext/sockets/tests/socket_create_pair-wrongparams.phpt [new file with mode: 0644]
ext/sockets/tests/socket_create_pair.phpt [new file with mode: 0644]
ext/sockets/tests/socket_listen-wrongparams.phpt [new file with mode: 0644]
ext/sockets/tests/socket_select-wrongparams-1.phpt [new file with mode: 0644]
ext/sockets/tests/socket_select-wrongparams-2.phpt [new file with mode: 0644]
ext/sockets/tests/socket_select-wrongparams-3.phpt [new file with mode: 0644]
ext/sockets/tests/socket_select-wrongparams-4.phpt [new file with mode: 0644]
ext/sockets/tests/socket_select.phpt [new file with mode: 0644]
ext/sockets/tests/socket_sentto_recvfrom_ipv4_udp.phpt [new file with mode: 0644]
ext/sockets/tests/socket_sentto_recvfrom_ipv6_udp.phpt [new file with mode: 0644]
ext/sockets/tests/socket_sentto_recvfrom_unix.phpt [new file with mode: 0644]
ext/sockets/tests/socket_set_block-retval.phpt [new file with mode: 0644]
ext/sockets/tests/socket_set_block-wrongparams.phpt [new file with mode: 0644]
ext/sockets/tests/socket_set_nonblock-retval.phpt [new file with mode: 0644]
ext/sockets/tests/socket_set_nonblock-wrongparams.phpt [new file with mode: 0644]
ext/sockets/tests/socket_set_option_error_socket_option.phpt [new file with mode: 0644]
ext/sockets/tests/socket_set_option_rcvtimeo.phpt [new file with mode: 0644]
ext/sockets/tests/socket_set_option_seolinger.phpt [new file with mode: 0644]
ext/sockets/tests/socket_set_option_sndtimeo.phpt [new file with mode: 0644]

diff --git a/ext/sockets/tests/socket_accept-wrongparams.phpt b/ext/sockets/tests/socket_accept-wrongparams.phpt
new file mode 100644 (file)
index 0000000..6bce05a
--- /dev/null
@@ -0,0 +1,16 @@
+--TEST--
+Test parameter handling in socket_accept()
+--SKIPIF--
+<?php
+if (!extension_loaded('sockets')) {
+    die('SKIP The sockets extension is not loaded.');
+}
+--FILE--
+<?php
+var_dump(socket_accept(null));
+--CREDITS--
+Till Klampaeckel, till@php.net
+Berlin TestFest 2009 
+--EXPECTF--
+Warning: socket_accept() expects parameter 1 to be resource, null given in %s on line %d
+NULL
diff --git a/ext/sockets/tests/socket_create_listen-nobind.phpt b/ext/sockets/tests/socket_create_listen-nobind.phpt
new file mode 100644 (file)
index 0000000..90ae26e
--- /dev/null
@@ -0,0 +1,25 @@
+--TEST--
+Test if socket_create_listen() returns false, when it cannot bind to the port.
+--SKIPIF--
+<?php
+if (!extension_loaded('sockets')) {
+    die('SKIP The sockets extension is not loaded.');
+}
+$filename = dirname(__FILE__) . '/006_root_check.tmp';
+$fp = fopen($filename, 'w');
+fclose($fp);
+if (fileowner($filename) == 0) {
+    unlink ($filename);
+    die('SKIP Test cannot be run as root.');
+}
+--FILE--
+<?php
+$sock = socket_create_listen(80);
+--EXPECTF--
+Warning: socket_create_listen(): unable to bind to given address [13]: Permission denied in %s on line %d
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/006_root_check.tmp');
+--CREDITS--
+Till Klampaeckel, till@php.net
+PHP Testfest Berlin 2009-05-09
\ No newline at end of file
diff --git a/ext/sockets/tests/socket_create_listen-wrongparams.phpt b/ext/sockets/tests/socket_create_listen-wrongparams.phpt
new file mode 100644 (file)
index 0000000..ecc5172
--- /dev/null
@@ -0,0 +1,18 @@
+--TEST--
+Test if socket_create_listen throws E_WARNING with wrong parameters.
+--SKIPIF--
+<?php
+if (!extension_loaded('sockets')) {
+    die('SKIP The sockets extension is not loaded.');
+}
+--FILE--
+<?php
+$sock1 = socket_create_listen(array());
+$sock2 = socket_create_listen(31337, array());
+--EXPECTF--
+Warning: socket_create_listen() expects parameter 1 to be long, array given in %s on line %d
+
+Warning: socket_create_listen() expects parameter 2 to be long, array given in %s on line %d
+--CREDITS--
+Till Klampaeckel, till@php.net
+PHP Testfest Berlin 2009-05-09
diff --git a/ext/sockets/tests/socket_create_listen.phpt b/ext/sockets/tests/socket_create_listen.phpt
new file mode 100644 (file)
index 0000000..6d607ca
--- /dev/null
@@ -0,0 +1,18 @@
+--TEST--
+Test if socket binds on 31337
+--SKIPIF--
+<?php
+if (!extension_loaded('sockets')) {
+    die('SKIP The sockets extension is not loaded.');
+}
+--FILE--
+<?php
+$sock = socket_create_listen(31337);
+socket_getsockname($sock, $addr, $port); 
+var_dump($addr, $port);
+--EXPECT--
+string(7) "0.0.0.0"
+int(31337)
+--CREDITS--
+Till Klampaeckel, till@php.net
+PHP Testfest Berlin 2009-05-09
diff --git a/ext/sockets/tests/socket_create_pair-wrongparams.phpt b/ext/sockets/tests/socket_create_pair-wrongparams.phpt
new file mode 100644 (file)
index 0000000..64c5048
--- /dev/null
@@ -0,0 +1,41 @@
+--TEST--
+Test parameter handling in socket_create_pair()
+--SKIPIF--
+<?php
+if (!extension_loaded('sockets')) {
+    die('SKIP The sockets extension is not loaded.');
+}
+--FILE--
+<?php
+var_dump(socket_create_pair(AF_INET, null, null));
+
+$domain = 'unknown';
+var_dump(socket_create_pair($domain, SOCK_STREAM, 0, $sockets));
+
+var_dump(socket_create_pair(AF_INET, null, null, $sockets));
+
+var_dump(socket_create_pair(31337, null, null, $sockets));
+
+var_dump(socket_create_pair(AF_INET, 31337, 0, $sockets));
+--EXPECTF--
+Warning: socket_create_pair() expects exactly 4 parameters, 3 given in %s on line %d
+NULL
+
+Warning: socket_create_pair() expects parameter 1 to be long, %unicode_string_optional% given in %s on line %d
+NULL
+
+Warning: socket_create_pair(): unable to create socket pair [94]: Socket type not supported in %s on line %d
+bool(false)
+
+Warning: socket_create_pair(): invalid socket domain [31337] specified for argument 1, assuming AF_INET in %s on line %d
+
+Warning: socket_create_pair(): unable to create socket pair [94]: Socket type not supported in %s on line %d
+bool(false)
+
+Warning: socket_create_pair(): invalid socket type [31337] specified for argument 2, assuming SOCK_STREAM in %s on line %d
+
+Warning: socket_create_pair(): unable to create socket pair [95]: Operation not supported in %s on line %d
+bool(false)
+--CREDITS--
+Till Klampaeckel, till@php.net
+Berlin TestFest 2009
diff --git a/ext/sockets/tests/socket_create_pair.phpt b/ext/sockets/tests/socket_create_pair.phpt
new file mode 100644 (file)
index 0000000..6af6e42
--- /dev/null
@@ -0,0 +1,24 @@
+--TEST--
+Test for socket_create_pair()
+--SKIPIF--
+<?php
+if (!extension_loaded('sockets')) {
+    die('SKIP The sockets extension is not loaded.');
+}
+--FILE--
+<?php
+$sockets = array();
+if (strtolower(substr(PHP_OS, 0, 3)) == 'win') {
+    $domain = AF_INET;
+} else {
+    $domain = AF_UNIX;
+}
+socket_create_pair($domain, SOCK_STREAM, 0, $sockets);
+var_dump($sockets);
+--EXPECT--
+array(2) {
+  [0]=>
+  resource(4) of type (Socket)
+  [1]=>
+  resource(5) of type (Socket)
+}
diff --git a/ext/sockets/tests/socket_listen-wrongparams.phpt b/ext/sockets/tests/socket_listen-wrongparams.phpt
new file mode 100644 (file)
index 0000000..7dd0d15
--- /dev/null
@@ -0,0 +1,21 @@
+--TEST--
+Test parameter handling in socket_listen().
+--SKIPIF--
+<?php
+if (!extension_loaded('sockets')) {
+    die('SKIP The sockets extension is not loaded.');
+}
+--FILE--
+<?php
+var_dump(socket_listen(null));
+$socket = socket_create(AF_UNIX, SOCK_STREAM, 0); 
+var_dump(socket_listen($socket));
+--EXPECTF--
+Warning: socket_listen() expects parameter 1 to be resource, null given in %s on line %d
+NULL
+
+Warning: socket_listen(): unable to listen on socket [%d]: Invalid argument in %s on line %d
+bool(false)
+--CREDITS--
+Till Klampaeckel, till@php.net
+Berlin TestFest 2009
diff --git a/ext/sockets/tests/socket_select-wrongparams-1.phpt b/ext/sockets/tests/socket_select-wrongparams-1.phpt
new file mode 100644 (file)
index 0000000..e786bc2
--- /dev/null
@@ -0,0 +1,27 @@
+--TEST--
+Test parameter handling in socket_select().
+--SKIPIF--
+<?php
+if (!extension_loaded('sockets')) {
+    die('SKIP The sockets extension is not loaded.');
+}
+--FILE--
+<?php
+$sockets = array();
+if (strtolower(substr(PHP_OS, 0, 3)) == 'win') {
+    $domain = AF_INET;
+} else {
+    $domain = AF_UNIX;
+}
+socket_create_pair($domain, SOCK_STREAM, 0, $sockets);
+
+$write  = null;
+$except = null;
+$time   = -1;
+var_dump(socket_select($sockets, $write, $except, $time));
+--EXPECTF--
+Warning: socket_select(): unable to select [%d]: Invalid argument in %s on line %d
+bool(false)
+--CREDITS--
+Till Klampaeckel, till@php.net
+Berlin TestFest 2009
diff --git a/ext/sockets/tests/socket_select-wrongparams-2.phpt b/ext/sockets/tests/socket_select-wrongparams-2.phpt
new file mode 100644 (file)
index 0000000..c149973
--- /dev/null
@@ -0,0 +1,23 @@
+--TEST--
+Test parameter handling in socket_select().
+--SKIPIF--
+<?php
+if (!extension_loaded('sockets')) {
+    die('SKIP The sockets extension is not loaded.');
+}
+--FILE--
+<?php
+$sockets = null;
+$write   = null;
+$except  = null;
+$time    = 0;
+var_dump(socket_select($sockets, $write, $except, $time));
+socket_select($sockets, $write, $except);
+--EXPECTF--
+Warning: socket_select(): no resource arrays were passed to select in %s on line %d
+bool(false)
+
+Warning: socket_select() expects at least 4 parameters, 3 given in %s on line %d
+--CREDITS--
+Till Klampaeckel, till@php.net
+Berlin TestFest 2009
diff --git a/ext/sockets/tests/socket_select-wrongparams-3.phpt b/ext/sockets/tests/socket_select-wrongparams-3.phpt
new file mode 100644 (file)
index 0000000..51686f9
--- /dev/null
@@ -0,0 +1,28 @@
+--TEST--
+Test parameter handling in socket_select().
+--DESCRIPTION--
+Time must be long, otherwise it's casted.
+--SKIPIF--
+<?php
+if (!extension_loaded('sockets')) {
+    die('SKIP The sockets extension is not loaded.');
+}
+--FILE--
+<?php
+$sockets = array();
+if (strtolower(substr(PHP_OS, 0, 3)) == 'win') {
+    $domain = AF_INET;
+} else {
+    $domain = AF_UNIX;
+}
+socket_create_pair($domain, SOCK_STREAM, 0, $sockets);
+
+$write  = null;
+$except = null;
+$time   = array();
+var_dump(socket_select($sockets, $write, $except, $time));
+--EXPECT--
+int(0)
+--CREDITS--
+Till Klampaeckel, till@php.net
+Berlin TestFest 2009
diff --git a/ext/sockets/tests/socket_select-wrongparams-4.phpt b/ext/sockets/tests/socket_select-wrongparams-4.phpt
new file mode 100644 (file)
index 0000000..7a107b4
--- /dev/null
@@ -0,0 +1,29 @@
+--TEST--
+Test parameter handling in socket_select().
+--DESCRIPTION--
+usec > 999999
+--SKIPIF--
+<?php
+if (!extension_loaded('sockets')) {
+    die('SKIP The sockets extension is not loaded.');
+}
+--FILE--
+<?php
+$sockets = array();
+if (strtolower(substr(PHP_OS, 0, 3)) == 'win') {
+    $domain = AF_INET;
+} else {
+    $domain = AF_UNIX;
+}
+socket_create_pair($domain, SOCK_STREAM, 0, $sockets);
+
+$write  = null;
+$except = null;
+$time   = 0;
+$usec   = 2000000;
+var_dump(socket_select($sockets, $write, $except, $time, $usec));
+--EXPECT--
+int(0)
+--CREDITS--
+Till Klampaeckel, till@php.net
+Berlin TestFest 2009
diff --git a/ext/sockets/tests/socket_select.phpt b/ext/sockets/tests/socket_select.phpt
new file mode 100644 (file)
index 0000000..3896a09
--- /dev/null
@@ -0,0 +1,25 @@
+--TEST--
+Test parameter handling in socket_select().
+--SKIPIF--
+<?php
+if (!extension_loaded('sockets')) {
+    die('SKIP The sockets extension is not loaded.');
+}
+--FILE--
+<?php
+$sockets = array();
+if (strtolower(substr(PHP_OS, 0, 3)) == 'win') {
+    $domain = AF_INET;
+} else {
+    $domain = AF_UNIX;
+}
+socket_create_pair($domain, SOCK_STREAM, 0, $sockets);
+
+$write  = null;
+$except = null;
+var_dump(socket_select($sockets, $write, $except, 0));
+--EXPECT--
+int(0)
+--CREDITS--
+Till Klampaeckel, till@php.net
+Berlin TestFest 2009
diff --git a/ext/sockets/tests/socket_sentto_recvfrom_ipv4_udp.phpt b/ext/sockets/tests/socket_sentto_recvfrom_ipv4_udp.phpt
new file mode 100644 (file)
index 0000000..64b657a
--- /dev/null
@@ -0,0 +1,57 @@
+--TEST--
+Test if socket_recvfrom() receives data sent by socket_sendto() via IPv4 UDP
+--SKIPIF--
+<?php
+if (!extension_loaded('sockets')) {
+    die('SKIP The sockets extension is not loaded.');
+}
+--FILE--
+<?php
+    $socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
+    if (!$socket) {
+        die('Unable to create AF_INET socket');
+    }
+    if (!socket_set_nonblock($socket)) {
+        die('Unable to set nonblocking mode for socket');
+    }
+    socket_recvfrom($socket, $buf, 12, 0, $from, $port); // cause warning
+    $address = '127.0.0.1';
+    socket_sendto($socket, '', 1, 0, $address); // cause warning
+    if (!socket_bind($socket, $address, 1223)) {
+        die("Unable to bind to $address:1223");
+    }
+
+    $msg = "Ping!";
+    $len = strlen($msg);
+    $bytes_sent = socket_sendto($socket, $msg, $len, 0, $address, 1223);
+    if ($bytes_sent == -1) {
+        die('An error occured while sending to the socket');
+    } else if ($bytes_sent != $len) {
+        die($bytes_sent . ' bytes have been sent instead of the ' . $len . ' bytes expected');
+    }
+
+    $from = "";
+    $port = 0;
+    socket_recvfrom($socket, $buf, 12, 0); // cause warning
+    socket_recvfrom($socket, $buf, 12, 0, $from); // cause warning
+    $bytes_received = socket_recvfrom($socket, $buf, 12, 0, $from, $port);
+    if ($bytes_received == -1) {
+        die('An error occured while receiving from the socket');
+    } else if ($bytes_received != $len) {
+        die($bytes_received . ' bytes have been received instead of the ' . $len . ' bytes expected');
+    }
+    echo "Received $buf from remote address $from and remote port $port" . PHP_EOL;
+
+    socket_close($socket);
+--EXPECTF--
+Warning: socket_recvfrom(): unable to recvfrom [11]: Resource temporarily unavailable in %s on line %d
+
+Warning: Wrong parameter count for socket_sendto() in %s on line %d
+
+Warning: socket_recvfrom() expects at least 5 parameters, 4 given in %s on line %d
+
+Warning: Wrong parameter count for socket_recvfrom() in %s on line %d
+Received Ping! from remote address 127.0.0.1 and remote port 1223
+--CREDITS--
+Falko Menge <mail at falko-menge dot de>
+PHP Testfest Berlin 2009-05-09
diff --git a/ext/sockets/tests/socket_sentto_recvfrom_ipv6_udp.phpt b/ext/sockets/tests/socket_sentto_recvfrom_ipv6_udp.phpt
new file mode 100644 (file)
index 0000000..5b8b742
--- /dev/null
@@ -0,0 +1,57 @@
+--TEST--
+Test if socket_recvfrom() receives data sent by socket_sendto() via IPv6 UDP
+--SKIPIF--
+<?php
+if (!extension_loaded('sockets')) {
+    die('SKIP The sockets extension is not loaded.');
+}
+--FILE--
+<?php
+    $socket = socket_create(AF_INET6, SOCK_DGRAM, SOL_UDP);
+    if (!$socket) {
+        die('Unable to create AF_INET6 socket');
+    }
+    if (!socket_set_nonblock($socket)) {
+        die('Unable to set nonblocking mode for socket');
+    }
+    socket_recvfrom($socket, $buf, 12, 0, $from, $port); // cause warning
+    $address = '::1';
+    socket_sendto($socket, '', 1, 0, $address); // cause warning
+    if (!socket_bind($socket, $address, 1223)) {
+        die("Unable to bind to $address:1223");
+    }
+
+    $msg = "Ping!";
+    $len = strlen($msg);
+    $bytes_sent = socket_sendto($socket, $msg, $len, 0, $address, 1223);
+    if ($bytes_sent == -1) {
+        die('An error occured while sending to the socket');
+    } else if ($bytes_sent != $len) {
+        die($bytes_sent . ' bytes have been sent instead of the ' . $len . ' bytes expected');
+    }
+
+    $from = "";
+    $port = 0;
+    socket_recvfrom($socket, $buf, 12, 0); // cause warning
+    socket_recvfrom($socket, $buf, 12, 0, $from); // cause warning
+    $bytes_received = socket_recvfrom($socket, $buf, 12, 0, $from, $port);
+    if ($bytes_received == -1) {
+        die('An error occured while receiving from the socket');
+    } else if ($bytes_received != $len) {
+        die($bytes_received . ' bytes have been received instead of the ' . $len . ' bytes expected');
+    }
+    echo "Received $buf from remote address $from and remote port $port" . PHP_EOL;
+
+    socket_close($socket);
+--EXPECTF--
+Warning: socket_recvfrom(): unable to recvfrom [11]: Resource temporarily unavailable in %s on line %d
+
+Warning: Wrong parameter count for socket_sendto() in %s on line %d
+
+Warning: socket_recvfrom() expects at least 5 parameters, 4 given in %s on line %d
+
+Warning: Wrong parameter count for socket_recvfrom() in %s on line %d
+Received Ping! from remote address ::1 and remote port 1223
+--CREDITS--
+Falko Menge <mail at falko-menge dot de>
+PHP Testfest Berlin 2009-05-09
diff --git a/ext/sockets/tests/socket_sentto_recvfrom_unix.phpt b/ext/sockets/tests/socket_sentto_recvfrom_unix.phpt
new file mode 100644 (file)
index 0000000..94eac3b
--- /dev/null
@@ -0,0 +1,55 @@
+--TEST--
+Test if socket_recvfrom() receives data sent by socket_sendto() through a Unix domain socket
+--SKIPIF--
+<?php
+if (!extension_loaded('sockets')) {
+    die('SKIP The sockets extension is not loaded.');
+}
+--FILE--
+<?php
+    $socket = socket_create(AF_UNIX, SOCK_DGRAM, SOL_UDP); // cause warning
+    $socket = socket_create(AF_UNIX, SOCK_DGRAM, 0);
+    if (!$socket) {
+        die('Unable to create AF_UNIX socket');
+    }
+    if (!socket_set_nonblock($socket)) {
+        die('Unable to set nonblocking mode for socket');
+    }
+    socket_recvfrom($socket, $buf, 12, 0, $from, $port); // cause warning
+    $address = sprintf("/tmp/%s.sock", uniqid());
+    if (!socket_bind($socket, $address)) {
+        die("Unable to bind to $address");
+    }
+
+    $msg = "Ping!";
+    $len = strlen($msg);
+    $bytes_sent = socket_sendto($socket, $msg, $len, 0); // cause warning
+    $bytes_sent = socket_sendto($socket, $msg, $len, 0, $address);
+    if ($bytes_sent == -1) {
+        die('An error occured while sending to the socket');
+    } else if ($bytes_sent != $len) {
+        die($bytes_sent . ' bytes have been sent instead of the ' . $len . ' bytes expected');
+    }
+
+    $from = "";
+    var_dump(socket_recvfrom($socket, $buf, 0, 0, $from)); // expect false
+    $bytes_received = socket_recvfrom($socket, $buf, 12, 0, $from);
+    if ($bytes_received == -1) {
+        die('An error occured while receiving from the socket');
+    } else if ($bytes_received != $len) {
+        die($bytes_received . ' bytes have been received instead of the ' . $len . ' bytes expected');
+    }
+    echo "Received $buf";
+
+    socket_close($socket);
+--EXPECTF--
+Warning: socket_create(): Unable to create socket [93]: Protocol not supported in %s on line %d
+
+Warning: socket_recvfrom(): unable to recvfrom [11]: Resource temporarily unavailable in %s on line %d
+
+Warning: socket_sendto() expects at least 5 parameters, 4 given in %s on line %d
+bool(false)
+Received Ping!
+--CREDITS--
+Falko Menge <mail at falko-menge dot de>
+PHP Testfest Berlin 2009-05-09
diff --git a/ext/sockets/tests/socket_set_block-retval.phpt b/ext/sockets/tests/socket_set_block-retval.phpt
new file mode 100644 (file)
index 0000000..fe09d5a
--- /dev/null
@@ -0,0 +1,28 @@
+--TEST--
+Test socket_set_block return values
+--SKIPIF--
+<?php
+if (!extension_loaded('sockets')) {
+    die('SKIP The sockets extension is not loaded.');
+}
+?>
+--FILE--
+<?php
+
+$socket = socket_create_listen(31337);
+var_dump(socket_set_block($socket));
+socket_close($socket);
+
+$socket2 = socket_create_listen(31338);
+socket_close($socket2);
+var_dump(socket_set_block($socket2));
+
+?>
+--EXPECTF--
+bool(true)
+
+Warning: socket_set_block(): %d is not a valid Socket resource in %s on line %d
+bool(false)
+--CREDITS--
+Robin Mehner, robin@coding-robin.de
+PHP Testfest Berlin 2009-05-09
diff --git a/ext/sockets/tests/socket_set_block-wrongparams.phpt b/ext/sockets/tests/socket_set_block-wrongparams.phpt
new file mode 100644 (file)
index 0000000..7c80695
--- /dev/null
@@ -0,0 +1,18 @@
+--TEST--
+Test if socket_set_block throws E_WARNING with wrong parameters.
+--SKIPIF--
+<?php
+if (!extension_loaded('sockets')) {
+    die('SKIP The sockets extension is not loaded.');
+}
+?>
+--FILE--
+<?php
+socket_set_block(array());
+?>
+--EXPECTF--
+Warning: socket_set_block() expects parameter 1 to be resource, array given in %s on line %d
+--CREDITS--
+Robin Mehner, robin@coding-robin.de
+PHP Testfest Berlin 2009-05-09
+
diff --git a/ext/sockets/tests/socket_set_nonblock-retval.phpt b/ext/sockets/tests/socket_set_nonblock-retval.phpt
new file mode 100644 (file)
index 0000000..3c4b515
--- /dev/null
@@ -0,0 +1,28 @@
+--TEST--
+Test socket_set_nonblock return values
+--SKIPIF--
+<?php
+if (!extension_loaded('sockets')) {
+    die('SKIP The sockets extension is not loaded.');
+}
+?>
+--FILE--
+<?php
+
+$socket = socket_create_listen(31337);
+var_dump(socket_set_nonblock($socket));
+socket_close($socket);
+
+$socket2 = socket_create_listen(31338);
+socket_close($socket2);
+var_dump(socket_set_nonblock($socket2));
+
+?>
+--EXPECTF--
+bool(true)
+
+Warning: socket_set_nonblock(): %d is not a valid Socket resource in %s on line %d
+bool(false)
+--CREDITS--
+Robin Mehner, robin@coding-robin.de
+PHP Testfest Berlin 2009-05-09
diff --git a/ext/sockets/tests/socket_set_nonblock-wrongparams.phpt b/ext/sockets/tests/socket_set_nonblock-wrongparams.phpt
new file mode 100644 (file)
index 0000000..4b7e5be
--- /dev/null
@@ -0,0 +1,13 @@
+--TEST--
+Test if socket_set_nonblock throws E_WARNING with wrong parameters.
+--SKIPIF--
+<?php
+if (!extension_loaded('sockets')) {
+    die('SKIP The sockets extension is not loaded.');
+}
+--FILE--
+<?php
+$socket = socket_set_nonblock(array());
+?>
+--EXPECTF--
+Warning: socket_set_nonblock() expects parameter 1 to be resource, array given in %s on line %d
diff --git a/ext/sockets/tests/socket_set_option_error_socket_option.phpt b/ext/sockets/tests/socket_set_option_error_socket_option.phpt
new file mode 100644 (file)
index 0000000..eaa0e64
--- /dev/null
@@ -0,0 +1,33 @@
+--TEST--
+Test if socket_set_option() returns 'unable to set socket option' failure for invalid options
+--SKIPIF--
+<?php
+if (!extension_loaded('sockets')) {
+        die('SKIP sockets extension not available.');
+}
+$filename = dirname(__FILE__) . '/006_root_check.tmp';
+$fp = fopen($filename, 'w');
+fclose($fp);
+if (fileowner($filename) == 0) {
+    unlink ($filename);
+    die('SKIP Test cannot be run as root.');
+}
+?>
+--FILE--
+<?php
+$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
+if (!$socket) {
+        die('Unable to create AF_INET socket [socket]');
+}
+
+socket_set_option( $socket, SOL_SOCKET, 1, 1);
+socket_close($socket);
+?>
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/006_root_check.tmp');
+--EXPECTF--
+Warning: socket_set_option(): unable to set socket option [%d]: Permission denied in %s on line %d
+--CREDITS--
+Moritz Neuhaeuser, info@xcompile.net
+PHP Testfest Berlin 2009-05-10
diff --git a/ext/sockets/tests/socket_set_option_rcvtimeo.phpt b/ext/sockets/tests/socket_set_option_rcvtimeo.phpt
new file mode 100644 (file)
index 0000000..84c533f
--- /dev/null
@@ -0,0 +1,39 @@
+--TEST--
+Test if socket_set_option() works, option:SO_RCVTIMEO
+--DESCRIPTION---
+-wrong params 
+-set/get params comparison 
+--SKIPIF--
+<?php
+if (!extension_loaded('sockets')) {
+        die('SKIP sockets extension not available.');
+}
+?>
+--FILE--
+<?php
+$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
+if (!$socket) {
+        die('Unable to create AF_INET socket [socket]');
+}
+socket_set_block($socket);
+
+//wrong params
+$retval_1 = socket_set_option( $socket, SOL_SOCKET, SO_RCVTIMEO, array());
+
+//set/get comparison
+$options = array("sec" => 1, "usec" => 0);
+$retval_2 = socket_set_option( $socket, SOL_SOCKET, SO_RCVTIMEO, $options);
+$retval_3 = socket_get_option( $socket, SOL_SOCKET, SO_RCVTIMEO);
+
+var_dump($retval_2);
+var_dump($retval_3 === $options);
+socket_close($socket);
+?>
+
+--EXPECTF--
+Warning: socket_set_option(): no key "sec" passed in optval in %s on line %d
+bool(true)
+bool(true)
+--CREDITS--
+Moritz Neuhaeuser, info@xcompile.net
+PHP Testfest Berlin 2009-05-10
diff --git a/ext/sockets/tests/socket_set_option_seolinger.phpt b/ext/sockets/tests/socket_set_option_seolinger.phpt
new file mode 100644 (file)
index 0000000..05bc213
--- /dev/null
@@ -0,0 +1,47 @@
+--TEST--
+Test if socket_set_option() works, option:SO_SEOLINGER
+--DESCRIPTION---
+-wrong params 
+-set/get params comparison 
+-l_linger not given
+--SKIPIF--
+<?php
+if (!extension_loaded('sockets')) {
+        die('SKIP sockets extension not available.');
+}
+?>
+--FILE--
+<?php
+$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
+
+if (!$socket) {
+        die('Unable to create AF_INET socket [socket]');
+}
+// wrong params
+$retval_1 = socket_set_option( $socket, SOL_SOCKET, SO_LINGER, array());
+
+// set/get comparison
+$options = array("l_onoff" => 1, "l_linger" => 1);
+$retval_2 = socket_set_option( $socket, SOL_SOCKET, SO_LINGER, $options);
+$retval_3 = socket_get_option( $socket, SOL_SOCKET, SO_LINGER);
+
+//l_linger not given
+$options_2 = array("l_onoff" => 1);
+var_dump(socket_set_option( $socket, SOL_SOCKET, SO_LINGER, $options_2));
+
+var_dump($retval_2);
+var_dump($retval_3 === $options);
+
+socket_close($socket);
+?>
+
+--EXPECTF--
+Warning: socket_set_option(): no key "l_onoff" passed in optval in %s on line %d
+
+Warning: socket_set_option(): no key "l_linger" passed in optval in %s on line %d
+bool(false)
+bool(true)
+bool(true)
+--CREDITS--
+Moritz Neuhaeuser, info@xcompile.net
+PHP Testfest Berlin 2009-05-10
diff --git a/ext/sockets/tests/socket_set_option_sndtimeo.phpt b/ext/sockets/tests/socket_set_option_sndtimeo.phpt
new file mode 100644 (file)
index 0000000..c4e4851
--- /dev/null
@@ -0,0 +1,39 @@
+--TEST--
+Test if socket_set_option() works, option:SO_SNDTIMEO
+--DESCRIPTION---
+-wrong params 
+-set/get params comparison 
+--SKIPIF--
+<?php
+if (!extension_loaded('sockets')) {
+        die('SKIP sockets extension not available.');
+}
+?>
+--FILE--
+<?php
+$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
+if (!$socket) {
+        die('Unable to create AF_INET socket [socket]');
+}
+socket_set_block($socket);
+
+//wrong params
+$retval_1 = socket_set_option( $socket, SOL_SOCKET, SO_SNDTIMEO, array());
+
+//set/get comparison
+$options = array("sec" => 1, "usec" => 0);
+$retval_2 = socket_set_option( $socket, SOL_SOCKET, SO_SNDTIMEO, $options);
+$retval_3 = socket_get_option( $socket, SOL_SOCKET, SO_SNDTIMEO);
+
+var_dump($retval_2);
+var_dump($retval_3 === $options);
+socket_close($socket);
+?>
+
+--EXPECTF--
+Warning: socket_set_option(): no key "sec" passed in optval in %s on line %d
+bool(true)
+bool(true)
+--CREDITS--
+Moritz Neuhaeuser, info@xcompile.net
+PHP Testfest Berlin 2009-05-10