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

1.1     ! misho       1: --TEST--
        !             2: Test ip2long() function : usage variation 
        !             3: --SKIPIF--
        !             4: <?php
        !             5: if(substr(PHP_OS, 0, 3) == "WIN")
        !             6:   die("skip. Windows is more compliant (like 0 for localhost, etc.)");
        !             7: ?>
        !             8: --FILE--
        !             9: <?php
        !            10: /* Prototype  : int ip2long(string ip_address)
        !            11:  * Description: Converts a string containing an (IPv4) Internet Protocol dotted address into a proper address 
        !            12:  * Source code: ext/standard/basic_functions.c
        !            13:  * Alias to functions: 
        !            14:  */
        !            15: 
        !            16: echo "*** Testing ip2long() : 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:       // int data
        !            61:       'int 0' => 0,
        !            62:       'int 1' => 1,
        !            63:       'int 12345' => 12345,
        !            64:       'int -12345' => -2345,
        !            65: 
        !            66:       // float data
        !            67:       'float 10.5' => 10.5,
        !            68:       'float -10.5' => -10.5,
        !            69:       'float 12.3456789000e10' => 12.3456789000e10,
        !            70:       'float -12.3456789000e10' => -12.3456789000e10,
        !            71:       'float .5' => .5,
        !            72: 
        !            73:       // array data
        !            74:       'empty array' => array(),
        !            75:       'int indexed array' => $index_array,
        !            76:       'associative array' => $assoc_array,
        !            77:       'nested arrays' => array('foo', $index_array, $assoc_array),
        !            78: 
        !            79:       // null data
        !            80:       'uppercase NULL' => NULL,
        !            81:       'lowercase null' => null,
        !            82: 
        !            83:       // boolean data
        !            84:       'lowercase true' => true,
        !            85:       'lowercase false' =>false,
        !            86:       'uppercase TRUE' =>TRUE,
        !            87:       'uppercase FALSE' =>FALSE,
        !            88: 
        !            89:       // empty data
        !            90:       'empty string DQ' => "",
        !            91:       'empty string SQ' => '',
        !            92: 
        !            93:       // object data
        !            94:       'instance of classWithToString' => new classWithToString(),
        !            95:       'instance of classWithoutToString' => new classWithoutToString(),
        !            96: 
        !            97:       // undefined data
        !            98:       'undefined var' => @$undefined_var,
        !            99: 
        !           100:       // unset data
        !           101:       'unset var' => @$unset_var,
        !           102:       
        !           103:       // resource
        !           104:       'resource' => $res,
        !           105: );
        !           106: 
        !           107: // loop through each element of the array for ip_address
        !           108: 
        !           109: foreach($inputs as $key =>$value) {
        !           110:       echo "\n--$key--\n";
        !           111:       var_dump( ip2long($value) );
        !           112: };
        !           113: 
        !           114: fclose($res);
        !           115: 
        !           116: ?>
        !           117: ===DONE===
        !           118: --EXPECTF--
        !           119: *** Testing ip2long() : usage variation ***
        !           120: 
        !           121: --int 0--
        !           122: bool(false)
        !           123: 
        !           124: --int 1--
        !           125: bool(false)
        !           126: 
        !           127: --int 12345--
        !           128: bool(false)
        !           129: 
        !           130: --int -12345--
        !           131: bool(false)
        !           132: 
        !           133: --float 10.5--
        !           134: bool(false)
        !           135: 
        !           136: --float -10.5--
        !           137: bool(false)
        !           138: 
        !           139: --float 12.3456789000e10--
        !           140: bool(false)
        !           141: 
        !           142: --float -12.3456789000e10--
        !           143: bool(false)
        !           144: 
        !           145: --float .5--
        !           146: bool(false)
        !           147: 
        !           148: --empty array--
        !           149: Error: 2 - ip2long() expects parameter 1 to be string, array given, %s(%d)
        !           150: NULL
        !           151: 
        !           152: --int indexed array--
        !           153: Error: 2 - ip2long() expects parameter 1 to be string, array given, %s(%d)
        !           154: NULL
        !           155: 
        !           156: --associative array--
        !           157: Error: 2 - ip2long() expects parameter 1 to be string, array given, %s(%d)
        !           158: NULL
        !           159: 
        !           160: --nested arrays--
        !           161: Error: 2 - ip2long() expects parameter 1 to be string, array given, %s(%d)
        !           162: NULL
        !           163: 
        !           164: --uppercase NULL--
        !           165: bool(false)
        !           166: 
        !           167: --lowercase null--
        !           168: bool(false)
        !           169: 
        !           170: --lowercase true--
        !           171: bool(false)
        !           172: 
        !           173: --lowercase false--
        !           174: bool(false)
        !           175: 
        !           176: --uppercase TRUE--
        !           177: bool(false)
        !           178: 
        !           179: --uppercase FALSE--
        !           180: bool(false)
        !           181: 
        !           182: --empty string DQ--
        !           183: bool(false)
        !           184: 
        !           185: --empty string SQ--
        !           186: bool(false)
        !           187: 
        !           188: --instance of classWithToString--
        !           189: bool(false)
        !           190: 
        !           191: --instance of classWithoutToString--
        !           192: Error: 2 - ip2long() expects parameter 1 to be string, object given, %s(%d)
        !           193: NULL
        !           194: 
        !           195: --undefined var--
        !           196: bool(false)
        !           197: 
        !           198: --unset var--
        !           199: bool(false)
        !           200: 
        !           201: --resource--
        !           202: Error: 2 - ip2long() expects parameter 1 to be string, resource given, %s(%d)
        !           203: NULL
        !           204: ===DONE===

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