diff options
author | Anatol Belski <ab@php.net> | 2016-06-20 09:32:19 +0200 |
---|---|---|
committer | Anatol Belski <ab@php.net> | 2016-06-20 12:45:39 +0200 |
commit | 3d3f11ede4cc7c83d64cc5edaae7c29ce9c6986f (patch) | |
tree | 0a569a11fc09514f52e08a887e82a4ad91ff2afd /ext/standard/tests/dir | |
parent | 3abd9c34c1e7249db92014a82b4430393c53928c (diff) | |
download | php-git-3d3f11ede4cc7c83d64cc5edaae7c29ce9c6986f.tar.gz |
Fixed the UTF-8 and long path support in the streams on Windows.
Since long the default PHP charset is UTF-8, however the Windows part is
out of step with this important point. The current implementation in PHP
doesn't technically permit to handle UTF-8 filepath and several other
things. Till now, only the ANSI compatible APIs are being used. Here is more
about it
https://msdn.microsoft.com/en-us/library/windows/desktop/dd317752%28v=vs.85%29.aspx
The patch fixes not only issues with multibyte filenames under
incompatible codepages, but indirectly also issues with some other multibyte
encodings like BIG5, Shift-JIS, etc. by providing a clean way to access
filenames in UTF-8. Below is a small list of issues from the bug tracker,
that are getting fixed:
https://bugs.php.net/63401
https://bugs.php.net/41199
https://bugs.php.net/50203
https://bugs.php.net/71509
https://bugs.php.net/64699
https://bugs.php.net/64506
https://bugs.php.net/30195
https://bugs.php.net/65358
https://bugs.php.net/61315
https://bugs.php.net/70943
https://bugs.php.net/70903
https://bugs.php.net/63593
https://bugs.php.net/54977
https://bugs.php.net/54028
https://bugs.php.net/43148
https://bugs.php.net/30730
https://bugs.php.net/33350
https://bugs.php.net/35300
https://bugs.php.net/46990
https://bugs.php.net/61309
https://bugs.php.net/69333
https://bugs.php.net/45517
https://bugs.php.net/70551
https://bugs.php.net/50197
https://bugs.php.net/72200
https://bugs.php.net/37672
Yet more related tickets can for sure be found - on bugs.php.net, Stackoverflow
and Github. Some of the bugs are pretty recent, some descend to early
2000th, but the user comments in there last even till today. Just for example,
bug #30195 was opened in 2004, the latest comment in there was made in 2014. It
is certain, that these bugs descend not only to pure PHP use cases, but get also
redirected from the popular PHP based projects. Given the modern systems (and
those supported by PHP) are always based on NTFS, there is no excuse to keep
these issues unresolved.
The internalization approach on Windows is in many ways different from
UNIX and Linux, while it supports and is based on Unicode. It depends on the
current system code page, APIs used and exact kind how the binary was compiled
The locale doesn't affect the way Unicode or ANSI API work. PHP in particular
is being compiled without _UNICODE defined and this is conditioned by the
way we handle strings. Here is more about it
https://msdn.microsoft.com/en-us/library/tsbaswba.aspx
However, with any system code page ANSI functions automatically convert
paths to UTF-16. Paths in some encodings incompatible with the
current system code page, won't work correctly with ANSI APIs. PHP
till now only uses the ANSI Windows APIs.
For example, on a system with the current code page 1252, the paths
in cp1252 are supported and transparently converted to UTF-16 by the
ANSI functions. Once one wants to handle a filepath encoded with cp932 on
that particular system, an ANSI or a POSIX compatible function used in
PHP will produce an erroneous result. When trying to convert that cp932 path
to UTF-8 and passing to the ANSI functions, an ANSI function would
likely interpret the UTF-8 string as some string in the current code page and
create a filepath that represents every single byte of the UTF-8 string.
These behaviors are not only broken but also disregard the documented
INI settings.
This patch solves the issies with the multibyte paths on Windows by
intelligently enforcing the usage of the Unicode aware APIs. For
functions expect Unicode (fe CreateFileW, FindFirstFileW, etc.), arguments
will be converted to UTF-16 wide chars. For functions returning Unicode
aware data (fe GetCurrentDirectoryW, etc.), resulting wide string is
converted back to char's depending on the current PHP charset settings,
either to the current ANSI codepage (this is the behavior prior to this patch)
or to UTF-8 (the default behavior).
In a particular case, users might have to explicitly set
internal_encoding or default_charset, if filenames in ANSI codepage are
necessary. Current tests show no regressions and witness that this will be an
exotic case, the current default UTF-8 encoding is compatible with any
supported system. The dependency libraries are long switching to Unicode APIs,
so some tests were also added for extensions not directly related to streams.
At large, the patch brings over 150 related tests into the core. Those target
and was run on various environments with European, Asian, etc. codepages.
General PHP frameworks was tested and showed no regressions.
The impact on the current C code base is low, the most places affected
are the Windows only places in the three files tsrm_win32.c, zend_virtual_cwd.c
and plain_wrapper.c. The actual implementation of the most of the wide
char supporting functionality is in win32/ioutil.* and win32/codepage.*,
several low level functionsare extended in place to avoid reimplementation for
now. No performance impact was sighted. As previously mentioned, the ANSI APIs
used prior the patch perform Unicode conversions internally. Using the
Unicode APIs directly while doing custom conversions just retains the status
quo. The ways to optimize it are open (fe. by implementing caching for the
strings converted to wide variants).
The long path implementation is user transparent. If a path exceeds the
length of _MAX_PATH, it'll be automatically prefixed with \\?\. The MAXPATHLEN
is set to 2048 bytes.
Appreciation to Pierre Joye, Matt Ficken, @algo13 and others for tips, ideas
and testing.
Thanks.
Diffstat (limited to 'ext/standard/tests/dir')
34 files changed, 3356 insertions, 0 deletions
diff --git a/ext/standard/tests/dir/chdir_basic-win32-mb.phpt b/ext/standard/tests/dir/chdir_basic-win32-mb.phpt new file mode 100644 index 0000000000..db08d51f40 --- /dev/null +++ b/ext/standard/tests/dir/chdir_basic-win32-mb.phpt @@ -0,0 +1,54 @@ +--TEST-- +Test chdir() function : basic functionality +--FILE-- +<?php +/* Prototype : bool chdir(string $directory) + * Description: Change the current directory + * Source code: ext/standard/dir.c + */ + +/* + * Test basic functionality of chdir() with absolute and relative paths + */ + +echo "*** Testing chdir() : basic functionality ***\n"; +$base_dir_path = dirname(__FILE__); + +$level_one_dir_name = "私はガラスを食べられますlevel_one"; +$level_one_dir_path = "$base_dir_path/$level_one_dir_name"; + +$level_two_dir_name = "私はガラスを食べられますlevel_two"; +$level_two_dir_path = "$base_dir_path/$level_one_dir_name/$level_two_dir_name"; + +// create directories +mkdir($level_one_dir_path); +mkdir($level_two_dir_path); + +echo "\n-- Testing chdir() with absolute path: --\n"; +chdir($base_dir_path); +var_dump(chdir($level_one_dir_path)); +var_dump(getcwd()); + +echo "\n-- Testing chdir() with relative paths: --\n"; +var_dump(chdir($level_two_dir_name)); +var_dump(getcwd()); +?> +===DONE=== +--CLEAN-- +<?php +$file_path = dirname(__FILE__); +chdir($file_path); +rmdir("$file_path/私はガラスを食べられますlevel_one/私はガラスを食べられますlevel_two"); +rmdir("$file_path/私はガラスを食べられますlevel_one"); +?> +--EXPECTF-- +*** Testing chdir() : basic functionality *** + +-- Testing chdir() with absolute path: -- +bool(true) +string(%d) "%s私はガラスを食べられますlevel_one" + +-- Testing chdir() with relative paths: -- +bool(true) +string(%d) "%s私はガラスを食べられますlevel_one%e私はガラスを食べられますlevel_two" +===DONE=== diff --git a/ext/standard/tests/dir/chdir_error2-win32-mb.phpt b/ext/standard/tests/dir/chdir_error2-win32-mb.phpt new file mode 100644 index 0000000000..a1f08939ed --- /dev/null +++ b/ext/standard/tests/dir/chdir_error2-win32-mb.phpt @@ -0,0 +1,26 @@ +--TEST-- +Test chdir() function : error conditions - Non-existent directory +--FILE-- +<?php +/* Prototype : bool chdir(string $directory) + * Description: Change the current directory + * Source code: ext/standard/dir.c + */ + +/* + * Pass a directory that does not exist as $directory to chdir() to test behaviour + */ + +echo "*** Testing chdir() : error conditions ***\n"; + +$directory = __FILE__ . '/私はガラスを食べられますidonotexist'; + +var_dump(chdir($directory)); +?> +===DONE=== +--EXPECTF-- +*** Testing chdir() : error conditions *** + +Warning: chdir(): %s (errno %d) in %s on line %d +bool(false) +===DONE=== diff --git a/ext/standard/tests/dir/chdir_variation1-win32-mb.phpt b/ext/standard/tests/dir/chdir_variation1-win32-mb.phpt new file mode 100644 index 0000000000..04fbc0bc18 --- /dev/null +++ b/ext/standard/tests/dir/chdir_variation1-win32-mb.phpt @@ -0,0 +1,235 @@ +--TEST-- +Test chdir() function : usage variations - different data type as $directory arg +--FILE-- +<?php +/* Prototype : bool chdir(string $directory) + * Description: Change the current directory + * Source code: ext/standard/dir.c + */ + +/* + * Pass different data types as $directory argument to test behaviour + */ + +echo "*** Testing chdir() : usage variations ***\n"; + +// create the temporary directory +$file_path = dirname(__FILE__); +$dir_path = $file_path."/私はガラスを食べられますchdir_basic"; +@mkdir($dir_path); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA { + var $dir_path; + + function __construct($dir) { + $this->dir_path = $dir; + } + + public function __toString() { + return "$this->dir_path"; + } +} + +// heredoc string +$heredoc = <<<EOT +$dir_path +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $directory argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + array(), + + // string data +/*19*/ "$dir_path", + 'string', + $heredoc, + + // object data +/*22*/ new classA($dir_path), + + // undefined data +/*23*/ @$undefined_var, + + // unset data +/*24*/ @$unset_var, + + // resource variable +/*25*/ $fp +); + +// loop through each element of $inputs to check the behavior of chdir() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( chdir($input) ); + $iterator++; +}; + +fclose($fp); + +?> +===DONE=== +--CLEAN-- +<?php +$file_path = dirname(__FILE__); +$dir_path = $file_path."/私はガラスを食べられますchdir_basic"; + +rmdir($dir_path); +?> +--EXPECTF-- +*** Testing chdir() : usage variations *** + +-- Iteration 1 -- + +Warning: chdir(): %s (errno %d) in %s on line %d +bool(false) + +-- Iteration 2 -- + +Warning: chdir(): %s (errno %d) in %s on line %d +bool(false) + +-- Iteration 3 -- + +Warning: chdir(): %s (errno %d) in %s on line %d +bool(false) + +-- Iteration 4 -- + +Warning: chdir(): %s (errno %d) in %s on line %d +bool(false) + +-- Iteration 5 -- + +Warning: chdir(): %s (errno %d) in %s on line %d +bool(false) + +-- Iteration 6 -- + +Warning: chdir(): %s (errno %d) in %s on line %d +bool(false) + +-- Iteration 7 -- + +Warning: chdir(): %s (errno %d) in %s on line %d +bool(false) + +-- Iteration 8 -- + +Warning: chdir(): %s (errno %d) in %s on line %d +bool(false) + +-- Iteration 9 -- + +Warning: chdir(): %s (errno %d) in %s on line %d +bool(false) + +-- Iteration 10 -- + +Warning: chdir(): %s (errno %d) in %s on line %d +bool(false) + +-- Iteration 11 -- + +Warning: chdir(): %s (errno %d) in %s on line %d +bool(false) + +-- Iteration 12 -- + +Warning: chdir(): %s (errno %d) in %s on line %d +bool(false) + +-- Iteration 13 -- + +Warning: chdir(): %s (errno %d) in %s on line %d +bool(false) + +-- Iteration 14 -- + +Warning: chdir(): %s (errno %d) in %s on line %d +bool(false) + +-- Iteration 15 -- + +Warning: chdir(): %s (errno %d) in %s on line %d +bool(false) + +-- Iteration 16 -- + +Warning: chdir(): %s (errno %d) in %s on line %d +bool(false) + +-- Iteration 17 -- + +Warning: chdir(): %s (errno %d) in %s on line %d +bool(false) + +-- Iteration 18 -- + +Warning: chdir() expects parameter 1 to be a valid path, array given in %s on line %d +bool(false) + +-- Iteration 19 -- +bool(true) + +-- Iteration 20 -- + +Warning: chdir(): %s (errno %d) in %s on line %d +bool(false) + +-- Iteration 21 -- +bool(true) + +-- Iteration 22 -- +bool(true) + +-- Iteration 23 -- + +Warning: chdir(): %s (errno %d) in %s on line %d +bool(false) + +-- Iteration 24 -- + +Warning: chdir(): %s (errno %d) in %s on line %d +bool(false) + +-- Iteration 25 -- + +Warning: chdir() expects parameter 1 to be a valid path, resource given in %s on line %d +bool(false) +===DONE=== diff --git a/ext/standard/tests/dir/chdir_variation2-win32-mb.phpt b/ext/standard/tests/dir/chdir_variation2-win32-mb.phpt new file mode 100644 index 0000000000..ad1f6b665a --- /dev/null +++ b/ext/standard/tests/dir/chdir_variation2-win32-mb.phpt @@ -0,0 +1,109 @@ +--TEST-- +Test chdir() function : usage variations - relative paths +--FILE-- +<?php +/* Prototype : bool chdir(string $directory) + * Description: Change the current directory + * Source code: ext/standard/dir.c + */ + +/* + * Test chdir() with variations of relative paths + */ + +echo "*** Testing chdir() : usage variations ***\n"; + +$base_dir_path = dirname(__FILE__); + +$level_one_dir_name = "私はガラスを食べられますlevel_one"; +$level_one_dir_path = "$base_dir_path/$level_one_dir_name"; + +$level_two_dir_name = "私はガラスを食べられますlevel_two"; +$level_two_dir_path = "$base_dir_path/$level_one_dir_name/$level_two_dir_name"; + +// create directories +mkdir($level_one_dir_path); +mkdir($level_two_dir_path); + +echo "\n-- \$directory = './私はガラスを食べられますlevel_one': --\n"; +var_dump(chdir($base_dir_path)); +var_dump(chdir("./$level_one_dir_name")); +var_dump(getcwd()); + +echo "\n-- \$directory = '私はガラスを食べられますlevel_one/私はガラスを食べられますlevel_two': --\n"; +var_dump(chdir($base_dir_path)); +var_dump(chdir("$level_one_dir_name/$level_two_dir_name")); +var_dump(getcwd()); + +echo "\n-- \$directory = '..': --\n"; +var_dump(chdir('..')); +var_dump(getcwd()); + +echo "\n-- \$directory = '私はガラスを食べられますlevel_two', '.': --\n"; +var_dump(chdir($level_two_dir_path)); +var_dump(chdir('.')); +var_dump(getcwd()); + +echo "\n-- \$directory = '../': --\n"; +var_dump(chdir('../')); +var_dump(getcwd()); + +echo "\n-- \$directory = './': --\n"; +var_dump(chdir($level_two_dir_path)); +var_dump(chdir('./')); +var_dump(getcwd()); + +echo "\n-- \$directory = '../../'私はガラスを食べられますlevel_one': --\n"; +var_dump(chdir($level_two_dir_path)); +var_dump(chdir("../../$level_one_dir_name")); +var_dump(getcwd()); + +$file_path = dirname(__FILE__); +chdir($file_path);/* not that PWD is accidentialy one of the dirs to be deleted. */ +rmdir("$file_path/私はガラスを食べられますlevel_one/私はガラスを食べられますlevel_two"); +rmdir("$file_path/私はガラスを食べられますlevel_one"); +?> +===DONE=== +--CLEAN-- +<?php +$file_path = dirname(__FILE__); +chdir($file_path);/* not that PWD is accidentialy one of the dirs to be deleted. */ +rmdir("$file_path/私はガラスを食べられますlevel_one/私はガラスを食べられますlevel_two"); +rmdir("$file_path/私はガラスを食べられますlevel_one"); +?> +--EXPECTF-- +*** Testing chdir() : usage variations *** + +-- $directory = './私はガラスを食べられますlevel_one': -- +bool(true) +bool(true) +string(%d) "%slevel_one" + +-- $directory = '私はガラスを食べられますlevel_one/私はガラスを食べられますlevel_two': -- +bool(true) +bool(true) +string(%d) "%s私はガラスを食べられますlevel_one%e私はガラスを食べられますlevel_two" + +-- $directory = '..': -- +bool(true) +string(%d) "%s私はガラスを食べられますlevel_one" + +-- $directory = '私はガラスを食べられますlevel_two', '.': -- +bool(true) +bool(true) +string(%d) "%s私はガラスを食べられますlevel_one%e私はガラスを食べられますlevel_two" + +-- $directory = '../': -- +bool(true) +string(%d) "%slevel_one" + +-- $directory = './': -- +bool(true) +bool(true) +string(%d) "%s私はガラスを食べられますlevel_one%e私はガラスを食べられますlevel_two" + +-- $directory = '../../'私はガラスを食べられますlevel_one': -- +bool(true) +bool(true) +string(%d) "%s私はガラスを食べられますlevel_one" +===DONE=== diff --git a/ext/standard/tests/dir/closedir_basic-win32-mb.phpt b/ext/standard/tests/dir/closedir_basic-win32-mb.phpt new file mode 100644 index 0000000000..4a871dbe74 --- /dev/null +++ b/ext/standard/tests/dir/closedir_basic-win32-mb.phpt @@ -0,0 +1,56 @@ +--TEST-- +Test closedir() function : basic functionality +--FILE-- +<?php +/* Prototype : void closedir([resource $dir_handle]) + * Description: Close directory connection identified by the dir_handle + * Source code: ext/standard/dir.c + * Alias to functions: close + */ + +/* + * Test basic functionality of closedir() + */ + +echo "*** Testing closedir() : basic functionality ***\n"; + +$base_dir = dirname(__FILE__); +$dir_path = $base_dir . '/私はガラスを食べられますclosedir_basic'; +mkdir($dir_path); + +echo "\n-- Call closedir() with no arguments: --\n"; +$dh1 = opendir($dir_path); +var_dump(closedir()); +echo "-- Check Directory Handle: --\n"; +var_dump($dh1); + +echo "\n-- Call closedir() with \$dir_handle argument supplied: --\n"; +$dh2 = opendir($dir_path); + +if ((int)$dh1 === (int)$dh2) { + echo "\nNo new resource created\n"; +} +var_dump(closedir($dh2)); +echo "-- Check Directory Handle: --\n"; +var_dump($dh2); +?> +===DONE=== +--CLEAN-- +<?php +$base_dir = dirname(__FILE__); +$dir_path = $base_dir . '/私はガラスを食べられますclosedir_basic'; +rmdir($dir_path); +?> +--EXPECTF-- +*** Testing closedir() : basic functionality *** + +-- Call closedir() with no arguments: -- +NULL +-- Check Directory Handle: -- +resource(%d) of type (Unknown) + +-- Call closedir() with $dir_handle argument supplied: -- +NULL +-- Check Directory Handle: -- +resource(%d) of type (Unknown) +===DONE=== diff --git a/ext/standard/tests/dir/closedir_error-win32-mb.phpt b/ext/standard/tests/dir/closedir_error-win32-mb.phpt new file mode 100644 index 0000000000..15e646e124 --- /dev/null +++ b/ext/standard/tests/dir/closedir_error-win32-mb.phpt @@ -0,0 +1,45 @@ +--TEST-- +Test closedir() function : error conditions - Pass incorrect number of arguments +--FILE-- +<?php +/* Prototype : void closedir([resource $dir_handle]) + * Description: Close directory connection identified by the dir_handle + * Source code: ext/standard/dir.c + * Alias to functions: close + */ + +/* + * Pass incorrect number of arguments to closedir() to test behaviour + */ + +echo "*** Testing closedir() : error conditions ***\n"; + + +//Test closedir with one more than the expected number of arguments +echo "\n-- Testing closedir() function with more than expected no. of arguments --\n"; + +$dir_path = dirname(__FILE__) . '\私はガラスを食べられますclosedir_error'; +mkdir($dir_path); +$dir_handle = opendir($dir_path); + +$extra_arg = 10; +var_dump( closedir($dir_handle, $extra_arg) ); + +//successfully close the directory handle so can delete in CLEAN section +closedir($dir_handle); +?> +===DONE=== +--CLEAN-- +<?php +$base_dir = dirname(__FILE__); +$dir_path = $base_dir . '\私はガラスを食べられますclosedir_error'; +rmdir($dir_path); +?> +--EXPECTF-- +*** Testing closedir() : error conditions *** + +-- Testing closedir() function with more than expected no. of arguments -- + +Warning: closedir() expects at most 1 parameter, 2 given in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/dir/closedir_variation2-win32-mb.phpt b/ext/standard/tests/dir/closedir_variation2-win32-mb.phpt new file mode 100644 index 0000000000..f166bd9f0d --- /dev/null +++ b/ext/standard/tests/dir/closedir_variation2-win32-mb.phpt @@ -0,0 +1,51 @@ +--TEST-- +Test closedir() function : usage variations - close directory handle twice +--FILE-- +<?php +/* Prototype : void closedir([resource $dir_handle]) + * Description: Close directory connection identified by the dir_handle + * Source code: ext/standard/dir.c + * Alias to functions: close + */ + +/* + * close the directory handle twice using closedir() to test behaviour + */ + +echo "*** Testing closedir() : usage variations ***\n"; + +//create temporary directory for test, removed in CLEAN section +$directory = dirname(__FILE__) . "/私はガラスを食べられますclosedir_variation2"; +mkdir($directory); + +$dh = opendir($directory); + +echo "\n-- Close directory handle first time: --\n"; +var_dump(closedir($dh)); +echo "Directory Handle: "; +var_dump($dh); + +echo "\n-- Close directory handle second time: --\n"; +var_dump(closedir($dh)); +echo "Directory Handle: "; +var_dump($dh); +?> +===DONE=== +--CLEAN-- +<?php +$directory = dirname(__FILE__) . "/私はガラスを食べられますclosedir_variation2"; +rmdir($directory); +?> +--EXPECTF-- +*** Testing closedir() : usage variations *** + +-- Close directory handle first time: -- +NULL +Directory Handle: resource(%d) of type (Unknown) + +-- Close directory handle second time: -- + +Warning: closedir(): %s is not a valid Directory resource in %s on line %d +bool(false) +Directory Handle: resource(%d) of type (Unknown) +===DONE=== diff --git a/ext/standard/tests/dir/dir_basic-win32-mb.phpt b/ext/standard/tests/dir/dir_basic-win32-mb.phpt new file mode 100644 index 0000000000..a491d23abc --- /dev/null +++ b/ext/standard/tests/dir/dir_basic-win32-mb.phpt @@ -0,0 +1,86 @@ +--TEST-- +Test dir() function : basic functionality +--FILE-- +<?php +/* + * Prototype : object dir(string $directory[, resource $context]) + * Description: Directory class with properties, handle and class and methods read, rewind and close + * Source code: ext/standard/dir.c + */ + +echo "*** Testing dir() : basic functionality ***\n"; + +// include the file.inc for Function: function create_files() +include(dirname(__FILE__)."/../file/file.inc"); + +// create the temporary directory +$file_path = dirname(__FILE__); +$dir_path = $file_path."/私はガラスを食べられますdir_basic"; +@mkdir($dir_path); + +// create files within the temporary directory +create_files($dir_path, 3, "alphanumeric", 0755, 1, "w", "私はガラスを食べられますdir_basic"); + +echo "Get Directory instance:\n"; +$d = dir($dir_path); +var_dump( $d ); + +echo "\nRead and rewind:\n"; +var_dump( $d->read() ); +var_dump( $d->read() ); +var_dump( $d->rewind() ); + +echo "\nTest using handle directly:\n"; +var_dump( readdir($d->handle) ); +var_dump( readdir($d->handle) ); + +echo "\nClose directory:\n"; +var_dump( $d->close() ); +var_dump( $d ); + +echo "\nTest read after closing the dir:"; +var_dump( $d->read() ); + +// delete temp files +delete_files($dir_path, 3, "私はガラスを食べられますdir_basic", 1, ".tmp"); +echo "Done"; +?> +--CLEAN-- +<?php +$file_path = dirname(__FILE__); +$dir_path = $file_path."/私はガラスを食べられますdir_basic"; + +rmdir($dir_path); +?> +--EXPECTF-- +*** Testing dir() : basic functionality *** +Get Directory instance: +object(Directory)#%d (2) { + ["path"]=> + string(%d) "%s/私はガラスを食べられますdir_basic" + ["handle"]=> + resource(%d) of type (stream) +} + +Read and rewind: +string(%d) "%s" +string(%d) "%s" +NULL + +Test using handle directly: +string(%d) "%s" +string(%d) "%s" + +Close directory: +NULL +object(Directory)#%d (2) { + ["path"]=> + string(%d) "%s私はガラスを食べられますdir_basic" + ["handle"]=> + resource(%d) of type (Unknown) +} + +Test read after closing the dir: +Warning: Directory::read(): %s is not a valid Directory resource in %s on line %d +bool(false) +Done diff --git a/ext/standard/tests/dir/dir_variation2-win32-mb.phpt b/ext/standard/tests/dir/dir_variation2-win32-mb.phpt new file mode 100644 index 0000000000..35f63cb649 --- /dev/null +++ b/ext/standard/tests/dir/dir_variation2-win32-mb.phpt @@ -0,0 +1,223 @@ +--TEST-- +Test dir() function : usage variations - unexpected value for 'context' argument +--FILE-- +<?php +/* + * Prototype : object dir(string $directory[, resource $context]) + * Description: Directory class with properties, handle and class and methods read, rewind and close + * Source code: ext/standard/dir.c + */ + +/* + * Passing non resource values to 'context' argument of dir() and see + * that the function outputs proper warning messages wherever expected. + */ + +echo "*** Testing dir() : unexpected values for \$context argument ***\n"; + +// create the temporary directory +$file_path = dirname(__FILE__); +$directory = $file_path."/私はガラスを食べられますdir_variation2"; +@mkdir($directory); + +// get an unset variable +$unset_var = stream_context_create(); +unset($unset_var); + +class classA +{ + public $var; + public function init() { + $this->var = 10; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// unexpected values to be passed to $directory argument +$unexpected_values = array ( + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // array data +/*10*/ array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + + // null data +/*15*/ NULL, + null, + + // boolean data +/*17*/ true, + false, + TRUE, + FALSE, + + // empty data +/*21*/ "", + '', + + // string data +/*23*/ "string", + 'string', + $heredoc, + + // object data +/*26*/ new classA(), + + // undefined data +/*27*/ @$undefined_var, + + // unset data +/*28*/ @$unset_var +); + +// loop through various elements of $unexpected_values to check the behavior of dir() +$iterator = 1; +foreach( $unexpected_values as $unexpected_value ) { + echo "\n-- Iteration $iterator --"; + var_dump( dir($directory, $unexpected_value) ); + $iterator++; +} + +echo "Done"; +?> +--CLEAN-- +<?php +$file_path = dirname(__FILE__); +$directory = $file_path."/私はガラスを食べられますdir_variation2"; + +rmdir($directory); +?> +--EXPECTF-- +*** Testing dir() : unexpected values for $context argument *** + +-- Iteration 1 -- +Warning: dir() expects parameter 2 to be resource, integer given in %s on line %d +NULL + +-- Iteration 2 -- +Warning: dir() expects parameter 2 to be resource, integer given in %s on line %d +NULL + +-- Iteration 3 -- +Warning: dir() expects parameter 2 to be resource, integer given in %s on line %d +NULL + +-- Iteration 4 -- +Warning: dir() expects parameter 2 to be resource, integer given in %s on line %d +NULL + +-- Iteration 5 -- +Warning: dir() expects parameter 2 to be resource, float given in %s on line %d +NULL + +-- Iteration 6 -- +Warning: dir() expects parameter 2 to be resource, float given in %s on line %d +NULL + +-- Iteration 7 -- +Warning: dir() expects parameter 2 to be resource, float given in %s on line %d +NULL + +-- Iteration 8 -- +Warning: dir() expects parameter 2 to be resource, float given in %s on line %d +NULL + +-- Iteration 9 -- +Warning: dir() expects parameter 2 to be resource, float given in %s on line %d +NULL + +-- Iteration 10 -- +Warning: dir() expects parameter 2 to be resource, array given in %s on line %d +NULL + +-- Iteration 11 -- +Warning: dir() expects parameter 2 to be resource, array given in %s on line %d +NULL + +-- Iteration 12 -- +Warning: dir() expects parameter 2 to be resource, array given in %s on line %d +NULL + +-- Iteration 13 -- +Warning: dir() expects parameter 2 to be resource, array given in %s on line %d +NULL + +-- Iteration 14 -- +Warning: dir() expects parameter 2 to be resource, array given in %s on line %d +NULL + +-- Iteration 15 -- +Warning: dir() expects parameter 2 to be resource, null given in %s on line %d +NULL + +-- Iteration 16 -- +Warning: dir() expects parameter 2 to be resource, null given in %s on line %d +NULL + +-- Iteration 17 -- +Warning: dir() expects parameter 2 to be resource, boolean given in %s on line %d +NULL + +-- Iteration 18 -- +Warning: dir() expects parameter 2 to be resource, boolean given in %s on line %d +NULL + +-- Iteration 19 -- +Warning: dir() expects parameter 2 to be resource, boolean given in %s on line %d +NULL + +-- Iteration 20 -- +Warning: dir() expects parameter 2 to be resource, boolean given in %s on line %d +NULL + +-- Iteration 21 -- +Warning: dir() expects parameter 2 to be resource, string given in %s on line %d +NULL + +-- Iteration 22 -- +Warning: dir() expects parameter 2 to be resource, string given in %s on line %d +NULL + +-- Iteration 23 -- +Warning: dir() expects parameter 2 to be resource, string given in %s on line %d +NULL + +-- Iteration 24 -- +Warning: dir() expects parameter 2 to be resource, string given in %s on line %d +NULL + +-- Iteration 25 -- +Warning: dir() expects parameter 2 to be resource, string given in %s on line %d +NULL + +-- Iteration 26 -- +Warning: dir() expects parameter 2 to be resource, object given in %s on line %d +NULL + +-- Iteration 27 -- +Warning: dir() expects parameter 2 to be resource, null given in %s on line %d +NULL + +-- Iteration 28 -- +Warning: dir() expects parameter 2 to be resource, null given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/dir/dir_variation4-win32-mb.phpt b/ext/standard/tests/dir/dir_variation4-win32-mb.phpt new file mode 100644 index 0000000000..c5bd263f7b --- /dev/null +++ b/ext/standard/tests/dir/dir_variation4-win32-mb.phpt @@ -0,0 +1,72 @@ +--TEST-- +Test dir() function : usage variations - operate on previously opened directory +--FILE-- +<?php +/* + * Prototype : object dir(string $directory[, resource $context]) + * Description: Directory class with properties, handle and class and methods read, rewind and close + * Source code: ext/standard/dir.c + */ + +/* + * Testing the behavior of dir() function by trying to open a + * directory which is already open. + */ + +echo "*** Testing dir() : operate on previously opened directory ***\n"; + +// include the file.inc for Function: function create_files() +include( dirname(__FILE__)."/../file/file.inc"); + +// create the temporary directory +$file_path = dirname(__FILE__); +$dir_path = $file_path."/私はガラスを食べられますdir_variation4"; +@mkdir($dir_path); + +// create files within the temporary directory +create_files($dir_path, 3, "alphanumeric", 0755, 1, "w", "私はガラスを食べられますdir_variation4"); + +// open the directory +$d = dir($dir_path); +var_dump( $d ); + +// open the same directory again without closing it +$e = dir($dir_path); +var_dump( $e ); + +echo "-- reading directory contents with previous handle --\n"; +var_dump( $d->read() ); // with previous handle + +echo "-- reading directory contents with current handle --\n"; +var_dump( $e->read() ); // with current handle + +// delete temporary files +delete_files($dir_path, 3, "私はガラスを食べられますdir_variation4"); +echo "Done"; +?> +--CLEAN-- +<?php +$file_path = dirname(__FILE__); +$dir_path = $file_path."/私はガラスを食べられますdir_variation4"; + +rmdir($dir_path); +?> +--EXPECTF-- +*** Testing dir() : operate on previously opened directory *** +object(Directory)#%d (2) { + ["path"]=> + string(%d) "%s/私はガラスを食べられますdir_variation4" + ["handle"]=> + resource(%d) of type (stream) +} +object(Directory)#%d (2) { + ["path"]=> + string(%d) "%s/私はガラスを食べられますdir_variation4" + ["handle"]=> + resource(%d) of type (stream) +} +-- reading directory contents with previous handle -- +string(%d) "%s" +-- reading directory contents with current handle -- +string(%d) "%s" +Done diff --git a/ext/standard/tests/dir/getcwd_basic-win32-mb.phpt b/ext/standard/tests/dir/getcwd_basic-win32-mb.phpt new file mode 100644 index 0000000000..8a00959049 --- /dev/null +++ b/ext/standard/tests/dir/getcwd_basic-win32-mb.phpt @@ -0,0 +1,34 @@ +--TEST-- +Test getcwd() function : basic functionality +--FILE-- +<?php +/* Prototype : mixed getcwd(void) + * Description: Gets the current directory + * Source code: ext/standard/dir.c + */ + +/* + * Test basic functionality of getcwd() + */ + +echo "*** Testing getcwd() : basic functionality ***\n"; + +//create temporary directory for test, removed in CLEAN section +$directory = dirname(__FILE__) . "/私はガラスを食べられますgetcwd_basic"; +mkdir($directory); + +var_dump(getcwd()); +chdir($directory); +var_dump(getcwd()); +?> +===DONE=== +--CLEAN-- +<?php +$directory = dirname(__FILE__) . "/私はガラスを食べられますgetcwd_basic"; +rmdir($directory); +?> +--EXPECTF-- +*** Testing getcwd() : basic functionality *** +string(%d) "%s" +string(%d) "%s%e私はガラスを食べられますgetcwd_basic" +===DONE=== diff --git a/ext/standard/tests/dir/opendir_basic-win32-mb.phpt b/ext/standard/tests/dir/opendir_basic-win32-mb.phpt new file mode 100644 index 0000000000..0c94c250be --- /dev/null +++ b/ext/standard/tests/dir/opendir_basic-win32-mb.phpt @@ -0,0 +1,62 @@ +--TEST-- +Test opendir() function : basic functionality +--FILE-- +<?php +/* Prototype : mixed opendir(string $path[, resource $context]) + * Description: Open a directory and return a dir_handle + * Source code: ext/standard/dir.c + */ + +/* + * Test basic functionality of opendir() with absolute and relative paths as $path argument + */ + +echo "*** Testing opendir() : basic functionality ***\n"; + +$base_dir_path = dirname(__FILE__); + +$level_one_dir_name = "私はガラスを食べられますlevel_one"; +$level_one_dir_path = "$base_dir_path/$level_one_dir_name"; + +$level_two_dir_name = "私はガラスを食べられますlevel_two"; +$level_two_dir_path = "$base_dir_path/$level_one_dir_name/$level_two_dir_name"; + +// create temporary directories - will remove in CLEAN section +mkdir($level_one_dir_path); +mkdir($level_two_dir_path); + +echo "\n-- Testing opendir() with absolute path: --\n"; +var_dump($dh1 = opendir($level_one_dir_path)); + + +echo "\n-- Testing opendir() with relative paths: --\n"; +var_dump(chdir($level_one_dir_path)); +var_dump($dh2 = opendir($level_two_dir_name)); + +echo "\n-- Close directory handles: --\n"; +closedir($dh1); +var_dump($dh1); +closedir($dh2); +var_dump($dh2); +?> +===DONE=== +--CLEAN-- +<?php +$file_path = dirname(__FILE__); +rmdir("$file_path/私はガラスを食べられますlevel_one/私はガラスを食べられますlevel_two"); +rmdir("$file_path/私はガラスを食べられますlevel_one"); +?> +--EXPECTF-- +*** Testing opendir() : basic functionality *** + +-- Testing opendir() with absolute path: -- +resource(%d) of type (stream) + +-- Testing opendir() with relative paths: -- +bool(true) +resource(%d) of type (stream) + +-- Close directory handles: -- +resource(%d) of type (Unknown) +resource(%d) of type (Unknown) +===DONE=== diff --git a/ext/standard/tests/dir/opendir_error1-win32-mb.phpt b/ext/standard/tests/dir/opendir_error1-win32-mb.phpt new file mode 100644 index 0000000000..71d07073ae --- /dev/null +++ b/ext/standard/tests/dir/opendir_error1-win32-mb.phpt @@ -0,0 +1,47 @@ +--TEST-- +Test opendir() function : error conditions - Incorrect number of args +--FILE-- +<?php +/* Prototype : mixed opendir(string $path[, resource $context]) + * Description: Open a directory and return a dir_handle + * Source code: ext/standard/dir.c + */ + +/* + * Pass incorrect number of arguments to opendir() to test behaviour + */ + +echo "*** Testing opendir() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing opendir() function with Zero arguments --\n"; +var_dump( opendir() ); + +//Test opendir with one more than the expected number of arguments +echo "\n-- Testing opendir() function with more than expected no. of arguments --\n"; +$path = dirname(__FILE__) . "/私はガラスを食べられますopendir_error"; +mkdir($path); +$context = stream_context_create(); + +$extra_arg = 10; +var_dump( opendir($path, $context, $extra_arg) ); +?> +===DONE=== +--CLEAN-- +<?php +$path = dirname(__FILE__) . "/私はガラスを食べられますopendir_error"; +rmdir($path); +?> +--EXPECTF-- +*** Testing opendir() : error conditions *** + +-- Testing opendir() function with Zero arguments -- + +Warning: opendir() expects at least 1 parameter, 0 given in %s on line %d +NULL + +-- Testing opendir() function with more than expected no. of arguments -- + +Warning: opendir() expects at most 2 parameters, 3 given in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/dir/opendir_variation2-win32-mb.phpt b/ext/standard/tests/dir/opendir_variation2-win32-mb.phpt new file mode 100644 index 0000000000..e82d32ee5f --- /dev/null +++ b/ext/standard/tests/dir/opendir_variation2-win32-mb.phpt @@ -0,0 +1,239 @@ +--TEST-- +Test opendir() function : usage variations - different data types as $context arg +--FILE-- +<?php +/* Prototype : mixed opendir(string $path[, resource $context]) + * Description: Open a directory and return a dir_handle + * Source code: ext/standard/dir.c + */ + +/* + * Pass different data types as $context argument to opendir() to test behaviour + */ + +echo "*** Testing opendir() : usage variation ***\n"; + + +// Initialise function arguments not being substituted (if any) +// create temporary directory for test, removed in CLEAN section +$path = dirname(__FILE__) . "/私はガラスを食べられますopendir_variation2"; +mkdir($path); + + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() + { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $context argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + array(), + + // string data +/*19*/ "string", + 'string', + $heredoc, + + // object data +/*22*/ new classA(), + + // undefined data +/*23*/ @$undefined_var, + + // unset data +/*24*/ @$unset_var, + + // resource variable +/*25*/ $fp +); + +// loop through each element of $inputs to check the behavior of opendir() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump($dh = opendir($path, $input) );# + if ($dh) { + closedir($dh); + } + $iterator++; +}; + +fclose($fp); +?> +===DONE=== +--CLEAN-- +<?php +$path = dirname(__FILE__) . "/私はガラスを食べられますopendir_variation2"; +rmdir($path); +?> +--EXPECTF-- +*** Testing opendir() : usage variation *** + +-- Iteration 1 -- + +Warning: opendir() expects parameter 2 to be resource, integer given in %s on line %d +NULL + +-- Iteration 2 -- + +Warning: opendir() expects parameter 2 to be resource, integer given in %s on line %d +NULL + +-- Iteration 3 -- + +Warning: opendir() expects parameter 2 to be resource, integer given in %s on line %d +NULL + +-- Iteration 4 -- + +Warning: opendir() expects parameter 2 to be resource, integer given in %s on line %d +NULL + +-- Iteration 5 -- + +Warning: opendir() expects parameter 2 to be resource, float given in %s on line %d +NULL + +-- Iteration 6 -- + +Warning: opendir() expects parameter 2 to be resource, float given in %s on line %d +NULL + +-- Iteration 7 -- + +Warning: opendir() expects parameter 2 to be resource, float given in %s on line %d +NULL + +-- Iteration 8 -- + +Warning: opendir() expects parameter 2 to be resource, float given in %s on line %d +NULL + +-- Iteration 9 -- + +Warning: opendir() expects parameter 2 to be resource, float given in %s on line %d +NULL + +-- Iteration 10 -- + +Warning: opendir() expects parameter 2 to be resource, null given in %s on line %d +NULL + +-- Iteration 11 -- + +Warning: opendir() expects parameter 2 to be resource, null given in %s on line %d +NULL + +-- Iteration 12 -- + +Warning: opendir() expects parameter 2 to be resource, boolean given in %s on line %d +NULL + +-- Iteration 13 -- + +Warning: opendir() expects parameter 2 to be resource, boolean given in %s on line %d +NULL + +-- Iteration 14 -- + +Warning: opendir() expects parameter 2 to be resource, boolean given in %s on line %d +NULL + +-- Iteration 15 -- + +Warning: opendir() expects parameter 2 to be resource, boolean given in %s on line %d +NULL + +-- Iteration 16 -- + +Warning: opendir() expects parameter 2 to be resource, string given in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: opendir() expects parameter 2 to be resource, string given in %s on line %d +NULL + +-- Iteration 18 -- + +Warning: opendir() expects parameter 2 to be resource, array given in %s on line %d +NULL + +-- Iteration 19 -- + +Warning: opendir() expects parameter 2 to be resource, string given in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: opendir() expects parameter 2 to be resource, string given in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: opendir() expects parameter 2 to be resource, string given in %s on line %d +NULL + +-- Iteration 22 -- + +Warning: opendir() expects parameter 2 to be resource, object given in %s on line %d +NULL + +-- Iteration 23 -- + +Warning: opendir() expects parameter 2 to be resource, null given in %s on line %d +NULL + +-- Iteration 24 -- + +Warning: opendir() expects parameter 2 to be resource, null given in %s on line %d +NULL + +-- Iteration 25 -- + +Warning: opendir(): supplied resource is not a valid Stream-Context resource in %s on line %d +resource(%d) of type (stream) +===DONE=== diff --git a/ext/standard/tests/dir/opendir_variation3-win32-mb.phpt b/ext/standard/tests/dir/opendir_variation3-win32-mb.phpt new file mode 100644 index 0000000000..af6d4fb1b4 --- /dev/null +++ b/ext/standard/tests/dir/opendir_variation3-win32-mb.phpt @@ -0,0 +1,50 @@ +--TEST-- +Test opendir() function : usage variations - open a directory twice +--FILE-- +<?php +/* Prototype : mixed opendir(string $path[, resource $context]) + * Description: Open a directory and return a dir_handle + * Source code: ext/standard/dir.c + */ + +/* + * Call opendir() twice with the same directory as $path argument + */ + +echo "*** Testing opendir() : usage variation ***\n"; + +$path = dirname(__FILE__) . "/私はガラスを食べられますopendir_variation3"; +mkdir($path); + +echo "\n-- Open directory first time: --\n"; +var_dump($dh1 = opendir($path)); + +echo "\n-- Open directory second time: --\n"; +var_dump($dh2 = opendir($path)); + +if ($dh1 !== $dh2) { + echo "\nNew resource created\n"; +} else { + echo "\nNo new resource created\n"; +} + +closedir($dh1); +closedir($dh2); +?> +===DONE=== +--CLEAN-- +<?php +$path = dirname(__FILE__) . "/私はガラスを食べられますopendir_variation3"; +rmdir($path); +?> +--EXPECTF-- +*** Testing opendir() : usage variation *** + +-- Open directory first time: -- +resource(%d) of type (stream) + +-- Open directory second time: -- +resource(%d) of type (stream) + +New resource created +===DONE=== diff --git a/ext/standard/tests/dir/opendir_variation4-win32-mb.phpt b/ext/standard/tests/dir/opendir_variation4-win32-mb.phpt new file mode 100644 index 0000000000..11ededf573 --- /dev/null +++ b/ext/standard/tests/dir/opendir_variation4-win32-mb.phpt @@ -0,0 +1,107 @@ +--TEST-- +Test opendir() function : usage variations - different relative paths +--FILE-- +<?php +/* Prototype : mixed opendir(string $path[, resource $context]) + * Description: Open a directory and return a dir_handle + * Source code: ext/standard/dir.c + */ + +/* + * Test opendir() with different relative paths as $path argument + */ + +echo "*** Testing opendir() : usage variation ***\n"; + +$base_dir_path = dirname(__FILE__); + +$level_one_dir_name = "私はガラスを食べられますlevel_one"; +$level_one_dir_path = "$base_dir_path/$level_one_dir_name"; + +$level_two_dir_name = "私はガラスを食べられますlevel_two"; +$level_two_dir_path = "$base_dir_path/$level_one_dir_name/$level_two_dir_name"; + +// create directories +mkdir($level_one_dir_path); +mkdir($level_two_dir_path); + +echo "\n-- \$path = './私はガラスを食べられますlevel_one': --\n"; +var_dump(chdir($base_dir_path)); +var_dump($dh = opendir("./$level_one_dir_name")); +clean_dh($dh); + +echo "\n-- \$path = '私はガラスを食べられますlevel_one/私はガラスを食べられますlevel_two': --\n"; +var_dump(chdir($base_dir_path)); +var_dump($dh = opendir("$level_one_dir_name/$level_two_dir_name")); +clean_dh($dh); + +echo "\n-- \$path = '..': --\n"; +var_dump($dh = opendir('..')); +clean_dh($dh); + +echo "\n-- \$path = 'level_two', '.': --\n"; +var_dump(chdir($level_two_dir_path)); +var_dump($dh = opendir('.')); +clean_dh($dh); + +echo "\n-- \$path = '../': --\n"; +var_dump($dh = opendir('../')); +clean_dh($dh); + +echo "\n-- \$path = './': --\n"; +var_dump(chdir($level_two_dir_path)); +var_dump($dh = opendir('./')); +clean_dh($dh); + +echo "\n-- \$path = '../../'私はガラスを食べられますlevel_one': --\n"; +var_dump(chdir($level_two_dir_path)); +var_dump($dh = opendir("../../$level_one_dir_name")); +clean_dh($dh); + +/* + * function to remove directory handle before re-using variable name in test + * and to ensure directory is not in use at CLEAN section so can me removed + */ +function clean_dh($dh){ + if (is_resource($dh)) { + closedir($dh); + } + unset($dh); +} +?> +===DONE=== +--CLEAN-- +<?php +$file_path = dirname(__FILE__); +rmdir("$file_path/私はガラスを食べられますlevel_one/私はガラスを食べられますlevel_two"); +rmdir("$file_path/私はガラスを食べられますlevel_one"); +?> +--EXPECTF-- +*** Testing opendir() : usage variation *** + +-- $path = './私はガラスを食べられますlevel_one': -- +bool(true) +resource(%d) of type (stream) + +-- $path = '私はガラスを食べられますlevel_one/私はガラスを食べられますlevel_two': -- +bool(true) +resource(%d) of type (stream) + +-- $path = '..': -- +resource(%d) of type (stream) + +-- $path = 'level_two', '.': -- +bool(true) +resource(%d) of type (stream) + +-- $path = '../': -- +resource(%d) of type (stream) + +-- $path = './': -- +bool(true) +resource(%d) of type (stream) + +-- $path = '../../'私はガラスを食べられますlevel_one': -- +bool(true) +resource(%d) of type (stream) +===DONE=== diff --git a/ext/standard/tests/dir/opendir_variation6-win32-mb.phpt b/ext/standard/tests/dir/opendir_variation6-win32-mb.phpt new file mode 100644 index 0000000000..f54a2ad4ae --- /dev/null +++ b/ext/standard/tests/dir/opendir_variation6-win32-mb.phpt @@ -0,0 +1,75 @@ +--TEST-- +Test opendir() function : usage variations - Different wildcards +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) != 'WIN') { + die("skip Valid only on Windows"); +} +?> +--FILE-- +<?php +/* Prototype : mixed opendir(string $path[, resource $context]) + * Description: Open a directory and return a dir_handle + * Source code: ext/standard/dir.c + */ + +/* + * Pass paths containing wildcards to test if opendir() recognises them + */ + +echo "*** Testing opendir() : usage variations ***\n"; +// create the temporary directories +$file_path = dirname(__FILE__); +$dir_path = $file_path . "/opendir_variation6"; +$sub_dir_path = $dir_path . "/sub_dir1"; + +mkdir($dir_path); +mkdir($sub_dir_path); + +// with different wildcard characters + +echo "\n-- Wildcard = '*' --\n"; +var_dump( opendir($file_path . "/opendir_var*") ); +var_dump( opendir($file_path . "/*") ); + +echo "\n-- Wildcard = '?' --\n"; +var_dump( opendir($dir_path . "/sub_dir?") ); +var_dump( opendir($dir_path . "/sub?dir1") ); + +?> +===DONE=== +--CLEAN-- +<?php +$dir_path = dirname(__FILE__) . "/opendir_variation6"; +$sub_dir_path = $dir_path . "/sub_dir1"; + +rmdir($sub_dir_path); +rmdir($dir_path); +?> +--EXPECTF-- +*** Testing opendir() : usage variations *** + +-- Wildcard = '*' -- + +Warning: opendir(%s/opendir_var*,%s/opendir_var*): %s in %s on line %d + +Warning: opendir(%s/opendir_var*): failed to open dir: %s in %s on line %d +bool(false) + +Warning: opendir(%s/*,%s/*): %s in %s on line %d + +Warning: opendir(%s/*): failed to open dir: %s in %s on line %d +bool(false) + +-- Wildcard = '?' -- + +Warning: opendir(%s/opendir_variation6/sub_dir?,%s/opendir_variation6/sub_dir?): %s in %s on line %d + +Warning: opendir(%s/opendir_variation6/sub_dir?): failed to open dir: %s in %s on line %d +bool(false) + +Warning: opendir(%s/opendir_variation6/sub?dir1,%s/opendir_variation6/sub?dir1): %s in %s on line %d + +Warning: opendir(%s/opendir_variation6/sub?dir1): failed to open dir: %s in %s on line %d +bool(false) +===DONE=== diff --git a/ext/standard/tests/dir/readdir_basic-win32-mb.phpt b/ext/standard/tests/dir/readdir_basic-win32-mb.phpt new file mode 100644 index 0000000000..36f96604e1 --- /dev/null +++ b/ext/standard/tests/dir/readdir_basic-win32-mb.phpt @@ -0,0 +1,73 @@ +--TEST-- +Test readdir() function : basic functionality +--FILE-- +<?php +/* Prototype : string readdir([resource $dir_handle]) + * Description: Read directory entry from dir_handle + * Source code: ext/standard/dir.C + */ + +/* + * Test basic functionality of readdir() + */ + +echo "*** Testing readdir() : basic functionality ***\n"; + +// include the file.inc for Function: function create_files() +chdir(dirname(__FILE__)); +include(dirname(__FILE__)."/../file/file.inc"); + +$path = dirname(__FILE__) . '/私はガラスを食べられますreaddir_basic'; +mkdir($path); +create_files($path, 3); + +echo "\n-- Call readdir() with \$path argument --\n"; +var_dump($dh = opendir($path)); +$a = array(); +while( FALSE !== ($file = readdir($dh)) ) { + $a[] = $file; +} +sort($a); +foreach($a as $file) { + var_dump($file); +} + +echo "\n-- Call readdir() without \$path argument --\n"; +var_dump($dh = opendir($path)); +$a = array(); +while( FALSE !== ( $file = readdir() ) ) { + $a[] = $file; +} +sort($a); +foreach($a as $file) { + var_dump($file); +} + +delete_files($path, 3); +closedir($dh); +?> +===DONE=== +--CLEAN-- +<?php +$path = dirname(__FILE__) . '/私はガラスを食べられますreaddir_basic'; +rmdir($path); +?> +--EXPECTF-- +*** Testing readdir() : basic functionality *** + +-- Call readdir() with $path argument -- +resource(%d) of type (stream) +string(1) "." +string(2) ".." +string(9) "file1.tmp" +string(9) "file2.tmp" +string(9) "file3.tmp" + +-- Call readdir() without $path argument -- +resource(%d) of type (stream) +string(1) "." +string(2) ".." +string(9) "file1.tmp" +string(9) "file2.tmp" +string(9) "file3.tmp" +===DONE=== diff --git a/ext/standard/tests/dir/readdir_error-win32-mb.phpt b/ext/standard/tests/dir/readdir_error-win32-mb.phpt new file mode 100644 index 0000000000..511d74c642 --- /dev/null +++ b/ext/standard/tests/dir/readdir_error-win32-mb.phpt @@ -0,0 +1,43 @@ +--TEST-- +Test readdir() function : error conditions - Incorrect number of args +--FILE-- +<?php +/* Prototype : string readdir([resource $dir_handle]) + * Description: Read directory entry from dir_handle + * Source code: ext/standard/dir.c + */ + +/* + * Pass incorrect number of arguments to readdir() to test behaviour + */ + +echo "*** Testing readdir() : error conditions ***\n"; + + +//Test readdir with one more than the expected number of arguments +echo "\n-- Testing readdir() function with more than expected no. of arguments --\n"; + +$path = dirname(__FILE__) . "/私はガラスを食べられますreaddir_error"; +mkdir($path); +$dir_handle = opendir($path); +$extra_arg = 10; + +var_dump( readdir($dir_handle, $extra_arg) ); + +// close the handle so can remove dir in CLEAN section +closedir($dir_handle); +?> +===DONE=== +--CLEAN-- +<?php +$path = dirname(__FILE__) . "/私はガラスを食べられますreaddir_error"; +rmdir($path); +?> +--EXPECTF-- +*** Testing readdir() : error conditions *** + +-- Testing readdir() function with more than expected no. of arguments -- + +Warning: readdir() expects at most 1 parameter, 2 given in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/dir/readdir_variation2-win32-mb.phpt b/ext/standard/tests/dir/readdir_variation2-win32-mb.phpt new file mode 100644 index 0000000000..59ea129e2e --- /dev/null +++ b/ext/standard/tests/dir/readdir_variation2-win32-mb.phpt @@ -0,0 +1,48 @@ +--TEST-- +Test readdir() function : usage variations - empty directories +--FILE-- +<?php +/* Prototype : string readdir([resource $dir_handle]) + * Description: Read directory entry from dir_handle + * Source code: ext/standard/dir.c + */ + +/* + * Pass readdir() a directory handle pointing to an empty directory to test behaviour + */ + +echo "*** Testing readdir() : usage variations ***\n"; + +$path = dirname(__FILE__) . '/私はガラスを食べられますreaddir_variation2'; +mkdir($path); +$dir_handle = opendir($path); + +echo "\n-- Pass an empty directory to readdir() --\n"; +function mysort($a,$b) { + return strlen($a) > strlen($b) ? 1 : -1; +} +$entries = array(); +while(FALSE !== ($file = readdir($dir_handle))){ + $entries[] = $file; +} + +closedir($dir_handle); + +usort($entries, "mysort"); +foreach($entries as $entry) { + var_dump($entry); +} +?> +===DONE=== +--CLEAN-- +<?php +$path = dirname(__FILE__) . '/私はガラスを食べられますreaddir_variation2'; +rmdir($path); +?> +--EXPECTF-- +*** Testing readdir() : usage variations *** + +-- Pass an empty directory to readdir() -- +string(1) "." +string(2) ".." +===DONE=== diff --git a/ext/standard/tests/dir/readdir_variation3-win32-mb.phpt b/ext/standard/tests/dir/readdir_variation3-win32-mb.phpt new file mode 100644 index 0000000000..c2bc84949e --- /dev/null +++ b/ext/standard/tests/dir/readdir_variation3-win32-mb.phpt @@ -0,0 +1,68 @@ +--TEST-- +Test readdir() function : usage variations - sub-directories +--FILE-- +<?php +/* Prototype : string readdir([resource $dir_handle]) + * Description: Read directory entry from dir_handle + * Source code: ext/standard/dir.c + */ + +/* + * Pass a directory handle pointing to a directory that has a sub-directory + * to test behaviour of readdir() + */ + +echo "*** Testing readdir() : usage variations ***\n"; + +// include the file.inc for Function: function create_files() +chdir(dirname(__FILE__)); +include(dirname(__FILE__)."/../file/file.inc"); + +$path_top = dirname(__FILE__) . '/readdir_variation3'; +$path_sub = $path_top . '/私はガラスを食べられますsub_folder'; +mkdir($path_top); +mkdir($path_sub); + +create_files($path_top, 2); +create_files($path_sub, 2); + +$dir_handle = opendir($path_top); +while(FALSE !== ($file = readdir($dir_handle))) { + + // different OS order files differently so will + // store file names into an array so can use sorted in expected output + $contents[] = $file; +} + +// more important to check that all contents are present than order they are returned in +sort($contents); +var_dump($contents); + +delete_files($path_top, 2); +delete_files($path_sub, 2); + +closedir($dir_handle); +?> +===DONE=== +--CLEAN-- +<?php +$path_top = dirname(__FILE__) . '/readdir_variation3'; +$path_sub = $path_top . '/私はガラスを食べられますsub_folder'; +rmdir($path_sub); +rmdir($path_top); +?> +--EXPECTF-- +*** Testing readdir() : usage variations *** +array(5) { + [0]=> + string(1) "." + [1]=> + string(2) ".." + [2]=> + string(9) "file1.tmp" + [3]=> + string(9) "file2.tmp" + [4]=> + string(46) "私はガラスを食べられますsub_folder" +} +===DONE=== diff --git a/ext/standard/tests/dir/readdir_variation4-win32-mb.phpt b/ext/standard/tests/dir/readdir_variation4-win32-mb.phpt new file mode 100644 index 0000000000..e8c4ff224c --- /dev/null +++ b/ext/standard/tests/dir/readdir_variation4-win32-mb.phpt @@ -0,0 +1,178 @@ +--TEST-- +Test readdir() function : usage variations - different file names +--FILE-- +<?php +/* Prototype : string readdir([resource $dir_handle]) + * Description: Read directory entry from dir_handle + * Source code: ext/standard/dir.c + */ + +/* + * Pass a directory handle pointing to a directory that contains + * files with different file names to test how readdir() reads them + */ + +echo "*** Testing readdir() : usage variations ***\n"; + +$dir_path = dirname(__FILE__) . "/私はガラスを食べられますreaddir_variation4/"; +mkdir($dir_path); + +// heredoc string +$heredoc = <<<EOT +hd_file +EOT; + +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // empty data +/*10*/ "", + array(), + + // string data +/*12*/ "double_file", + 'single_file', + $heredoc, +); + +$iterator = 1; +foreach($inputs as $key => $input) { + echo "\n-- Iteration $iterator --\n"; + $handle = "fp{$iterator}"; + var_dump( $$handle = @fopen($dir_path . "私はガラスを食べられます$input.tmp", 'w') ); + var_dump( fwrite($$handle, $key)); + fclose($$handle); + $iterator++; +}; + +echo "\n-- Call to readdir() --\n"; +$dir_handle = opendir($dir_path); +while(FALSE !== ($file = readdir($dir_handle))){ + + // different OS order files differently so will + // store file names into an array so can use sorted in expected output + $contents[] = $file; + + // remove files while going through directory + @unlink($dir_path . $file); +} + +// more important to check that all contents are present than order they are returned in +sort($contents); +var_dump($contents); + +closedir($dir_handle); +?> +===DONE=== +--CLEAN-- +<?php +$dir_path = dirname(__FILE__) . "/私はガラスを食べられますreaddir_variation4/"; +rmdir($dir_path); +?> +--EXPECTF-- +*** Testing readdir() : usage variations *** + +-- Iteration 1 -- +resource(%d) of type (stream) +int(1) + +-- Iteration 2 -- +resource(%d) of type (stream) +int(1) + +-- Iteration 3 -- +resource(%d) of type (stream) +int(1) + +-- Iteration 4 -- +resource(%d) of type (stream) +int(1) + +-- Iteration 5 -- +resource(%d) of type (stream) +int(1) + +-- Iteration 6 -- +resource(%d) of type (stream) +int(1) + +-- Iteration 7 -- +resource(%d) of type (stream) +int(1) + +-- Iteration 8 -- +resource(%d) of type (stream) +int(1) + +-- Iteration 9 -- +resource(%d) of type (stream) +int(1) + +-- Iteration 10 -- +resource(%d) of type (stream) +int(1) + +-- Iteration 11 -- +resource(%d) of type (stream) +int(2) + +-- Iteration 12 -- +resource(%d) of type (stream) +int(2) + +-- Iteration 13 -- +resource(%d) of type (stream) +int(2) + +-- Iteration 14 -- +resource(%d) of type (stream) +int(2) + +-- Call to readdir() -- +array(16) { + [0]=> + string(1) "." + [1]=> + string(2) ".." + [2]=> + string(45) "私はガラスを食べられます-10.5.tmp" + [3]=> + string(45) "私はガラスを食べられます-2345.tmp" + [4]=> + string(40) "私はガラスを食べられます.tmp" + [5]=> + string(43) "私はガラスを食べられます0.5.tmp" + [6]=> + string(41) "私はガラスを食べられます0.tmp" + [7]=> + string(53) "私はガラスを食べられます1.23456789E-9.tmp" + [8]=> + string(41) "私はガラスを食べられます1.tmp" + [9]=> + string(44) "私はガラスを食べられます10.5.tmp" + [10]=> + string(45) "私はガラスを食べられます12345.tmp" + [11]=> + string(52) "私はガラスを食べられます123456789000.tmp" + [12]=> + string(45) "私はガラスを食べられますArray.tmp" + [13]=> + string(51) "私はガラスを食べられますdouble_file.tmp" + [14]=> + string(47) "私はガラスを食べられますhd_file.tmp" + [15]=> + string(51) "私はガラスを食べられますsingle_file.tmp" +} +===DONE=== diff --git a/ext/standard/tests/dir/readdir_variation6-win32-mb.phpt b/ext/standard/tests/dir/readdir_variation6-win32-mb.phpt new file mode 100644 index 0000000000..4faadcaf86 --- /dev/null +++ b/ext/standard/tests/dir/readdir_variation6-win32-mb.phpt @@ -0,0 +1,80 @@ +--TEST-- +Test readdir() function : usage variations - operate on previously opened directory +--FILE-- +<?php +/* Prototype : string readdir([resource $dir_handle]) + * Description: Read directory entry from dir_handle + * Source code: ext/standard/dir.c + */ + +/* + * Open two directory handles on the same directory and pass both + * to readdir() to test behaviour + */ + +echo "*** Testing readdir() : usage variations ***\n"; + +// include the file.inc for Function: function create_files() +include( dirname(__FILE__)."/../file/file.inc"); + +// create the temporary directory +$dir_path = dirname(__FILE__) . "/私はガラスを食べられますreaddir_variation6"; +mkdir($dir_path); + +// create files within the temporary directory +create_files($dir_path, 3, "alphanumeric", 0755, 1, "w", "私はガラスを食べられますreaddir_variation6"); + +// open the directory +$dir_handle1 = opendir($dir_path); + +// open the same directory again without closing it +opendir($dir_path); + +echo "\n-- Reading Directory Contents with Previous Handle --\n"; +$a = array(); +while (FALSE !== ($file = readdir($dir_handle1))) { + $a[] = $file; +} +sort($a); +foreach ($a as $file) { + var_dump($file); +} + +echo "\n-- Reading Directory Contents with Current Handle (no arguments supplied) --\n"; +$a = array(); +while (FALSE !== ($file = readdir())) { + $a[] = $file; +} +sort($a); +foreach ($a as $file) { + var_dump($file); +} + +// delete temporary files +delete_files($dir_path, 3, "私はガラスを食べられますreaddir_variation6"); +closedir($dir_handle1); +closedir(); +?> +===DONE=== +--CLEAN-- +<?php +$dir_path = dirname(__FILE__) . "/私はガラスを食べられますreaddir_variation6"; +rmdir($dir_path); +?> +--EXPECTF-- +*** Testing readdir() : usage variations *** + +-- Reading Directory Contents with Previous Handle -- +string(1) "." +string(2) ".." +string(59) "私はガラスを食べられますreaddir_variation61.tmp" +string(59) "私はガラスを食べられますreaddir_variation62.tmp" +string(59) "私はガラスを食べられますreaddir_variation63.tmp" + +-- Reading Directory Contents with Current Handle (no arguments supplied) -- +string(1) "." +string(2) ".." +string(59) "私はガラスを食べられますreaddir_variation61.tmp" +string(59) "私はガラスを食べられますreaddir_variation62.tmp" +string(59) "私はガラスを食べられますreaddir_variation63.tmp" +===DONE=== diff --git a/ext/standard/tests/dir/rewinddir_basic-win32-mb.phpt b/ext/standard/tests/dir/rewinddir_basic-win32-mb.phpt new file mode 100644 index 0000000000..e1f134a707 --- /dev/null +++ b/ext/standard/tests/dir/rewinddir_basic-win32-mb.phpt @@ -0,0 +1,96 @@ +--TEST-- +Test rewinddir() function : basic functionality +--FILE-- +<?php +/* Prototype : void rewinddir([resource $dir_handle]) + * Description: Rewind dir_handle back to the start + * Source code: ext/standard/dir.c + * Alias to functions: rewind + */ + +/* + * Test basic functionality of rewinddir() + */ + +echo "*** Testing rewinddir() : basic functionality ***\n"; + +// include file.inc for create_files function +include(dirname(__FILE__) . "/../file/file.inc"); + +$dir_path1 = dirname(__FILE__) . "/私はガラスを食べられますrewinddir_basic_dir1"; +$dir_path2 = dirname(__FILE__) . "/私はガラスを食べられますrewinddir_basic_dir2"; +mkdir($dir_path1); +mkdir($dir_path2); + +@create_files($dir_path1, 1, "numeric", 0755, 1, "w", "私はガラスを食べられますfile"); +@create_files($dir_path2, 1, 'numeric', 0755, 1, 'w', "私はガラスを食べられますfile", 2); +var_dump($dh1 = opendir($dir_path1)); +var_dump($dh2 = opendir($dir_path2)); + +$data = array(); +echo "\n-- Read and rewind first directory (argument supplied) --\n"; +while(FALSE !== $file1 = readdir($dh1)) { + $data[] = $file1; +} +$first = $data[0]; +sort($data); +var_dump($data); + +var_dump(rewinddir($dh1)); +var_dump(readdir($dh1) == $first); + +$data = array(); +echo "\n-- Read and rewind second directory (no argument supplied) --\n"; +while(FALSE !== $file2 = readdir()) { + $data[] = $file2; +} +$first = $data[0]; +sort($data); +var_dump($data); + +var_dump(rewinddir()); +var_dump(readdir() == $first); + +closedir($dh1); +closedir($dh2); + +delete_files($dir_path1, 1, "私はガラスを食べられますfile"); +delete_files($dir_path2, 1, "私はガラスを食べられますfile", 2); +?> +===DONE=== +--CLEAN-- +<?php +$dir_path1 = dirname(__FILE__) . "/私はガラスを食べられますrewinddir_basic_dir1"; +$dir_path2 = dirname(__FILE__) . "/私はガラスを食べられますrewinddir_basic_dir2"; +rmdir($dir_path1); +rmdir($dir_path2); +?> +--EXPECTF-- +*** Testing rewinddir() : basic functionality *** +resource(%d) of type (stream) +resource(%d) of type (stream) + +-- Read and rewind first directory (argument supplied) -- +array(3) { + [0]=> + string(1) "." + [1]=> + string(2) ".." + [2]=> + string(45) "私はガラスを食べられますfile1.tmp" +} +NULL +bool(true) + +-- Read and rewind second directory (no argument supplied) -- +array(3) { + [0]=> + string(1) "." + [1]=> + string(2) ".." + [2]=> + string(45) "私はガラスを食べられますfile2.tmp" +} +NULL +bool(true) +===DONE=== diff --git a/ext/standard/tests/dir/rewinddir_error-win32-mb.phpt b/ext/standard/tests/dir/rewinddir_error-win32-mb.phpt new file mode 100644 index 0000000000..d78271e0f6 --- /dev/null +++ b/ext/standard/tests/dir/rewinddir_error-win32-mb.phpt @@ -0,0 +1,42 @@ +--TEST-- +Test rewinddir() function : error conditions - incorrect number of args +--FILE-- +<?php +/* Prototype : void rewinddir([resource $dir_handle]) + * Description: Rewind dir_handle back to the start + * Source code: ext/standard/dir.c + * Alias to functions: rewind + */ + +/* + * Pass incorrect number of arguments to rewinddir() to test behaviour + */ + +echo "*** Testing rewinddir() : error conditions ***\n"; + + +//Test rewinddir with one more than the expected number of arguments +echo "\n-- Testing rewinddir() function with more than expected no. of arguments --\n"; + +$dir_path = dirname(__FILE__) . "/私はガラスを食べられますrewinddir_error"; +mkdir($dir_path); +$dir_handle = opendir($dir_path); +$extra_arg = 10; + +var_dump( rewinddir($dir_handle, $extra_arg) ); +closedir($dir_handle); +?> +===DONE=== +--CLEAN-- +<?php +$dir_path = dirname(__FILE__) . "/私はガラスを食べられますrewinddir_error"; +rmdir($dir_path); +?> +--EXPECTF-- +*** Testing rewinddir() : error conditions *** + +-- Testing rewinddir() function with more than expected no. of arguments -- + +Warning: rewinddir() expects at most 1 parameter, 2 given in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/dir/rewinddir_variation2-win32-mb.phpt b/ext/standard/tests/dir/rewinddir_variation2-win32-mb.phpt new file mode 100644 index 0000000000..71d40f1147 --- /dev/null +++ b/ext/standard/tests/dir/rewinddir_variation2-win32-mb.phpt @@ -0,0 +1,45 @@ +--TEST-- +Test rewinddir() function : usage variations - operate on a closed directory +--FILE-- +<?php +/* Prototype : void rewinddir([resource $dir_handle]) + * Description: Rewind dir_handle back to the start + * Source code: ext/standard/dir.c + * Alias to functions: rewind + */ + +/* + * Open and close a directory handle then call rewinddir() to test behaviour + */ + +echo "*** Testing rewinddir() : usage variations ***\n"; + +$dir_path = dirname(__FILE__) . '/私はガラスを食べられますrewinddir_variation2'; +mkdir($dir_path); + +echo "\n-- Create the directory handle, read and close the directory --\n"; +var_dump($dir_handle = opendir($dir_path)); +var_dump(readdir($dir_handle)); +closedir($dir_handle); + +echo "\n-- Call to rewinddir() --\n"; +var_dump(rewinddir($dir_handle)); +?> +===DONE=== +--CLEAN-- +<?php +$dir_path = dirname(__FILE__) . '/私はガラスを食べられますrewinddir_variation2'; +rmdir($dir_path); +?> +--EXPECTF-- +*** Testing rewinddir() : usage variations *** + +-- Create the directory handle, read and close the directory -- +resource(%d) of type (stream) +string(%d) "%s" + +-- Call to rewinddir() -- + +Warning: rewinddir(): %s is not a valid Directory resource in %s on line %d +bool(false) +===DONE=== diff --git a/ext/standard/tests/dir/scandir_basic-win32-mb.phpt b/ext/standard/tests/dir/scandir_basic-win32-mb.phpt new file mode 100644 index 0000000000..ca99cf0ada --- /dev/null +++ b/ext/standard/tests/dir/scandir_basic-win32-mb.phpt @@ -0,0 +1,70 @@ +--TEST-- +Test scandir() function : basic functionality +--FILE-- +<?php +/* Prototype : array scandir(string $dir [, int $sorting_order [, resource $context]]) + * Description: List files & directories inside the specified path + * Source code: ext/standard/dir.c + */ + +/* + * Test basic functionality of scandir() + */ + +echo "*** Testing scandir() : basic functionality ***\n"; + +// include file.inc for create_files function +include (dirname(__FILE__) . '/../file/file.inc'); + +// set up directory +$directory = dirname(__FILE__) . '/私はガラスを食べられますscandir_basic'; +mkdir($directory); +create_files($directory, 3, "numeric", 0755, 1, "w", "私はガラスを食べられますfile"); + +echo "\n-- scandir() with mandatory arguments --\n"; +var_dump(scandir($directory)); + +echo "\n-- scandir() with all arguments --\n"; +$sorting_order = SCANDIR_SORT_DESCENDING; +$context = stream_context_create(); +var_dump(scandir($directory, $sorting_order, $context)); + +delete_files($directory, 3, "私はガラスを食べられますfile"); +?> +===DONE=== +--CLEAN-- +<?php +$directory = dirname(__FILE__) . '/私はガラスを食べられますscandir_basic'; +rmdir($directory); +?> +--EXPECTF-- +*** Testing scandir() : basic functionality *** + +-- scandir() with mandatory arguments -- +array(5) { + [0]=> + string(1) "." + [1]=> + string(2) ".." + [2]=> + string(45) "私はガラスを食べられますfile1.tmp" + [3]=> + string(45) "私はガラスを食べられますfile2.tmp" + [4]=> + string(45) "私はガラスを食べられますfile3.tmp" +} + +-- scandir() with all arguments -- +array(5) { + [0]=> + string(45) "私はガラスを食べられますfile3.tmp" + [1]=> + string(45) "私はガラスを食べられますfile2.tmp" + [2]=> + string(45) "私はガラスを食べられますfile1.tmp" + [3]=> + string(2) ".." + [4]=> + string(1) "." +} +===DONE=== diff --git a/ext/standard/tests/dir/scandir_error1-win32-mb.phpt b/ext/standard/tests/dir/scandir_error1-win32-mb.phpt new file mode 100644 index 0000000000..b0ed08a20d --- /dev/null +++ b/ext/standard/tests/dir/scandir_error1-win32-mb.phpt @@ -0,0 +1,47 @@ +--TEST-- +Test scandir() function : error conditions - Incorrect number of args +--FILE-- +<?php +/* Prototype : array scandir(string $dir [, int $sorting_order [, resource $context]]) + * Description: List files & directories inside the specified path + * Source code: ext/standard/dir.c + */ + +/* + * Pass incorrect number of arguments to scandir() to test behaviour + */ + +echo "*** Testing scandir() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing scandir() function with Zero arguments --\n"; +var_dump( scandir() ); + +//Test scandir with one more than the expected number of arguments +echo "\n-- Testing scandir() function with more than expected no. of arguments --\n"; +$dir = dirname(__FILE__) . '/私はガラスを食べられますscandir_error'; +mkdir($dir); +$sorting_order = 10; +$context = stream_context_create(); +$extra_arg = 10; +var_dump( scandir($dir, $sorting_order, $context, $extra_arg) ); +?> +===DONE=== +--CLEAN-- +<?php +$directory = dirname(__FILE__) . '/私はガラスを食べられますscandir_error'; +rmdir($directory); +?> +--EXPECTF-- +*** Testing scandir() : error conditions *** + +-- Testing scandir() function with Zero arguments -- + +Warning: scandir() expects at least 1 parameter, 0 given in %s on line %d +NULL + +-- Testing scandir() function with more than expected no. of arguments -- + +Warning: scandir() expects at most 3 parameters, 4 given in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/dir/scandir_variation10-win32-mb.phpt b/ext/standard/tests/dir/scandir_variation10-win32-mb.phpt new file mode 100644 index 0000000000..435a710fbc --- /dev/null +++ b/ext/standard/tests/dir/scandir_variation10-win32-mb.phpt @@ -0,0 +1,79 @@ +--TEST-- +Test scandir() function : usage variations - different sorting constants +--FILE-- +<?php +/* Prototype : array scandir(string $dir [, int $sorting_order [, resource $context]]) + * Description: List files & directories inside the specified path + * Source code: ext/standard/dir.c + */ + +printf("SCANDIR_SORT_ASCENDING: %d\n", SCANDIR_SORT_ASCENDING); +printf("SCANDIR_SORT_DESCENDING: %d\n", SCANDIR_SORT_DESCENDING); +printf("SCANDIR_SORT_NONE: %d\n", SCANDIR_SORT_NONE); + +/* + * Pass different integers as $sorting_order argument to test how scandir() + * re-orders the array + */ + +echo "*** Testing scandir() : usage variations ***\n"; + +// include for create_files/delete_files functions +include(dirname(__FILE__) . '/../file/file.inc'); + +// create directory and files +$dir = dirname(__FILE__) . '/私はガラスを食べられますscandir_variation10'; +mkdir($dir); +@create_files($dir, 2, "numeric", 0755, 1, "w", "私はガラスを食べられますfile"); + +// Deterministic tests. +var_dump(scandir($dir, SCANDIR_SORT_ASCENDING)); +var_dump(scandir($dir, SCANDIR_SORT_DESCENDING)); + +// Non-deterministic tests. +$files = scandir($dir, SCANDIR_SORT_NONE); +var_dump(count($files)); +var_dump(in_array('.', $files)); +var_dump(in_array('..', $files)); +var_dump(in_array('私はガラスを食べられますfile1.tmp', $files)); +var_dump(in_array('私はガラスを食べられますfile2.tmp', $files)); + +delete_files($dir, 2, "私はガラスを食べられますfile"); +?> +===DONE=== +--CLEAN-- +<?php +$dir = dirname(__FILE__) . '/私はガラスを食べられますscandir_variation10'; +rmdir($dir); +?> +--EXPECTF-- +SCANDIR_SORT_ASCENDING: 0 +SCANDIR_SORT_DESCENDING: 1 +SCANDIR_SORT_NONE: 2 +*** Testing scandir() : usage variations *** +array(4) { + [0]=> + string(1) "." + [1]=> + string(2) ".." + [2]=> + string(45) "私はガラスを食べられますfile1.tmp" + [3]=> + string(45) "私はガラスを食べられますfile2.tmp" +} +array(4) { + [0]=> + string(45) "私はガラスを食べられますfile2.tmp" + [1]=> + string(45) "私はガラスを食べられますfile1.tmp" + [2]=> + string(2) ".." + [3]=> + string(1) "." +} +int(4) +bool(true) +bool(true) +bool(true) +bool(true) +===DONE=== diff --git a/ext/standard/tests/dir/scandir_variation2-win32-mb.phpt b/ext/standard/tests/dir/scandir_variation2-win32-mb.phpt new file mode 100644 index 0000000000..4e32a85f95 --- /dev/null +++ b/ext/standard/tests/dir/scandir_variation2-win32-mb.phpt @@ -0,0 +1,283 @@ +--TEST-- +Test scandir() function : usage variations - diff data types as $sorting_order arg +--FILE-- +<?php +/* Prototype : array scandir(string $dir [, int $sorting_order [, resource $context]]) + * Description: List files & directories inside the specified path + * Source code: ext/standard/dir.c + */ + +/* + * Pass different data types as $sorting_order argument to test how scandir() behaves + */ + +echo "*** Testing scandir() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$dir = dirname(__FILE__) . '/私はガラスを食べられますscandir_variation2'; +mkdir($dir); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $sorting_order argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + array(), + + // string data +/*19*/ "string", + 'string', + $heredoc, + + // object data +/*22*/ new classA(), + + // undefined data +/*23*/ @$undefined_var, + + // unset data +/*24*/ @$unset_var, + + // resource variable +/*25*/ $fp +); + +// loop through each element of $inputs to check the behavior of scandir() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( scandir($dir, $input) ); + $iterator++; +}; + +fclose($fp); +?> +===DONE=== +--CLEAN-- +<?php +$dir = dirname(__FILE__) . '/私はガラスを食べられますscandir_variation2'; +rmdir($dir); +?> +--EXPECTF-- +*** Testing scandir() : usage variations *** + +-- Iteration 1 -- +array(2) { + [0]=> + string(1) "." + [1]=> + string(2) ".." +} + +-- Iteration 2 -- +array(2) { + [0]=> + string(2) ".." + [1]=> + string(1) "." +} + +-- Iteration 3 -- +array(2) { + [0]=> + string(2) ".." + [1]=> + string(1) "." +} + +-- Iteration 4 -- +array(2) { + [0]=> + string(2) ".." + [1]=> + string(1) "." +} + +-- Iteration 5 -- +array(2) { + [0]=> + string(2) ".." + [1]=> + string(1) "." +} + +-- Iteration 6 -- +array(2) { + [0]=> + string(2) ".." + [1]=> + string(1) "." +} + +-- Iteration 7 -- +array(2) { + [0]=> + string(2) ".." + [1]=> + string(1) "." +} + +-- Iteration 8 -- +array(2) { + [0]=> + string(1) "." + [1]=> + string(2) ".." +} + +-- Iteration 9 -- +array(2) { + [0]=> + string(1) "." + [1]=> + string(2) ".." +} + +-- Iteration 10 -- +array(2) { + [0]=> + string(1) "." + [1]=> + string(2) ".." +} + +-- Iteration 11 -- +array(2) { + [0]=> + string(1) "." + [1]=> + string(2) ".." +} + +-- Iteration 12 -- +array(2) { + [0]=> + string(2) ".." + [1]=> + string(1) "." +} + +-- Iteration 13 -- +array(2) { + [0]=> + string(1) "." + [1]=> + string(2) ".." +} + +-- Iteration 14 -- +array(2) { + [0]=> + string(2) ".." + [1]=> + string(1) "." +} + +-- Iteration 15 -- +array(2) { + [0]=> + string(1) "." + [1]=> + string(2) ".." +} + +-- Iteration 16 -- + +Warning: scandir() expects parameter 2 to be integer, string given in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: scandir() expects parameter 2 to be integer, string given in %s on line %d +NULL + +-- Iteration 18 -- + +Warning: scandir() expects parameter 2 to be integer, array given in %s on line %d +NULL + +-- Iteration 19 -- + +Warning: scandir() expects parameter 2 to be integer, string given in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: scandir() expects parameter 2 to be integer, string given in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: scandir() expects parameter 2 to be integer, string given in %s on line %d +NULL + +-- Iteration 22 -- + +Warning: scandir() expects parameter 2 to be integer, object given in %s on line %d +NULL + +-- Iteration 23 -- +array(2) { + [0]=> + string(1) "." + [1]=> + string(2) ".." +} + +-- Iteration 24 -- +array(2) { + [0]=> + string(1) "." + [1]=> + string(2) ".." +} + +-- Iteration 25 -- + +Warning: scandir() expects parameter 2 to be integer, resource given in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/dir/scandir_variation3-win32-mb.phpt b/ext/standard/tests/dir/scandir_variation3-win32-mb.phpt new file mode 100644 index 0000000000..c6eae7cae1 --- /dev/null +++ b/ext/standard/tests/dir/scandir_variation3-win32-mb.phpt @@ -0,0 +1,238 @@ +--TEST-- +Test scandir() function : usage variations - diff data types as $context arg +--FILE-- +<?php +/* Prototype : array scandir(string $dir [, int $sorting_order [, resource $context]]) + * Description: List files & directories inside the specified path + * Source code: ext/standard/dir.c + */ + +/* + * Pass different data types as $context argument to test how scandir() behaves + */ + +echo "*** Testing scandir() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$dir = dirname(__FILE__) . '/私はガラスを食べられますscandir_variation3'; +mkdir($dir); +$sorting_order = SCANDIR_SORT_ASCENDING; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $context argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + array(), + + // string data +/*19*/ "string", + 'string', + $heredoc, + + // object data +/*22*/ new classA(), + + // undefined data +/*23*/ @$undefined_var, + + // unset data +/*24*/ @$unset_var, + + // resource variable +/*25*/ $fp +); + +// loop through each element of $inputs to check the behavior of scandir() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( scandir($dir, $sorting_order, $input) ); + $iterator++; +}; + +fclose($fp); +?> +===DONE=== +--CLEAN-- +<?php +$dir = dirname(__FILE__) . '/私はガラスを食べられますscandir_variation3'; +rmdir($dir); +?> +--EXPECTF-- +*** Testing scandir() : usage variations *** + +-- Iteration 1 -- + +Warning: scandir() expects parameter 3 to be resource, integer given in %s on line %d +NULL + +-- Iteration 2 -- + +Warning: scandir() expects parameter 3 to be resource, integer given in %s on line %d +NULL + +-- Iteration 3 -- + +Warning: scandir() expects parameter 3 to be resource, integer given in %s on line %d +NULL + +-- Iteration 4 -- + +Warning: scandir() expects parameter 3 to be resource, integer given in %s on line %d +NULL + +-- Iteration 5 -- + +Warning: scandir() expects parameter 3 to be resource, float given in %s on line %d +NULL + +-- Iteration 6 -- + +Warning: scandir() expects parameter 3 to be resource, float given in %s on line %d +NULL + +-- Iteration 7 -- + +Warning: scandir() expects parameter 3 to be resource, float given in %s on line %d +NULL + +-- Iteration 8 -- + +Warning: scandir() expects parameter 3 to be resource, float given in %s on line %d +NULL + +-- Iteration 9 -- + +Warning: scandir() expects parameter 3 to be resource, float given in %s on line %d +NULL + +-- Iteration 10 -- + +Warning: scandir() expects parameter 3 to be resource, null given in %s on line %d +NULL + +-- Iteration 11 -- + +Warning: scandir() expects parameter 3 to be resource, null given in %s on line %d +NULL + +-- Iteration 12 -- + +Warning: scandir() expects parameter 3 to be resource, boolean given in %s on line %d +NULL + +-- Iteration 13 -- + +Warning: scandir() expects parameter 3 to be resource, boolean given in %s on line %d +NULL + +-- Iteration 14 -- + +Warning: scandir() expects parameter 3 to be resource, boolean given in %s on line %d +NULL + +-- Iteration 15 -- + +Warning: scandir() expects parameter 3 to be resource, boolean given in %s on line %d +NULL + +-- Iteration 16 -- + +Warning: scandir() expects parameter 3 to be resource, string given in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: scandir() expects parameter 3 to be resource, string given in %s on line %d +NULL + +-- Iteration 18 -- + +Warning: scandir() expects parameter 3 to be resource, array given in %s on line %d +NULL + +-- Iteration 19 -- + +Warning: scandir() expects parameter 3 to be resource, string given in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: scandir() expects parameter 3 to be resource, string given in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: scandir() expects parameter 3 to be resource, string given in %s on line %d +NULL + +-- Iteration 22 -- + +Warning: scandir() expects parameter 3 to be resource, object given in %s on line %d +NULL + +-- Iteration 23 -- + +Warning: scandir() expects parameter 3 to be resource, null given in %s on line %d +NULL + +-- Iteration 24 -- + +Warning: scandir() expects parameter 3 to be resource, null given in %s on line %d +NULL + +-- Iteration 25 -- + +Warning: scandir(): supplied resource is not a valid Stream-Context resource in %s on line %d +array(2) { + [0]=> + string(1) "." + [1]=> + string(2) ".." +} +===DONE=== diff --git a/ext/standard/tests/dir/scandir_variation4-win32-mb.phpt b/ext/standard/tests/dir/scandir_variation4-win32-mb.phpt new file mode 100644 index 0000000000..8090a276b7 --- /dev/null +++ b/ext/standard/tests/dir/scandir_variation4-win32-mb.phpt @@ -0,0 +1,169 @@ +--TEST-- +Test scandir() function : usage variations - different relative paths +--FILE-- +<?php +/* Prototype : array scandir(string $dir [, int $sorting_order [, resource $context]]) + * Description: List files & directories inside the specified path + * Source code: ext/standard/dir.c + */ + +/* + * Test scandir() with relative paths as $dir argument + */ + +echo "*** Testing scandir() : usage variations ***\n"; + +// include for create_files/delete_files functions +include (dirname(__FILE__) . '/../file/file.inc'); + +$base_dir_path = dirname(__FILE__); + +$level_one_dir_path = "$base_dir_path/私はガラスを食べられますlevel_one"; +$level_two_dir_path = "$level_one_dir_path/私はガラスを食べられますlevel_two"; + +// create directories and files +mkdir($level_one_dir_path); +create_files($level_one_dir_path, 2, 'numeric', 0755, 1, 'w', '私はガラスを食べられますlevel_one', 1); +mkdir($level_two_dir_path); +create_files($level_two_dir_path, 2, 'numeric', 0755, 1, 'w', '私はガラスを食べられますlevel_two', 1); + +echo "\n-- \$path = './私はガラスを食べられますlevel_one': --\n"; +var_dump(chdir($base_dir_path)); +var_dump(scandir('./私はガラスを食べられますlevel_one')); + +echo "\n-- \$path = 'level_one/私はガラスを食べられますlevel_two': --\n"; +var_dump(chdir($base_dir_path)); +var_dump(scandir('私はガラスを食べられますlevel_one/私はガラスを食べられますlevel_two')); + +echo "\n-- \$path = '..': --\n"; +var_dump(chdir($level_two_dir_path)); +var_dump(scandir('..')); + +echo "\n-- \$path = '私はガラスを食べられますlevel_two', '.': --\n"; +var_dump(chdir($level_two_dir_path)); +var_dump(scandir('.')); + +echo "\n-- \$path = '../': --\n"; +var_dump(chdir($level_two_dir_path)); +var_dump(scandir('../')); + +echo "\n-- \$path = './': --\n"; +var_dump(chdir($level_two_dir_path)); +var_dump(scandir('./')); + +echo "\n-- \$path = '../../'私はガラスを食べられますlevel_one': --\n"; +var_dump(chdir($level_two_dir_path)); +var_dump(scandir('../../私はガラスを食べられますlevel_one')); + +@delete_files($level_one_dir_path, 2, '私はガラスを食べられますlevel_one'); +@delete_files($level_two_dir_path, 2, '私はガラスを食べられますlevel_two'); +?> +===DONE=== +--CLEAN-- +<?php +$dir_path = dirname(__FILE__); +rmdir("$dir_path/私はガラスを食べられますlevel_one/私はガラスを食べられますlevel_two"); +rmdir("$dir_path/私はガラスを食べられますlevel_one"); +?> +--EXPECTF-- +*** Testing scandir() : usage variations *** + +-- $path = './私はガラスを食べられますlevel_one': -- +bool(true) +array(5) { + [0]=> + string(1) "." + [1]=> + string(2) ".." + [2]=> + string(50) "私はガラスを食べられますlevel_one1.tmp" + [3]=> + string(50) "私はガラスを食べられますlevel_one2.tmp" + [4]=> + string(45) "私はガラスを食べられますlevel_two" +} + +-- $path = 'level_one/私はガラスを食べられますlevel_two': -- +bool(true) +array(4) { + [0]=> + string(1) "." + [1]=> + string(2) ".." + [2]=> + string(50) "私はガラスを食べられますlevel_two1.tmp" + [3]=> + string(50) "私はガラスを食べられますlevel_two2.tmp" +} + +-- $path = '..': -- +bool(true) +array(5) { + [0]=> + string(1) "." + [1]=> + string(2) ".." + [2]=> + string(50) "私はガラスを食べられますlevel_one1.tmp" + [3]=> + string(50) "私はガラスを食べられますlevel_one2.tmp" + [4]=> + string(45) "私はガラスを食べられますlevel_two" +} + +-- $path = '私はガラスを食べられますlevel_two', '.': -- +bool(true) +array(4) { + [0]=> + string(1) "." + [1]=> + string(2) ".." + [2]=> + string(50) "私はガラスを食べられますlevel_two1.tmp" + [3]=> + string(50) "私はガラスを食べられますlevel_two2.tmp" +} + +-- $path = '../': -- +bool(true) +array(5) { + [0]=> + string(1) "." + [1]=> + string(2) ".." + [2]=> + string(50) "私はガラスを食べられますlevel_one1.tmp" + [3]=> + string(50) "私はガラスを食べられますlevel_one2.tmp" + [4]=> + string(45) "私はガラスを食べられますlevel_two" +} + +-- $path = './': -- +bool(true) +array(4) { + [0]=> + string(1) "." + [1]=> + string(2) ".." + [2]=> + string(50) "私はガラスを食べられますlevel_two1.tmp" + [3]=> + string(50) "私はガラスを食べられますlevel_two2.tmp" +} + +-- $path = '../../'私はガラスを食べられますlevel_one': -- +bool(true) +array(5) { + [0]=> + string(1) "." + [1]=> + string(2) ".." + [2]=> + string(50) "私はガラスを食べられますlevel_one1.tmp" + [3]=> + string(50) "私はガラスを食べられますlevel_one2.tmp" + [4]=> + string(45) "私はガラスを食べられますlevel_two" +} +===DONE=== diff --git a/ext/standard/tests/dir/scandir_variation8-win32-mb.phpt b/ext/standard/tests/dir/scandir_variation8-win32-mb.phpt new file mode 100644 index 0000000000..7ae165fd92 --- /dev/null +++ b/ext/standard/tests/dir/scandir_variation8-win32-mb.phpt @@ -0,0 +1,154 @@ +--TEST-- +Test scandir() function : usage variations - different file names +--FILE-- +<?php +/* Prototype : array scandir(string $dir [, int $sorting_order [, resource $context]]) + * Description: List files & directories inside the specified path + * Source code: ext/standard/dir.c + */ + +/* + * Pass a directory containing files with different types of names to test how scandir() + * reads them + */ + +echo "*** Testing scandir() : usage variations ***\n"; + +$dir_path = dirname(__FILE__) . "/私はガラスを食べられますscandir_variation8/"; +mkdir($dir_path); + +// heredoc string +$heredoc = <<<EOT +hd_file +EOT; + +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // empty data +/*10*/ "", + array(), + + // string data +/*12*/ "double_file", + 'single_file', + $heredoc, +); + +$iterator = 1; +foreach($inputs as $key => $input) { + echo "\n-- Iteration $iterator --\n"; + $handle = "fp{$iterator}"; + var_dump( $$handle = @fopen($dir_path . "/私はガラスを食べられます$input.tmp", 'w') ); + fclose($$handle); + $iterator++; +}; + +echo "\n-- Call to scandir() --\n"; +var_dump($content = scandir($dir_path)); + +// remove all files in directory so can remove directory in CLEAN section +foreach ($content as $file_name) { + // suppress errors as won't be able to remove "." and ".." entries + @unlink($dir_path . $file_name); +} +?> +===DONE=== +--CLEAN-- +<?php +$dir_path = dirname(__FILE__) . "/私はガラスを食べられますscandir_variation8"; +rmdir($dir_path); +?> +--EXPECTF-- +*** Testing scandir() : usage variations *** + +-- Iteration 1 -- +resource(%d) of type (stream) + +-- Iteration 2 -- +resource(%d) of type (stream) + +-- Iteration 3 -- +resource(%d) of type (stream) + +-- Iteration 4 -- +resource(%d) of type (stream) + +-- Iteration 5 -- +resource(%d) of type (stream) + +-- Iteration 6 -- +resource(%d) of type (stream) + +-- Iteration 7 -- +resource(%d) of type (stream) + +-- Iteration 8 -- +resource(%d) of type (stream) + +-- Iteration 9 -- +resource(%d) of type (stream) + +-- Iteration 10 -- +resource(%d) of type (stream) + +-- Iteration 11 -- +resource(%d) of type (stream) + +-- Iteration 12 -- +resource(%d) of type (stream) + +-- Iteration 13 -- +resource(%d) of type (stream) + +-- Iteration 14 -- +resource(%d) of type (stream) + +-- Call to scandir() -- +array(16) { + [0]=> + string(1) "." + [1]=> + string(2) ".." + [2]=> + string(45) "私はガラスを食べられます-10.5.tmp" + [3]=> + string(45) "私はガラスを食べられます-2345.tmp" + [4]=> + string(40) "私はガラスを食べられます.tmp" + [5]=> + string(43) "私はガラスを食べられます0.5.tmp" + [6]=> + string(41) "私はガラスを食べられます0.tmp" + [7]=> + string(53) "私はガラスを食べられます1.23456789E-9.tmp" + [8]=> + string(41) "私はガラスを食べられます1.tmp" + [9]=> + string(44) "私はガラスを食べられます10.5.tmp" + [10]=> + string(45) "私はガラスを食べられます12345.tmp" + [11]=> + string(52) "私はガラスを食べられます123456789000.tmp" + [12]=> + string(45) "私はガラスを食べられますArray.tmp" + [13]=> + string(51) "私はガラスを食べられますdouble_file.tmp" + [14]=> + string(47) "私はガラスを食べられますhd_file.tmp" + [15]=> + string(51) "私はガラスを食べられますsingle_file.tmp" +} +===DONE=== diff --git a/ext/standard/tests/dir/scandir_variation9-win32-mb.phpt b/ext/standard/tests/dir/scandir_variation9-win32-mb.phpt new file mode 100644 index 0000000000..b4e1aee282 --- /dev/null +++ b/ext/standard/tests/dir/scandir_variation9-win32-mb.phpt @@ -0,0 +1,72 @@ +--TEST-- +Test scandir() function : usage variations - different ints as $sorting_order arg +--FILE-- +<?php +/* Prototype : array scandir(string $dir [, int $sorting_order [, resource $context]]) + * Description: List files & directories inside the specified path + * Source code: ext/standard/dir.c + */ + +/* + * Pass different integers as $sorting_order argument to test how scandir() + * re-orders the array + */ + +echo "*** Testing scandir() : usage variations ***\n"; + +// include for create_files/delete_files functions +include(dirname(__FILE__) . '/../file/file.inc'); + +// create directory and files +$dir = dirname(__FILE__) . '/私はガラスを食べられますscandir_variation9'; +mkdir($dir); +@create_files($dir, 2, "numeric", 0755, 1, "w", "私はガラスを食べられますfile"); + +// different ints to pass as $sorting_order argument +$ints = array (PHP_INT_MAX, -PHP_INT_MAX, 0); + +foreach($ints as $sorting_order) { + var_dump( scandir($dir, $sorting_order) ); +} + +delete_files($dir, 2, "私はガラスを食べられますfile"); +?> +===DONE=== +--CLEAN-- +<?php +$dir = dirname(__FILE__) . '/私はガラスを食べられますscandir_variation9'; +rmdir($dir); +?> +--EXPECTF-- +*** Testing scandir() : usage variations *** +array(4) { + [0]=> + string(45) "私はガラスを食べられますfile2.tmp" + [1]=> + string(45) "私はガラスを食べられますfile1.tmp" + [2]=> + string(2) ".." + [3]=> + string(1) "." +} +array(4) { + [0]=> + string(45) "私はガラスを食べられますfile2.tmp" + [1]=> + string(45) "私はガラスを食べられますfile1.tmp" + [2]=> + string(2) ".." + [3]=> + string(1) "." +} +array(4) { + [0]=> + string(1) "." + [1]=> + string(2) ".." + [2]=> + string(45) "私はガラスを食べられますfile1.tmp" + [3]=> + string(45) "私はガラスを食べられますfile2.tmp" +} +===DONE=== |