summaryrefslogtreecommitdiff
path: root/ext/standard/tests/file/file.inc
diff options
context:
space:
mode:
Diffstat (limited to 'ext/standard/tests/file/file.inc')
-rw-r--r--ext/standard/tests/file/file.inc188
1 files changed, 94 insertions, 94 deletions
diff --git a/ext/standard/tests/file/file.inc b/ext/standard/tests/file/file.inc
index aff9d107d9..afee2d20ce 100644
--- a/ext/standard/tests/file/file.inc
+++ b/ext/standard/tests/file/file.inc
@@ -1,29 +1,29 @@
<?php
-/* Header file for common file test functions
+/* Header file for common file test functions
Following functions are provided :
- create_files() : create files with specified contents
+ create_files() : create files with specified contents
delete_files() : delete files
create_links() : crate links of different types
- delete_links() : delete links
- fill_files() : fill file with specified contents
- change_file_perms() : Change permission of files
+ delete_links() : delete links
+ fill_files() : fill file with specified contents
+ change_file_perms() : Change permission of files
fill_buffer() : fills buffer with specified contents
- compare_self_stat() : compares the first 13 elements of the
+ compare_self_stat() : compares the first 13 elements of the
stat with the corresponding named key values of
the same stat.
compare_stats() : Compares two stat values
-*/
+*/
define('file_not_found', 2, 1);
-/*
+/*
Function: bool create_file(string $filename, string $mode = "w");
- Description: creates a new file using fopen() call
- $filename = Name of the file
+ Description: creates a new file using fopen() call
+ $filename = Name of the file
$mode = Mode as specified in fopen call, read documentation of fopen() call for more info
- Returns:
+ Returns:
true on success, false otherwise
*/
function create_file($filename, $mode = "w") {
@@ -83,23 +83,23 @@ function fill_buffer(&$buffer, $fill_type, $fill_size) {
Function : bool fill_file(resource $file_handle, string $fill_type, string $file_size);
Description: Fills the file with data as specified with requested size.
$file_handle = file handle, opened with write options,
- $fill_type:
+ $fill_type:
"text" = fills with string of size $file_size
"numeric" = fills with numeric value of size $file_size
"empty" = no fill operation performed, returns true
"text_with_new_line" = similar to "text" fill type but writes with new line
- "alphanumeric" = fills with alphnumeric values
+ "alphanumeric" = fills with alphnumeric values
Returns: true on success, false on failure & invalid fill type
*/
function fill_file($file_handle, $fill_type, $file_size) {
-
+
if ( $fill_type == "empty" ) {
// no fill required, return true
return true;
} if ( $fill_type == "text" ) {
$data = "text ";
- $size_divider = strlen($data);
+ $size_divider = strlen($data);
$add_value = strlen($data);
} else if ( $fill_type == "text_with_new_line" ) {
$data = "line\nline of text\n";
@@ -113,7 +113,7 @@ function fill_file($file_handle, $fill_type, $file_size) {
$data = 2;
$size_divider = 1;
$add_value = 0;
- } else {
+ } else {
// invalid fill type;
return false;
}
@@ -124,7 +124,7 @@ function fill_file($file_handle, $fill_type, $file_size) {
if ( $size > $chunk_size ) {
$loop_count = 1;
do {
- $loop_count ++;
+ $loop_count ++;
if ( $size <= $chunk_size ) {
$chunk_size = $size;
}
@@ -142,14 +142,14 @@ function fill_file($file_handle, $fill_type, $file_size) {
return false;
}
}
-
+
// successful, return true
return true;
}
/*
- Function: int change_file_perms(string $file_path, int $count = 1, int $perms = 0755,
- string $name_prefix = "file",
+ Function: int change_file_perms(string $file_path, int $count = 1, int $perms = 0755,
+ string $name_prefix = "file",
string $name_suffix = 1, $file_extension = ".tmp");
Description: changes file permission for given file(s).
$file_path = dir path where file exists
@@ -157,21 +157,21 @@ function fill_file($file_handle, $fill_type, $file_size) {
$perms = new permission of the file, similar to $mode args of chmod() call
$name_prefix = common name prefix, default is "file"
$name_suffix = suffix to end the common name given in name_prefix to create
- a unique name. default is 1.
+ a unique name. default is 1.
$file_extension = default is .tmp
Returns:
Integer, Count of total files permission changed.
*/
function change_file_perms($file_path,
- $count = 1,
- $perms = 0755,
- $name_prefix = "file",
- $name_suffix = 1,
- $file_extension = ".tmp" )
+ $count = 1,
+ $perms = 0755,
+ $name_prefix = "file",
+ $name_suffix = 1,
+ $file_extension = ".tmp" )
{
$changed = 0;
- if( $count <= 0 )
+ if( $count <= 0 )
return $changed;
if ( $name_suffix <= 0)
@@ -182,34 +182,34 @@ function change_file_perms($file_path,
if( chmod($filename, $perms) )
$changed++;
$name_suffix++;
- }
+ }
return $changed;
}
-/*
+/*
Function: array create_files( string $file_path,
int $count = 1,
- string $content_type = "numeric",
- int $permission = 0755,
+ string $content_type = "numeric",
+ int $permission = 0755,
int $size = 1,
- string $mode = "w",
- string $name_prefix = "file",
+ string $mode = "w",
+ string $name_prefix = "file",
int $name_suffix = 1,
string $flag = "kilobytes"
string $file_extension = ".tmp"
);
- Description: Creates given number of files with specified mode and
+ Description: Creates given number of files with specified mode and
permissions. File is filled with content of size specified.
$file_path = dir where files will be created
- $name_prefix = prefix to be used for names, name is suffix with a
+ $name_prefix = prefix to be used for names, name is suffix with a
unqiue numeric value to make the file name unique, default = file
$name_suffix = suffix to be used for the name, default = 1
$count = total no. of files to be created, default = 1
- $mode = file open mode as specified in fopen() call. Do not use
+ $mode = file open mode as specified in fopen() call. Do not use
modes used for only reading the file. Default = "w"
- $permission = An octal number, This should be similar to $mode
- specified in chmod() call.
- $content_type = Specify type of the content to fill in the file.
+ $permission = An octal number, This should be similar to $mode
+ specified in chmod() call.
+ $content_type = Specify type of the content to fill in the file.
"numeric" = fill file with numeric vlaues
"text" = fill file with regular text
"empty" = empty file
@@ -218,16 +218,16 @@ function change_file_perms($file_path,
If imporper $content type is specified, file is created as empty
$size = size of the fill in terms of kilobyte, i.e size of the file.
if $flag is specified as "byte", then then given size is taken in bytes
- $flag = specifiy if size has to be treated as no of total bytes or
+ $flag = specifiy if size has to be treated as no of total bytes or
multiple of KB.
"kilobytes" = take size in terms of multiple of KB
- "byte" = take size in terms of bytes
+ "byte" = take size in terms of bytes
$file_extension = default is .tmp
Returns:
An array with following key value pair:
created => total file created
- filled => total files filled
+ filled => total files filled
perms_changed => total files permission changed
*/
function create_files( $file_path,
@@ -253,7 +253,7 @@ function create_files( $file_path,
if ( $size == 0 )
return $return_value;
- // prepare the size based on flag
+ // prepare the size based on flag
$file_size = $size;
if ( $flag == "kilobytes" ) {
$file_size = $file_size * 1024;
@@ -288,11 +288,11 @@ function create_files( $file_path,
fclose($file_handle);
return $return_value;
} // end of if
-
- // call fill_file() to fill the file
+
+ // call fill_file() to fill the file
if( fill_file($file_handle, $content_type, $file_size) )
$return_value['filled']++;
-
+
fclose($file_handle);
$tmp_name_suffix++;
@@ -300,9 +300,9 @@ function create_files( $file_path,
}
// change all file's permissions
- $return_value['perms_changed'] = change_file_perms($file_path, $count, $permission, $name_prefix,
+ $return_value['perms_changed'] = change_file_perms($file_path, $count, $permission, $name_prefix,
$name_suffix, $file_extension);
-
+
return $return_value;
}
@@ -336,8 +336,8 @@ function create_files( $file_path,
alphanumeric = fill with alphanumeric text
If imporper $content type is specified, file is created as empty
$size = size of the fill in terms of kilobyte, i.e size of the file.
- $link_type = type of the link to be created
- "soft" = soft link
+ $link_type = type of the link to be created
+ "soft" = soft link
"hard" = hard link
$filename = file used to create a link on
@@ -392,12 +392,12 @@ function create_links($file_path,
}
break;
}
-
+
if ( $link_file_content == "empty" ) {
$return_value['filled'] = 1;
return $return_value;
}
-
+
// fill the file with specific type of data and size
$tmp_name_suffix = $link_name_suffix;
$linkname = $file_path."/".$link_name_prefix.$tmp_name_suffix.$link_file_extension;
@@ -405,8 +405,8 @@ function create_links($file_path,
if($file_handle == false) {
return $return_value;
} // end of if
-
- // call fill_file() to fill the file
+
+ // call fill_file() to fill the file
if( fill_file($file_handle, $link_file_content, $link_size) )
$return_value['filled']++;
@@ -415,11 +415,11 @@ function create_links($file_path,
// change the permission of the link file, only if hard link.
// this is not applicable to soft links
- if( $link_type == "hard" ) {
- $return_value['perms_changed'] = change_file_perms($file_path,
- $link_count,
- $link_perms,
- $link_name_prefix,
+ if( $link_type == "hard" ) {
+ $return_value['perms_changed'] = change_file_perms($file_path,
+ $link_count,
+ $link_perms,
+ $link_name_prefix,
$link_name_suffix,
$link_file_extension );
}
@@ -427,10 +427,10 @@ function create_links($file_path,
return $return_value;
}
-/*
+/*
Function: bool delete_file(string $filename);
- Description: delete a given file if exists
- Returns: true on success
+ Description: delete a given file if exists
+ Returns: true on success
false on failure
file_not_found if file doesn't exist
*/
@@ -446,7 +446,7 @@ function delete_file($filename) {
}
/*
- Function: array delete_files(string $file_path, int $count = 1, string $name_prefix = "file",
+ Function: array delete_files(string $file_path, int $count = 1, string $name_prefix = "file",
int name_suffix = 1, $file_extension = ".tmp" );
Description: Deletes given number of files if exists.
$file_path = location of the files
@@ -460,15 +460,15 @@ function delete_file($filename) {
failed = Count of failed to delete
*/
function delete_files($file_path,
- $count = 1,
- $name_prefix = "file",
- $name_suffix = 1,
- $file_extension = ".tmp")
+ $count = 1,
+ $name_prefix = "file",
+ $name_suffix = 1,
+ $file_extension = ".tmp")
{
$return_value = array ('deleted' => 0, 'notfound' => 0, 'failed' => 0);
if ( $name_suffix < 1 )
- $name_suffix = 1;
+ $name_suffix = 1;
for($loop_counter = 1; $loop_counter <= $count; $loop_counter++) {
$filename = $file_path."/".$name_prefix.$name_suffix.$file_extension;
$name_suffix++;
@@ -480,20 +480,20 @@ function delete_files($file_path,
} else {
$return_value['failed']++;
}
-
+
} // end of for
return $return_value;
}
/*
- Function: array delete_links( $file_path,
- $link_file_count,
- $link_name_prefix,
- $link_name_suffix,
+ Function: array delete_links( $file_path,
+ $link_file_count,
+ $link_name_prefix,
+ $link_name_suffix,
$link_file_extension );
Description: Deletes given number of links if exists. Uses delete_files() function
- $file_path = location of link files
- $link_file_count = Number of link files
+ $file_path = location of link files
+ $link_file_count = Number of link files
$link_name_prefix = prefix for the linkname, rest of the name is incremental(increment by 1 only)
numeric starting from $link_name_suffix up to count
$link_name_suffix = first numeric suffix in the name
@@ -504,16 +504,16 @@ function delete_files($file_path,
failed = Count of failed to delete
*/
function delete_links($file_path,
- $link_file_count = 1,
- $link_name_prefix = "link",
- $link_name_suffix = 1,
- $link_file_extension = ".tmp")
+ $link_file_count = 1,
+ $link_name_prefix = "link",
+ $link_name_suffix = 1,
+ $link_file_extension = ".tmp")
{
- // call the delete files to delete links
- $return_value = delete_files( $file_path,
- $link_file_count,
- $link_name_prefix,
- $link_name_suffix,
+ // call the delete files to delete links
+ $return_value = delete_files( $file_path,
+ $link_file_count,
+ $link_name_prefix,
+ $link_name_suffix,
$link_file_extension );
return $return_value;
}
@@ -524,7 +524,7 @@ function delete_links($file_path,
Prototype:
function compare_self_stat( array $stat );
Description:
- Compares the each of the first 13 values of the stat array with the
+ Compares the each of the first 13 values of the stat array with the
corresponding next 13 values of the same stat for equality
$stat = stat array
@@ -536,7 +536,7 @@ function compare_self_stat( array $stat )
$return_value = true;
// named keys present in a stat
- $string_keys = array("dev", "ino", "mode", "nlink", "uid", "gid",
+ $string_keys = array("dev", "ino", "mode", "nlink", "uid", "gid",
"rdev", "size", "atime", "mtime", "ctime",
"blksize", "blocks");
@@ -557,7 +557,7 @@ function compare_self_stat( array $stat )
}
} // end of foreach
- // if the $return_value is false, i.e all the element do not match then
+ // if the $return_value is false, i.e all the element do not match then
// dump the stat array so that its easy to figure out the error
if ($return_value == false ) {
echo "\n Dumping stat array ...\n";
@@ -569,7 +569,7 @@ function compare_self_stat( array $stat )
/*
Prototype:
- function compare_stats( array $stat1, array $stat2, array $fields,
+ function compare_stats( array $stat1, array $stat2, array $fields,
[string $op = "==", [ bool $flag = false] ]);
Description:
Compares two stat values, stat value should be obtained by stat/lstat
@@ -580,12 +580,12 @@ Description:
"==" compare for equality
">" if each element of stat1 is > than stat2
"<" if each element of stat1 is < than stat2
- $fields = contains the key of the elements that needs to be compared.
+ $fields = contains the key of the elements that needs to be compared.
type of the comparison is based on $op argument value
- $flag = specify true to dump the stat1 and stat2
+ $flag = specify true to dump the stat1 and stat2
*/
-$all_stat_keys = array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
+$all_stat_keys = array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
"dev", "ino", "mode", "nlink", "uid", "gid",
"rdev", "size", "atime", "mtime", "ctime",
"blksize", "blocks");
@@ -599,8 +599,8 @@ function compare_stats($stat1, $stat2, $fields, $op = "==", $flag = false ) {
$result = true;
- // compare values of given key from each stat array
- for($index = 0; $index < count($fields); $index++)
+ // compare values of given key from each stat array
+ for($index = 0; $index < count($fields); $index++)
{
switch( $op )
{
@@ -635,7 +635,7 @@ function compare_stats($stat1, $stat2, $fields, $op = "==", $flag = false ) {
break;
}
}
- // if the result is false(i.e values are not as expected),
+ // if the result is false(i.e values are not as expected),
// dump the stat array so that easy to figure out the error
if ( $result == false ) {
echo "\n Dumping stat array 1...\n";