Annotation of embedaddon/php/ext/standard/tests/file/fwrite_variation4.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test fwrite() function : usage variations - x, xb, xt, x+, x+b & x+t modes
3: --SKIPIF--
4: <?php
5: if( substr(PHP_OS, 0, 3) == 'WIN' ) {
6: die('skip...Not valid for Windows');
7: }
8: ?>
9: --FILE--
10: <?php
11: /*
12: Prototype: int fwrite ( resource $handle,string string, [, int $length] );
13: Description: fwrite() writes the contents of string to the file stream pointed to by handle.
14: If the length arquement is given,writing will stop after length bytes have been
15: written or the end of string reached, whichever comes first.
16: fwrite() returns the number of bytes written or FALSE on error
17: */
18:
19:
20: echo "*** Testing fwrite() various operations ***\n";
21:
22: // include the file.inc for Function: function delete_file($filename)
23: include ("file.inc");
24:
25: /*
26: Test fwrite with file opened in mode : x, xb, xt, x+, x+b, x+t
27: File having content of type numeric, text,text_with_new_line & alphanumeric
28: */
29:
30: $file_modes = array("x","xb","xt","x+","x+b","x+t");
31: $file_content_types = array("numeric","text","text_with_new_line","alphanumeric");
32:
33:
34: foreach($file_content_types as $file_content_type) {
35: echo "\n-- Testing fwrite() with file having content of type ". $file_content_type ." --\n";
36:
37: /* open the file using $files_modes and perform fwrite() on it */
38: foreach($file_modes as $file_mode) {
39: echo "-- Opening file in $file_mode --\n";
40:
41: $filename = dirname(__FILE__)."/fwrite_variation4.tmp"; // this is name of the file
42:
43: $file_handle = fopen($filename, $file_mode);
44: if(!$file_handle) {
45: echo "Error: failed to fopen() file: $filename!";
46: exit();
47: }
48:
49: $data_to_be_written="";
50: fill_buffer($data_to_be_written,$file_content_type,1024); //get the data of size 1024
51:
52: /* Write the data into the file, verify it by checking the file pointer position, eof position,
53: filesize & by displaying the content */
54: // write data to the file
55: var_dump( ftell($file_handle) );
56: var_dump( fwrite($file_handle,$data_to_be_written,400));
57: var_dump( ftell($file_handle) );
58: var_dump( feof($file_handle) ); // expected: true
59:
60: //check the filesize and content
61: // close the file, get the size and content of the file.
62: var_dump( fclose($file_handle) );
63: clearstatcache();//clears file status cache
64: var_dump( filesize($filename) );
65: var_dump(md5(file_get_contents($filename)));
66: // delete the file created
67: delete_file($filename); // delete file with name fwrite_variation4.tmp
68: } // end of inner foreach loop
69: } // end of outer foreach loop
70:
71: echo "Done\n";
72: ?>
73: --EXPECTF--
74: *** Testing fwrite() various operations ***
75:
76: -- Testing fwrite() with file having content of type numeric --
77: -- Opening file in x --
78: int(0)
79: int(400)
80: int(400)
81: bool(false)
82: bool(true)
83: int(400)
84: string(32) "f255efe87ebdf755e515868cea9ad24b"
85: -- Opening file in xb --
86: int(0)
87: int(400)
88: int(400)
89: bool(false)
90: bool(true)
91: int(400)
92: string(32) "f255efe87ebdf755e515868cea9ad24b"
93: -- Opening file in xt --
94: int(0)
95: int(400)
96: int(400)
97: bool(false)
98: bool(true)
99: int(400)
100: string(32) "f255efe87ebdf755e515868cea9ad24b"
101: -- Opening file in x+ --
102: int(0)
103: int(400)
104: int(400)
105: bool(false)
106: bool(true)
107: int(400)
108: string(32) "f255efe87ebdf755e515868cea9ad24b"
109: -- Opening file in x+b --
110: int(0)
111: int(400)
112: int(400)
113: bool(false)
114: bool(true)
115: int(400)
116: string(32) "f255efe87ebdf755e515868cea9ad24b"
117: -- Opening file in x+t --
118: int(0)
119: int(400)
120: int(400)
121: bool(false)
122: bool(true)
123: int(400)
124: string(32) "f255efe87ebdf755e515868cea9ad24b"
125:
126: -- Testing fwrite() with file having content of type text --
127: -- Opening file in x --
128: int(0)
129: int(400)
130: int(400)
131: bool(false)
132: bool(true)
133: int(400)
134: string(32) "c2244282eeca7c2d32d0dacf21e19432"
135: -- Opening file in xb --
136: int(0)
137: int(400)
138: int(400)
139: bool(false)
140: bool(true)
141: int(400)
142: string(32) "c2244282eeca7c2d32d0dacf21e19432"
143: -- Opening file in xt --
144: int(0)
145: int(400)
146: int(400)
147: bool(false)
148: bool(true)
149: int(400)
150: string(32) "c2244282eeca7c2d32d0dacf21e19432"
151: -- Opening file in x+ --
152: int(0)
153: int(400)
154: int(400)
155: bool(false)
156: bool(true)
157: int(400)
158: string(32) "c2244282eeca7c2d32d0dacf21e19432"
159: -- Opening file in x+b --
160: int(0)
161: int(400)
162: int(400)
163: bool(false)
164: bool(true)
165: int(400)
166: string(32) "c2244282eeca7c2d32d0dacf21e19432"
167: -- Opening file in x+t --
168: int(0)
169: int(400)
170: int(400)
171: bool(false)
172: bool(true)
173: int(400)
174: string(32) "c2244282eeca7c2d32d0dacf21e19432"
175:
176: -- Testing fwrite() with file having content of type text_with_new_line --
177: -- Opening file in x --
178: int(0)
179: int(400)
180: int(400)
181: bool(false)
182: bool(true)
183: int(400)
184: string(32) "fa6c79b925c2fc754b9d063c6de1d8df"
185: -- Opening file in xb --
186: int(0)
187: int(400)
188: int(400)
189: bool(false)
190: bool(true)
191: int(400)
192: string(32) "fa6c79b925c2fc754b9d063c6de1d8df"
193: -- Opening file in xt --
194: int(0)
195: int(400)
196: int(400)
197: bool(false)
198: bool(true)
199: int(400)
200: string(32) "fa6c79b925c2fc754b9d063c6de1d8df"
201: -- Opening file in x+ --
202: int(0)
203: int(400)
204: int(400)
205: bool(false)
206: bool(true)
207: int(400)
208: string(32) "fa6c79b925c2fc754b9d063c6de1d8df"
209: -- Opening file in x+b --
210: int(0)
211: int(400)
212: int(400)
213: bool(false)
214: bool(true)
215: int(400)
216: string(32) "fa6c79b925c2fc754b9d063c6de1d8df"
217: -- Opening file in x+t --
218: int(0)
219: int(400)
220: int(400)
221: bool(false)
222: bool(true)
223: int(400)
224: string(32) "fa6c79b925c2fc754b9d063c6de1d8df"
225:
226: -- Testing fwrite() with file having content of type alphanumeric --
227: -- Opening file in x --
228: int(0)
229: int(400)
230: int(400)
231: bool(false)
232: bool(true)
233: int(400)
234: string(32) "b2a123e1d84e6a03c8520aff7689219e"
235: -- Opening file in xb --
236: int(0)
237: int(400)
238: int(400)
239: bool(false)
240: bool(true)
241: int(400)
242: string(32) "b2a123e1d84e6a03c8520aff7689219e"
243: -- Opening file in xt --
244: int(0)
245: int(400)
246: int(400)
247: bool(false)
248: bool(true)
249: int(400)
250: string(32) "b2a123e1d84e6a03c8520aff7689219e"
251: -- Opening file in x+ --
252: int(0)
253: int(400)
254: int(400)
255: bool(false)
256: bool(true)
257: int(400)
258: string(32) "b2a123e1d84e6a03c8520aff7689219e"
259: -- Opening file in x+b --
260: int(0)
261: int(400)
262: int(400)
263: bool(false)
264: bool(true)
265: int(400)
266: string(32) "b2a123e1d84e6a03c8520aff7689219e"
267: -- Opening file in x+t --
268: int(0)
269: int(400)
270: int(400)
271: bool(false)
272: bool(true)
273: int(400)
274: string(32) "b2a123e1d84e6a03c8520aff7689219e"
275: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>