summaryrefslogtreecommitdiff
path: root/ext/standard/tests/file/fscanf_variation7.phpt
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@baserock.org>2013-03-14 05:42:27 +0000
committer <>2013-04-03 16:25:08 +0000
commitc4dd7a1a684490673e25aaf4fabec5df138854c4 (patch)
tree4d57c44caae4480efff02b90b9be86f44bf25409 /ext/standard/tests/file/fscanf_variation7.phpt
downloadphp2-master.tar.gz
Imported from /home/lorry/working-area/delta_php2/php-5.4.13.tar.bz2.HEADphp-5.4.13master
Diffstat (limited to 'ext/standard/tests/file/fscanf_variation7.phpt')
-rw-r--r--ext/standard/tests/file/fscanf_variation7.phpt246
1 files changed, 246 insertions, 0 deletions
diff --git a/ext/standard/tests/file/fscanf_variation7.phpt b/ext/standard/tests/file/fscanf_variation7.phpt
new file mode 100644
index 0000000..33354e7
--- /dev/null
+++ b/ext/standard/tests/file/fscanf_variation7.phpt
@@ -0,0 +1,246 @@
+--TEST--
+Test fscanf() function: usage variations - integer formats with boolean
+--FILE--
+<?php
+
+/*
+ Prototype: mixed fscanf ( resource $handle, string $format [, mixed &$...] );
+ Description: Parses input from a file according to a format
+*/
+
+/* Test fscanf() to scan boolean data using different integer format types */
+
+$file_path = dirname(__FILE__);
+
+echo "*** Test fscanf(): different integer format types with boolean data ***\n";
+
+// create a file
+$filename = "$file_path/fscanf_variation7.tmp";
+$file_handle = fopen($filename, "w");
+if($file_handle == false)
+ exit("Error:failed to open file $filename");
+
+// array of boolean types
+$bool_types = array (
+ true,
+ false,
+ TRUE,
+ FALSE,
+);
+
+$int_formats = array( "%d", "%hd", "%ld", "%Ld", " %d", "%d ", "% d", "\t%d", "\n%d", "%4d", "%30d", "%[0-9]", "%*d");
+
+$counter = 1;
+
+// writing to the file
+foreach($bool_types as $value) {
+ @fprintf($file_handle, $value);
+ @fprintf($file_handle, "\n");
+}
+// closing the file
+fclose($file_handle);
+
+// opening the file for reading
+$file_handle = fopen($filename, "r");
+if($file_handle == false) {
+ exit("Error:failed to open file $filename");
+}
+
+$counter = 1;
+// reading the values from file using different integer formats
+foreach($int_formats as $int_format) {
+ // rewind the file so that for every foreach iteration the file pointer starts from bof
+ rewind($file_handle);
+ echo "\n-- iteration $counter --\n";
+ while( !feof($file_handle) ) {
+ var_dump( fscanf($file_handle,$int_format) );
+ }
+ $counter++;
+}
+
+echo "\n*** Done ***";
+?>
+--CLEAN--
+<?php
+$file_path = dirname(__FILE__);
+$filename = "$file_path/fscanf_variation7.tmp";
+unlink($filename);
+?>
+--EXPECTF--
+*** Test fscanf(): different integer format types with boolean data ***
+
+-- iteration 1 --
+array(1) {
+ [0]=>
+ int(1)
+}
+NULL
+array(1) {
+ [0]=>
+ int(1)
+}
+NULL
+bool(false)
+
+-- iteration 2 --
+array(1) {
+ [0]=>
+ int(1)
+}
+NULL
+array(1) {
+ [0]=>
+ int(1)
+}
+NULL
+bool(false)
+
+-- iteration 3 --
+array(1) {
+ [0]=>
+ int(1)
+}
+NULL
+array(1) {
+ [0]=>
+ int(1)
+}
+NULL
+bool(false)
+
+-- iteration 4 --
+array(1) {
+ [0]=>
+ int(1)
+}
+NULL
+array(1) {
+ [0]=>
+ int(1)
+}
+NULL
+bool(false)
+
+-- iteration 5 --
+array(1) {
+ [0]=>
+ int(1)
+}
+NULL
+array(1) {
+ [0]=>
+ int(1)
+}
+NULL
+bool(false)
+
+-- iteration 6 --
+array(1) {
+ [0]=>
+ int(1)
+}
+NULL
+array(1) {
+ [0]=>
+ int(1)
+}
+NULL
+bool(false)
+
+-- iteration 7 --
+
+Warning: fscanf(): Bad scan conversion character " " in %s on line %d
+NULL
+
+Warning: fscanf(): Bad scan conversion character " " in %s on line %d
+NULL
+
+Warning: fscanf(): Bad scan conversion character " " in %s on line %d
+NULL
+
+Warning: fscanf(): Bad scan conversion character " " in %s on line %d
+NULL
+bool(false)
+
+-- iteration 8 --
+array(1) {
+ [0]=>
+ int(1)
+}
+NULL
+array(1) {
+ [0]=>
+ int(1)
+}
+NULL
+bool(false)
+
+-- iteration 9 --
+array(1) {
+ [0]=>
+ int(1)
+}
+NULL
+array(1) {
+ [0]=>
+ int(1)
+}
+NULL
+bool(false)
+
+-- iteration 10 --
+array(1) {
+ [0]=>
+ int(1)
+}
+NULL
+array(1) {
+ [0]=>
+ int(1)
+}
+NULL
+bool(false)
+
+-- iteration 11 --
+array(1) {
+ [0]=>
+ int(1)
+}
+NULL
+array(1) {
+ [0]=>
+ int(1)
+}
+NULL
+bool(false)
+
+-- iteration 12 --
+array(1) {
+ [0]=>
+ string(1) "1"
+}
+array(1) {
+ [0]=>
+ NULL
+}
+array(1) {
+ [0]=>
+ string(1) "1"
+}
+array(1) {
+ [0]=>
+ NULL
+}
+bool(false)
+
+-- iteration 13 --
+array(0) {
+}
+NULL
+array(0) {
+}
+NULL
+bool(false)
+
+*** Done ***
+