Annotation of embedaddon/php/ext/standard/tests/streams/stream_set_timeout_error.phpt, revision 1.1.1.2

1.1       misho       1: --TEST--
                      2: Test stream_set_timeout() function : error conditions 
                      3: --FILE--
                      4: <?php
                      5: /* Prototype  : proto bool stream_set_timeout(resource stream, int seconds, int microseconds)
                      6:  * Description: Set timeout on stream read to seconds + microseonds 
                      7:  * Source code: ext/standard/streamsfuncs.c
                      8:  * Alias to functions: socket_set_timeout
                      9:  */
                     10: 
                     11: echo "*** Testing stream_set_timeout() : error conditions ***\n";
                     12: 
                     13: //Test stream_set_timeout with one more than the expected number of arguments
                     14: echo "\n-- Testing stream_set_timeout() function with more than expected no. of arguments --\n";
                     15: 
1.1.1.2 ! misho      16: for ($i=0; $i<100; $i++) {
        !            17:   $port = rand(10000, 65000);
        !            18:   /* Setup socket server */
        !            19:   $server = @stream_socket_server("tcp://127.0.0.1:$port");
        !            20:   if ($server) {
        !            21:     break;
        !            22:   }
        !            23: }
1.1       misho      24: /* Connect to it */
1.1.1.2 ! misho      25: $client = fsockopen("tcp://127.0.0.1:$port");
1.1       misho      26: 
                     27: $seconds = 10;
                     28: $microseconds = 10;
                     29: $extra_arg = 10;
                     30: var_dump( stream_set_timeout($client, $seconds, $microseconds, $extra_arg) );
                     31: 
                     32: // Testing stream_set_timeout with one less than the expected number of arguments
                     33: echo "\n-- Testing stream_set_timeout() function with less than expected no. of arguments --\n";
                     34: 
                     35: $seconds = 10;
                     36: var_dump( stream_set_timeout($client) );
                     37: 
                     38: 
                     39: echo "\n-- Testing stream_set_timeout() function with a closed socket --\n";
                     40: fclose($client);
                     41: var_dump( stream_set_timeout($client, $seconds) );
                     42: 
                     43: echo "\n-- Testing stream_set_timeout() function with an invalid stream --\n";
                     44: var_dump( stream_set_timeout($seconds, $seconds) );
                     45: 
                     46: echo "\n-- Testing stream_set_timeout() function with a stream that does not support timeouts --\n";
                     47: $filestream = fopen(__FILE__, "r");
                     48: var_dump( stream_set_timeout($filestream, $seconds) );
                     49: 
                     50: fclose($filestream);
                     51: fclose($server);
                     52: 
                     53: echo "Done";
                     54: ?>
                     55: --EXPECTF--
                     56: *** Testing stream_set_timeout() : error conditions ***
                     57: 
                     58: -- Testing stream_set_timeout() function with more than expected no. of arguments --
                     59: 
                     60: Warning: stream_set_timeout() expects at most 3 parameters, 4 given in %s on line %i
                     61: NULL
                     62: 
                     63: -- Testing stream_set_timeout() function with less than expected no. of arguments --
                     64: 
                     65: Warning: stream_set_timeout() expects at least 2 parameters, 1 given in %s on line %i
                     66: NULL
                     67: 
                     68: -- Testing stream_set_timeout() function with a closed socket --
                     69: 
                     70: Warning: stream_set_timeout(): %i is not a valid stream resource in %s on line %i
                     71: bool(false)
                     72: 
                     73: -- Testing stream_set_timeout() function with an invalid stream --
                     74: 
                     75: Warning: stream_set_timeout() expects parameter 1 to be resource, integer given in %s on line %i
                     76: NULL
                     77: 
                     78: -- Testing stream_set_timeout() function with a stream that does not support timeouts --
                     79: bool(false)
                     80: Done

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>