1--TEST--
2Test fscanf() function: usage variations - unsigned formats with float values
3--SKIPIF--
4<?php
5if (PHP_INT_SIZE != 4) {
6	die("skip this test is for 32bit platform only");
7}
8?>
9--FILE--
10<?php
11
12/*
13  Prototype: mixed fscanf ( resource $handle, string $format [, mixed &$...] );
14  Description: Parses input from a file according to a format
15*/
16
17/* Test fscanf() to scan float values using different unsigned format types */
18
19$file_path = dirname(__FILE__);
20
21echo "*** Test fscanf(): different unsigned format types with float values ***\n";
22
23// create a file
24$filename = "$file_path/fscanf_variation40.tmp";
25$file_handle = fopen($filename, "w");
26if($file_handle == false)
27  exit("Error:failed to open file $filename");
28
29// array of float type values
30
31$float_values = array (
32  -2147483649,
33  2147483648,
34  -0x80000001, // float value, beyond max negative int
35  0x800000001, // float value, beyond max positive int
36  020000000001, // float value, beyond max positive int
37  -020000000001, // float value, beyond max negative int
38  0.0,
39  -0.1,
40  1.0,
41  1e5,
42  -1e6,
43  1E8,
44  -1E9,
45  10.0000000000000000005,
46  10.5e+5
47);
48
49$unsigned_formats = array( "%u", "%hu", "%lu", "%Lu", " %u", "%u ", "% u", "\t%u", "\n%u", "%4u", "%30u", "%[0-9]", "%*u");
50
51$counter = 1;
52
53// writing to the file
54foreach($float_values as $value) {
55  @fprintf($file_handle, $value);
56  @fprintf($file_handle, "\n");
57}
58// closing the file
59fclose($file_handle);
60
61// opening the file for reading
62$file_handle = fopen($filename, "r");
63if($file_handle == false) {
64  exit("Error:failed to open file $filename");
65}
66
67$counter = 1;
68// reading the values from file using different unsigned formats
69foreach($unsigned_formats as $unsigned_format) {
70  // rewind the file so that for every foreach iteration the file pointer starts from bof
71  rewind($file_handle);
72  echo "\n-- iteration $counter --\n";
73  while( !feof($file_handle) ) {
74    var_dump( fscanf($file_handle,$unsigned_format) );
75  }
76  $counter++;
77}
78
79echo "\n*** Done ***";
80?>
81--CLEAN--
82<?php
83$file_path = dirname(__FILE__);
84$filename = "$file_path/fscanf_variation40.tmp";
85unlink($filename);
86?>
87--EXPECTF--
88*** Test fscanf(): different unsigned format types with float values ***
89
90-- iteration 1 --
91array(1) {
92  [0]=>
93  int(2147483647)
94}
95array(1) {
96  [0]=>
97  string(10) "2147483648"
98}
99array(1) {
100  [0]=>
101  int(2147483647)
102}
103array(1) {
104  [0]=>
105  string(10) "4294967295"
106}
107array(1) {
108  [0]=>
109  string(10) "2147483649"
110}
111array(1) {
112  [0]=>
113  int(2147483647)
114}
115array(1) {
116  [0]=>
117  int(0)
118}
119array(1) {
120  [0]=>
121  int(0)
122}
123array(1) {
124  [0]=>
125  int(1)
126}
127array(1) {
128  [0]=>
129  int(100000)
130}
131array(1) {
132  [0]=>
133  string(10) "4293967296"
134}
135array(1) {
136  [0]=>
137  int(100000000)
138}
139array(1) {
140  [0]=>
141  string(10) "3294967296"
142}
143array(1) {
144  [0]=>
145  int(10)
146}
147array(1) {
148  [0]=>
149  int(1050000)
150}
151bool(false)
152
153-- iteration 2 --
154array(1) {
155  [0]=>
156  int(2147483647)
157}
158array(1) {
159  [0]=>
160  string(10) "2147483648"
161}
162array(1) {
163  [0]=>
164  int(2147483647)
165}
166array(1) {
167  [0]=>
168  string(10) "4294967295"
169}
170array(1) {
171  [0]=>
172  string(10) "2147483649"
173}
174array(1) {
175  [0]=>
176  int(2147483647)
177}
178array(1) {
179  [0]=>
180  int(0)
181}
182array(1) {
183  [0]=>
184  int(0)
185}
186array(1) {
187  [0]=>
188  int(1)
189}
190array(1) {
191  [0]=>
192  int(100000)
193}
194array(1) {
195  [0]=>
196  string(10) "4293967296"
197}
198array(1) {
199  [0]=>
200  int(100000000)
201}
202array(1) {
203  [0]=>
204  string(10) "3294967296"
205}
206array(1) {
207  [0]=>
208  int(10)
209}
210array(1) {
211  [0]=>
212  int(1050000)
213}
214bool(false)
215
216-- iteration 3 --
217array(1) {
218  [0]=>
219  int(2147483647)
220}
221array(1) {
222  [0]=>
223  string(10) "2147483648"
224}
225array(1) {
226  [0]=>
227  int(2147483647)
228}
229array(1) {
230  [0]=>
231  string(10) "4294967295"
232}
233array(1) {
234  [0]=>
235  string(10) "2147483649"
236}
237array(1) {
238  [0]=>
239  int(2147483647)
240}
241array(1) {
242  [0]=>
243  int(0)
244}
245array(1) {
246  [0]=>
247  int(0)
248}
249array(1) {
250  [0]=>
251  int(1)
252}
253array(1) {
254  [0]=>
255  int(100000)
256}
257array(1) {
258  [0]=>
259  string(10) "4293967296"
260}
261array(1) {
262  [0]=>
263  int(100000000)
264}
265array(1) {
266  [0]=>
267  string(10) "3294967296"
268}
269array(1) {
270  [0]=>
271  int(10)
272}
273array(1) {
274  [0]=>
275  int(1050000)
276}
277bool(false)
278
279-- iteration 4 --
280array(1) {
281  [0]=>
282  int(2147483647)
283}
284array(1) {
285  [0]=>
286  string(10) "2147483648"
287}
288array(1) {
289  [0]=>
290  int(2147483647)
291}
292array(1) {
293  [0]=>
294  string(10) "4294967295"
295}
296array(1) {
297  [0]=>
298  string(10) "2147483649"
299}
300array(1) {
301  [0]=>
302  int(2147483647)
303}
304array(1) {
305  [0]=>
306  int(0)
307}
308array(1) {
309  [0]=>
310  int(0)
311}
312array(1) {
313  [0]=>
314  int(1)
315}
316array(1) {
317  [0]=>
318  int(100000)
319}
320array(1) {
321  [0]=>
322  string(10) "4293967296"
323}
324array(1) {
325  [0]=>
326  int(100000000)
327}
328array(1) {
329  [0]=>
330  string(10) "3294967296"
331}
332array(1) {
333  [0]=>
334  int(10)
335}
336array(1) {
337  [0]=>
338  int(1050000)
339}
340bool(false)
341
342-- iteration 5 --
343array(1) {
344  [0]=>
345  int(2147483647)
346}
347array(1) {
348  [0]=>
349  string(10) "2147483648"
350}
351array(1) {
352  [0]=>
353  int(2147483647)
354}
355array(1) {
356  [0]=>
357  string(10) "4294967295"
358}
359array(1) {
360  [0]=>
361  string(10) "2147483649"
362}
363array(1) {
364  [0]=>
365  int(2147483647)
366}
367array(1) {
368  [0]=>
369  int(0)
370}
371array(1) {
372  [0]=>
373  int(0)
374}
375array(1) {
376  [0]=>
377  int(1)
378}
379array(1) {
380  [0]=>
381  int(100000)
382}
383array(1) {
384  [0]=>
385  string(10) "4293967296"
386}
387array(1) {
388  [0]=>
389  int(100000000)
390}
391array(1) {
392  [0]=>
393  string(10) "3294967296"
394}
395array(1) {
396  [0]=>
397  int(10)
398}
399array(1) {
400  [0]=>
401  int(1050000)
402}
403bool(false)
404
405-- iteration 6 --
406array(1) {
407  [0]=>
408  int(2147483647)
409}
410array(1) {
411  [0]=>
412  string(10) "2147483648"
413}
414array(1) {
415  [0]=>
416  int(2147483647)
417}
418array(1) {
419  [0]=>
420  string(10) "4294967295"
421}
422array(1) {
423  [0]=>
424  string(10) "2147483649"
425}
426array(1) {
427  [0]=>
428  int(2147483647)
429}
430array(1) {
431  [0]=>
432  int(0)
433}
434array(1) {
435  [0]=>
436  int(0)
437}
438array(1) {
439  [0]=>
440  int(1)
441}
442array(1) {
443  [0]=>
444  int(100000)
445}
446array(1) {
447  [0]=>
448  string(10) "4293967296"
449}
450array(1) {
451  [0]=>
452  int(100000000)
453}
454array(1) {
455  [0]=>
456  string(10) "3294967296"
457}
458array(1) {
459  [0]=>
460  int(10)
461}
462array(1) {
463  [0]=>
464  int(1050000)
465}
466bool(false)
467
468-- iteration 7 --
469
470Warning: fscanf(): Bad scan conversion character " " in %s on line %d
471NULL
472
473Warning: fscanf(): Bad scan conversion character " " in %s on line %d
474NULL
475
476Warning: fscanf(): Bad scan conversion character " " in %s on line %d
477NULL
478
479Warning: fscanf(): Bad scan conversion character " " in %s on line %d
480NULL
481
482Warning: fscanf(): Bad scan conversion character " " in %s on line %d
483NULL
484
485Warning: fscanf(): Bad scan conversion character " " in %s on line %d
486NULL
487
488Warning: fscanf(): Bad scan conversion character " " in %s on line %d
489NULL
490
491Warning: fscanf(): Bad scan conversion character " " in %s on line %d
492NULL
493
494Warning: fscanf(): Bad scan conversion character " " in %s on line %d
495NULL
496
497Warning: fscanf(): Bad scan conversion character " " in %s on line %d
498NULL
499
500Warning: fscanf(): Bad scan conversion character " " in %s on line %d
501NULL
502
503Warning: fscanf(): Bad scan conversion character " " in %s on line %d
504NULL
505
506Warning: fscanf(): Bad scan conversion character " " in %s on line %d
507NULL
508
509Warning: fscanf(): Bad scan conversion character " " in %s on line %d
510NULL
511
512Warning: fscanf(): Bad scan conversion character " " in %s on line %d
513NULL
514bool(false)
515
516-- iteration 8 --
517array(1) {
518  [0]=>
519  int(2147483647)
520}
521array(1) {
522  [0]=>
523  string(10) "2147483648"
524}
525array(1) {
526  [0]=>
527  int(2147483647)
528}
529array(1) {
530  [0]=>
531  string(10) "4294967295"
532}
533array(1) {
534  [0]=>
535  string(10) "2147483649"
536}
537array(1) {
538  [0]=>
539  int(2147483647)
540}
541array(1) {
542  [0]=>
543  int(0)
544}
545array(1) {
546  [0]=>
547  int(0)
548}
549array(1) {
550  [0]=>
551  int(1)
552}
553array(1) {
554  [0]=>
555  int(100000)
556}
557array(1) {
558  [0]=>
559  string(10) "4293967296"
560}
561array(1) {
562  [0]=>
563  int(100000000)
564}
565array(1) {
566  [0]=>
567  string(10) "3294967296"
568}
569array(1) {
570  [0]=>
571  int(10)
572}
573array(1) {
574  [0]=>
575  int(1050000)
576}
577bool(false)
578
579-- iteration 9 --
580array(1) {
581  [0]=>
582  int(2147483647)
583}
584array(1) {
585  [0]=>
586  string(10) "2147483648"
587}
588array(1) {
589  [0]=>
590  int(2147483647)
591}
592array(1) {
593  [0]=>
594  string(10) "4294967295"
595}
596array(1) {
597  [0]=>
598  string(10) "2147483649"
599}
600array(1) {
601  [0]=>
602  int(2147483647)
603}
604array(1) {
605  [0]=>
606  int(0)
607}
608array(1) {
609  [0]=>
610  int(0)
611}
612array(1) {
613  [0]=>
614  int(1)
615}
616array(1) {
617  [0]=>
618  int(100000)
619}
620array(1) {
621  [0]=>
622  string(10) "4293967296"
623}
624array(1) {
625  [0]=>
626  int(100000000)
627}
628array(1) {
629  [0]=>
630  string(10) "3294967296"
631}
632array(1) {
633  [0]=>
634  int(10)
635}
636array(1) {
637  [0]=>
638  int(1050000)
639}
640bool(false)
641
642-- iteration 10 --
643array(1) {
644  [0]=>
645  string(10) "4294967082"
646}
647array(1) {
648  [0]=>
649  int(2147)
650}
651array(1) {
652  [0]=>
653  string(10) "4294967082"
654}
655array(1) {
656  [0]=>
657  int(3435)
658}
659array(1) {
660  [0]=>
661  int(2147)
662}
663array(1) {
664  [0]=>
665  string(10) "4294967082"
666}
667array(1) {
668  [0]=>
669  int(0)
670}
671array(1) {
672  [0]=>
673  int(0)
674}
675array(1) {
676  [0]=>
677  int(1)
678}
679array(1) {
680  [0]=>
681  int(1000)
682}
683array(1) {
684  [0]=>
685  string(10) "4294967196"
686}
687array(1) {
688  [0]=>
689  int(1000)
690}
691array(1) {
692  [0]=>
693  string(10) "4294967196"
694}
695array(1) {
696  [0]=>
697  int(10)
698}
699array(1) {
700  [0]=>
701  int(1050)
702}
703bool(false)
704
705-- iteration 11 --
706array(1) {
707  [0]=>
708  int(2147483647)
709}
710array(1) {
711  [0]=>
712  string(10) "2147483648"
713}
714array(1) {
715  [0]=>
716  int(2147483647)
717}
718array(1) {
719  [0]=>
720  string(10) "4294967295"
721}
722array(1) {
723  [0]=>
724  string(10) "2147483649"
725}
726array(1) {
727  [0]=>
728  int(2147483647)
729}
730array(1) {
731  [0]=>
732  int(0)
733}
734array(1) {
735  [0]=>
736  int(0)
737}
738array(1) {
739  [0]=>
740  int(1)
741}
742array(1) {
743  [0]=>
744  int(100000)
745}
746array(1) {
747  [0]=>
748  string(10) "4293967296"
749}
750array(1) {
751  [0]=>
752  int(100000000)
753}
754array(1) {
755  [0]=>
756  string(10) "3294967296"
757}
758array(1) {
759  [0]=>
760  int(10)
761}
762array(1) {
763  [0]=>
764  int(1050000)
765}
766bool(false)
767
768-- iteration 12 --
769array(1) {
770  [0]=>
771  NULL
772}
773array(1) {
774  [0]=>
775  string(10) "2147483648"
776}
777array(1) {
778  [0]=>
779  NULL
780}
781array(1) {
782  [0]=>
783  string(11) "34359738369"
784}
785array(1) {
786  [0]=>
787  string(10) "2147483649"
788}
789array(1) {
790  [0]=>
791  NULL
792}
793array(1) {
794  [0]=>
795  string(1) "0"
796}
797array(1) {
798  [0]=>
799  NULL
800}
801array(1) {
802  [0]=>
803  string(1) "1"
804}
805array(1) {
806  [0]=>
807  string(6) "100000"
808}
809array(1) {
810  [0]=>
811  NULL
812}
813array(1) {
814  [0]=>
815  string(9) "100000000"
816}
817array(1) {
818  [0]=>
819  NULL
820}
821array(1) {
822  [0]=>
823  string(2) "10"
824}
825array(1) {
826  [0]=>
827  string(7) "1050000"
828}
829bool(false)
830
831-- iteration 13 --
832array(0) {
833}
834array(0) {
835}
836array(0) {
837}
838array(0) {
839}
840array(0) {
841}
842array(0) {
843}
844array(0) {
845}
846array(0) {
847}
848array(0) {
849}
850array(0) {
851}
852array(0) {
853}
854array(0) {
855}
856array(0) {
857}
858array(0) {
859}
860array(0) {
861}
862bool(false)
863
864*** Done ***
865