Annotation of embedaddon/php/ext/standard/tests/file/filesize_variation4-win32.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test filesize() function: usage variations - file mode & holes in file
3: --SKIPIF--
4: <?php
5: if (substr(PHP_OS, 0, 3) != 'WIN') {
6: die('skip only valid for Windows');
7: }
8: --FILE--
9: <?php
10: /*
11: Prototype : int filesize ( string $filename );
12: Description : Returns the size of the file in bytes, or FALSE
13: (and generates an error of level E_WARNING) in case of an error.
14: */
15:
16: $file_path = dirname(__FILE__);
17: require($file_path."/file.inc");
18:
19: echo "*** Testing filesize(): usage variations ***\n";
20: echo "\n*** Testing filesize() with data written using different file modes and by creating holes in file ***\n";
21:
22: $filename = $file_path."/filesize_variation4.tmp";
23: $string = "Test 2 test the filesize() fn, with data containing all the types like !@@##$%^&*():<>?|~+!;',.\][{}(special) chars, 12345(numeric) chars, and \n(newline char), \t(tab), \0, \r and so on........\0";
24: echo "-- opening the file in 'w' mode and get the size --\n";
25: $file_handle = fopen($filename, "w");
26: var_dump( strlen($string) ); //strlen of the string
27: fwrite($file_handle, $string);
28: fclose($file_handle);
29: var_dump( filesize($filename) ); //size of the file = strlen of string
30: clearstatcache();
31:
32: echo "-- opening the file in 'wt' mode and get the size --\n";
33: $file_handle = fopen($filename, "wt");
34: var_dump( strlen($string) ); //strlen of the string = 191 bytes
35: fwrite($file_handle, $string);
36: fclose($file_handle);
37: var_dump( filesize($filename) ); //size of the file = 192 bytes != strlen of string
38: clearstatcache();
39:
40: echo "-- opening the file in 'a' mode, adding data and checking the file --\n";
41: $file_handle = fopen($filename, "a");
42: fwrite($file_handle, "Hello, world");
43: fclose($file_handle);
44: var_dump( filesize($filename) ); //204 bytes
45: clearstatcache();
46:
47: echo "-- opening the file in 'at' mode, adding data and checking the file --\n";
48: $file_handle = fopen($filename, "at");
49: fwrite($file_handle, "Hello, world\n");
50: fclose($file_handle);
51: var_dump( filesize($filename) ); //218 bytes
52: clearstatcache();
53:
54: echo "-- creating a hole and checking the size --\n";
55: $file_handle = fopen($filename, "a");
56: var_dump( ftruncate($file_handle, 220) ); //creating 4 bytes of hole
57: fclose($file_handle);
58: var_dump( filesize($filename) ); //220 bytes
59: clearstatcache();
60:
61: echo "-- writing data after hole and checking the size --\n";
62: $file_handle = fopen($filename, "a");
63: fwrite($file_handle, "Hello\0"); //wrting 6 bytes of data
64: fclose($file_handle);
65: var_dump( filesize($filename) ); //226 bytes
66: clearstatcache();
67:
68: echo "-- opening the existing file in write mode --\n";
69: fclose( fopen($filename, "w") );
70: var_dump( filesize($filename) ); //0 bytes
71: clearstatcache();
72:
73: echo "-- with empty file --\n";
74: $filename = dirname(__FILE__)."/filesize_variation4_empty.tmp";
75: fclose( fopen($filename, "w") );
76: var_dump( filesize($filename) ); //0 bytes
77:
78: echo "*** Done ***\n";
79: ?>
80: --CLEAN--
81: <?php
82: $file_path = dirname(__FILE__);
83: unlink($file_path."/filesize_variation4.tmp");
84: unlink($file_path."/filesize_variation4_empty.tmp");
85: ?>
86: --EXPECTF--
87: *** Testing filesize(): usage variations ***
88:
89: *** Testing filesize() with data written using different file modes and by creating holes in file ***
90: -- opening the file in 'w' mode and get the size --
91: int(191)
92: int(191)
93: -- opening the file in 'wt' mode and get the size --
94: int(191)
95: int(192)
96: -- opening the file in 'a' mode, adding data and checking the file --
97: int(204)
98: -- opening the file in 'at' mode, adding data and checking the file --
99: int(218)
100: -- creating a hole and checking the size --
101: bool(true)
102: int(220)
103: -- writing data after hole and checking the size --
104: int(226)
105: -- opening the existing file in write mode --
106: int(0)
107: -- with empty file --
108: int(0)
109: *** Done ***
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>