1--TEST--
2stream_set_chunk_size basic tests
3--FILE--
4<?php
5class 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
26var_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 */
33echo "should return previous chunk size (8192)\n";
34var_dump(stream_set_chunk_size($f, 1));
35echo "should be read without buffer (\$count == 10000)\n";
36var_dump(strlen(fread($f, 10000)));
37echo "should elicit 3 writes of size 1 and return 3\n";
38var_dump(fwrite($f, str_repeat('b', 3)));
39
40echo "should return previous chunk size (1)\n";
41var_dump(stream_set_chunk_size($f, 100));
42echo "should elicit one read of size 100 (chunk size)\n";
43var_dump(strlen(fread($f, 250)));
44echo "should elicit one read of size 100 (chunk size)\n";
45var_dump(strlen(fread($f, 50)));
46echo "should elicit no read because there is sufficient cached data\n";
47var_dump(strlen(fread($f, 50)));
48echo "should elicit 2 writes of size 100 and one of size 50\n";
49var_dump(strlen(fwrite($f, str_repeat('b', 250))));
50
51echo "\nerror conditions\n";
52var_dump(stream_set_chunk_size($f, 0));
53var_dump(stream_set_chunk_size($f, -1));
54var_dump(stream_set_chunk_size($f, array()));
55
56--EXPECTF--
57bool(true)
58should return previous chunk size (8192)
59int(8192)
60should be read without buffer ($count == 10000)
61read with size: 10000
62int(10000)
63should elicit 3 writes of size 1 and return 3
64write with size: 1
65write with size: 1
66write with size: 1
67int(3)
68should return previous chunk size (1)
69int(1)
70should elicit one read of size 100 (chunk size)
71read with size: 100
72int(100)
73should elicit one read of size 100 (chunk size)
74read with size: 100
75int(50)
76should elicit no read because there is sufficient cached data
77int(50)
78should elicit 2 writes of size 100 and one of size 50
79write with size: 100
80write with size: 100
81write with size: 50
82int(3)
83
84error conditions
85
86Warning: stream_set_chunk_size(): The chunk size must be a positive integer, given 0 in %s on line %d
87bool(false)
88
89Warning: stream_set_chunk_size(): The chunk size must be a positive integer, given -1 in %s on line %d
90bool(false)
91
92Warning: stream_set_chunk_size() expects parameter 2 to be integer, array given in %s on line %d
93bool(false)
94