Annotation of embedaddon/php/ext/standard/tests/file/filesize_variation4.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 Linux');
                      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: /* Testing filesize() with data written using different file modes and by creating holes in file */
                     17: 
                     18: $file_path = dirname(__FILE__);
                     19: 
                     20: echo "*** Testing filesize(): usage variations ***\n"; 
                     21: echo "\n*** Testing filesize() with data written using different file modes and by creating holes in file ***\n";
                     22: 
                     23: $filename = $file_path."/filesize_variation4.tmp";
                     24: $string = "Test 2 test the filesize() fn, with data containing all the types like !@@##$%^&*():<>?|~+!;',.\][{}(special) cha
                     25: rs, 12345(numeric) chars, and \n(newline char), \t(tab), \0, \r and so on........\0";
                     26: echo "-- opening the file in 'w' mode and get the size --\n";
                     27: $file_handle = fopen($filename, "w");
                     28: var_dump( strlen($string) );  //strlen of the string
                     29: fwrite($file_handle, $string);
                     30: fclose($file_handle);
                     31: var_dump( filesize($filename) );  //size of the file = strlen of string
                     32: clearstatcache();
                     33: 
                     34: echo "-- opening the file in 'wt' mode and get the size --\n";
                     35: $file_handle = fopen($filename, "wt");
                     36: var_dump( strlen($string) );  //strlen of the string = 191 bytes
                     37: fwrite($file_handle, $string);
                     38: fclose($file_handle);
                     39: var_dump( filesize($filename) );  //size of the file = strlen of string = 191 bytes
                     40: clearstatcache();
                     41: 
                     42: echo "-- opening the file in 'a' mode, adding data and checking the file --\n";
                     43: $file_handle = fopen($filename, "a");
                     44: fwrite($file_handle, "Hello, world");
                     45: fclose($file_handle);
                     46: var_dump( filesize($filename) );  //203 bytes
                     47: clearstatcache();
                     48: 
                     49: echo "-- opening the file in 'at' mode, adding data and checking the file --\n";
                     50: $file_handle = fopen($filename, "at");
                     51: fwrite($file_handle, "Hello, world\n");
                     52: fclose($file_handle);
                     53: var_dump( filesize($filename) );  //216 bytes
                     54: clearstatcache();
                     55: 
                     56: echo "-- creating a hole and checking the size --\n";
                     57: $file_handle = fopen($filename, "a");
                     58: var_dump( ftruncate($file_handle, 220) );  //creating 4 bytes of hole
                     59: fclose($file_handle);
                     60: var_dump( filesize($filename) );  //220 bytes
                     61: clearstatcache();
                     62: 
                     63: echo "-- writing data after hole and checking the size --\n";
                     64: $file_handle = fopen($filename, "a");
                     65: fwrite($file_handle, "Hello\0");  //wrting 6 bytes of data
                     66: fclose($file_handle);
                     67: var_dump( filesize($filename) );  //226 bytes
                     68: clearstatcache();
                     69: 
                     70: echo "-- opening the existing file in write mode --\n";
                     71: fclose( fopen($filename, "w") );
                     72: var_dump( filesize($filename) );  //0 bytes
                     73: clearstatcache();
                     74: 
                     75: echo "-- with empty file --\n";
                     76: $filename = dirname(__FILE__)."/filesize_variation4_empty.tmp";
                     77: fclose( fopen($filename, "w") );
                     78: var_dump( filesize($filename) );  //0 bytes
                     79: 
                     80: echo "*** Done ***\n";
                     81: ?>
                     82: --CLEAN--
                     83: <?php
                     84: $file_path = dirname(__FILE__);
                     85: unlink($file_path."/filesize_variation4.tmp");
                     86: unlink($file_path."/filesize_variation4_empty.tmp");
                     87: ?>
                     88: --EXPECTF--
                     89: *** Testing filesize(): usage variations ***
                     90: 
                     91: *** Testing filesize() with data written using different file modes and by creating holes in file ***
                     92: -- opening the file in 'w' mode and get the size --
                     93: int(192)
                     94: int(192)
                     95: -- opening the file in 'wt' mode and get the size --
                     96: int(192)
                     97: int(192)
                     98: -- opening the file in 'a' mode, adding data and checking the file --
                     99: int(204)
                    100: -- opening the file in 'at' mode, adding data and checking the file --
                    101: int(217)
                    102: -- creating a hole and checking the size --
                    103: bool(true)
                    104: int(220)
                    105: -- writing data after hole and checking the size --
                    106: int(226)
                    107: -- opening the existing file in write mode --
                    108: int(0)
                    109: -- with empty file --
                    110: int(0)
                    111: *** Done ***

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>