Annotation of embedaddon/php/ext/standard/tests/file/fscanf_variation3.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test fscanf() function: usage variations - integer formats with float 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 float values using different integer format types */
18:
19: $file_path = dirname(__FILE__);
20:
21: echo "*** Test fscanf(): different integer format types with float values ***\n";
22:
23: // create a file
24: $filename = "$file_path/fscanf_variation3.tmp";
25: $file_handle = fopen($filename, "w");
26: if($file_handle == false)
27: exit("Error:failed to open file $filename");
28:
29: // array of float type values
30:
31: $float_values = array (
32: -2147483649,
33: 2147483648,
34: -0x80000001, // float value, beyond max negative int
35: 0x800000001, // float value, beyond max positive int
36: 020000000001, // float value, beyond max positive int
37: -020000000001, // float value, beyond max negative int
38: 0.0,
39: -0.1,
40: 1.0,
41: 1e5,
42: -1e6,
43: 1E8,
44: -1E9,
45: 10.0000000000000000005,
46: 10.5e+5
47: );
48:
49: $int_formats = array( "%d", "%hd", "%ld", "%Ld", " %d", "%d ", "% d", "\t%d", "\n%d", "%4d", "%30d", "%[0-9]", "%*d");
50:
51: $counter = 1;
52:
53: // writing to the file
54: foreach($float_values as $value) {
55: @fprintf($file_handle, $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 integer formats
69: foreach($int_formats as $int_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,$int_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_variation3.tmp";
85: unlink($filename);
86: ?>
87: --EXPECTF--
88: *** Test fscanf(): different integer format types with float values ***
89:
90: -- iteration 1 --
91: array(1) {
92: [0]=>
93: int(-2147483648)
94: }
95: array(1) {
96: [0]=>
97: int(2147483647)
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(-2147483648)
114: }
115: array(1) {
116: [0]=>
117: int(0)
118: }
119: array(1) {
120: [0]=>
121: int(0)
122: }
123: array(1) {
124: [0]=>
125: int(1)
126: }
127: array(1) {
128: [0]=>
129: int(100000)
130: }
131: array(1) {
132: [0]=>
133: int(-1000000)
134: }
135: array(1) {
136: [0]=>
137: int(100000000)
138: }
139: array(1) {
140: [0]=>
141: int(-1000000000)
142: }
143: array(1) {
144: [0]=>
145: int(10)
146: }
147: array(1) {
148: [0]=>
149: int(1050000)
150: }
151: bool(false)
152:
153: -- iteration 2 --
154: array(1) {
155: [0]=>
156: int(-2147483648)
157: }
158: array(1) {
159: [0]=>
160: int(2147483647)
161: }
162: array(1) {
163: [0]=>
164: int(-2147483648)
165: }
166: array(1) {
167: [0]=>
168: int(2147483647)
169: }
170: array(1) {
171: [0]=>
172: int(2147483647)
173: }
174: array(1) {
175: [0]=>
176: int(-2147483648)
177: }
178: array(1) {
179: [0]=>
180: int(0)
181: }
182: array(1) {
183: [0]=>
184: int(0)
185: }
186: array(1) {
187: [0]=>
188: int(1)
189: }
190: array(1) {
191: [0]=>
192: int(100000)
193: }
194: array(1) {
195: [0]=>
196: int(-1000000)
197: }
198: array(1) {
199: [0]=>
200: int(100000000)
201: }
202: array(1) {
203: [0]=>
204: int(-1000000000)
205: }
206: array(1) {
207: [0]=>
208: int(10)
209: }
210: array(1) {
211: [0]=>
212: int(1050000)
213: }
214: bool(false)
215:
216: -- iteration 3 --
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(-2147483648)
228: }
229: array(1) {
230: [0]=>
231: int(2147483647)
232: }
233: array(1) {
234: [0]=>
235: int(2147483647)
236: }
237: array(1) {
238: [0]=>
239: int(-2147483648)
240: }
241: array(1) {
242: [0]=>
243: int(0)
244: }
245: array(1) {
246: [0]=>
247: int(0)
248: }
249: array(1) {
250: [0]=>
251: int(1)
252: }
253: array(1) {
254: [0]=>
255: int(100000)
256: }
257: array(1) {
258: [0]=>
259: int(-1000000)
260: }
261: array(1) {
262: [0]=>
263: int(100000000)
264: }
265: array(1) {
266: [0]=>
267: int(-1000000000)
268: }
269: array(1) {
270: [0]=>
271: int(10)
272: }
273: array(1) {
274: [0]=>
275: int(1050000)
276: }
277: bool(false)
278:
279: -- iteration 4 --
280: array(1) {
281: [0]=>
282: int(-2147483648)
283: }
284: array(1) {
285: [0]=>
286: int(2147483647)
287: }
288: array(1) {
289: [0]=>
290: int(-2147483648)
291: }
292: array(1) {
293: [0]=>
294: int(2147483647)
295: }
296: array(1) {
297: [0]=>
298: int(2147483647)
299: }
300: array(1) {
301: [0]=>
302: int(-2147483648)
303: }
304: array(1) {
305: [0]=>
306: int(0)
307: }
308: array(1) {
309: [0]=>
310: int(0)
311: }
312: array(1) {
313: [0]=>
314: int(1)
315: }
316: array(1) {
317: [0]=>
318: int(100000)
319: }
320: array(1) {
321: [0]=>
322: int(-1000000)
323: }
324: array(1) {
325: [0]=>
326: int(100000000)
327: }
328: array(1) {
329: [0]=>
330: int(-1000000000)
331: }
332: array(1) {
333: [0]=>
334: int(10)
335: }
336: array(1) {
337: [0]=>
338: int(1050000)
339: }
340: bool(false)
341:
342: -- iteration 5 --
343: array(1) {
344: [0]=>
345: int(-2147483648)
346: }
347: array(1) {
348: [0]=>
349: int(2147483647)
350: }
351: array(1) {
352: [0]=>
353: int(-2147483648)
354: }
355: array(1) {
356: [0]=>
357: int(2147483647)
358: }
359: array(1) {
360: [0]=>
361: int(2147483647)
362: }
363: array(1) {
364: [0]=>
365: int(-2147483648)
366: }
367: array(1) {
368: [0]=>
369: int(0)
370: }
371: array(1) {
372: [0]=>
373: int(0)
374: }
375: array(1) {
376: [0]=>
377: int(1)
378: }
379: array(1) {
380: [0]=>
381: int(100000)
382: }
383: array(1) {
384: [0]=>
385: int(-1000000)
386: }
387: array(1) {
388: [0]=>
389: int(100000000)
390: }
391: array(1) {
392: [0]=>
393: int(-1000000000)
394: }
395: array(1) {
396: [0]=>
397: int(10)
398: }
399: array(1) {
400: [0]=>
401: int(1050000)
402: }
403: bool(false)
404:
405: -- iteration 6 --
406: array(1) {
407: [0]=>
408: int(-2147483648)
409: }
410: array(1) {
411: [0]=>
412: int(2147483647)
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(-2147483648)
429: }
430: array(1) {
431: [0]=>
432: int(0)
433: }
434: array(1) {
435: [0]=>
436: int(0)
437: }
438: array(1) {
439: [0]=>
440: int(1)
441: }
442: array(1) {
443: [0]=>
444: int(100000)
445: }
446: array(1) {
447: [0]=>
448: int(-1000000)
449: }
450: array(1) {
451: [0]=>
452: int(100000000)
453: }
454: array(1) {
455: [0]=>
456: int(-1000000000)
457: }
458: array(1) {
459: [0]=>
460: int(10)
461: }
462: array(1) {
463: [0]=>
464: int(1050000)
465: }
466: bool(false)
467:
468: -- iteration 7 --
469:
470: Warning: fscanf(): Bad scan conversion character " " in %s on line %d
471: NULL
472:
473: Warning: fscanf(): Bad scan conversion character " " in %s on line %d
474: NULL
475:
476: Warning: fscanf(): Bad scan conversion character " " in %s on line %d
477: NULL
478:
479: Warning: fscanf(): Bad scan conversion character " " in %s on line %d
480: NULL
481:
482: Warning: fscanf(): Bad scan conversion character " " in %s on line %d
483: NULL
484:
485: Warning: fscanf(): Bad scan conversion character " " in %s on line %d
486: NULL
487:
488: Warning: fscanf(): Bad scan conversion character " " in %s on line %d
489: NULL
490:
491: Warning: fscanf(): Bad scan conversion character " " in %s on line %d
492: NULL
493:
494: Warning: fscanf(): Bad scan conversion character " " in %s on line %d
495: NULL
496:
497: Warning: fscanf(): Bad scan conversion character " " in %s on line %d
498: NULL
499:
500: Warning: fscanf(): Bad scan conversion character " " in %s on line %d
501: NULL
502:
503: Warning: fscanf(): Bad scan conversion character " " in %s on line %d
504: NULL
505:
506: Warning: fscanf(): Bad scan conversion character " " in %s on line %d
507: NULL
508:
509: Warning: fscanf(): Bad scan conversion character " " in %s on line %d
510: NULL
511:
512: Warning: fscanf(): Bad scan conversion character " " in %s on line %d
513: NULL
514: bool(false)
515:
516: -- iteration 8 --
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(-2147483648)
528: }
529: array(1) {
530: [0]=>
531: int(2147483647)
532: }
533: array(1) {
534: [0]=>
535: int(2147483647)
536: }
537: array(1) {
538: [0]=>
539: int(-2147483648)
540: }
541: array(1) {
542: [0]=>
543: int(0)
544: }
545: array(1) {
546: [0]=>
547: int(0)
548: }
549: array(1) {
550: [0]=>
551: int(1)
552: }
553: array(1) {
554: [0]=>
555: int(100000)
556: }
557: array(1) {
558: [0]=>
559: int(-1000000)
560: }
561: array(1) {
562: [0]=>
563: int(100000000)
564: }
565: array(1) {
566: [0]=>
567: int(-1000000000)
568: }
569: array(1) {
570: [0]=>
571: int(10)
572: }
573: array(1) {
574: [0]=>
575: int(1050000)
576: }
577: bool(false)
578:
579: -- iteration 9 --
580: array(1) {
581: [0]=>
582: int(-2147483648)
583: }
584: array(1) {
585: [0]=>
586: int(2147483647)
587: }
588: array(1) {
589: [0]=>
590: int(-2147483648)
591: }
592: array(1) {
593: [0]=>
594: int(2147483647)
595: }
596: array(1) {
597: [0]=>
598: int(2147483647)
599: }
600: array(1) {
601: [0]=>
602: int(-2147483648)
603: }
604: array(1) {
605: [0]=>
606: int(0)
607: }
608: array(1) {
609: [0]=>
610: int(0)
611: }
612: array(1) {
613: [0]=>
614: int(1)
615: }
616: array(1) {
617: [0]=>
618: int(100000)
619: }
620: array(1) {
621: [0]=>
622: int(-1000000)
623: }
624: array(1) {
625: [0]=>
626: int(100000000)
627: }
628: array(1) {
629: [0]=>
630: int(-1000000000)
631: }
632: array(1) {
633: [0]=>
634: int(10)
635: }
636: array(1) {
637: [0]=>
638: int(1050000)
639: }
640: bool(false)
641:
642: -- iteration 10 --
643: array(1) {
644: [0]=>
645: int(-214)
646: }
647: array(1) {
648: [0]=>
649: int(2147)
650: }
651: array(1) {
652: [0]=>
653: int(-214)
654: }
655: array(1) {
656: [0]=>
657: int(3435)
658: }
659: array(1) {
660: [0]=>
661: int(2147)
662: }
663: array(1) {
664: [0]=>
665: int(-214)
666: }
667: array(1) {
668: [0]=>
669: int(0)
670: }
671: array(1) {
672: [0]=>
673: int(0)
674: }
675: array(1) {
676: [0]=>
677: int(1)
678: }
679: array(1) {
680: [0]=>
681: int(1000)
682: }
683: array(1) {
684: [0]=>
685: int(-100)
686: }
687: array(1) {
688: [0]=>
689: int(1000)
690: }
691: array(1) {
692: [0]=>
693: int(-100)
694: }
695: array(1) {
696: [0]=>
697: int(10)
698: }
699: array(1) {
700: [0]=>
701: int(1050)
702: }
703: bool(false)
704:
705: -- iteration 11 --
706: array(1) {
707: [0]=>
708: int(-2147483648)
709: }
710: array(1) {
711: [0]=>
712: int(2147483647)
713: }
714: array(1) {
715: [0]=>
716: int(-2147483648)
717: }
718: array(1) {
719: [0]=>
720: int(2147483647)
721: }
722: array(1) {
723: [0]=>
724: int(2147483647)
725: }
726: array(1) {
727: [0]=>
728: int(-2147483648)
729: }
730: array(1) {
731: [0]=>
732: int(0)
733: }
734: array(1) {
735: [0]=>
736: int(0)
737: }
738: array(1) {
739: [0]=>
740: int(1)
741: }
742: array(1) {
743: [0]=>
744: int(100000)
745: }
746: array(1) {
747: [0]=>
748: int(-1000000)
749: }
750: array(1) {
751: [0]=>
752: int(100000000)
753: }
754: array(1) {
755: [0]=>
756: int(-1000000000)
757: }
758: array(1) {
759: [0]=>
760: int(10)
761: }
762: array(1) {
763: [0]=>
764: int(1050000)
765: }
766: bool(false)
767:
768: -- iteration 12 --
769: array(1) {
770: [0]=>
771: NULL
772: }
773: array(1) {
774: [0]=>
775: string(10) "2147483648"
776: }
777: array(1) {
778: [0]=>
779: NULL
780: }
781: array(1) {
782: [0]=>
783: string(11) "34359738369"
784: }
785: array(1) {
786: [0]=>
787: string(10) "2147483649"
788: }
789: array(1) {
790: [0]=>
791: NULL
792: }
793: array(1) {
794: [0]=>
795: string(1) "0"
796: }
797: array(1) {
798: [0]=>
799: NULL
800: }
801: array(1) {
802: [0]=>
803: string(1) "1"
804: }
805: array(1) {
806: [0]=>
807: string(6) "100000"
808: }
809: array(1) {
810: [0]=>
811: NULL
812: }
813: array(1) {
814: [0]=>
815: string(9) "100000000"
816: }
817: array(1) {
818: [0]=>
819: NULL
820: }
821: array(1) {
822: [0]=>
823: string(2) "10"
824: }
825: array(1) {
826: [0]=>
827: string(7) "1050000"
828: }
829: bool(false)
830:
831: -- iteration 13 --
832: array(0) {
833: }
834: array(0) {
835: }
836: array(0) {
837: }
838: array(0) {
839: }
840: array(0) {
841: }
842: array(0) {
843: }
844: array(0) {
845: }
846: array(0) {
847: }
848: array(0) {
849: }
850: array(0) {
851: }
852: array(0) {
853: }
854: array(0) {
855: }
856: array(0) {
857: }
858: array(0) {
859: }
860: array(0) {
861: }
862: bool(false)
863:
864: *** Done ***
865:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>