Annotation of embedaddon/php/ext/iconv/tests/iconv_set_encoding_error.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: Test iconv_set_encoding() function : basic functionality
! 3: --SKIPIF--
! 4: <?php
! 5: extension_loaded('iconv') or die('skip');
! 6: function_exists('iconv_set_encoding') or die("skip iconv_set_encoding() is not available in this build");
! 7: ?>
! 8: --FILE--
! 9: <?php
! 10: /* Prototype : bool iconv_set_encoding(string type, string charset)
! 11: * Description: Sets internal encoding and output encoding for ob_iconv_handler()
! 12: * Source code: ext/iconv/iconv.c
! 13: */
! 14:
! 15: /*
! 16: * Test Error functionality of iconv_get_encoding
! 17: */
! 18:
! 19: echo "*** Testing iconv_set_encoding() : error functionality ***\n";
! 20:
! 21: //get an unset variable
! 22: $unset_var = 10;
! 23: unset ($unset_var);
! 24:
! 25: // get a class
! 26: class classA
! 27: {
! 28: public function __toString() {
! 29: return "UTF-8";
! 30: }
! 31: }
! 32:
! 33: // heredoc string
! 34: $heredoc = <<<EOT
! 35: Nothing
! 36: EOT;
! 37:
! 38: // get a resource variable
! 39: $fp = fopen(__FILE__, "r");
! 40:
! 41: // unexpected values to be passed to $encoding argument
! 42: $inputs = array(
! 43:
! 44: // int data
! 45: /*1*/ 0,
! 46: 1,
! 47: 12345,
! 48: -2345,
! 49:
! 50: // float data
! 51: /*5*/ 10.5,
! 52: -10.5,
! 53: 12.3456789000e10,
! 54: 12.3456789000E-10,
! 55: .5,
! 56:
! 57: // null data
! 58: /*10*/ NULL,
! 59: null,
! 60:
! 61: // boolean data
! 62: /*12*/ true,
! 63: false,
! 64: TRUE,
! 65: FALSE,
! 66:
! 67: // empty data
! 68: /*16*/ "",
! 69: '',
! 70:
! 71: // invalid string data
! 72: /*18*/ "Nothing",
! 73: 'Nothing',
! 74: $heredoc,
! 75:
! 76: // object data
! 77: /*21*/ new classA(),
! 78:
! 79: // undefined data
! 80: /*22*/ @$undefined_var,
! 81:
! 82: // unset data
! 83: /*23*/ @$unset_var,
! 84:
! 85: // resource variable
! 86: /*24*/ $fp
! 87: );
! 88:
! 89: // loop through each element of $inputs to check the behavior of mb_regex_encoding()
! 90: $iterator = 1;
! 91: foreach($inputs as $input) {
! 92: echo "\n-- Iteration $iterator --\n";
! 93: var_dump( iconv_set_encoding($input, "UTF-8") );
! 94: $iterator++;
! 95: };
! 96:
! 97: fclose($fp);
! 98:
! 99: echo "Done";
! 100: ?>
! 101: --EXPECTF--
! 102: *** Testing iconv_set_encoding() : error functionality ***
! 103:
! 104: -- Iteration 1 --
! 105: bool(false)
! 106:
! 107: -- Iteration 2 --
! 108: bool(false)
! 109:
! 110: -- Iteration 3 --
! 111: bool(false)
! 112:
! 113: -- Iteration 4 --
! 114: bool(false)
! 115:
! 116: -- Iteration 5 --
! 117: bool(false)
! 118:
! 119: -- Iteration 6 --
! 120: bool(false)
! 121:
! 122: -- Iteration 7 --
! 123: bool(false)
! 124:
! 125: -- Iteration 8 --
! 126: bool(false)
! 127:
! 128: -- Iteration 9 --
! 129: bool(false)
! 130:
! 131: -- Iteration 10 --
! 132: bool(false)
! 133:
! 134: -- Iteration 11 --
! 135: bool(false)
! 136:
! 137: -- Iteration 12 --
! 138: bool(false)
! 139:
! 140: -- Iteration 13 --
! 141: bool(false)
! 142:
! 143: -- Iteration 14 --
! 144: bool(false)
! 145:
! 146: -- Iteration 15 --
! 147: bool(false)
! 148:
! 149: -- Iteration 16 --
! 150: bool(false)
! 151:
! 152: -- Iteration 17 --
! 153: bool(false)
! 154:
! 155: -- Iteration 18 --
! 156: bool(false)
! 157:
! 158: -- Iteration 19 --
! 159: bool(false)
! 160:
! 161: -- Iteration 20 --
! 162: bool(false)
! 163:
! 164: -- Iteration 21 --
! 165: bool(false)
! 166:
! 167: -- Iteration 22 --
! 168: bool(false)
! 169:
! 170: -- Iteration 23 --
! 171: bool(false)
! 172:
! 173: -- Iteration 24 --
! 174:
! 175: Warning: iconv_set_encoding() expects parameter 1 to be string, resource given in %s on line %d
! 176: NULL
! 177: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>