~ubuntu-branches/ubuntu/quantal/php5/quantal

« back to all changes in this revision

Viewing changes to ext/standard/tests/url/base64_decode_variation_001.phpt

  • Committer: Bazaar Package Importer
  • Author(s): Sean Finney
  • Date: 2009-07-01 09:12:10 UTC
  • mto: (0.9.1) (1.1.17 upstream)
  • mto: This revision was merged to the branch mainline in revision 58.
  • Revision ID: james.westby@ubuntu.com-20090701091210-go0h6506p62on17r
Tags: upstream-5.3.0
ImportĀ upstreamĀ versionĀ 5.3.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
--TEST--
 
2
Test base64_decode() function : usage variations  - unexpected types for arg 1
 
3
--FILE--
 
4
<?php
 
5
/* Prototype  : proto string base64_decode(string str[, bool strict])
 
6
 * Description: Decodes string using MIME base64 algorithm 
 
7
 * Source code: ext/standard/base64.c
 
8
 * Alias to functions: 
 
9
 */
 
10
 
 
11
function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
 
12
        echo "Error: $err_no - $err_msg, $filename($linenum)\n";
 
13
}
 
14
set_error_handler('test_error_handler');
 
15
 
 
16
echo "*** Testing base64_decode() : usage variations ***\n";
 
17
 
 
18
// Initialise function arguments not being substituted (if any)
 
19
$strict = true;
 
20
 
 
21
//getting the resource
 
22
$file_handle = fopen(__FILE__, "r");
 
23
 
 
24
//get an unset variable
 
25
$unset_var = 10;
 
26
unset ($unset_var);
 
27
 
 
28
//array of values to iterate over
 
29
$values =  array (
 
30
        // int data
 
31
        "0" =>  0,
 
32
        "1" =>  1,
 
33
        "12345" =>  12345,
 
34
        "-2345" =>  -2345,
 
35
                
 
36
        // float data
 
37
    "10.5" =>  10.5,
 
38
        "-10.5" => -10.5,
 
39
        "10.1234567e10" =>      10.1234567e10,
 
40
        "10.7654321E-10" => 10.7654321E-10,
 
41
        ".5" => .5,
 
42
                
 
43
    // array data
 
44
    "array()" =>   array(),
 
45
        "array(0)" =>  array(0),
 
46
        "array(1)" =>  array(1),
 
47
        "array(1, 2)" => array(1, 2),
 
48
        "array('color' => 'red', 'item' => 'pen'" => array('color' => 'red', 'item' => 'pen'),
 
49
                
 
50
        // null data
 
51
        "NULL" => NULL,
 
52
        "null" => null,
 
53
                
 
54
        // boolean data
 
55
        "true" => true,
 
56
        "false" => false,
 
57
        "TRUE" => TRUE,
 
58
        "FALSE" => FALSE,
 
59
                
 
60
        // empty data
 
61
        "\"\"" => "",
 
62
        "''" => '',
 
63
                
 
64
        // object data
 
65
        "stdClass object" => new stdclass(),
 
66
                
 
67
        // undefined data
 
68
    "undefined variable" => $undefined_var,
 
69
                
 
70
        // unset data
 
71
        "unset variable" => $unset_var,
 
72
        
 
73
        // resource data
 
74
        "resource" => $file_handle
 
75
);
 
76
 
 
77
// loop through each element of the array for str argument
 
78
 
 
79
foreach($values as $key=>$value) {
 
80
    echo "\n-- Arg value $key --\n";
 
81
    $output =  base64_decode($value, $strict);
 
82
       
 
83
        if (is_string($output)) { 
 
84
                var_dump(bin2hex($output));
 
85
    } else {
 
86
        var_dump($output); 
 
87
    }   
 
88
};
 
89
 
 
90
?>
 
91
===Done===
 
92
--EXPECTF--
 
93
*** Testing base64_decode() : usage variations ***
 
94
Error: 8 - Undefined variable: undefined_var, %s(%d)
 
95
Error: 8 - Undefined variable: unset_var, %s(%d)
 
96
 
 
97
-- Arg value 0 --
 
98
string(0) ""
 
99
 
 
100
-- Arg value 1 --
 
101
string(0) ""
 
102
 
 
103
-- Arg value 12345 --
 
104
string(6) "d76df8"
 
105
 
 
106
-- Arg value -2345 --
 
107
bool(false)
 
108
 
 
109
-- Arg value 10.5 --
 
110
bool(false)
 
111
 
 
112
-- Arg value -10.5 --
 
113
bool(false)
 
114
 
 
115
-- Arg value 10.1234567e10 --
 
116
string(18) "d74d76df8e7aef4d34"
 
117
 
 
118
-- Arg value 10.7654321E-10 --
 
119
bool(false)
 
120
 
 
121
-- Arg value .5 --
 
122
bool(false)
 
123
 
 
124
-- Arg value array() --
 
125
Error: 2 - base64_decode() expects parameter 1 to be string, array given, %s(%d)
 
126
NULL
 
127
 
 
128
-- Arg value array(0) --
 
129
Error: 2 - base64_decode() expects parameter 1 to be string, array given, %s(%d)
 
130
NULL
 
131
 
 
132
-- Arg value array(1) --
 
133
Error: 2 - base64_decode() expects parameter 1 to be string, array given, %s(%d)
 
134
NULL
 
135
 
 
136
-- Arg value array(1, 2) --
 
137
Error: 2 - base64_decode() expects parameter 1 to be string, array given, %s(%d)
 
138
NULL
 
139
 
 
140
-- Arg value array('color' => 'red', 'item' => 'pen' --
 
141
Error: 2 - base64_decode() expects parameter 1 to be string, array given, %s(%d)
 
142
NULL
 
143
 
 
144
-- Arg value NULL --
 
145
string(0) ""
 
146
 
 
147
-- Arg value null --
 
148
string(0) ""
 
149
 
 
150
-- Arg value true --
 
151
string(0) ""
 
152
 
 
153
-- Arg value false --
 
154
string(0) ""
 
155
 
 
156
-- Arg value TRUE --
 
157
string(0) ""
 
158
 
 
159
-- Arg value FALSE --
 
160
string(0) ""
 
161
 
 
162
-- Arg value "" --
 
163
string(0) ""
 
164
 
 
165
-- Arg value '' --
 
166
string(0) ""
 
167
 
 
168
-- Arg value stdClass object --
 
169
Error: 2 - base64_decode() expects parameter 1 to be string, object given, %s(%d)
 
170
NULL
 
171
 
 
172
-- Arg value undefined variable --
 
173
string(0) ""
 
174
 
 
175
-- Arg value unset variable --
 
176
string(0) ""
 
177
 
 
178
-- Arg value resource --
 
179
Error: 2 - base64_decode() expects parameter 1 to be string, resource given, %s(%d)
 
180
NULL
 
181
===Done===
 
 
b'\\ No newline at end of file'