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