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

1.1       misho       1: --TEST--
                      2: Test ftruncate() function : usage variations - truncate file to half size
                      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: bool ftruncate ( resource $handle, int $size );
                     13:  Description: Truncates a file to a given length
                     14: */
                     15: 
                     16: // include common file related test functions
                     17: include ("file.inc");
                     18: 
                     19: echo "*** Testing ftruncate() : usage variations ***\n";
                     20: 
                     21: /* test ftruncate with file opened in different modes */
                     22: $file_modes = array("r", "rb", "rt", "r+", "r+b", "r+t", 
                     23:                     "w", "wb", "wt", "w+", "w+b", "w+t",
                     24:                     "x", "xb", "xt", "x+", "x+b", "x+t",
                     25:                     "a", "ab", "at", "a+", "a+b", "a+t");
                     26: 
                     27: $file_content_types = array("numeric","text_with_new_line");
                     28: 
                     29: foreach($file_content_types as $file_content_type) {
                     30:  echo "\n-- Testing ftruncate() with file having data of type ". $file_content_type ." --\n";
                     31: 
                     32:  for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) {
                     33:    echo "-- Testing ftruncate() with file opening using $file_modes[$mode_counter] mode --\n";
                     34: 
                     35:    // create 1 file with some contents
                     36:    $filename = dirname(__FILE__)."/ftruncate_variation3.tmp";
                     37:    if( strstr($file_modes[$mode_counter], "x") || strstr($file_modes[$mode_counter], "w") ) {
                     38:      // fopen the file using the $file_modes
                     39:      $file_handle = fopen($filename, $file_modes[$mode_counter]);
                     40:      fill_file($file_handle, $file_content_type, 1024);
                     41:    } else {
                     42:      create_files ( dirname(__FILE__), 1, $file_content_type, 0755, 1, "w", "ftruncate_variation", 3);
                     43:      // fopen the file using the $file_modes
                     44:      $file_handle = fopen($filename, $file_modes[$mode_counter]);
                     45:    }
                     46:    if (!$file_handle) {
                     47:      echo "Error: failed to open file $filename!\n"; 
                     48:      exit();
                     49:    }
                     50: 
                     51:    rewind($file_handle); // file pointer to 0
                     52: 
                     53:    echo "-- Testing ftruncate(): truncate file to half of its current size --\n";
                     54:    /* truncate it to half of its current size */ 
                     55:    $new_size = filesize($filename)/2;
                     56:    var_dump( filesize($filename) );  // current filesize
                     57:    var_dump( ftell($file_handle) );
                     58:    var_dump( ftruncate($file_handle, $new_size) ); // truncate it
                     59:    var_dump( ftell($file_handle) );
                     60:    var_dump( feof($file_handle) );
                     61:    fclose($file_handle);
                     62:    clearstatcache(); // clear previous size value in cache
                     63:    var_dump( filesize($filename) ); // new file size = $new_size
                     64: 
                     65:    // delete file
                     66:    delete_file($filename);
                     67:  }//end of inner for loop
                     68: }//end of outer foreach loop
                     69: echo "Done\n";
                     70: ?>
                     71: --EXPECTF--
                     72: *** Testing ftruncate() : usage variations ***
                     73: 
                     74: -- Testing ftruncate() with file having data of type numeric --
                     75: -- Testing ftruncate() with file opening using r mode --
                     76: -- Testing ftruncate(): truncate file to half of its current size --
                     77: int(1024)
                     78: int(0)
                     79: bool(false)
                     80: int(0)
                     81: bool(false)
                     82: int(1024)
                     83: -- Testing ftruncate() with file opening using rb mode --
                     84: -- Testing ftruncate(): truncate file to half of its current size --
                     85: int(1024)
                     86: int(0)
                     87: bool(false)
                     88: int(0)
                     89: bool(false)
                     90: int(1024)
                     91: -- Testing ftruncate() with file opening using rt mode --
                     92: -- Testing ftruncate(): truncate file to half of its current size --
                     93: int(1024)
                     94: int(0)
                     95: bool(false)
                     96: int(0)
                     97: bool(false)
                     98: int(1024)
                     99: -- Testing ftruncate() with file opening using r+ mode --
                    100: -- Testing ftruncate(): truncate file to half of its current size --
                    101: int(1024)
                    102: int(0)
                    103: bool(true)
                    104: int(0)
                    105: bool(false)
                    106: int(512)
                    107: -- Testing ftruncate() with file opening using r+b mode --
                    108: -- Testing ftruncate(): truncate file to half of its current size --
                    109: int(1024)
                    110: int(0)
                    111: bool(true)
                    112: int(0)
                    113: bool(false)
                    114: int(512)
                    115: -- Testing ftruncate() with file opening using r+t mode --
                    116: -- Testing ftruncate(): truncate file to half of its current size --
                    117: int(1024)
                    118: int(0)
                    119: bool(true)
                    120: int(0)
                    121: bool(false)
                    122: int(512)
                    123: -- Testing ftruncate() with file opening using w mode --
                    124: -- Testing ftruncate(): truncate file to half of its current size --
                    125: int(1024)
                    126: int(0)
                    127: bool(true)
                    128: int(0)
                    129: bool(false)
                    130: int(512)
                    131: -- Testing ftruncate() with file opening using wb mode --
                    132: -- Testing ftruncate(): truncate file to half of its current size --
                    133: int(1024)
                    134: int(0)
                    135: bool(true)
                    136: int(0)
                    137: bool(false)
                    138: int(512)
                    139: -- Testing ftruncate() with file opening using wt mode --
                    140: -- Testing ftruncate(): truncate file to half of its current size --
                    141: int(1024)
                    142: int(0)
                    143: bool(true)
                    144: int(0)
                    145: bool(false)
                    146: int(512)
                    147: -- Testing ftruncate() with file opening using w+ mode --
                    148: -- Testing ftruncate(): truncate file to half of its current size --
                    149: int(1024)
                    150: int(0)
                    151: bool(true)
                    152: int(0)
                    153: bool(false)
                    154: int(512)
                    155: -- Testing ftruncate() with file opening using w+b mode --
                    156: -- Testing ftruncate(): truncate file to half of its current size --
                    157: int(1024)
                    158: int(0)
                    159: bool(true)
                    160: int(0)
                    161: bool(false)
                    162: int(512)
                    163: -- Testing ftruncate() with file opening using w+t mode --
                    164: -- Testing ftruncate(): truncate file to half of its current size --
                    165: int(1024)
                    166: int(0)
                    167: bool(true)
                    168: int(0)
                    169: bool(false)
                    170: int(512)
                    171: -- Testing ftruncate() with file opening using x mode --
                    172: -- Testing ftruncate(): truncate file to half of its current size --
                    173: int(1024)
                    174: int(0)
                    175: bool(true)
                    176: int(0)
                    177: bool(false)
                    178: int(512)
                    179: -- Testing ftruncate() with file opening using xb mode --
                    180: -- Testing ftruncate(): truncate file to half of its current size --
                    181: int(1024)
                    182: int(0)
                    183: bool(true)
                    184: int(0)
                    185: bool(false)
                    186: int(512)
                    187: -- Testing ftruncate() with file opening using xt mode --
                    188: -- Testing ftruncate(): truncate file to half of its current size --
                    189: int(1024)
                    190: int(0)
                    191: bool(true)
                    192: int(0)
                    193: bool(false)
                    194: int(512)
                    195: -- Testing ftruncate() with file opening using x+ mode --
                    196: -- Testing ftruncate(): truncate file to half of its current size --
                    197: int(1024)
                    198: int(0)
                    199: bool(true)
                    200: int(0)
                    201: bool(false)
                    202: int(512)
                    203: -- Testing ftruncate() with file opening using x+b mode --
                    204: -- Testing ftruncate(): truncate file to half of its current size --
                    205: int(1024)
                    206: int(0)
                    207: bool(true)
                    208: int(0)
                    209: bool(false)
                    210: int(512)
                    211: -- Testing ftruncate() with file opening using x+t mode --
                    212: -- Testing ftruncate(): truncate file to half of its current size --
                    213: int(1024)
                    214: int(0)
                    215: bool(true)
                    216: int(0)
                    217: bool(false)
                    218: int(512)
                    219: -- Testing ftruncate() with file opening using a mode --
                    220: -- Testing ftruncate(): truncate file to half of its current size --
                    221: int(1024)
                    222: int(0)
                    223: bool(true)
                    224: int(0)
                    225: bool(false)
                    226: int(512)
                    227: -- Testing ftruncate() with file opening using ab mode --
                    228: -- Testing ftruncate(): truncate file to half of its current size --
                    229: int(1024)
                    230: int(0)
                    231: bool(true)
                    232: int(0)
                    233: bool(false)
                    234: int(512)
                    235: -- Testing ftruncate() with file opening using at mode --
                    236: -- Testing ftruncate(): truncate file to half of its current size --
                    237: int(1024)
                    238: int(0)
                    239: bool(true)
                    240: int(0)
                    241: bool(false)
                    242: int(512)
                    243: -- Testing ftruncate() with file opening using a+ mode --
                    244: -- Testing ftruncate(): truncate file to half of its current size --
                    245: int(1024)
                    246: int(0)
                    247: bool(true)
                    248: int(0)
                    249: bool(false)
                    250: int(512)
                    251: -- Testing ftruncate() with file opening using a+b mode --
                    252: -- Testing ftruncate(): truncate file to half of its current size --
                    253: int(1024)
                    254: int(0)
                    255: bool(true)
                    256: int(0)
                    257: bool(false)
                    258: int(512)
                    259: -- Testing ftruncate() with file opening using a+t mode --
                    260: -- Testing ftruncate(): truncate file to half of its current size --
                    261: int(1024)
                    262: int(0)
                    263: bool(true)
                    264: int(0)
                    265: bool(false)
                    266: int(512)
                    267: 
                    268: -- Testing ftruncate() with file having data of type text_with_new_line --
                    269: -- Testing ftruncate() with file opening using r mode --
                    270: -- Testing ftruncate(): truncate file to half of its current size --
                    271: int(1024)
                    272: int(0)
                    273: bool(false)
                    274: int(0)
                    275: bool(false)
                    276: int(1024)
                    277: -- Testing ftruncate() with file opening using rb mode --
                    278: -- Testing ftruncate(): truncate file to half of its current size --
                    279: int(1024)
                    280: int(0)
                    281: bool(false)
                    282: int(0)
                    283: bool(false)
                    284: int(1024)
                    285: -- Testing ftruncate() with file opening using rt mode --
                    286: -- Testing ftruncate(): truncate file to half of its current size --
                    287: int(1024)
                    288: int(0)
                    289: bool(false)
                    290: int(0)
                    291: bool(false)
                    292: int(1024)
                    293: -- Testing ftruncate() with file opening using r+ mode --
                    294: -- Testing ftruncate(): truncate file to half of its current size --
                    295: int(1024)
                    296: int(0)
                    297: bool(true)
                    298: int(0)
                    299: bool(false)
                    300: int(512)
                    301: -- Testing ftruncate() with file opening using r+b mode --
                    302: -- Testing ftruncate(): truncate file to half of its current size --
                    303: int(1024)
                    304: int(0)
                    305: bool(true)
                    306: int(0)
                    307: bool(false)
                    308: int(512)
                    309: -- Testing ftruncate() with file opening using r+t mode --
                    310: -- Testing ftruncate(): truncate file to half of its current size --
                    311: int(1024)
                    312: int(0)
                    313: bool(true)
                    314: int(0)
                    315: bool(false)
                    316: int(512)
                    317: -- Testing ftruncate() with file opening using w mode --
                    318: -- Testing ftruncate(): truncate file to half of its current size --
                    319: int(1024)
                    320: int(0)
                    321: bool(true)
                    322: int(0)
                    323: bool(false)
                    324: int(512)
                    325: -- Testing ftruncate() with file opening using wb mode --
                    326: -- Testing ftruncate(): truncate file to half of its current size --
                    327: int(1024)
                    328: int(0)
                    329: bool(true)
                    330: int(0)
                    331: bool(false)
                    332: int(512)
                    333: -- Testing ftruncate() with file opening using wt mode --
                    334: -- Testing ftruncate(): truncate file to half of its current size --
                    335: int(1024)
                    336: int(0)
                    337: bool(true)
                    338: int(0)
                    339: bool(false)
                    340: int(512)
                    341: -- Testing ftruncate() with file opening using w+ mode --
                    342: -- Testing ftruncate(): truncate file to half of its current size --
                    343: int(1024)
                    344: int(0)
                    345: bool(true)
                    346: int(0)
                    347: bool(false)
                    348: int(512)
                    349: -- Testing ftruncate() with file opening using w+b mode --
                    350: -- Testing ftruncate(): truncate file to half of its current size --
                    351: int(1024)
                    352: int(0)
                    353: bool(true)
                    354: int(0)
                    355: bool(false)
                    356: int(512)
                    357: -- Testing ftruncate() with file opening using w+t mode --
                    358: -- Testing ftruncate(): truncate file to half of its current size --
                    359: int(1024)
                    360: int(0)
                    361: bool(true)
                    362: int(0)
                    363: bool(false)
                    364: int(512)
                    365: -- Testing ftruncate() with file opening using x mode --
                    366: -- Testing ftruncate(): truncate file to half of its current size --
                    367: int(1024)
                    368: int(0)
                    369: bool(true)
                    370: int(0)
                    371: bool(false)
                    372: int(512)
                    373: -- Testing ftruncate() with file opening using xb mode --
                    374: -- Testing ftruncate(): truncate file to half of its current size --
                    375: int(1024)
                    376: int(0)
                    377: bool(true)
                    378: int(0)
                    379: bool(false)
                    380: int(512)
                    381: -- Testing ftruncate() with file opening using xt mode --
                    382: -- Testing ftruncate(): truncate file to half of its current size --
                    383: int(1024)
                    384: int(0)
                    385: bool(true)
                    386: int(0)
                    387: bool(false)
                    388: int(512)
                    389: -- Testing ftruncate() with file opening using x+ mode --
                    390: -- Testing ftruncate(): truncate file to half of its current size --
                    391: int(1024)
                    392: int(0)
                    393: bool(true)
                    394: int(0)
                    395: bool(false)
                    396: int(512)
                    397: -- Testing ftruncate() with file opening using x+b mode --
                    398: -- Testing ftruncate(): truncate file to half of its current size --
                    399: int(1024)
                    400: int(0)
                    401: bool(true)
                    402: int(0)
                    403: bool(false)
                    404: int(512)
                    405: -- Testing ftruncate() with file opening using x+t mode --
                    406: -- Testing ftruncate(): truncate file to half of its current size --
                    407: int(1024)
                    408: int(0)
                    409: bool(true)
                    410: int(0)
                    411: bool(false)
                    412: int(512)
                    413: -- Testing ftruncate() with file opening using a mode --
                    414: -- Testing ftruncate(): truncate file to half of its current size --
                    415: int(1024)
                    416: int(0)
                    417: bool(true)
                    418: int(0)
                    419: bool(false)
                    420: int(512)
                    421: -- Testing ftruncate() with file opening using ab mode --
                    422: -- Testing ftruncate(): truncate file to half of its current size --
                    423: int(1024)
                    424: int(0)
                    425: bool(true)
                    426: int(0)
                    427: bool(false)
                    428: int(512)
                    429: -- Testing ftruncate() with file opening using at mode --
                    430: -- Testing ftruncate(): truncate file to half of its current size --
                    431: int(1024)
                    432: int(0)
                    433: bool(true)
                    434: int(0)
                    435: bool(false)
                    436: int(512)
                    437: -- Testing ftruncate() with file opening using a+ mode --
                    438: -- Testing ftruncate(): truncate file to half of its current size --
                    439: int(1024)
                    440: int(0)
                    441: bool(true)
                    442: int(0)
                    443: bool(false)
                    444: int(512)
                    445: -- Testing ftruncate() with file opening using a+b mode --
                    446: -- Testing ftruncate(): truncate file to half of its current size --
                    447: int(1024)
                    448: int(0)
                    449: bool(true)
                    450: int(0)
                    451: bool(false)
                    452: int(512)
                    453: -- Testing ftruncate() with file opening using a+t mode --
                    454: -- Testing ftruncate(): truncate file to half of its current size --
                    455: int(1024)
                    456: int(0)
                    457: bool(true)
                    458: int(0)
                    459: bool(false)
                    460: int(512)
                    461: Done

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