Annotation of embedaddon/php/ext/standard/tests/file/fwrite_variation2-win32.phpt, revision 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 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+,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: 
        !            85:   } // end of inner foreach loop
        !            86: } // end of outer foreach loop
        !            87: 
        !            88: echo "Done\n";
        !            89: ?>
        !            90: --EXPECTF--
        !            91: *** Testing fwrite() various  operations ***
        !            92: 
        !            93: -- Testing fwrite() with file having content of type numeric --
        !            94: -- Opening file in r+ --
        !            95: int(0)
        !            96: int(400)
        !            97: int(400)
        !            98: bool(false)
        !            99: int(400)
        !           100: int(200)
        !           101: int(600)
        !           102: bool(false)
        !           103: int(2)
        !           104: bool(false)
        !           105: int(200)
        !           106: int(202)
        !           107: bool(false)
        !           108: bool(true)
        !           109: int(1024)
        !           110: string(32) "950b7457d1deb6332f2fc5d42f3129d6"
        !           111: -- Opening file in r+b --
        !           112: int(0)
        !           113: int(400)
        !           114: int(400)
        !           115: bool(false)
        !           116: int(400)
        !           117: int(200)
        !           118: int(600)
        !           119: bool(false)
        !           120: int(2)
        !           121: bool(false)
        !           122: int(200)
        !           123: int(202)
        !           124: bool(false)
        !           125: bool(true)
        !           126: int(1024)
        !           127: string(32) "950b7457d1deb6332f2fc5d42f3129d6"
        !           128: -- Opening file in r+t --
        !           129: int(0)
        !           130: int(400)
        !           131: int(400)
        !           132: bool(false)
        !           133: int(400)
        !           134: int(200)
        !           135: int(600)
        !           136: bool(false)
        !           137: int(2)
        !           138: bool(false)
        !           139: int(200)
        !           140: int(202)
        !           141: bool(false)
        !           142: bool(true)
        !           143: int(1024)
        !           144: string(32) "950b7457d1deb6332f2fc5d42f3129d6"
        !           145: 
        !           146: -- Testing fwrite() with file having content of type text --
        !           147: -- Opening file in r+ --
        !           148: int(0)
        !           149: int(400)
        !           150: int(400)
        !           151: bool(false)
        !           152: int(400)
        !           153: int(200)
        !           154: int(600)
        !           155: bool(false)
        !           156: int(2)
        !           157: bool(false)
        !           158: int(200)
        !           159: int(202)
        !           160: bool(false)
        !           161: bool(true)
        !           162: int(1024)
        !           163: string(32) "3bdaf80dae28bc24bb304daa5ffee16c"
        !           164: -- Opening file in r+b --
        !           165: int(0)
        !           166: int(400)
        !           167: int(400)
        !           168: bool(false)
        !           169: int(400)
        !           170: int(200)
        !           171: int(600)
        !           172: bool(false)
        !           173: int(2)
        !           174: bool(false)
        !           175: int(200)
        !           176: int(202)
        !           177: bool(false)
        !           178: bool(true)
        !           179: int(1024)
        !           180: string(32) "3bdaf80dae28bc24bb304daa5ffee16c"
        !           181: -- Opening file in r+t --
        !           182: int(0)
        !           183: int(400)
        !           184: int(400)
        !           185: bool(false)
        !           186: int(400)
        !           187: int(200)
        !           188: int(600)
        !           189: bool(false)
        !           190: int(2)
        !           191: bool(false)
        !           192: int(200)
        !           193: int(202)
        !           194: bool(false)
        !           195: bool(true)
        !           196: int(1024)
        !           197: string(32) "3bdaf80dae28bc24bb304daa5ffee16c"
        !           198: 
        !           199: -- Testing fwrite() with file having content of type text_with_new_line --
        !           200: -- Opening file in r+ --
        !           201: int(0)
        !           202: int(400)
        !           203: int(400)
        !           204: bool(false)
        !           205: int(400)
        !           206: int(200)
        !           207: int(600)
        !           208: bool(false)
        !           209: int(2)
        !           210: bool(false)
        !           211: int(200)
        !           212: int(202)
        !           213: bool(false)
        !           214: bool(true)
        !           215: int(1024)
        !           216: string(32) "b188d7c8aa229cbef067e5970f2daba9"
        !           217: -- Opening file in r+b --
        !           218: int(0)
        !           219: int(400)
        !           220: int(400)
        !           221: bool(false)
        !           222: int(400)
        !           223: int(200)
        !           224: int(600)
        !           225: bool(false)
        !           226: int(2)
        !           227: bool(false)
        !           228: int(200)
        !           229: int(202)
        !           230: bool(false)
        !           231: bool(true)
        !           232: int(1024)
        !           233: string(32) "b188d7c8aa229cbef067e5970f2daba9"
        !           234: -- Opening file in r+t --
        !           235: int(0)
        !           236: int(400)
        !           237: int(400)
        !           238: bool(false)
        !           239: int(400)
        !           240: int(200)
        !           241: int(600)
        !           242: bool(false)
        !           243: int(2)
        !           244: bool(false)
        !           245: int(200)
        !           246: int(202)
        !           247: bool(false)
        !           248: bool(true)
        !           249: int(1024)
        !           250: string(32) "991652c76db8d17c790c702ac0a6dc5f"
        !           251: 
        !           252: -- Testing fwrite() with file having content of type alphanumeric --
        !           253: -- Opening file in r+ --
        !           254: int(0)
        !           255: int(400)
        !           256: int(400)
        !           257: bool(false)
        !           258: int(400)
        !           259: int(200)
        !           260: int(600)
        !           261: bool(false)
        !           262: int(2)
        !           263: bool(false)
        !           264: int(200)
        !           265: int(202)
        !           266: bool(false)
        !           267: bool(true)
        !           268: int(1024)
        !           269: string(32) "5d4ec23a3d9dd447e2f702d9e0e114d9"
        !           270: -- Opening file in r+b --
        !           271: int(0)
        !           272: int(400)
        !           273: int(400)
        !           274: bool(false)
        !           275: int(400)
        !           276: int(200)
        !           277: int(600)
        !           278: bool(false)
        !           279: int(2)
        !           280: bool(false)
        !           281: int(200)
        !           282: int(202)
        !           283: bool(false)
        !           284: bool(true)
        !           285: int(1024)
        !           286: string(32) "5d4ec23a3d9dd447e2f702d9e0e114d9"
        !           287: -- Opening file in r+t --
        !           288: int(0)
        !           289: int(400)
        !           290: int(400)
        !           291: bool(false)
        !           292: int(400)
        !           293: int(200)
        !           294: int(600)
        !           295: bool(false)
        !           296: int(2)
        !           297: bool(false)
        !           298: int(200)
        !           299: int(202)
        !           300: bool(false)
        !           301: bool(true)
        !           302: int(1024)
        !           303: string(32) "5d4ec23a3d9dd447e2f702d9e0e114d9"
        !           304: Done

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