Annotation of embedaddon/php/ext/standard/tests/file/ftruncate_error.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: Test ftruncate() function : error conditions
                      3: --FILE--
                      4: <?php
                      5: /*
                      6:  Prototype: bool ftruncate ( resource $handle, int $size );
                      7:  Description: truncates a file to a given length
                      8: */
                      9: 
                     10: echo "*** Testing ftruncate() : error conditions ***\n";
                     11: 
                     12: $filename = dirname(__FILE__)."/ftruncate_error.tmp";
                     13: $file_handle = fopen($filename, "w" );
                     14: fwrite($file_handle, (binary)"Testing ftruncate error conditions \n");
                     15: fflush($file_handle);
                     16: echo "\n Initial file size = ".filesize($filename)."\n";
                     17: 
                     18: echo "-- Testing ftruncate() with less than expected number of arguments --\n";
                     19: 
                     20: // zero arguments 
                     21: var_dump( ftruncate() );
                     22: 
                     23: // arguments less than expected numbers
                     24: var_dump( ftruncate( $file_handle ) );
                     25: // check the first size 
                     26: var_dump( filesize($filename) );
                     27: 
                     28: echo "-- Testing ftruncate() with more than expected number of arguments --\n";
                     29: // more than expected number of arguments 
                     30: var_dump( ftruncate($file_handle, 10, 20) );
                     31: // check the first size 
                     32: var_dump( filesize($filename) );
                     33: 
                     34: // test invalid arguments : non-resources
                     35: echo "-- Testing ftruncate() with invalid file pointer --\n";
                     36: $invalid_args = array (
                     37:   "string",
                     38:   10,
                     39:   10.5,
                     40:   true,
                     41:   array(1,2,3),
                     42:   new stdclass,
                     43: );
                     44: /* loop to test ftruncate() with different invalid type of args */
                     45: for($loop_counter = 1; $loop_counter <= count($invalid_args); $loop_counter++) {
                     46:   echo "-- Iteration $loop_counter --\n";
                     47:   var_dump( ftruncate($invalid_args[$loop_counter - 1], 10) );
                     48: }
                     49: 
                     50: // ftruncate() on a file handle which is already closed/unset
                     51: echo "-- Testing ftruncate() with closed/unset file handle --\n";
                     52: 
                     53: // ftruncate on close file handle
                     54: fclose($file_handle);
                     55: var_dump( ftruncate($file_handle,10) );
                     56: // check the first size 
                     57: var_dump( filesize($filename) );
                     58: 
                     59: // ftruncate on a file handle which is unset
                     60: $fp = fopen($filename, "w");
                     61: unset($fp); //unset file handle
                     62: var_dump( ftruncate(@$fp,10));
                     63: // check the first size 
                     64: var_dump( filesize($filename) );
                     65: 
                     66: echo "Done\n";
                     67: ?> 
                     68: --CLEAN--
                     69: <?php
                     70: $filename = dirname(__FILE__)."/ftruncate_error.tmp";
                     71: unlink( $filename );
                     72: ?>
                     73: --EXPECTF--
                     74: *** Testing ftruncate() : error conditions ***
                     75: 
                     76:  Initial file size = 36
                     77: -- Testing ftruncate() with less than expected number of arguments --
                     78: 
                     79: Warning: ftruncate() expects exactly 2 parameters, 0 given in %s on line %d
                     80: bool(false)
                     81: 
                     82: Warning: ftruncate() expects exactly 2 parameters, 1 given in %s on line %d
                     83: bool(false)
                     84: int(36)
                     85: -- Testing ftruncate() with more than expected number of arguments --
                     86: 
                     87: Warning: ftruncate() expects exactly 2 parameters, 3 given in %s on line %d
                     88: bool(false)
                     89: int(36)
                     90: -- Testing ftruncate() with invalid file pointer --
                     91: -- Iteration 1 --
                     92: 
                     93: Warning: ftruncate() expects parameter 1 to be resource, string given in %s on line %d
                     94: bool(false)
                     95: -- Iteration 2 --
                     96: 
                     97: Warning: ftruncate() expects parameter 1 to be resource, integer given in %s on line %d
                     98: bool(false)
                     99: -- Iteration 3 --
                    100: 
                    101: Warning: ftruncate() expects parameter 1 to be resource, double given in %s on line %d
                    102: bool(false)
                    103: -- Iteration 4 --
                    104: 
                    105: Warning: ftruncate() expects parameter 1 to be resource, boolean given in %s on line %d
                    106: bool(false)
                    107: -- Iteration 5 --
                    108: 
                    109: Warning: ftruncate() expects parameter 1 to be resource, array given in %s on line %d
                    110: bool(false)
                    111: -- Iteration 6 --
                    112: 
                    113: Warning: ftruncate() expects parameter 1 to be resource, object given in %s on line %d
                    114: bool(false)
                    115: -- Testing ftruncate() with closed/unset file handle --
                    116: 
                    117: Warning: ftruncate(): 5 is not a valid stream resource in %s on line %d
                    118: bool(false)
                    119: int(36)
                    120: 
                    121: Warning: ftruncate() expects parameter 1 to be resource, null given in %s on line %d
                    122: bool(false)
                    123: int(36)
                    124: Done

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