Annotation of embedaddon/php/ext/standard/tests/file/fwrite_basic.phpt, revision 1.1

1.1     ! misho       1: --TEST--
        !             2: Test fwrite() function : basic functionality
        !             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: // include the file.inc for Function: function delete_file($filename)
        !            20: include ("file.inc");
        !            21: 
        !            22: echo "*** Testing fwrite() basic operations ***\n";
        !            23: /*
        !            24:  test fwrite with file opened in mode : w,wb,wt,w+,w+b,w+t
        !            25:  File containing data of type,  numeric, text, text_with_new_line, alphanumeric
        !            26: */
        !            27: $file_modes = array( "w", "wb", "wt", "w+", "w+b", "w+t");
        !            28: $file_content_types = array("numeric","text","text_with_new_line","alphanumeric");
        !            29: 
        !            30: foreach($file_content_types as $file_content_type) {
        !            31:   echo "\n-- Testing fwrite() with file having data of type ". $file_content_type ." --\n";
        !            32:   $filename = dirname(__FILE__)."/fwrite_basic.tmp"; // this is name of the file
        !            33: 
        !            34:   for($inner_loop_counter = 0; 
        !            35:       $inner_loop_counter < count($file_modes); 
        !            36:       $inner_loop_counter++) {
        !            37:      echo "--  File opened in mode : " . $file_modes[$inner_loop_counter]. " --\n";
        !            38:      /* open the file using $files_modes and perform fwrite() on it */
        !            39:      $file_handle = fopen($filename, $file_modes[$inner_loop_counter]);
        !            40:      if (!$file_handle) {
        !            41:        echo "Error: failed to fopen() file: $filename!";
        !            42:        exit();
        !            43:      }
        !            44:      $data_to_be_written="";
        !            45:      fill_buffer($data_to_be_written, $file_content_type, 1024);  //get the data of size 1024
        !            46: 
        !            47:     /* Write the data in to the file, verify the write by checking file pointer position, 
        !            48:        eof position, and data. */
        !            49:     // writing 100 bytes
        !            50:     var_dump( ftell($file_handle) );  // Expecting 0
        !            51:     var_dump( fwrite($file_handle, $data_to_be_written, 100)); //int(100)
        !            52:     var_dump( feof($file_handle) );  // expected : false
        !            53:     var_dump( ftell($file_handle) );  //expected: 100
        !            54:    
        !            55:     // trying to write more than the available data, available 1024 bytes but trying 2048
        !            56:     var_dump( fwrite($file_handle, $data_to_be_written, 2048)); //int(1024)
        !            57:     var_dump( feof($file_handle) );  // expected : false
        !            58:     var_dump( ftell($file_handle) );  // expected: 1124
        !            59: 
        !            60:     // fwrite() without length parameter
        !            61:     var_dump( fwrite($file_handle, $data_to_be_written)); //int(1024)
        !            62:     var_dump( ftell($file_handle) );  // expected: 2148
        !            63:     var_dump( feof($file_handle) );  // expected: false
        !            64: 
        !            65:     // close the file, get the size and content of the file.
        !            66:     var_dump( fclose($file_handle) ); //expected : true
        !            67:     clearstatcache();//clears file status cache
        !            68:     var_dump( filesize($filename) );  // expected:  2148
        !            69:     var_dump(md5(file_get_contents($filename))); // hash the output 
        !            70: 
        !            71:   } // end of inner for loop
        !            72: 
        !            73:   // delete the file created : fwrite_basic.tmp
        !            74:   delete_file($filename);
        !            75: } // end of outer foreach loop
        !            76: echo "Done\n";
        !            77: ?>
        !            78: --EXPECTF--
        !            79: *** Testing fwrite() basic operations ***
        !            80: 
        !            81: -- Testing fwrite() with file having data of type numeric --
        !            82: --  File opened in mode : w --
        !            83: int(0)
        !            84: int(100)
        !            85: bool(false)
        !            86: int(100)
        !            87: int(1024)
        !            88: bool(false)
        !            89: int(1124)
        !            90: int(1024)
        !            91: int(2148)
        !            92: bool(false)
        !            93: bool(true)
        !            94: int(2148)
        !            95: string(32) "04db34906fe2c56dcfbd649b7d916974"
        !            96: --  File opened in mode : wb --
        !            97: int(0)
        !            98: int(100)
        !            99: bool(false)
        !           100: int(100)
        !           101: int(1024)
        !           102: bool(false)
        !           103: int(1124)
        !           104: int(1024)
        !           105: int(2148)
        !           106: bool(false)
        !           107: bool(true)
        !           108: int(2148)
        !           109: string(32) "04db34906fe2c56dcfbd649b7d916974"
        !           110: --  File opened in mode : wt --
        !           111: int(0)
        !           112: int(100)
        !           113: bool(false)
        !           114: int(100)
        !           115: int(1024)
        !           116: bool(false)
        !           117: int(1124)
        !           118: int(1024)
        !           119: int(2148)
        !           120: bool(false)
        !           121: bool(true)
        !           122: int(2148)
        !           123: string(32) "04db34906fe2c56dcfbd649b7d916974"
        !           124: --  File opened in mode : w+ --
        !           125: int(0)
        !           126: int(100)
        !           127: bool(false)
        !           128: int(100)
        !           129: int(1024)
        !           130: bool(false)
        !           131: int(1124)
        !           132: int(1024)
        !           133: int(2148)
        !           134: bool(false)
        !           135: bool(true)
        !           136: int(2148)
        !           137: string(32) "04db34906fe2c56dcfbd649b7d916974"
        !           138: --  File opened in mode : w+b --
        !           139: int(0)
        !           140: int(100)
        !           141: bool(false)
        !           142: int(100)
        !           143: int(1024)
        !           144: bool(false)
        !           145: int(1124)
        !           146: int(1024)
        !           147: int(2148)
        !           148: bool(false)
        !           149: bool(true)
        !           150: int(2148)
        !           151: string(32) "04db34906fe2c56dcfbd649b7d916974"
        !           152: --  File opened in mode : w+t --
        !           153: int(0)
        !           154: int(100)
        !           155: bool(false)
        !           156: int(100)
        !           157: int(1024)
        !           158: bool(false)
        !           159: int(1124)
        !           160: int(1024)
        !           161: int(2148)
        !           162: bool(false)
        !           163: bool(true)
        !           164: int(2148)
        !           165: string(32) "04db34906fe2c56dcfbd649b7d916974"
        !           166: 
        !           167: -- Testing fwrite() with file having data of type text --
        !           168: --  File opened in mode : w --
        !           169: int(0)
        !           170: int(100)
        !           171: bool(false)
        !           172: int(100)
        !           173: int(1024)
        !           174: bool(false)
        !           175: int(1124)
        !           176: int(1024)
        !           177: int(2148)
        !           178: bool(false)
        !           179: bool(true)
        !           180: int(2148)
        !           181: string(32) "9c08ac77b7a93a84dd0b055900165e84"
        !           182: --  File opened in mode : wb --
        !           183: int(0)
        !           184: int(100)
        !           185: bool(false)
        !           186: int(100)
        !           187: int(1024)
        !           188: bool(false)
        !           189: int(1124)
        !           190: int(1024)
        !           191: int(2148)
        !           192: bool(false)
        !           193: bool(true)
        !           194: int(2148)
        !           195: string(32) "9c08ac77b7a93a84dd0b055900165e84"
        !           196: --  File opened in mode : wt --
        !           197: int(0)
        !           198: int(100)
        !           199: bool(false)
        !           200: int(100)
        !           201: int(1024)
        !           202: bool(false)
        !           203: int(1124)
        !           204: int(1024)
        !           205: int(2148)
        !           206: bool(false)
        !           207: bool(true)
        !           208: int(2148)
        !           209: string(32) "9c08ac77b7a93a84dd0b055900165e84"
        !           210: --  File opened in mode : w+ --
        !           211: int(0)
        !           212: int(100)
        !           213: bool(false)
        !           214: int(100)
        !           215: int(1024)
        !           216: bool(false)
        !           217: int(1124)
        !           218: int(1024)
        !           219: int(2148)
        !           220: bool(false)
        !           221: bool(true)
        !           222: int(2148)
        !           223: string(32) "9c08ac77b7a93a84dd0b055900165e84"
        !           224: --  File opened in mode : w+b --
        !           225: int(0)
        !           226: int(100)
        !           227: bool(false)
        !           228: int(100)
        !           229: int(1024)
        !           230: bool(false)
        !           231: int(1124)
        !           232: int(1024)
        !           233: int(2148)
        !           234: bool(false)
        !           235: bool(true)
        !           236: int(2148)
        !           237: string(32) "9c08ac77b7a93a84dd0b055900165e84"
        !           238: --  File opened in mode : w+t --
        !           239: int(0)
        !           240: int(100)
        !           241: bool(false)
        !           242: int(100)
        !           243: int(1024)
        !           244: bool(false)
        !           245: int(1124)
        !           246: int(1024)
        !           247: int(2148)
        !           248: bool(false)
        !           249: bool(true)
        !           250: int(2148)
        !           251: string(32) "9c08ac77b7a93a84dd0b055900165e84"
        !           252: 
        !           253: -- Testing fwrite() with file having data of type text_with_new_line --
        !           254: --  File opened in mode : w --
        !           255: int(0)
        !           256: int(100)
        !           257: bool(false)
        !           258: int(100)
        !           259: int(1024)
        !           260: bool(false)
        !           261: int(1124)
        !           262: int(1024)
        !           263: int(2148)
        !           264: bool(false)
        !           265: bool(true)
        !           266: int(2148)
        !           267: string(32) "56a1963cc292d7f8245219116d9eca40"
        !           268: --  File opened in mode : wb --
        !           269: int(0)
        !           270: int(100)
        !           271: bool(false)
        !           272: int(100)
        !           273: int(1024)
        !           274: bool(false)
        !           275: int(1124)
        !           276: int(1024)
        !           277: int(2148)
        !           278: bool(false)
        !           279: bool(true)
        !           280: int(2148)
        !           281: string(32) "56a1963cc292d7f8245219116d9eca40"
        !           282: --  File opened in mode : wt --
        !           283: int(0)
        !           284: int(100)
        !           285: bool(false)
        !           286: int(100)
        !           287: int(1024)
        !           288: bool(false)
        !           289: int(1124)
        !           290: int(1024)
        !           291: int(2148)
        !           292: bool(false)
        !           293: bool(true)
        !           294: int(2148)
        !           295: string(32) "56a1963cc292d7f8245219116d9eca40"
        !           296: --  File opened in mode : w+ --
        !           297: int(0)
        !           298: int(100)
        !           299: bool(false)
        !           300: int(100)
        !           301: int(1024)
        !           302: bool(false)
        !           303: int(1124)
        !           304: int(1024)
        !           305: int(2148)
        !           306: bool(false)
        !           307: bool(true)
        !           308: int(2148)
        !           309: string(32) "56a1963cc292d7f8245219116d9eca40"
        !           310: --  File opened in mode : w+b --
        !           311: int(0)
        !           312: int(100)
        !           313: bool(false)
        !           314: int(100)
        !           315: int(1024)
        !           316: bool(false)
        !           317: int(1124)
        !           318: int(1024)
        !           319: int(2148)
        !           320: bool(false)
        !           321: bool(true)
        !           322: int(2148)
        !           323: string(32) "56a1963cc292d7f8245219116d9eca40"
        !           324: --  File opened in mode : w+t --
        !           325: int(0)
        !           326: int(100)
        !           327: bool(false)
        !           328: int(100)
        !           329: int(1024)
        !           330: bool(false)
        !           331: int(1124)
        !           332: int(1024)
        !           333: int(2148)
        !           334: bool(false)
        !           335: bool(true)
        !           336: int(2148)
        !           337: string(32) "56a1963cc292d7f8245219116d9eca40"
        !           338: 
        !           339: -- Testing fwrite() with file having data of type alphanumeric --
        !           340: --  File opened in mode : w --
        !           341: int(0)
        !           342: int(100)
        !           343: bool(false)
        !           344: int(100)
        !           345: int(1024)
        !           346: bool(false)
        !           347: int(1124)
        !           348: int(1024)
        !           349: int(2148)
        !           350: bool(false)
        !           351: bool(true)
        !           352: int(2148)
        !           353: string(32) "719e3329c19218c12d232f2ee81e100f"
        !           354: --  File opened in mode : wb --
        !           355: int(0)
        !           356: int(100)
        !           357: bool(false)
        !           358: int(100)
        !           359: int(1024)
        !           360: bool(false)
        !           361: int(1124)
        !           362: int(1024)
        !           363: int(2148)
        !           364: bool(false)
        !           365: bool(true)
        !           366: int(2148)
        !           367: string(32) "719e3329c19218c12d232f2ee81e100f"
        !           368: --  File opened in mode : wt --
        !           369: int(0)
        !           370: int(100)
        !           371: bool(false)
        !           372: int(100)
        !           373: int(1024)
        !           374: bool(false)
        !           375: int(1124)
        !           376: int(1024)
        !           377: int(2148)
        !           378: bool(false)
        !           379: bool(true)
        !           380: int(2148)
        !           381: string(32) "719e3329c19218c12d232f2ee81e100f"
        !           382: --  File opened in mode : w+ --
        !           383: int(0)
        !           384: int(100)
        !           385: bool(false)
        !           386: int(100)
        !           387: int(1024)
        !           388: bool(false)
        !           389: int(1124)
        !           390: int(1024)
        !           391: int(2148)
        !           392: bool(false)
        !           393: bool(true)
        !           394: int(2148)
        !           395: string(32) "719e3329c19218c12d232f2ee81e100f"
        !           396: --  File opened in mode : w+b --
        !           397: int(0)
        !           398: int(100)
        !           399: bool(false)
        !           400: int(100)
        !           401: int(1024)
        !           402: bool(false)
        !           403: int(1124)
        !           404: int(1024)
        !           405: int(2148)
        !           406: bool(false)
        !           407: bool(true)
        !           408: int(2148)
        !           409: string(32) "719e3329c19218c12d232f2ee81e100f"
        !           410: --  File opened in mode : w+t --
        !           411: int(0)
        !           412: int(100)
        !           413: bool(false)
        !           414: int(100)
        !           415: int(1024)
        !           416: bool(false)
        !           417: int(1124)
        !           418: int(1024)
        !           419: int(2148)
        !           420: bool(false)
        !           421: bool(true)
        !           422: int(2148)
        !           423: string(32) "719e3329c19218c12d232f2ee81e100f"
        !           424: Done

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