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