Annotation of embedaddon/php/ext/standard/tests/network/long2ip_variation1.phpt, revision 1.1

1.1     ! misho       1: --TEST--
        !             2: Test long2ip() function : usage variation 
        !             3: --SKIPIF--
        !             4: <?php
        !             5: if(substr(PHP_OS, 0, 3) == "WIN")
        !             6:   die("skip don't run on Windows");
        !             7: ?> 
        !             8: --FILE--
        !             9: <?php
        !            10: /* Prototype  : string long2ip(int proper_address)
        !            11:  * Description: Converts an (IPv4) Internet network address into a string in Internet standard dotted format 
        !            12:  * Source code: ext/standard/basic_functions.c
        !            13:  * Alias to functions: 
        !            14:  */
        !            15: 
        !            16: echo "*** Testing long2ip() : usage variation ***\n";
        !            17: 
        !            18: // Define error handler
        !            19: function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
        !            20:        if (error_reporting() != 0) {
        !            21:                // report non-silenced errors
        !            22:                echo "Error: $err_no - $err_msg, $filename($linenum)\n";
        !            23:        }
        !            24: }
        !            25: set_error_handler('test_error_handler');
        !            26: 
        !            27: // Initialise function arguments not being substituted (if any)
        !            28: 
        !            29: //get an unset variable
        !            30: $unset_var = 10;
        !            31: unset ($unset_var);
        !            32: 
        !            33: // define some classes
        !            34: class classWithToString
        !            35: {
        !            36:        public function __toString() {
        !            37:                return "Class A object";
        !            38:        }
        !            39: }
        !            40: 
        !            41: class classWithoutToString
        !            42: {
        !            43: }
        !            44: 
        !            45: // heredoc string
        !            46: $heredoc = <<<EOT
        !            47: hello world
        !            48: EOT;
        !            49: 
        !            50: // add arrays
        !            51: $index_array = array (1, 2, 3);
        !            52: $assoc_array = array ('one' => 1, 'two' => 2);
        !            53: 
        !            54: // resource
        !            55: $res = fopen(__FILE__,'r');
        !            56: 
        !            57: //array of values to iterate over
        !            58: $inputs = array(
        !            59: 
        !            60:       // float data
        !            61:       'float 10.5' => 10.5,
        !            62:       'float -10.5' => -10.5,
        !            63:       'float .5' => .5,
        !            64: 
        !            65:       // array data
        !            66:       'empty array' => array(),
        !            67:       'int indexed array' => $index_array,
        !            68:       'associative array' => $assoc_array,
        !            69:       'nested arrays' => array('foo', $index_array, $assoc_array),
        !            70: 
        !            71:       // null data
        !            72:       'uppercase NULL' => NULL,
        !            73:       'lowercase null' => null,
        !            74: 
        !            75:       // boolean data
        !            76:       'lowercase true' => true,
        !            77:       'lowercase false' =>false,
        !            78:       'uppercase TRUE' =>TRUE,
        !            79:       'uppercase FALSE' =>FALSE,
        !            80: 
        !            81:       // empty data
        !            82:       'empty string DQ' => "",
        !            83:       'empty string SQ' => '',
        !            84: 
        !            85:       // string data
        !            86:       'string DQ' => "string",
        !            87:       'string SQ' => 'string',
        !            88:       'mixed case string' => "sTrInG",
        !            89:       'heredoc' => $heredoc,
        !            90: 
        !            91:       // object data
        !            92:       'instance of classWithToString' => new classWithToString(),
        !            93:       'instance of classWithoutToString' => new classWithoutToString(),
        !            94: 
        !            95:       // undefined data
        !            96:       'undefined var' => @$undefined_var,
        !            97: 
        !            98:       // unset data
        !            99:       'unset var' => @$unset_var,
        !           100:       
        !           101:       // resource
        !           102:       'resource' => $res,      
        !           103: );
        !           104: 
        !           105: // loop through each element of the array for proper_address
        !           106: 
        !           107: foreach($inputs as $key =>$value) {
        !           108:       echo "\n--$key--\n";
        !           109:       var_dump( long2ip($value) );
        !           110: };
        !           111: 
        !           112: fclose($res);
        !           113: 
        !           114: ?>
        !           115: ===DONE===
        !           116: --EXPECTF--
        !           117: *** Testing long2ip() : usage variation ***
        !           118: 
        !           119: --float 10.5--
        !           120: string(8) "0.0.0.10"
        !           121: 
        !           122: --float -10.5--
        !           123: string(15) "255.255.255.246"
        !           124: 
        !           125: --float .5--
        !           126: string(7) "0.0.0.0"
        !           127: 
        !           128: --empty array--
        !           129: Error: 2 - long2ip() expects parameter 1 to be string, array given, %s(%d)
        !           130: NULL
        !           131: 
        !           132: --int indexed array--
        !           133: Error: 2 - long2ip() expects parameter 1 to be string, array given, %s(%d)
        !           134: NULL
        !           135: 
        !           136: --associative array--
        !           137: Error: 2 - long2ip() expects parameter 1 to be string, array given, %s(%d)
        !           138: NULL
        !           139: 
        !           140: --nested arrays--
        !           141: Error: 2 - long2ip() expects parameter 1 to be string, array given, %s(%d)
        !           142: NULL
        !           143: 
        !           144: --uppercase NULL--
        !           145: string(7) "0.0.0.0"
        !           146: 
        !           147: --lowercase null--
        !           148: string(7) "0.0.0.0"
        !           149: 
        !           150: --lowercase true--
        !           151: string(7) "0.0.0.1"
        !           152: 
        !           153: --lowercase false--
        !           154: string(7) "0.0.0.0"
        !           155: 
        !           156: --uppercase TRUE--
        !           157: string(7) "0.0.0.1"
        !           158: 
        !           159: --uppercase FALSE--
        !           160: string(7) "0.0.0.0"
        !           161: 
        !           162: --empty string DQ--
        !           163: string(7) "0.0.0.0"
        !           164: 
        !           165: --empty string SQ--
        !           166: string(7) "0.0.0.0"
        !           167: 
        !           168: --string DQ--
        !           169: string(7) "0.0.0.0"
        !           170: 
        !           171: --string SQ--
        !           172: string(7) "0.0.0.0"
        !           173: 
        !           174: --mixed case string--
        !           175: string(7) "0.0.0.0"
        !           176: 
        !           177: --heredoc--
        !           178: string(7) "0.0.0.0"
        !           179: 
        !           180: --instance of classWithToString--
        !           181: string(7) "0.0.0.0"
        !           182: 
        !           183: --instance of classWithoutToString--
        !           184: Error: 2 - long2ip() expects parameter 1 to be string, object given, %s(%d)
        !           185: NULL
        !           186: 
        !           187: --undefined var--
        !           188: string(7) "0.0.0.0"
        !           189: 
        !           190: --unset var--
        !           191: string(7) "0.0.0.0"
        !           192: 
        !           193: --resource--
        !           194: Error: 2 - long2ip() expects parameter 1 to be string, resource given, %s(%d)
        !           195: NULL
        !           196: ===DONE===

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