Annotation of embedaddon/php/ext/standard/tests/file/fwrite_variation1-win32.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: Test fwrite() function : usage variations - r, rb & rt modes
                      3: --SKIPIF--
                      4: <?php
                      5: if( substr(PHP_OS, 0, 3) != 'WIN' ) {
                      6:    die('skip...Not valid for Linux');
                      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,rb,rt
                     27:  File having content of type numeric, text,text_with_new_line & alphanumeric
                     28: */
                     29: 
                     30: $file_modes = array("r","rb","rt");
                     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 the temp file with content of type $file_content_type
                     42:     $filename = dirname(__FILE__)."/fwrite_variation1.tmp"; // this is name of the file
                     43:     create_files ( dirname(__FILE__), 1, $file_content_type, 0755, 1, "w", "fwrite_variation");
                     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:     var_dump( ftell($file_handle) );  // expected: 0
                     58:     var_dump( fwrite($file_handle, $data_to_be_written ));
                     59:     var_dump( ftell($file_handle) );  // expected: 0
                     60:     var_dump( feof($file_handle) );  // expected: false
                     61: 
                     62:     // move the file pointer to end of the file and try fwrite()
                     63:     fseek($file_handle, SEEK_END, 0);
                     64:     var_dump( ftell($file_handle) );  // expecting 1024
                     65:     var_dump( fwrite($file_handle, $data_to_be_written) ); // fwrite to fail
                     66:     var_dump( ftell($file_handle) );  //check that file pointer points at eof, expected: 1024
                     67:     var_dump( feof($file_handle) );  // ensure that  feof() points to eof, expected: true
                     68: 
                     69:     // ensure that file content/size didn't change.
                     70:     var_dump( fclose($file_handle) );
                     71:     clearstatcache();//clears file status cache
                     72:     var_dump( filesize($filename) );  // expected: 1024
                     73:     var_dump(md5(file_get_contents($filename))); // hash the output
                     74:     delete_file($filename); // delete file with name fwrite_variation1.tmp
                     75: 
                     76:   } // end of inner foreach loop
                     77: } // end of outer foreach loop
                     78: 
                     79: echo "Done\n";
                     80: ?>
                     81: --EXPECTF--
                     82: *** Testing fwrite() various  operations ***
                     83: 
                     84: -- Testing fwrite() with file having content of type numeric --
                     85: -- Opening file in r --
                     86: int(0)
                     87: int(0)
                     88: int(0)
                     89: bool(false)
                     90: int(2)
                     91: int(0)
                     92: int(2)
                     93: bool(false)
                     94: bool(true)
                     95: int(1024)
                     96: string(32) "950b7457d1deb6332f2fc5d42f3129d6"
                     97: -- Opening file in rb --
                     98: int(0)
                     99: int(0)
                    100: int(0)
                    101: bool(false)
                    102: int(2)
                    103: int(0)
                    104: int(2)
                    105: bool(false)
                    106: bool(true)
                    107: int(1024)
                    108: string(32) "950b7457d1deb6332f2fc5d42f3129d6"
                    109: -- Opening file in rt --
                    110: int(0)
                    111: int(0)
                    112: int(0)
                    113: bool(false)
                    114: int(2)
                    115: int(0)
                    116: int(2)
                    117: bool(false)
                    118: bool(true)
                    119: int(1024)
                    120: string(32) "950b7457d1deb6332f2fc5d42f3129d6"
                    121: 
                    122: -- Testing fwrite() with file having content of type text --
                    123: -- Opening file in r --
                    124: int(0)
                    125: int(0)
                    126: int(0)
                    127: bool(false)
                    128: int(2)
                    129: int(0)
                    130: int(2)
                    131: bool(false)
                    132: bool(true)
                    133: int(1024)
                    134: string(32) "e486000c4c8452774f746a27658d87fa"
                    135: -- Opening file in rb --
                    136: int(0)
                    137: int(0)
                    138: int(0)
                    139: bool(false)
                    140: int(2)
                    141: int(0)
                    142: int(2)
                    143: bool(false)
                    144: bool(true)
                    145: int(1024)
                    146: string(32) "e486000c4c8452774f746a27658d87fa"
                    147: -- Opening file in rt --
                    148: int(0)
                    149: int(0)
                    150: int(0)
                    151: bool(false)
                    152: int(2)
                    153: int(0)
                    154: int(2)
                    155: bool(false)
                    156: bool(true)
                    157: int(1024)
                    158: string(32) "e486000c4c8452774f746a27658d87fa"
                    159: 
                    160: -- Testing fwrite() with file having content of type text_with_new_line --
                    161: -- Opening file in r --
                    162: int(0)
                    163: int(0)
                    164: int(0)
                    165: bool(false)
                    166: int(2)
                    167: int(0)
                    168: int(2)
                    169: bool(false)
                    170: bool(true)
                    171: int(1024)
                    172: string(32) "b09c8026a64a88d36d4c2f17983964bb"
                    173: -- Opening file in rb --
                    174: int(0)
                    175: int(0)
                    176: int(0)
                    177: bool(false)
                    178: int(2)
                    179: int(0)
                    180: int(2)
                    181: bool(false)
                    182: bool(true)
                    183: int(1024)
                    184: string(32) "b09c8026a64a88d36d4c2f17983964bb"
                    185: -- Opening file in rt --
                    186: int(0)
                    187: int(0)
                    188: int(0)
                    189: bool(false)
                    190: int(2)
                    191: int(0)
                    192: int(2)
                    193: bool(false)
                    194: bool(true)
                    195: int(1024)
                    196: string(32) "b09c8026a64a88d36d4c2f17983964bb"
                    197: 
                    198: -- Testing fwrite() with file having content of type alphanumeric --
                    199: -- Opening file in r --
                    200: int(0)
                    201: int(0)
                    202: int(0)
                    203: bool(false)
                    204: int(2)
                    205: int(0)
                    206: int(2)
                    207: bool(false)
                    208: bool(true)
                    209: int(1024)
                    210: string(32) "3fabd48d8eaa65c14e0d93d6880c560c"
                    211: -- Opening file in rb --
                    212: int(0)
                    213: int(0)
                    214: int(0)
                    215: bool(false)
                    216: int(2)
                    217: int(0)
                    218: int(2)
                    219: bool(false)
                    220: bool(true)
                    221: int(1024)
                    222: string(32) "3fabd48d8eaa65c14e0d93d6880c560c"
                    223: -- Opening file in rt --
                    224: int(0)
                    225: int(0)
                    226: int(0)
                    227: bool(false)
                    228: int(2)
                    229: int(0)
                    230: int(2)
                    231: bool(false)
                    232: bool(true)
                    233: int(1024)
                    234: string(32) "3fabd48d8eaa65c14e0d93d6880c560c"
                    235: Done

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