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