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