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--EXPECTF--
56bool(true)
57should return previous chunk size (8192)
58int(8192)
59should be read without buffer ($count == 10000)
60read with size: 10000
61int(10000)
62should elicit 3 writes of size 1 and return 3
63write with size: 1
64write with size: 1
65write with size: 1
66int(3)
67should return previous chunk size (1)
68int(1)
69should elicit one read of size 100 (chunk size)
70read with size: 100
71int(100)
72should elicit one read of size 100 (chunk size)
73read with size: 100
74int(50)
75should elicit no read because there is sufficient cached data
76int(50)
77should elicit 2 writes of size 100 and one of size 50
78write with size: 100
79write with size: 100
80write with size: 50
81int(3)
82
83error conditions
84
85Warning: stream_set_chunk_size(): The chunk size must be a positive integer, given 0 in %s on line %d
86bool(false)
87
88Warning: stream_set_chunk_size(): The chunk size must be a positive integer, given -1 in %s on line %d
89bool(false)
90
91Warning: stream_set_chunk_size() expects parameter 2 to be integer, array given in %s on line %d
92bool(false)
93