Annotation of embedaddon/php/ext/standard/tests/strings/count_chars_variation1.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: Test count_chars() function : usage variations - test values for $string argument
                      3: --FILE--
                      4: <?php
                      5: 
                      6: /* Prototype  : mixed count_chars  ( string $string  [, int $mode  ] )
                      7:  * Description: Return information about characters used in a string
                      8:  * Source code: ext/standard/string.c
                      9: */
                     10: 
                     11: echo "*** Testing count_chars() function: with unexpected inputs for 'string' argument ***\n";
                     12: 
                     13: //get an unset variable
                     14: $unset_var = 'string_val';
                     15: unset($unset_var);
                     16: 
                     17: //defining a class
                     18: class sample  {
                     19:   public function __toString() {
                     20:     return "sample object";
                     21:   } 
                     22: }
                     23: 
                     24: //getting the resource
                     25: $file_handle = fopen(__FILE__, "r");
                     26: 
                     27: // array with different values for $input
                     28: $inputs =  array (
                     29: 
                     30:                          // integer values
                     31: /* 1 */                  0,
                     32:                          1,
                     33:                          255,
                     34:                          256,
                     35:                  2147483647,
                     36:                         -2147483648,
                     37:                        
                     38:                          // float values
                     39: /* 7 */                  10.5,
                     40:                          -20.5,
                     41:                          10.1234567e10,
                     42:                        
                     43:                          // array values
                     44: /* 10 */         array(),
                     45:                          array(0),
                     46:                          array(1, 2),
                     47:                        
                     48:                          // boolean values
                     49: /* 13 */         true,
                     50:                          false,
                     51:                          TRUE,
                     52:                          FALSE,
                     53:                        
                     54:                          // null values
                     55: /* 17 */         NULL,
                     56:                          null,
                     57:                        
                     58:                          // objects
                     59: /* 19 */         new sample(),
                     60:                        
                     61:                          // resource
                     62: /* 20 */         $file_handle,
                     63:                        
                     64:                          // undefined variable
                     65: /* 21 */         @$undefined_var,
                     66:                        
                     67:                          // unset variable
                     68: /* 22 */         @$unset_var
                     69: );
                     70: 
                     71: // loop through with each element of the $inputs array to test count_chars() function
                     72: $count = 1;
                     73: foreach($inputs as $input) {
                     74:   echo "-- Iteration $count --\n";
                     75:   // only list characters with a frequency > 0
                     76:   var_dump(count_chars($input, 1));
                     77:   $count ++;
                     78: }
                     79: 
                     80: fclose($file_handle);  //closing the file handle
                     81: 
                     82: ?>
                     83: ===DONE===
                     84: --EXPECTF--
                     85: *** Testing count_chars() function: with unexpected inputs for 'string' argument ***
                     86: -- Iteration 1 --
                     87: array(1) {
                     88:   [48]=>
                     89:   int(1)
                     90: }
                     91: -- Iteration 2 --
                     92: array(1) {
                     93:   [49]=>
                     94:   int(1)
                     95: }
                     96: -- Iteration 3 --
                     97: array(2) {
                     98:   [50]=>
                     99:   int(1)
                    100:   [53]=>
                    101:   int(2)
                    102: }
                    103: -- Iteration 4 --
                    104: array(3) {
                    105:   [50]=>
                    106:   int(1)
                    107:   [53]=>
                    108:   int(1)
                    109:   [54]=>
                    110:   int(1)
                    111: }
                    112: -- Iteration 5 --
                    113: array(7) {
                    114:   [49]=>
                    115:   int(1)
                    116:   [50]=>
                    117:   int(1)
                    118:   [51]=>
                    119:   int(1)
                    120:   [52]=>
                    121:   int(3)
                    122:   [54]=>
                    123:   int(1)
                    124:   [55]=>
                    125:   int(2)
                    126:   [56]=>
                    127:   int(1)
                    128: }
                    129: -- Iteration 6 --
                    130: array(8) {
                    131:   [45]=>
                    132:   int(1)
                    133:   [49]=>
                    134:   int(1)
                    135:   [50]=>
                    136:   int(1)
                    137:   [51]=>
                    138:   int(1)
                    139:   [52]=>
                    140:   int(3)
                    141:   [54]=>
                    142:   int(1)
                    143:   [55]=>
                    144:   int(1)
                    145:   [56]=>
                    146:   int(2)
                    147: }
                    148: -- Iteration 7 --
                    149: array(4) {
                    150:   [46]=>
                    151:   int(1)
                    152:   [48]=>
                    153:   int(1)
                    154:   [49]=>
                    155:   int(1)
                    156:   [53]=>
                    157:   int(1)
                    158: }
                    159: -- Iteration 8 --
                    160: array(5) {
                    161:   [45]=>
                    162:   int(1)
                    163:   [46]=>
                    164:   int(1)
                    165:   [48]=>
                    166:   int(1)
                    167:   [50]=>
                    168:   int(1)
                    169:   [53]=>
                    170:   int(1)
                    171: }
                    172: -- Iteration 9 --
                    173: array(8) {
                    174:   [48]=>
                    175:   int(4)
                    176:   [49]=>
                    177:   int(2)
                    178:   [50]=>
                    179:   int(1)
                    180:   [51]=>
                    181:   int(1)
                    182:   [52]=>
                    183:   int(1)
                    184:   [53]=>
                    185:   int(1)
                    186:   [54]=>
                    187:   int(1)
                    188:   [55]=>
                    189:   int(1)
                    190: }
                    191: -- Iteration 10 --
                    192: 
                    193: Warning: count_chars() expects parameter 1 to be string, array given in %s on line %d
                    194: NULL
                    195: -- Iteration 11 --
                    196: 
                    197: Warning: count_chars() expects parameter 1 to be string, array given in %s on line %d
                    198: NULL
                    199: -- Iteration 12 --
                    200: 
                    201: Warning: count_chars() expects parameter 1 to be string, array given in %s on line %d
                    202: NULL
                    203: -- Iteration 13 --
                    204: array(1) {
                    205:   [49]=>
                    206:   int(1)
                    207: }
                    208: -- Iteration 14 --
                    209: array(0) {
                    210: }
                    211: -- Iteration 15 --
                    212: array(1) {
                    213:   [49]=>
                    214:   int(1)
                    215: }
                    216: -- Iteration 16 --
                    217: array(0) {
                    218: }
                    219: -- Iteration 17 --
                    220: array(0) {
                    221: }
                    222: -- Iteration 18 --
                    223: array(0) {
                    224: }
                    225: -- Iteration 19 --
                    226: array(12) {
                    227:   [32]=>
                    228:   int(1)
                    229:   [97]=>
                    230:   int(1)
                    231:   [98]=>
                    232:   int(1)
                    233:   [99]=>
                    234:   int(1)
                    235:   [101]=>
                    236:   int(2)
                    237:   [106]=>
                    238:   int(1)
                    239:   [108]=>
                    240:   int(1)
                    241:   [109]=>
                    242:   int(1)
                    243:   [111]=>
                    244:   int(1)
                    245:   [112]=>
                    246:   int(1)
                    247:   [115]=>
                    248:   int(1)
                    249:   [116]=>
                    250:   int(1)
                    251: }
                    252: -- Iteration 20 --
                    253: 
                    254: Warning: count_chars() expects parameter 1 to be string, resource given in %s on line %d
                    255: NULL
                    256: -- Iteration 21 --
                    257: array(0) {
                    258: }
                    259: -- Iteration 22 --
                    260: array(0) {
                    261: }
                    262: ===DONE===

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