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