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