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