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