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