2 stream_set_chunk_size basic tests
6 function stream_open($path, $mode, $openedpath) {
9 function stream_eof() {
12 function stream_read($count) {
13 echo "read with size: ", $count, "\n";
14 return str_repeat('a', $count);
16 function stream_write($data) {
17 echo "write with size: ", strlen($data), "\n";
20 function stream_set_option($option, $arg1, $arg2) {
21 echo "option: ", $option, ", ", $arg1, ", ", $arg2, "\n";
26 var_dump(stream_wrapper_register('test', 'test_wrapper'));
28 $f = fopen("test://foo","r");
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)));
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))));
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()));
58 should return previous chunk size (8192)
60 should be read without buffer ($count == 10000)
63 should elicit 3 writes of size 1 and return 3
68 should return previous chunk size (1)
70 should elicit one read of size 100 (chunk size)
73 should elicit one read of size 100 (chunk size)
76 should elicit no read because there is sufficient cached data
78 should elicit 2 writes of size 100 and one of size 50
86 Warning: stream_set_chunk_size(): The chunk size must be a positive integer, given 0 in %s on line %d
89 Warning: stream_set_chunk_size(): The chunk size must be a positive integer, given -1 in %s on line %d
92 Warning: stream_set_chunk_size() expects parameter 2 to be long, array given in %s on line %d