diff options
author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2013-03-14 05:42:27 +0000 |
---|---|---|
committer | <> | 2013-04-03 16:25:08 +0000 |
commit | c4dd7a1a684490673e25aaf4fabec5df138854c4 (patch) | |
tree | 4d57c44caae4480efff02b90b9be86f44bf25409 /ext/standard/tests/file/fscanf_error.phpt | |
download | php2-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_error.phpt')
-rw-r--r-- | ext/standard/tests/file/fscanf_error.phpt | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/ext/standard/tests/file/fscanf_error.phpt b/ext/standard/tests/file/fscanf_error.phpt new file mode 100644 index 0000000..85c0ac4 --- /dev/null +++ b/ext/standard/tests/file/fscanf_error.phpt @@ -0,0 +1,99 @@ +--TEST-- +Test fscanf() function: error conditions + +--FILE-- +<?php +/* + Prototype: mixed fscanf ( resource $handle, string $format [, mixed &$...] ); + Description: Parses input from a file according to a format +*/ + +echo "*** Testing fscanf() for error conditions ***\n"; +$file_path = dirname(__FILE__); + +$filename = "$file_path/fscanf_error.tmp"; +$file_handle = fopen($filename, 'w'); +if ($file_handle == false) + exit("Error:failed to open file $filename"); +fwrite($file_handle, "hello world"); +fclose($file_handle); + +// zero argument +var_dump( fscanf() ); + +// single argument +$file_handle = fopen($filename, 'r'); +if ($file_handle == false) + exit("Error:failed to open file $filename"); +var_dump( fscanf($file_handle) ); +fclose($file_handle); + +// invalid file handle +var_dump( fscanf($file_handle, "%s") ); + +// number of formats in format strings not matching the no of variables +$file_handle = fopen($filename, 'r'); +if ($file_handle == false) + exit("Error:failed to open file $filename"); +var_dump( fscanf($file_handle, "%d%s%f", $int_var, $string_var) ); +fclose($file_handle); + +// different invalid format strings +$invalid_formats = array( $undefined_var, undefined_constant, + "%", "%h", "%.", "%d%m" + ); + + +// looping to use various invalid formats with fscanf() +foreach($invalid_formats as $format) { + $file_handle = fopen($filename, 'r'); + if ($file_handle == false) + exit("Error:failed to open file $filename"); + var_dump( fscanf($file_handle, $format) ); + fclose($file_handle); +} + +echo "\n*** Done ***"; +?> +--CLEAN-- +<?php +$file_path = dirname(__FILE__); +$filename = "$file_path/fscanf_error.tmp"; +unlink($filename); +?> +--EXPECTF-- +*** Testing fscanf() for error conditions *** + +Warning: fscanf() expects at least 2 parameters, 0 given in %s on line %d +NULL + +Warning: fscanf() expects at least 2 parameters, 1 given in %s on line %d +NULL + +Warning: fscanf(): %d is not a valid File-Handle resource in %s on line %d +bool(false) + +Warning: fscanf(): Different numbers of variable names and field specifiers in %s on line %d +int(-1) + +Notice: Undefined variable: undefined_var in %s on line %d + +Notice: Use of undefined constant undefined_constant - assumed 'undefined_constant' in %s on line %d +array(0) { +} +array(0) { +} + +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 "m" in %s on line %d +NULL + +*** Done *** |