diff options
Diffstat (limited to 'ext')
-rw-r--r-- | ext/standard/tests/dir/closedir_variation3.phpt | 42 | ||||
-rw-r--r-- | ext/standard/tests/dir/readdir_variation7.phpt | 36 | ||||
-rw-r--r-- | ext/standard/tests/dir/rewinddir_variation3.phpt | 41 |
3 files changed, 119 insertions, 0 deletions
diff --git a/ext/standard/tests/dir/closedir_variation3.phpt b/ext/standard/tests/dir/closedir_variation3.phpt new file mode 100644 index 0000000000..d0e3412b6c --- /dev/null +++ b/ext/standard/tests/dir/closedir_variation3.phpt @@ -0,0 +1,42 @@ +--TEST-- +Test closedir() function : usage variations - close a file pointer +--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 + */ + +/* + * Create a file pointer using fopen() then try to close it using closedir() + */ + +echo "*** Testing closedir() : usage variations ***\n"; + +echo "\n-- Open a file using fopen() --\n"; +var_dump($fp = fopen(__FILE__, 'r')); + +echo "\n-- Try to close the file pointer using closedir() --\n"; +var_dump(closedir($fp)); + +echo "\n-- Check file pointer: --\n"; +var_dump($fp); + +if(is_resource($fp)) { + fclose($fp); +} +?> +===DONE=== +--EXPECTF-- +*** Testing closedir() : usage variations *** + +-- Open a file using fopen() -- +resource(%d) of type (stream) + +-- Try to close the file pointer using closedir() -- +Warning: closedir(): %d is not a valid Directory resource in %s on line %d + +-- Check file pointer: -- +resource(%d) of type (stream) +===DONE=== diff --git a/ext/standard/tests/dir/readdir_variation7.phpt b/ext/standard/tests/dir/readdir_variation7.phpt new file mode 100644 index 0000000000..86bd43061e --- /dev/null +++ b/ext/standard/tests/dir/readdir_variation7.phpt @@ -0,0 +1,36 @@ +--TEST-- +Test readdir() function : usage variations - use file pointers +--FILE-- +<?php +/* Prototype : string readdir([resource $dir_handle]) + * Description: Read directory entry from dir_handle + * Source code: ext/standard/dir.c + */ + +/* + * Open a file pointer using fopen and pass to readdir() to test behaviour + */ + +echo "*** Testing readdir() : usage variations ***\n"; + +// get a resource variable +var_dump($fp = fopen(__FILE__, "r")); +var_dump( readdir($fp) ); + +// get file length over 256 characters +<<<EOT +123456789012345678901234567890 +123456789012345678901234567890 +123456789012345678901234567890 +123456789012345678901234567890 +123456789012345678901234567890 +EOT; +?> +===DONE=== +--EXPECTF-- +*** Testing readdir() : usage variations *** +resource(%d) of type (stream) + +Warning: readdir(): %d is not a valid Directory resource in %s on line %d +bool(false) +===DONE=== diff --git a/ext/standard/tests/dir/rewinddir_variation3.phpt b/ext/standard/tests/dir/rewinddir_variation3.phpt new file mode 100644 index 0000000000..b681e470f6 --- /dev/null +++ b/ext/standard/tests/dir/rewinddir_variation3.phpt @@ -0,0 +1,41 @@ +--TEST-- +Test rewinddir() function : usage variations - file pointers +--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 a file pointer to rewinddir() to test behaviour + */ + +echo "*** Testing rewinddir() : usage variations ***\n"; + +echo "\n-- Open a file using fopen --\n"; +var_dump($fp = fopen(__FILE__, 'r')); + +$result1 = fread($fp, 5); +var_dump(rewinddir($fp)); +$result2 = fread($fp, 5); + +echo "\n-- Check if rewinddir() has repositioned the file pointer --\n"; +if ($result1 === $result2) { + echo "rewinddir() works on file pointers\n"; +} else { + echo "rewinddir() does not work on file pointers\n"; +} +?> +===DONE=== +--EXPECTF-- +*** Testing rewinddir() : usage variations *** + +-- Open a file using fopen -- +resource(%d) of type (stream) +NULL + +-- Check if rewinddir() has repositioned the file pointer -- +rewinddir() does not work on file pointers +===DONE=== |