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

1.1       misho       1: --TEST--
                      2: Test fwrite() function : usage variations - r+, r+b & r+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 : r+,r+b,r+t
                     27:  File having content of type numeric, text,text_with_new_line & alphanumeric
                     28: */
                     29: 
                     30: $file_modes = array("r+", "r+b", "r+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:     // create temp file and fill the data of type $file_content_type
                     42:     $filename = dirname(__FILE__)."/fwrite_variation2.tmp"; // this is name of the file
                     43:     create_files ( dirname(__FILE__), 1, $file_content_type, 0755, 1, "w", "fwrite_variation", 2);
                     44: 
                     45:     $file_handle = fopen($filename, $file_mode);
                     46:     if(!$file_handle) {
                     47:       echo "Error: failed to fopen() file: $filename!";
                     48:       exit();
                     49:     }
                     50: 
                     51:     $data_to_be_written="";
                     52:     fill_buffer($data_to_be_written,$file_content_type,1024);  //get the data of size 1024
                     53: 
                     54:     /*  Write the data into the file, verify it by checking the file pointer position, eof position, 
                     55:         filesize & by displaying the content */
                     56: 
                     57:     /*overwrite first 400 bytes in the file*/
                     58:     var_dump( ftell($file_handle) );  // expected : 0
                     59:     var_dump( fwrite($file_handle, $data_to_be_written, 400));
                     60:     var_dump( ftell($file_handle) );  // expected: 400
                     61:     var_dump( feof($file_handle) );  //Expecting bool(false)
                     62: 
                     63:     /*overwrite data in middle of the file*/
                     64:     fseek($file_handle, SEEK_SET, 1024/2 ); 
                     65:     var_dump( ftell($file_handle));  // expected: 1024/2
                     66:     var_dump( fwrite($file_handle, $data_to_be_written, 200) );
                     67:     var_dump( ftell($file_handle) );
                     68:     var_dump( feof($file_handle) );  //Expecting bool(false)
                     69: 
                     70:     /* write at the end of the file */
                     71:     fseek($file_handle, SEEK_END, 0); 
                     72:     var_dump( ftell($file_handle) );  // expected: 1024
                     73:     var_dump( feof($file_handle) );
                     74:     var_dump( fwrite($file_handle, $data_to_be_written, 200) );
                     75:     var_dump( ftell($file_handle) );
                     76:     var_dump( feof($file_handle) );  //Expecting bool(false)
                     77: 
                     78:     /* display the file content, check the file size  */
                     79:     var_dump( fclose($file_handle) );
                     80:     clearstatcache();//clears file status cache
                     81:     var_dump( filesize($filename) );
                     82:     var_dump(md5(file_get_contents($filename)));
                     83:     delete_file($filename); // delete file with name fwrite_variation2.tmp
                     84:   } // end of inner foreach loop
                     85: } // end of outer foreach loop
                     86: 
                     87: echo "Done\n";
                     88: ?>
                     89: --EXPECTF--
                     90: *** Testing fwrite() various  operations ***
                     91: 
                     92: -- Testing fwrite() with file having content of type numeric --
                     93: -- Opening file in r+ --
                     94: int(0)
                     95: int(400)
                     96: int(400)
                     97: bool(false)
                     98: int(400)
                     99: int(200)
                    100: int(600)
                    101: bool(false)
                    102: int(2)
                    103: bool(false)
                    104: int(200)
                    105: int(202)
                    106: bool(false)
                    107: bool(true)
                    108: int(1024)
                    109: string(32) "950b7457d1deb6332f2fc5d42f3129d6"
                    110: -- Opening file in r+b --
                    111: int(0)
                    112: int(400)
                    113: int(400)
                    114: bool(false)
                    115: int(400)
                    116: int(200)
                    117: int(600)
                    118: bool(false)
                    119: int(2)
                    120: bool(false)
                    121: int(200)
                    122: int(202)
                    123: bool(false)
                    124: bool(true)
                    125: int(1024)
                    126: string(32) "950b7457d1deb6332f2fc5d42f3129d6"
                    127: -- Opening file in r+t --
                    128: int(0)
                    129: int(400)
                    130: int(400)
                    131: bool(false)
                    132: int(400)
                    133: int(200)
                    134: int(600)
                    135: bool(false)
                    136: int(2)
                    137: bool(false)
                    138: int(200)
                    139: int(202)
                    140: bool(false)
                    141: bool(true)
                    142: int(1024)
                    143: string(32) "950b7457d1deb6332f2fc5d42f3129d6"
                    144: 
                    145: -- Testing fwrite() with file having content of type text --
                    146: -- Opening file in r+ --
                    147: int(0)
                    148: int(400)
                    149: int(400)
                    150: bool(false)
                    151: int(400)
                    152: int(200)
                    153: int(600)
                    154: bool(false)
                    155: int(2)
                    156: bool(false)
                    157: int(200)
                    158: int(202)
                    159: bool(false)
                    160: bool(true)
                    161: int(1024)
                    162: string(32) "3bdaf80dae28bc24bb304daa5ffee16c"
                    163: -- Opening file in r+b --
                    164: int(0)
                    165: int(400)
                    166: int(400)
                    167: bool(false)
                    168: int(400)
                    169: int(200)
                    170: int(600)
                    171: bool(false)
                    172: int(2)
                    173: bool(false)
                    174: int(200)
                    175: int(202)
                    176: bool(false)
                    177: bool(true)
                    178: int(1024)
                    179: string(32) "3bdaf80dae28bc24bb304daa5ffee16c"
                    180: -- Opening file in r+t --
                    181: int(0)
                    182: int(400)
                    183: int(400)
                    184: bool(false)
                    185: int(400)
                    186: int(200)
                    187: int(600)
                    188: bool(false)
                    189: int(2)
                    190: bool(false)
                    191: int(200)
                    192: int(202)
                    193: bool(false)
                    194: bool(true)
                    195: int(1024)
                    196: string(32) "3bdaf80dae28bc24bb304daa5ffee16c"
                    197: 
                    198: -- Testing fwrite() with file having content of type text_with_new_line --
                    199: -- Opening file in r+ --
                    200: int(0)
                    201: int(400)
                    202: int(400)
                    203: bool(false)
                    204: int(400)
                    205: int(200)
                    206: int(600)
                    207: bool(false)
                    208: int(2)
                    209: bool(false)
                    210: int(200)
                    211: int(202)
                    212: bool(false)
                    213: bool(true)
                    214: int(1024)
                    215: string(32) "b188d7c8aa229cbef067e5970f2daba9"
                    216: -- Opening file in r+b --
                    217: int(0)
                    218: int(400)
                    219: int(400)
                    220: bool(false)
                    221: int(400)
                    222: int(200)
                    223: int(600)
                    224: bool(false)
                    225: int(2)
                    226: bool(false)
                    227: int(200)
                    228: int(202)
                    229: bool(false)
                    230: bool(true)
                    231: int(1024)
                    232: string(32) "b188d7c8aa229cbef067e5970f2daba9"
                    233: -- Opening file in r+t --
                    234: int(0)
                    235: int(400)
                    236: int(400)
                    237: bool(false)
                    238: int(400)
                    239: int(200)
                    240: int(600)
                    241: bool(false)
                    242: int(2)
                    243: bool(false)
                    244: int(200)
                    245: int(202)
                    246: bool(false)
                    247: bool(true)
                    248: int(1024)
                    249: string(32) "b188d7c8aa229cbef067e5970f2daba9"
                    250: 
                    251: -- Testing fwrite() with file having content of type alphanumeric --
                    252: -- Opening file in r+ --
                    253: int(0)
                    254: int(400)
                    255: int(400)
                    256: bool(false)
                    257: int(400)
                    258: int(200)
                    259: int(600)
                    260: bool(false)
                    261: int(2)
                    262: bool(false)
                    263: int(200)
                    264: int(202)
                    265: bool(false)
                    266: bool(true)
                    267: int(1024)
                    268: string(32) "5d4ec23a3d9dd447e2f702d9e0e114d9"
                    269: -- Opening file in r+b --
                    270: int(0)
                    271: int(400)
                    272: int(400)
                    273: bool(false)
                    274: int(400)
                    275: int(200)
                    276: int(600)
                    277: bool(false)
                    278: int(2)
                    279: bool(false)
                    280: int(200)
                    281: int(202)
                    282: bool(false)
                    283: bool(true)
                    284: int(1024)
                    285: string(32) "5d4ec23a3d9dd447e2f702d9e0e114d9"
                    286: -- Opening file in r+t --
                    287: int(0)
                    288: int(400)
                    289: int(400)
                    290: bool(false)
                    291: int(400)
                    292: int(200)
                    293: int(600)
                    294: bool(false)
                    295: int(2)
                    296: bool(false)
                    297: int(200)
                    298: int(202)
                    299: bool(false)
                    300: bool(true)
                    301: int(1024)
                    302: string(32) "5d4ec23a3d9dd447e2f702d9e0e114d9"
                    303: Done

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