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