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

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

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