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