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

« back to all changes in this revision

Viewing changes to ext/standard/tests/strings/vfprintf_variation20.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 vfprintf() function : usage variations - unexpected values for the format argument
 
3
--FILE--
 
4
<?php
 
5
/* Prototype  : int vfprintf  ( resource $handle  , string $format , array $args  )
 
6
 * Description: Write a formatted string to a stream
 
7
 * Source code: ext/standard/formatted_print.c
 
8
*/
 
9
 
 
10
/*
 
11
 * Test vfprintf() when different unexpected format strings are passed to
 
12
 * the '$format' argument of the function
 
13
*/
 
14
 
 
15
echo "*** Testing vfprintf() : with unexpected values for format argument ***\n";
 
16
 
 
17
// initialising the required variables
 
18
$args = array(1, 2);
 
19
 
 
20
//get an unset variable
 
21
$unset_var = 10;
 
22
unset ($unset_var);
 
23
 
 
24
// declaring a class
 
25
class sample
 
26
{
 
27
  public function __toString() {
 
28
  return "object";
 
29
  }
 
30
}
 
31
 
 
32
// Defining resource
 
33
$file_handle = fopen(__FILE__, 'r');
 
34
 
 
35
 
 
36
//array of values to iterate over
 
37
$values = array(
 
38
 
 
39
                  // int data
 
40
/*1*/     0,
 
41
                  1,
 
42
                  12345,
 
43
                  -2345,
 
44
                
 
45
                  // float data
 
46
/*5*/     10.5,
 
47
                  -10.5,
 
48
                  10.1234567e10,
 
49
                  10.7654321E-10,
 
50
                  .5,
 
51
                
 
52
                  // array data
 
53
/*10*/    array(),
 
54
                  array(0),
 
55
                  array(1),
 
56
                  array(1,2),
 
57
                  array('color' => 'red', 'item' => 'pen'),
 
58
                
 
59
                  // null data
 
60
/*15*/    NULL,
 
61
                  null,
 
62
                
 
63
                  // boolean data
 
64
/*17*/    true,
 
65
                  false,
 
66
                  TRUE,
 
67
                  FALSE,
 
68
                
 
69
                  // empty data
 
70
/*21*/    "",
 
71
                  '',
 
72
                
 
73
                  // object data
 
74
/*23*/    new sample(),
 
75
                
 
76
                  // undefined data
 
77
/*24*/    @$undefined_var,
 
78
                
 
79
                  // unset data
 
80
/*25*/    @$unset_var,
 
81
                 
 
82
                  // resource data
 
83
/*26*/    $file_handle
 
84
);
 
85
 
 
86
/* creating dumping file */
 
87
$data_file = dirname(__FILE__) . '/dump.txt';
 
88
if (!($fp = fopen($data_file, 'wt')))
 
89
   return;
 
90
 
 
91
fprintf($fp, "\n*** Testing vprintf() with with unexpected values for format argument ***\n");
 
92
 
 
93
$counter = 1;
 
94
foreach( $values as $value ) {
 
95
  fprintf( $fp, "\n-- Iteration %d --\n",$counter);
 
96
  vfprintf($fp, $value, $args);
 
97
  $counter++;
 
98
}
 
99
 
 
100
fclose($fp);
 
101
print_r(file_get_contents($data_file));
 
102
echo "\n";
 
103
 
 
104
unlink($data_file);
 
105
 
 
106
?>
 
107
===DONE===
 
108
--EXPECTF--
 
109
*** Testing vfprintf() : with unexpected values for format argument ***
 
110
 
 
111
Notice: Array to string conversion in %s on line %d
 
112
 
 
113
Notice: Array to string conversion in %s on line %d
 
114
 
 
115
Notice: Array to string conversion in %s on line %d
 
116
 
 
117
Notice: Array to string conversion in %s on line %d
 
118
 
 
119
Notice: Array to string conversion in %s on line %d
 
120
 
 
121
*** Testing vprintf() with with unexpected values for format argument ***
 
122
 
 
123
-- Iteration 1 --
 
124
0
 
125
-- Iteration 2 --
 
126
1
 
127
-- Iteration 3 --
 
128
12345
 
129
-- Iteration 4 --
 
130
-2345
 
131
-- Iteration 5 --
 
132
10.5
 
133
-- Iteration 6 --
 
134
-10.5
 
135
-- Iteration 7 --
 
136
101234567000
 
137
-- Iteration 8 --
 
138
1.07654321E-9
 
139
-- Iteration 9 --
 
140
0.5
 
141
-- Iteration 10 --
 
142
Array
 
143
-- Iteration 11 --
 
144
Array
 
145
-- Iteration 12 --
 
146
Array
 
147
-- Iteration 13 --
 
148
Array
 
149
-- Iteration 14 --
 
150
Array
 
151
-- Iteration 15 --
 
152
 
 
153
-- Iteration 16 --
 
154
 
 
155
-- Iteration 17 --
 
156
1
 
157
-- Iteration 18 --
 
158
 
 
159
-- Iteration 19 --
 
160
1
 
161
-- Iteration 20 --
 
162
 
 
163
-- Iteration 21 --
 
164
 
 
165
-- Iteration 22 --
 
166
 
 
167
-- Iteration 23 --
 
168
object
 
169
-- Iteration 24 --
 
170
 
 
171
-- Iteration 25 --
 
172
 
 
173
-- Iteration 26 --
 
174
Resource id #%d
 
175
===DONE===