Annotation of embedaddon/php/ext/standard/tests/streams/stream_set_chunk_size.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: stream_set_chunk_size basic tests
                      3: --FILE--
                      4: <?php
                      5: class test_wrapper {
                      6:        function stream_open($path, $mode, $openedpath) {
                      7:                return true;
                      8:        }
                      9:        function stream_eof() {
                     10:                return false;
                     11:        }
                     12:        function stream_read($count) {
                     13:                echo "read with size: ", $count, "\n";
                     14:                return str_repeat('a', $count);
                     15:        }
                     16:        function stream_write($data) {
                     17:                echo "write with size: ", strlen($data), "\n";
                     18:                return strlen($data);
                     19:        }
                     20:        function stream_set_option($option, $arg1, $arg2) {
                     21:                echo "option: ", $option, ", ", $arg1, ", ", $arg2, "\n";
                     22:                return false;
                     23:        }
                     24: }
                     25: 
                     26: var_dump(stream_wrapper_register('test', 'test_wrapper'));
                     27: 
                     28: $f = fopen("test://foo","r");
                     29: 
                     30: /* when the chunk size is 1, the read buffer is skipped, but the
                     31:  * the writes are made in chunks of size 1 (business as usual)
                     32:  * This should probably be revisited */
                     33: echo "should return previous chunk size (8192)\n";
                     34: var_dump(stream_set_chunk_size($f, 1));
                     35: echo "should be read without buffer (\$count == 10000)\n";
                     36: var_dump(strlen(fread($f, 10000)));
                     37: echo "should elicit 3 writes of size 1 and return 3\n";
                     38: var_dump(fwrite($f, str_repeat('b', 3)));
                     39: 
                     40: echo "should return previous chunk size (1)\n";
                     41: var_dump(stream_set_chunk_size($f, 100));
                     42: echo "should elicit one read of size 100 (chunk size)\n";
                     43: var_dump(strlen(fread($f, 250)));
                     44: echo "should elicit one read of size 100 (chunk size)\n";
                     45: var_dump(strlen(fread($f, 50)));
                     46: echo "should elicit no read because there is sufficient cached data\n";
                     47: var_dump(strlen(fread($f, 50)));
                     48: echo "should elicit 2 writes of size 100 and one of size 50\n";
                     49: var_dump(strlen(fwrite($f, str_repeat('b', 250))));
                     50: 
                     51: echo "\nerror conditions\n";
                     52: var_dump(stream_set_chunk_size($f, 0));
                     53: var_dump(stream_set_chunk_size($f, -1));
                     54: var_dump(stream_set_chunk_size($f, array()));
                     55: 
                     56: --EXPECTF--
                     57: bool(true)
                     58: should return previous chunk size (8192)
                     59: int(8192)
                     60: should be read without buffer ($count == 10000)
                     61: read with size: 10000
                     62: int(10000)
                     63: should elicit 3 writes of size 1 and return 3
                     64: write with size: 1
                     65: write with size: 1
                     66: write with size: 1
                     67: int(3)
                     68: should return previous chunk size (1)
                     69: int(1)
                     70: should elicit one read of size 100 (chunk size)
                     71: read with size: 100
                     72: int(100)
                     73: should elicit one read of size 100 (chunk size)
                     74: read with size: 100
                     75: int(50)
                     76: should elicit no read because there is sufficient cached data
                     77: int(50)
                     78: should elicit 2 writes of size 100 and one of size 50
                     79: write with size: 100
                     80: write with size: 100
                     81: write with size: 50
                     82: int(3)
                     83: 
                     84: error conditions
                     85: 
                     86: Warning: stream_set_chunk_size(): The chunk size must be a positive integer, given 0 in %s on line %d
                     87: bool(false)
                     88: 
                     89: Warning: stream_set_chunk_size(): The chunk size must be a positive integer, given -1 in %s on line %d
                     90: bool(false)
                     91: 
                     92: Warning: stream_set_chunk_size() expects parameter 2 to be long, array given in %s on line %d
                     93: bool(false)

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