]> granicus.if.org Git - php/commitdiff
New tests for file handling system functions
authorRaghubansh Kumar <kraghuba@php.net>
Wed, 13 Jun 2007 22:38:49 +0000 (22:38 +0000)
committerRaghubansh Kumar <kraghuba@php.net>
Wed, 13 Jun 2007 22:38:49 +0000 (22:38 +0000)
12 files changed:
ext/standard/tests/file/copy_basic.phpt [new file with mode: 0644]
ext/standard/tests/file/copy_error.phpt [new file with mode: 0644]
ext/standard/tests/file/file_get_contents_file_put_contents_variation.phpt [new file with mode: 0644]
ext/standard/tests/file/filegroup_basic.phpt [new file with mode: 0644]
ext/standard/tests/file/filegroup_error.phpt [new file with mode: 0644]
ext/standard/tests/file/fileowner_basic.phpt [new file with mode: 0644]
ext/standard/tests/file/fileowner_error.phpt [new file with mode: 0644]
ext/standard/tests/file/fwrite_basic-win32.phpt [new file with mode: 0644]
ext/standard/tests/file/fwrite_basic.phpt [new file with mode: 0644]
ext/standard/tests/file/fwrite_error.phpt [new file with mode: 0644]
ext/standard/tests/file/fwrite_variation-win32.phpt [new file with mode: 0644]
ext/standard/tests/file/fwrite_variation.phpt [new file with mode: 0644]

diff --git a/ext/standard/tests/file/copy_basic.phpt b/ext/standard/tests/file/copy_basic.phpt
new file mode 100644 (file)
index 0000000..7663dc6
--- /dev/null
@@ -0,0 +1,57 @@
+--TEST--
+Test copy() function: basic functionality
+--FILE--
+<?php
+/* Prototype: bool copy ( string $source, string $dest );
+ * Description: Makes a copy of the file source to dest.
+ *              Returns TRUE on success or FALSE on failure.
+ */
+
+echo "*** Testing copy() function: to copy file from source to destination --\n"; 
+
+var_dump( file_exists(__FILE__) );
+
+/* copying the file */
+$file_path = dirname(__FILE__);
+$file_name1 = $file_path."/copy_basic1.tmp";
+$file_name2 = $file_path."/copy_basic2.tmp";
+var_dump( copy(__FILE__, $file_name1) );
+var_dump( copy($file_name1, $file_name2) );
+
+echo "-- Checking whether the copy of file exists --\n";
+var_dump( file_exists($file_name1) );
+var_dump( file_exists($file_name2) );
+
+echo "-- Checking filepermissions of file and its copies --\n";
+printf( "%o", fileperms(__FILE__) );
+echo "\n";
+printf( "%o", fileperms($file_name1) );
+echo "\n";
+printf( "%o", fileperms($file_name2) );
+echo "\n";
+
+echo "*** Done ***\n";
+?>
+
+--CLEAN--
+<?php
+$file_path = dirname(__FILE__);
+$file_name1 = $file_path."/copy_basic1.tmp";
+$file_name2 = $file_path."/copy_basic2.tmp";
+unlink($file_name1);
+unlink($file_name2);
+?>
+
+--EXPECTF--
+*** Testing copy() function: to copy file from source to destination --
+bool(true)
+bool(true)
+bool(true)
+-- Checking whether the copy of file exists --
+bool(true)
+bool(true)
+-- Checking filepermissions of file and its copies --
+%d
+%d
+%d
+*** Done ***
diff --git a/ext/standard/tests/file/copy_error.phpt b/ext/standard/tests/file/copy_error.phpt
new file mode 100644 (file)
index 0000000..c0c3712
--- /dev/null
@@ -0,0 +1,38 @@
+--TEST--
+Test copy() function: error conditions
+--FILE--
+<?php
+/* Prototype: bool copy ( string $source, string $dest );
+ * Description: Makes a copy of the file source to dest.
+ *              Returns TRUE on success or FALSE on failure.
+ */
+
+echo "*** Testing copy() function: error conditions --\n"; 
+/* Invalid args */
+var_dump( copy("/no/file", "file") );
+
+/* No.of args less than expected */
+var_dump( copy() );
+var_dump( copy(__FILE__) );
+
+/* No.of args less than expected */
+var_dump( copy(__FILE__, "file1", "file1") );
+
+echo "*** Done ***\n";
+?>
+
+--EXPECTF--
+*** Testing copy() function: error conditions --
+
+Warning: copy(/no/file): failed to open stream: No such file or directory in %s on line %d
+bool(false)
+
+Warning: Wrong parameter count for copy() in %s on line %d
+NULL
+
+Warning: Wrong parameter count for copy() in %s on line %d
+NULL
+
+Warning: Wrong parameter count for copy() in %s on line %d
+NULL
+*** Done ***
diff --git a/ext/standard/tests/file/file_get_contents_file_put_contents_variation.phpt b/ext/standard/tests/file/file_get_contents_file_put_contents_variation.phpt
new file mode 100644 (file)
index 0000000..2f87004
--- /dev/null
@@ -0,0 +1,145 @@
+--TEST--
+Test file_get_contents() and file_put_contents() functions : usage variations
+
+--FILE--
+<?php
+/* Prototype: string file_get_contents( string $filename[, bool $use_include_path[, 
+ *                                      resource $context[, int $offset[, int $maxlen]]]] )
+ * Description: Reads entire file into a string
+ */
+
+/* Prototype: int file_put_contents( string $filename, mixed $data[,int $flags[, resource $context]] )
+ * Description: Write a string to a file
+ */
+
+$file_path = dirname(__FILE__);
+include($file_path."/file.inc");
+
+echo "*** Testing with variations in the arguments values ***\n";
+
+$buffer_types = array("text", "numeric", "text_with_new_line", "alphanumeric");
+
+foreach( $buffer_types as $type) {
+  fill_buffer($buffer, $type, 100);
+  file_put_contents( $file_path."/file_put_contents.tmp", $buffer);
+  var_dump( file_get_contents($file_path."/file_put_contents.tmp", 0) );
+  var_dump( file_get_contents($file_path."/file_put_contents.tmp", 1) );
+  var_dump( file_get_contents($file_path."/file_put_contents.tmp", 0, NULL, 5) );
+  var_dump( file_get_contents($file_path."/file_put_contents.tmp", 1, NULL, 5) );
+  var_dump( file_get_contents($file_path."/file_put_contents.tmp", 0, NULL, 5, 20) );
+  var_dump( file_get_contents($file_path."/file_put_contents.tmp", 1, NULL, 5, 20) );
+
+}
+
+echo "*** Testing with variation in use_include_path argument ***\n";
+$dir = "file_get_contents";
+mkdir($file_path."/".$dir);
+$filename = $file_path."/".$dir."/"."file_get_contents1.tmp";
+
+ini_set( 'include_path',$file_path."/".$dir );
+
+$data_array = array( 1, "  Data1 in an array", 2, "  Data2 in an array" );
+fill_buffer( $buffer, "text", 100);
+file_put_contents( $filename, $buffer );
+fill_buffer( $buffer, "numeric", 100);
+file_put_contents( $filename, $buffer, FILE_APPEND, NULL );
+file_put_contents( $filename, $data_array, FILE_APPEND, NULL );
+var_dump( file_get_contents($filename, 0) );
+var_dump( file_get_contents($filename, 1) );
+var_dump( file_get_contents($filename, 0, NULL, 5) );
+var_dump( file_get_contents($filename, 1, NULL, 5) );
+var_dump( file_get_contents($filename, 0, NULL, 5, 20) );
+var_dump( file_get_contents($filename, 1, NULL, 5, 20) );
+
+echo "--- Done ---";
+?>
+--CLEAN--
+<?php
+//Deleting the temporary files and directory used in the testcase
+
+$file_path = dirname(__FILE__);
+unlink($file_path."/file_put_contents.tmp");
+unlink($file_path."/file_get_contents/file_get_contents1.tmp");
+rmdir($file_path."/file_get_contents");
+
+?>
+--EXPECTF--
+*** Testing with variations in the arguments values ***
+string(100) "text text text text text text text text text text text text text text text text text text text text "
+string(100) "text text text text text text text text text text text text text text text text text text text text "
+string(95) "text text text text text text text text text text text text text text text text text text text "
+string(95) "text text text text text text text text text text text text text text text text text text text "
+string(20) "text text text text "
+string(20) "text text text text "
+string(100) "2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222"
+string(100) "2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222"
+string(95) "22222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222"
+string(95) "22222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222"
+string(20) "22222222222222222222"
+string(20) "22222222222222222222"
+string(100) "line
+line of text
+line
+line of text
+line
+line of text
+line
+line of text
+line
+line of text
+line
+line "
+string(100) "line
+line of text
+line
+line of text
+line
+line of text
+line
+line of text
+line
+line of text
+line
+line "
+string(95) "line of text
+line
+line of text
+line
+line of text
+line
+line of text
+line
+line of text
+line
+line "
+string(95) "line of text
+line
+line of text
+line
+line of text
+line
+line of text
+line
+line of text
+line
+line "
+string(20) "line of text
+line
+li"
+string(20) "line of text
+line
+li"
+string(100) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
+string(100) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
+string(95) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
+string(95) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
+string(20) "ab12 ab12 ab12 ab12 "
+string(20) "ab12 ab12 ab12 ab12 "
+*** Testing with variation in use_include_path argument ***
+string(240) "text text text text text text text text text text text text text text text text text text text text 22222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222221  Data1 in an array2  Data2 in an array"
+string(240) "text text text text text text text text text text text text text text text text text text text text 22222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222221  Data1 in an array2  Data2 in an array"
+string(235) "text text text text text text text text text text text text text text text text text text text 22222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222221  Data1 in an array2  Data2 in an array"
+string(235) "text text text text text text text text text text text text text text text text text text text 22222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222221  Data1 in an array2  Data2 in an array"
+string(20) "text text text text "
+string(20) "text text text text "
+--- Done ---
diff --git a/ext/standard/tests/file/filegroup_basic.phpt b/ext/standard/tests/file/filegroup_basic.phpt
new file mode 100644 (file)
index 0000000..c836a8a
--- /dev/null
@@ -0,0 +1,79 @@
+--TEST--
+Test filegroup() function: basic functionality
+--SKIPIF--
+<?php
+if (!function_exists("posix_getgrgid")) { 
+   die("skip no posix_getgrgid");
+}
+?>
+--FILE--
+<?php
+/* Prototype: int filegroup ( string $filename )
+ * Description: Returns the group ID of the file, or FALSE in case of an error.
+ */
+
+echo "*** Testing filegroup(): basic functionality ***\n"; 
+
+echo "-- Testing with the file or directory created by owner --\n";
+
+$file_path = dirname(__FILE__);
+var_dump( posix_getgrgid( filegroup(__FILE__) ) );
+var_dump( filegroup(".") );
+var_dump( filegroup("./..") );
+
+/* Newly created files and dirs */
+$file_name = $file_path."/filegroup_basic.tmp";
+$file_handle = fopen($file_name, "w");
+
+$string = "Hello, world\n1234\n123Hello";
+fwrite($file_handle, $string);
+var_dump( filegroup($file_name) );
+fclose($file_handle);
+
+$dir_name = $file_path."/filegroup_basic";
+mkdir($dir_name);
+var_dump( filegroup($dir_name) );
+
+echo "\n-- Testing with the standard file or directory --\n";
+var_dump( filegroup("/etc/passwd") );
+var_dump( filegroup("/etc") );
+var_dump( filegroup("/") );
+
+echo "\n*** Done ***\n";
+?>
+
+--CLEAN--
+<?php
+
+$file_path = dirname(__FILE__);
+$file_name = $file_path."/filegroup_basic.tmp";
+$dir_name  = $file_path."/filegroup_basic";
+unlink($file_name);
+rmdir($dir_name);
+?>
+
+--EXPECTF--
+*** Testing filegroup(): basic functionality ***
+-- Testing with the file or directory created by owner --
+array(4) {
+  ["name"]=>
+  string(%d) "%s"
+  ["passwd"]=>
+  string(1) "x"
+  ["members"]=>
+  array(0) {
+  }
+  ["gid"]=>
+  int(%d)
+}
+int(%d)
+int(%d)
+int(%d)
+int(%d)
+
+-- Testing with the standard file or directory --
+int(0)
+int(0)
+int(0)
+
+*** Done ***
diff --git a/ext/standard/tests/file/filegroup_error.phpt b/ext/standard/tests/file/filegroup_error.phpt
new file mode 100644 (file)
index 0000000..d121394
--- /dev/null
@@ -0,0 +1,43 @@
+--TEST--
+Test filegroup() function: error conditions
+--FILE--
+<?php
+/* Prototype: int filegroup ( string $filename )
+ *  Description: Returns the group ID of the file, or FALSE in case of an error.
+ */
+
+echo "*** Testing filegroup(): error conditions ***\n";
+
+/* Non-existing file or dir */
+var_dump( filegroup("/no/such/file/dir") );
+
+/* Invalid arguments */
+var_dump( filegroup("string") );
+var_dump( filegroup(100) );
+
+/* Invalid no.of arguments */
+var_dump( filegroup() );  // args < expected
+var_dump( filegroup("/no/such/file", "root") );  // args > expected
+
+echo "\n*** Done ***\n";
+?>
+
+--EXPECTF--
+*** Testing filegroup(): error conditions ***
+
+Warning: filegroup(): stat failed for /no/such/file/dir in %s on line %d
+bool(false)
+
+Warning: filegroup(): stat failed for string in %s on line %d
+bool(false)
+
+Warning: filegroup(): stat failed for 100 in %s on line %d
+bool(false)
+
+Warning: Wrong parameter count for filegroup() in %s on line %d
+NULL
+
+Warning: Wrong parameter count for filegroup() in %s on line %d
+NULL
+
+*** Done ***
diff --git a/ext/standard/tests/file/fileowner_basic.phpt b/ext/standard/tests/file/fileowner_basic.phpt
new file mode 100644 (file)
index 0000000..f9cace1
--- /dev/null
@@ -0,0 +1,82 @@
+--TEST--
+Test fileowner() function: basic functionality
+--SKIPIF--
+<?php
+if (!function_exists("posix_getpwuid")) {
+   die("skip no posix_getpwuid");
+}
+?>
+--FILE--
+<?php
+/* Prototype: int fileowner ( string $filename )
+ * Description: Returns the user ID of the owner of the file, or
+ *              FALSE in case of an error.
+ */
+
+echo "*** Testing fileowner(): basic functionality ***\n"; 
+
+echo "-- Testing with the file or directory created by owner --\n";
+var_dump( posix_getpwuid ( fileowner(__FILE__) ) );
+var_dump( fileowner(".") );
+var_dump( fileowner("./..") );
+
+/* Newly created files and dirs */
+$file_path = dirname(__FILE__);
+$file_name = $file_path."/fileowner_basic.tmp";
+$file_handle = fopen($file_name, "w");
+$string = "Hello, world\n1234\n123Hello";
+fwrite($file_handle, $string);
+var_dump( fileowner($file_name) );
+fclose($file_handle);
+
+$dir_name = $file_path."/fileowner_basic";
+mkdir($dir_name);
+var_dump( fileowner($dir_name) );
+
+echo "\n-- Testing with the standard file or directory --\n";
+var_dump( fileowner("/etc/passwd") );
+var_dump( fileowner("/etc") );
+var_dump( fileowner("/") );
+
+echo "\n*** Done ***\n";
+?>
+
+--CLEAN--
+<?php
+$file_path = dirname(__FILE__);
+$file_name = $file_path."/fileowner_basic.tmp";
+$dir_name = $file_path."/fileowner_basic";
+unlink($file_name);
+rmdir($dir_name);
+?>
+
+--EXPECTF--
+*** Testing fileowner(): basic functionality ***
+-- Testing with the file or directory created by owner --
+array(7) {
+  ["name"]=>
+  string(%d) %s
+  ["passwd"]=>
+  string(1) "x"
+  ["uid"]=>
+  int(%d)
+  ["gid"]=>
+  int(%d)
+  ["gecos"]=>
+  string(%d) %s
+  ["dir"]=>
+  string(%d) %s
+  ["shell"]=>
+  string(%d) %s
+}
+int(%d)
+int(%d)
+int(%d)
+int(%d)
+
+-- Testing with the standard file or directory --
+int(0)
+int(0)
+int(0)
+
+*** Done ***
diff --git a/ext/standard/tests/file/fileowner_error.phpt b/ext/standard/tests/file/fileowner_error.phpt
new file mode 100644 (file)
index 0000000..b58927f
--- /dev/null
@@ -0,0 +1,43 @@
+--TEST--
+Test of fileowner() function: error conditions
+--FILE--
+<?php
+/* Prototype: int fileowner ( string $filename )
+ * Description: Returns the user ID of the owner of the file, or
+ *              FALSE in case of an error.
+ */
+
+echo "*** Testing fileowner(): error conditions ***\n";
+/* Non-existing file or dir */
+var_dump( fileowner("/no/such/file/dir") );
+
+/* Invalid arguments */
+var_dump( fileowner("string") );
+var_dump( fileowner(100) );
+
+/* Invalid no.of arguments */
+var_dump( fileowner() );  // args < expected
+var_dump( fileowner("/no/such/file", "root") );  // args > expected
+
+echo "\n*** Done ***\n";
+?>
+
+--EXPECTF--
+*** Testing fileowner(): error conditions ***
+
+Warning: fileowner(): stat failed for /no/such/file/dir in %s on line %d
+bool(false)
+
+Warning: fileowner(): stat failed for string in %s on line %d
+bool(false)
+
+Warning: fileowner(): stat failed for 100 in %s on line %d
+bool(false)
+
+Warning: Wrong parameter count for fileowner() in %s on line %d
+NULL
+
+Warning: Wrong parameter count for fileowner() in %s on line %d
+NULL
+
+*** Done ***
diff --git a/ext/standard/tests/file/fwrite_basic-win32.phpt b/ext/standard/tests/file/fwrite_basic-win32.phpt
new file mode 100644 (file)
index 0000000..81d9360
--- /dev/null
@@ -0,0 +1,424 @@
+--TEST--
+Test fwrite() function : basic functionality
+--SKIPIF--
+<?php
+if( substr(PHP_OS, 0, 3) != 'WIN' ) {
+   die('skip...Valid for Windows only');
+}
+?>
+--FILE--
+<?php
+/*
+ Prototype: int fwrite ( resource $handle,string string, [, int $length] );
+ Description: fwrite() writes the contents of string to the file stream pointed to by handle.
+              If the length arquement is given,writing will stop after length bytes have been
+              written or the end of string reached, whichever comes first.
+              fwrite() returns the number of bytes written or FALSE on error
+*/
+
+// include the file.inc for Function: function delete_file($filename)
+include ("file.inc");
+
+echo "*** Testing fwrite() basic operations ***\n";
+/*
+ test fwrite with file opened in mode : w,wb,wt,w+,w+b,w+t
+ File containing data of type,  numeric, text, text_with_new_line, alphanumeric
+*/
+$file_modes = array( "w", "wb", "wt", "w+", "w+b", "w+t");
+$file_content_types = array("numeric","text","text_with_new_line","alphanumeric");
+
+foreach($file_content_types as $file_content_type) {
+  echo "\n-- Testing fwrite() with file having data of type ". $file_content_type ." --\n";
+  $filename = dirname(__FILE__)."/fwrite_basic-win32.tmp"; // this is name of the file
+
+  for($inner_loop_counter = 0; 
+      $inner_loop_counter < count($file_modes); 
+      $inner_loop_counter++) {
+     echo "--  File opened in mode : " . $file_modes[$inner_loop_counter]. " --\n";
+     /* open the file using $files_modes and perform fwrite() on it */
+     $file_handle = fopen($filename, $file_modes[$inner_loop_counter]);
+     if (!$file_handle) {
+       echo "Error: failed to fopen() file: $filename!";
+       exit();
+     }
+     $data_to_be_written="";
+     fill_buffer($data_to_be_written, $file_content_type, 1024);  //get the data of size 1024
+
+    /* Write the data in to the file, verify the write by checking file pointer position, 
+       eof position, and data. */
+    // writing 100 bytes
+    var_dump( ftell($file_handle) );  // Expecting 0
+    var_dump( fwrite($file_handle, $data_to_be_written, 100)); //int(100)
+    var_dump( feof($file_handle) );  // expected : false
+    var_dump( ftell($file_handle) );  //expected: 100
+   
+    // trying to write more than the available data, available 1024 bytes but trying 2048
+    var_dump( fwrite($file_handle, $data_to_be_written, 2048)); //int(1024)
+    var_dump( feof($file_handle) );  // expected : false
+    var_dump( ftell($file_handle) );  // expected: 1124
+
+    // fwrite() without length parameter
+    var_dump( fwrite($file_handle, $data_to_be_written)); //int(1024)
+    var_dump( ftell($file_handle) );  // expected: 2148
+    var_dump( feof($file_handle) );  // expected: false
+
+    // close the file, get the size and content of the file.
+    var_dump( fclose($file_handle) ); //expected : true
+    clearstatcache();//clears file status cache
+    var_dump( filesize($filename) );  // expected:  2148
+    var_dump(md5(file_get_contents($filename))); // hash the output 
+
+  } // end of inner for loop
+
+  // delete the file created : fwrite_basic.tmp
+  delete_file($filename);
+} // end of outer foreach loop
+echo "Done\n";
+?>
+--EXPECTF--
+*** Testing fwrite() basic operations ***
+
+-- Testing fwrite() with file having data of type numeric --
+--  File opened in mode : w --
+int(0)
+int(100)
+bool(false)
+int(100)
+int(1024)
+bool(false)
+int(1124)
+int(1024)
+int(2148)
+bool(false)
+bool(true)
+int(2148)
+string(32) "04db34906fe2c56dcfbd649b7d916974"
+--  File opened in mode : wb --
+int(0)
+int(100)
+bool(false)
+int(100)
+int(1024)
+bool(false)
+int(1124)
+int(1024)
+int(2148)
+bool(false)
+bool(true)
+int(2148)
+string(32) "04db34906fe2c56dcfbd649b7d916974"
+--  File opened in mode : wt --
+int(0)
+int(100)
+bool(false)
+int(100)
+int(1024)
+bool(false)
+int(1124)
+int(1024)
+int(2148)
+bool(false)
+bool(true)
+int(2148)
+string(32) "04db34906fe2c56dcfbd649b7d916974"
+--  File opened in mode : w+ --
+int(0)
+int(100)
+bool(false)
+int(100)
+int(1024)
+bool(false)
+int(1124)
+int(1024)
+int(2148)
+bool(false)
+bool(true)
+int(2148)
+string(32) "04db34906fe2c56dcfbd649b7d916974"
+--  File opened in mode : w+b --
+int(0)
+int(100)
+bool(false)
+int(100)
+int(1024)
+bool(false)
+int(1124)
+int(1024)
+int(2148)
+bool(false)
+bool(true)
+int(2148)
+string(32) "04db34906fe2c56dcfbd649b7d916974"
+--  File opened in mode : w+t --
+int(0)
+int(100)
+bool(false)
+int(100)
+int(1024)
+bool(false)
+int(1124)
+int(1024)
+int(2148)
+bool(false)
+bool(true)
+int(2148)
+string(32) "04db34906fe2c56dcfbd649b7d916974"
+
+-- Testing fwrite() with file having data of type text --
+--  File opened in mode : w --
+int(0)
+int(100)
+bool(false)
+int(100)
+int(1024)
+bool(false)
+int(1124)
+int(1024)
+int(2148)
+bool(false)
+bool(true)
+int(2148)
+string(32) "9c08ac77b7a93a84dd0b055900165e84"
+--  File opened in mode : wb --
+int(0)
+int(100)
+bool(false)
+int(100)
+int(1024)
+bool(false)
+int(1124)
+int(1024)
+int(2148)
+bool(false)
+bool(true)
+int(2148)
+string(32) "9c08ac77b7a93a84dd0b055900165e84"
+--  File opened in mode : wt --
+int(0)
+int(100)
+bool(false)
+int(100)
+int(1024)
+bool(false)
+int(1124)
+int(1024)
+int(2148)
+bool(false)
+bool(true)
+int(2148)
+string(32) "9c08ac77b7a93a84dd0b055900165e84"
+--  File opened in mode : w+ --
+int(0)
+int(100)
+bool(false)
+int(100)
+int(1024)
+bool(false)
+int(1124)
+int(1024)
+int(2148)
+bool(false)
+bool(true)
+int(2148)
+string(32) "9c08ac77b7a93a84dd0b055900165e84"
+--  File opened in mode : w+b --
+int(0)
+int(100)
+bool(false)
+int(100)
+int(1024)
+bool(false)
+int(1124)
+int(1024)
+int(2148)
+bool(false)
+bool(true)
+int(2148)
+string(32) "9c08ac77b7a93a84dd0b055900165e84"
+--  File opened in mode : w+t --
+int(0)
+int(100)
+bool(false)
+int(100)
+int(1024)
+bool(false)
+int(1124)
+int(1024)
+int(2148)
+bool(false)
+bool(true)
+int(2148)
+string(32) "9c08ac77b7a93a84dd0b055900165e84"
+
+-- Testing fwrite() with file having data of type text_with_new_line --
+--  File opened in mode : w --
+int(0)
+int(100)
+bool(false)
+int(100)
+int(1024)
+bool(false)
+int(1124)
+int(1024)
+int(2148)
+bool(false)
+bool(true)
+int(2148)
+string(32) "56a1963cc292d7f8245219116d9eca40"
+--  File opened in mode : wb --
+int(0)
+int(100)
+bool(false)
+int(100)
+int(1024)
+bool(false)
+int(1124)
+int(1024)
+int(2148)
+bool(false)
+bool(true)
+int(2148)
+string(32) "56a1963cc292d7f8245219116d9eca40"
+--  File opened in mode : wt --
+int(0)
+int(100)
+bool(false)
+int(100)
+int(1024)
+bool(false)
+int(1124)
+int(1024)
+int(2148)
+bool(false)
+bool(true)
+int(2385)
+string(32) "62b09dac6d598bf54de7b02e0e68e5c7"
+--  File opened in mode : w+ --
+int(0)
+int(100)
+bool(false)
+int(100)
+int(1024)
+bool(false)
+int(1124)
+int(1024)
+int(2148)
+bool(false)
+bool(true)
+int(2148)
+string(32) "56a1963cc292d7f8245219116d9eca40"
+--  File opened in mode : w+b --
+int(0)
+int(100)
+bool(false)
+int(100)
+int(1024)
+bool(false)
+int(1124)
+int(1024)
+int(2148)
+bool(false)
+bool(true)
+int(2148)
+string(32) "56a1963cc292d7f8245219116d9eca40"
+--  File opened in mode : w+t --
+int(0)
+int(100)
+bool(false)
+int(100)
+int(1024)
+bool(false)
+int(1124)
+int(1024)
+int(2148)
+bool(false)
+bool(true)
+int(2385)
+string(32) "62b09dac6d598bf54de7b02e0e68e5c7"
+
+-- Testing fwrite() with file having data of type alphanumeric --
+--  File opened in mode : w --
+int(0)
+int(100)
+bool(false)
+int(100)
+int(1024)
+bool(false)
+int(1124)
+int(1024)
+int(2148)
+bool(false)
+bool(true)
+int(2148)
+string(32) "719e3329c19218c12d232f2ee81e100f"
+--  File opened in mode : wb --
+int(0)
+int(100)
+bool(false)
+int(100)
+int(1024)
+bool(false)
+int(1124)
+int(1024)
+int(2148)
+bool(false)
+bool(true)
+int(2148)
+string(32) "719e3329c19218c12d232f2ee81e100f"
+--  File opened in mode : wt --
+int(0)
+int(100)
+bool(false)
+int(100)
+int(1024)
+bool(false)
+int(1124)
+int(1024)
+int(2148)
+bool(false)
+bool(true)
+int(2148)
+string(32) "719e3329c19218c12d232f2ee81e100f"
+--  File opened in mode : w+ --
+int(0)
+int(100)
+bool(false)
+int(100)
+int(1024)
+bool(false)
+int(1124)
+int(1024)
+int(2148)
+bool(false)
+bool(true)
+int(2148)
+string(32) "719e3329c19218c12d232f2ee81e100f"
+--  File opened in mode : w+b --
+int(0)
+int(100)
+bool(false)
+int(100)
+int(1024)
+bool(false)
+int(1124)
+int(1024)
+int(2148)
+bool(false)
+bool(true)
+int(2148)
+string(32) "719e3329c19218c12d232f2ee81e100f"
+--  File opened in mode : w+t --
+int(0)
+int(100)
+bool(false)
+int(100)
+int(1024)
+bool(false)
+int(1124)
+int(1024)
+int(2148)
+bool(false)
+bool(true)
+int(2148)
+string(32) "719e3329c19218c12d232f2ee81e100f"
+Done
\ No newline at end of file
diff --git a/ext/standard/tests/file/fwrite_basic.phpt b/ext/standard/tests/file/fwrite_basic.phpt
new file mode 100644 (file)
index 0000000..c568b7c
--- /dev/null
@@ -0,0 +1,424 @@
+--TEST--
+Test fwrite() function : basic functionality
+--SKIPIF--
+<?php
+if( substr(PHP_OS, 0, 3) == 'WIN' ) {
+   die('skip...Not valid for Windows');
+}
+?>
+--FILE--
+<?php
+/*
+ Prototype: int fwrite ( resource $handle,string string, [, int $length] );
+ Description: fwrite() writes the contents of string to the file stream pointed to by handle.
+              If the length arquement is given,writing will stop after length bytes have been
+              written or the end of string reached, whichever comes first.
+              fwrite() returns the number of bytes written or FALSE on error
+*/
+
+// include the file.inc for Function: function delete_file($filename)
+include ("file.inc");
+
+echo "*** Testing fwrite() basic operations ***\n";
+/*
+ test fwrite with file opened in mode : w,wb,wt,w+,w+b,w+t
+ File containing data of type,  numeric, text, text_with_new_line, alphanumeric
+*/
+$file_modes = array( "w", "wb", "wt", "w+", "w+b", "w+t");
+$file_content_types = array("numeric","text","text_with_new_line","alphanumeric");
+
+foreach($file_content_types as $file_content_type) {
+  echo "\n-- Testing fwrite() with file having data of type ". $file_content_type ." --\n";
+  $filename = dirname(__FILE__)."/fwrite_basic.tmp"; // this is name of the file
+
+  for($inner_loop_counter = 0; 
+      $inner_loop_counter < count($file_modes); 
+      $inner_loop_counter++) {
+     echo "--  File opened in mode : " . $file_modes[$inner_loop_counter]. " --\n";
+     /* open the file using $files_modes and perform fwrite() on it */
+     $file_handle = fopen($filename, $file_modes[$inner_loop_counter]);
+     if (!$file_handle) {
+       echo "Error: failed to fopen() file: $filename!";
+       exit();
+     }
+     $data_to_be_written="";
+     fill_buffer($data_to_be_written, $file_content_type, 1024);  //get the data of size 1024
+
+    /* Write the data in to the file, verify the write by checking file pointer position, 
+       eof position, and data. */
+    // writing 100 bytes
+    var_dump( ftell($file_handle) );  // Expecting 0
+    var_dump( fwrite($file_handle, $data_to_be_written, 100)); //int(100)
+    var_dump( feof($file_handle) );  // expected : false
+    var_dump( ftell($file_handle) );  //expected: 100
+   
+    // trying to write more than the available data, available 1024 bytes but trying 2048
+    var_dump( fwrite($file_handle, $data_to_be_written, 2048)); //int(1024)
+    var_dump( feof($file_handle) );  // expected : false
+    var_dump( ftell($file_handle) );  // expected: 1124
+
+    // fwrite() without length parameter
+    var_dump( fwrite($file_handle, $data_to_be_written)); //int(1024)
+    var_dump( ftell($file_handle) );  // expected: 2148
+    var_dump( feof($file_handle) );  // expected: false
+
+    // close the file, get the size and content of the file.
+    var_dump( fclose($file_handle) ); //expected : true
+    clearstatcache();//clears file status cache
+    var_dump( filesize($filename) );  // expected:  2148
+    var_dump(md5(file_get_contents($filename))); // hash the output 
+
+  } // end of inner for loop
+
+  // delete the file created : fwrite_basic.tmp
+  delete_file($filename);
+} // end of outer foreach loop
+echo "Done\n";
+?>
+--EXPECTF--
+*** Testing fwrite() basic operations ***
+
+-- Testing fwrite() with file having data of type numeric --
+--  File opened in mode : w --
+int(0)
+int(100)
+bool(false)
+int(100)
+int(1024)
+bool(false)
+int(1124)
+int(1024)
+int(2148)
+bool(false)
+bool(true)
+int(2148)
+string(32) "04db34906fe2c56dcfbd649b7d916974"
+--  File opened in mode : wb --
+int(0)
+int(100)
+bool(false)
+int(100)
+int(1024)
+bool(false)
+int(1124)
+int(1024)
+int(2148)
+bool(false)
+bool(true)
+int(2148)
+string(32) "04db34906fe2c56dcfbd649b7d916974"
+--  File opened in mode : wt --
+int(0)
+int(100)
+bool(false)
+int(100)
+int(1024)
+bool(false)
+int(1124)
+int(1024)
+int(2148)
+bool(false)
+bool(true)
+int(2148)
+string(32) "04db34906fe2c56dcfbd649b7d916974"
+--  File opened in mode : w+ --
+int(0)
+int(100)
+bool(false)
+int(100)
+int(1024)
+bool(false)
+int(1124)
+int(1024)
+int(2148)
+bool(false)
+bool(true)
+int(2148)
+string(32) "04db34906fe2c56dcfbd649b7d916974"
+--  File opened in mode : w+b --
+int(0)
+int(100)
+bool(false)
+int(100)
+int(1024)
+bool(false)
+int(1124)
+int(1024)
+int(2148)
+bool(false)
+bool(true)
+int(2148)
+string(32) "04db34906fe2c56dcfbd649b7d916974"
+--  File opened in mode : w+t --
+int(0)
+int(100)
+bool(false)
+int(100)
+int(1024)
+bool(false)
+int(1124)
+int(1024)
+int(2148)
+bool(false)
+bool(true)
+int(2148)
+string(32) "04db34906fe2c56dcfbd649b7d916974"
+
+-- Testing fwrite() with file having data of type text --
+--  File opened in mode : w --
+int(0)
+int(100)
+bool(false)
+int(100)
+int(1024)
+bool(false)
+int(1124)
+int(1024)
+int(2148)
+bool(false)
+bool(true)
+int(2148)
+string(32) "9c08ac77b7a93a84dd0b055900165e84"
+--  File opened in mode : wb --
+int(0)
+int(100)
+bool(false)
+int(100)
+int(1024)
+bool(false)
+int(1124)
+int(1024)
+int(2148)
+bool(false)
+bool(true)
+int(2148)
+string(32) "9c08ac77b7a93a84dd0b055900165e84"
+--  File opened in mode : wt --
+int(0)
+int(100)
+bool(false)
+int(100)
+int(1024)
+bool(false)
+int(1124)
+int(1024)
+int(2148)
+bool(false)
+bool(true)
+int(2148)
+string(32) "9c08ac77b7a93a84dd0b055900165e84"
+--  File opened in mode : w+ --
+int(0)
+int(100)
+bool(false)
+int(100)
+int(1024)
+bool(false)
+int(1124)
+int(1024)
+int(2148)
+bool(false)
+bool(true)
+int(2148)
+string(32) "9c08ac77b7a93a84dd0b055900165e84"
+--  File opened in mode : w+b --
+int(0)
+int(100)
+bool(false)
+int(100)
+int(1024)
+bool(false)
+int(1124)
+int(1024)
+int(2148)
+bool(false)
+bool(true)
+int(2148)
+string(32) "9c08ac77b7a93a84dd0b055900165e84"
+--  File opened in mode : w+t --
+int(0)
+int(100)
+bool(false)
+int(100)
+int(1024)
+bool(false)
+int(1124)
+int(1024)
+int(2148)
+bool(false)
+bool(true)
+int(2148)
+string(32) "9c08ac77b7a93a84dd0b055900165e84"
+
+-- Testing fwrite() with file having data of type text_with_new_line --
+--  File opened in mode : w --
+int(0)
+int(100)
+bool(false)
+int(100)
+int(1024)
+bool(false)
+int(1124)
+int(1024)
+int(2148)
+bool(false)
+bool(true)
+int(2148)
+string(32) "56a1963cc292d7f8245219116d9eca40"
+--  File opened in mode : wb --
+int(0)
+int(100)
+bool(false)
+int(100)
+int(1024)
+bool(false)
+int(1124)
+int(1024)
+int(2148)
+bool(false)
+bool(true)
+int(2148)
+string(32) "56a1963cc292d7f8245219116d9eca40"
+--  File opened in mode : wt --
+int(0)
+int(100)
+bool(false)
+int(100)
+int(1024)
+bool(false)
+int(1124)
+int(1024)
+int(2148)
+bool(false)
+bool(true)
+int(2148)
+string(32) "56a1963cc292d7f8245219116d9eca40"
+--  File opened in mode : w+ --
+int(0)
+int(100)
+bool(false)
+int(100)
+int(1024)
+bool(false)
+int(1124)
+int(1024)
+int(2148)
+bool(false)
+bool(true)
+int(2148)
+string(32) "56a1963cc292d7f8245219116d9eca40"
+--  File opened in mode : w+b --
+int(0)
+int(100)
+bool(false)
+int(100)
+int(1024)
+bool(false)
+int(1124)
+int(1024)
+int(2148)
+bool(false)
+bool(true)
+int(2148)
+string(32) "56a1963cc292d7f8245219116d9eca40"
+--  File opened in mode : w+t --
+int(0)
+int(100)
+bool(false)
+int(100)
+int(1024)
+bool(false)
+int(1124)
+int(1024)
+int(2148)
+bool(false)
+bool(true)
+int(2148)
+string(32) "56a1963cc292d7f8245219116d9eca40"
+
+-- Testing fwrite() with file having data of type alphanumeric --
+--  File opened in mode : w --
+int(0)
+int(100)
+bool(false)
+int(100)
+int(1024)
+bool(false)
+int(1124)
+int(1024)
+int(2148)
+bool(false)
+bool(true)
+int(2148)
+string(32) "719e3329c19218c12d232f2ee81e100f"
+--  File opened in mode : wb --
+int(0)
+int(100)
+bool(false)
+int(100)
+int(1024)
+bool(false)
+int(1124)
+int(1024)
+int(2148)
+bool(false)
+bool(true)
+int(2148)
+string(32) "719e3329c19218c12d232f2ee81e100f"
+--  File opened in mode : wt --
+int(0)
+int(100)
+bool(false)
+int(100)
+int(1024)
+bool(false)
+int(1124)
+int(1024)
+int(2148)
+bool(false)
+bool(true)
+int(2148)
+string(32) "719e3329c19218c12d232f2ee81e100f"
+--  File opened in mode : w+ --
+int(0)
+int(100)
+bool(false)
+int(100)
+int(1024)
+bool(false)
+int(1124)
+int(1024)
+int(2148)
+bool(false)
+bool(true)
+int(2148)
+string(32) "719e3329c19218c12d232f2ee81e100f"
+--  File opened in mode : w+b --
+int(0)
+int(100)
+bool(false)
+int(100)
+int(1024)
+bool(false)
+int(1124)
+int(1024)
+int(2148)
+bool(false)
+bool(true)
+int(2148)
+string(32) "719e3329c19218c12d232f2ee81e100f"
+--  File opened in mode : w+t --
+int(0)
+int(100)
+bool(false)
+int(100)
+int(1024)
+bool(false)
+int(1124)
+int(1024)
+int(2148)
+bool(false)
+bool(true)
+int(2148)
+string(32) "719e3329c19218c12d232f2ee81e100f"
+Done
\ No newline at end of file
diff --git a/ext/standard/tests/file/fwrite_error.phpt b/ext/standard/tests/file/fwrite_error.phpt
new file mode 100644 (file)
index 0000000..c6f529f
--- /dev/null
@@ -0,0 +1,120 @@
+--TEST--
+Test fwrite() function : error conditions
+--FILE--
+<?php
+/*
+ Prototype: int fwrite ( resource $handle,string string, [, int $length] );
+ Description: fwrite() writes the contents of string to the file stream pointed to by handle.
+              If the length arquement is given,writing will stop after length bytes have been
+              written or the end of string reached, whichever comes first.
+              fwrite() returns the number of bytes written or FALSE on error
+*/
+
+// include the file.inc for Function: function delete_file($filename)
+include ("file.inc");
+
+echo "*** Testing fwrite() : error conditions ***\n";
+
+$filename = dirname(__FILE__)."/fwrite_error.tmp";
+
+echo "-- Testing fwrite() with less than expected number of arguments --\n";
+// zero argument
+var_dump( fwrite() ); 
+// less than expected, 1 arg
+$file_handle  = fopen ( $filename, "w");
+var_dump( fwrite($file_handle) );
+
+// more than expected no. of args
+echo "-- Testing fwrite() with more than expected number of arguments --\n";
+$data = "data";
+var_dump( fwrite($file_handle, $data, strlen($data), 10) );
+
+// invalid length argument
+echo "-- Testing fwrite() with invalid length arguments --\n";
+$len = 0;
+var_dump( fwrite($file_handle, $data, $len) );
+$len = -10;
+var_dump( fwrite($file_handle, $data, $len) );
+
+// test invalid arguments : non-resources
+echo "-- Testing fwrite() with invalid arguments --\n";
+$invalid_args = array (
+  "string",
+  10,
+  10.5,
+  true,
+  array(1,2,3),
+  new stdclass,
+);
+/* loop to test fwrite() with different invalid type of args */
+for($loop_counter = 1; $loop_counter <= count($invalid_args); $loop_counter++) {
+  echo "-- Iteration $loop_counter --\n";
+  var_dump( fwrite($invalid_args[$loop_counter - 1], 10) );
+}
+
+// fwrite() on a file handle which is already closed 
+echo "-- Testing fwrite() with closed/unset file handle --\n";
+fclose($file_handle);
+var_dump(fwrite($file_handle,"data"));
+
+// fwrite on a file handle which is unset 
+$fp = fopen($filename, "w");
+unset($fp); //unset file handle 
+var_dump( fwrite(@$fp,"data"));
+
+echo "Done\n";
+?>
+--CLEAN--
+<?php
+$filename = dirname(__FILE__)."/fwrite_error.tmp";
+unlink( $filename );
+?>
+--EXPECTF--
+*** Testing fwrite() : error conditions ***
+-- Testing fwrite() with less than expected number of arguments --
+
+Warning: Wrong parameter count for fwrite() in %s on line %d
+NULL
+
+Warning: Wrong parameter count for fwrite() in %s on line %d
+NULL
+-- Testing fwrite() with more than expected number of arguments --
+
+Warning: Wrong parameter count for fwrite() in %s on line %d
+NULL
+-- Testing fwrite() with invalid length arguments --
+int(0)
+int(0)
+-- Testing fwrite() with invalid arguments --
+-- Iteration 1 --
+
+Warning: fwrite(): supplied argument is not a valid stream resource in %s on line %d
+bool(false)
+-- Iteration 2 --
+
+Warning: fwrite(): supplied argument is not a valid stream resource in %s on line %d
+bool(false)
+-- Iteration 3 --
+
+Warning: fwrite(): supplied argument is not a valid stream resource in %s on line %d
+bool(false)
+-- Iteration 4 --
+
+Warning: fwrite(): supplied argument is not a valid stream resource in %s on line %d
+bool(false)
+-- Iteration 5 --
+
+Warning: fwrite(): supplied argument is not a valid stream resource in %s on line %d
+bool(false)
+-- Iteration 6 --
+
+Warning: fwrite(): supplied argument is not a valid stream resource in %s on line %d
+bool(false)
+-- Testing fwrite() with closed/unset file handle --
+
+Warning: fwrite(): 6 is not a valid stream resource in %s on line %d
+bool(false)
+
+Warning: fwrite(): supplied argument is not a valid stream resource in %s on line %d
+bool(false)
+Done
diff --git a/ext/standard/tests/file/fwrite_variation-win32.phpt b/ext/standard/tests/file/fwrite_variation-win32.phpt
new file mode 100644 (file)
index 0000000..d3c456f
--- /dev/null
@@ -0,0 +1,1008 @@
+--TEST--
+Test fwrite() function : usage variations
+--SKIPIF--
+<?php
+if( substr(PHP_OS, 0, 3) != 'WIN' ) {
+   die('skip...Not valid for Linux');
+}
+?>
+--FILE--
+<?php
+/*
+ Prototype: int fwrite ( resource $handle,string string, [, int $length] );
+ Description: fwrite() writes the contents of string to the file stream pointed to by handle.
+              If the length arquement is given,writing will stop after length bytes have been
+              written or the end of string reached, whichever comes first.
+              fwrite() returns the number of bytes written or FALSE on error
+*/
+
+
+echo "*** Testing fwrite() various  operations ***\n";
+
+// include the file.inc for Function: function delete_file($filename)
+include ("file.inc");
+
+/*
+ Test fwrite with file opened in mode : a,ab,at,a+,a+b,a+t,r,rb,rt,r+,r+b,r+t
+ File having content of type numeric, text,text_with_new_line & alphanumeric
+*/
+
+$file_modes = array("r","rb","rt","r+", "r+b", "r+t","a","ab","at","a+","a+b",
+                    "a+t","x","xb","xt","x+","x+b","x+t");
+$file_content_types = array("numeric","text","text_with_new_line","alphanumeric");
+
+
+foreach($file_content_types as $file_content_type) {
+  echo "\n-- Testing fwrite() with file having content of type ". $file_content_type ." --\n";
+
+  /* open the file using $files_modes and perform fwrite() on it */
+  foreach($file_modes as $file_mode) {
+    echo "-- Opening file in $file_mode --\n";
+
+    $filename = dirname(__FILE__)."/fwrite_variation-win321.tmp"; // this is name of the file
+    if ( ! strstr( $file_mode, "x" ) ) {
+      create_files ( dirname(__FILE__), 1, $file_content_type, 0755, 1, "w", "fwrite_variation-win32");
+    }
+
+    $file_handle = fopen($filename, $file_mode);
+    if(!$file_handle) {
+      echo "Error: failed to fopen() file: $filename!";
+      exit();
+    }
+
+    $data_to_be_written="";
+    fill_buffer($data_to_be_written,$file_content_type,1024);  //get the data of size 1024
+
+    /*  Write the in to the file, verify it by checking the file pointer position, eof position, 
+        filesize & by displaying the content */
+    switch($file_mode) {
+      case "r":
+      case "rb":
+      case "rt":
+        var_dump( ftell($file_handle) );  // expected: 0
+        var_dump( fwrite($file_handle, $data_to_be_written )); 
+        var_dump( ftell($file_handle) );  // expected: 0
+        var_dump( feof($file_handle) );  // expected: false 
+  
+        // move the file pointer to end of the file and try fwrite()
+        fseek($file_handle, SEEK_END, 0);
+        var_dump( ftell($file_handle) );  // expecting 1024
+        var_dump( fwrite($file_handle, $data_to_be_written) ); // fwrite to fail
+        var_dump( ftell($file_handle) );  //check that file pointer points at eof, expected: 1024
+        var_dump( feof($file_handle) );  // ensure that  feof() points to eof, expected: true
+
+       // ensure that file content/size didn't change.
+        var_dump( fclose($file_handle) );
+        clearstatcache();//clears file status cache
+        var_dump( filesize($filename) );  // expected: 1024
+        var_dump(md5(file_get_contents($filename))); // hash the output
+       delete_file($filename); // delete file with name fwrite_variation1.tmp
+       break;
+
+      case "r+b":
+      case "r+":
+      case "r+t":
+        /*overwrite first 400 bytes in the file*/
+        var_dump( ftell($file_handle) );  // expected : 0
+        var_dump( fwrite($file_handle, $data_to_be_written, 400));
+        var_dump( ftell($file_handle) );  // expected: 400
+        var_dump( feof($file_handle) );  //Expecting bool(false)
+
+       /*overwrite data in middle of the file*/
+        fseek($file_handle, SEEK_SET, 1024/2 ); 
+       var_dump( ftell($file_handle));  // expected: 1024/2
+       var_dump( fwrite($file_handle, $data_to_be_written, 200) );
+        var_dump( ftell($file_handle) );
+       var_dump( feof($file_handle) );  //Expecting bool(false)
+
+        /* write at the end of the file */
+        fseek($file_handle, SEEK_END, 0); 
+       var_dump( ftell($file_handle) );  // expected: 1024
+        var_dump( feof($file_handle) );
+       var_dump( fwrite($file_handle, $data_to_be_written, 200) );
+        var_dump( ftell($file_handle) );
+       var_dump( feof($file_handle) );  //Expecting bool(false)
+
+       /* display the file content, check the file size  */
+        var_dump( fclose($file_handle) );
+        clearstatcache();//clears file status cache
+        var_dump( filesize($filename) );
+        var_dump(md5(file_get_contents($filename)));
+        delete_file($filename); // delete file with name fwrite_variation1.tmp
+        break;
+
+      case "a":
+      case "ab":
+      case "at":
+      case "a+":
+      case "a+b":
+      case "a+t":
+        // append the data to the file, starting from current position of the file pointer
+        var_dump( ftell($file_handle) ); // expected: 1024
+        var_dump( fwrite($file_handle,$data_to_be_written,400) );
+        var_dump( ftell($file_handle) ); // expected: 1024 + 400
+        var_dump( feof($file_handle) );  // expected : true
+
+        /*overwrite data in middle of the file*/
+        fseek($file_handle, SEEK_SET, (1024 + 400)/2 );
+        var_dump( ftell($file_handle));  // expected: (1024 + 400)/2
+        var_dump( fwrite($file_handle, $data_to_be_written, 200) );
+        var_dump( ftell($file_handle) ); 
+        var_dump( feof($file_handle) );  //Expecting bool(false)
+        
+        /* check the filesize and display file content */
+        // close the file, get the size and content of the file.
+        var_dump( fclose($file_handle) );
+        clearstatcache();//clears file status cache
+        var_dump( filesize($filename) );
+        var_dump(md5(file_get_contents($filename)));
+        // delete the file created
+        delete_file($filename); // delete file with name fwrite_variation.tmp
+        break;
+
+      case "x":
+      case "xb":
+      case "xt":
+      case "x+":
+      case "x+b":
+      case "x+t":
+        // write data to the file
+        var_dump( ftell($file_handle) );
+        var_dump( fwrite($file_handle,$data_to_be_written,400));
+        var_dump( ftell($file_handle) );
+        var_dump( feof($file_handle) );  // expected: true
+
+        //check the filesize and content
+        // close the file, get the size and content of the file.
+        var_dump( fclose($file_handle) );
+        clearstatcache();//clears file status cache
+        var_dump( filesize($filename) );
+        var_dump(md5(file_get_contents($filename)));
+        // delete the file created
+        delete_file($filename); // delete file with name fwrite_variation.tmp
+        break;
+    } //end of switch
+  } // end of inner foreach loop
+} // end of outer foreach loop
+
+echo "Done\n";
+?>
+--EXPECTF--
+*** Testing fwrite() various  operations ***
+
+-- Testing fwrite() with file having content of type numeric --
+-- Opening file in r --
+int(0)
+int(0)
+int(0)
+bool(false)
+int(2)
+int(0)
+int(2)
+bool(false)
+bool(true)
+int(1024)
+string(32) "950b7457d1deb6332f2fc5d42f3129d6"
+-- Opening file in rb --
+int(0)
+int(0)
+int(0)
+bool(false)
+int(2)
+int(0)
+int(2)
+bool(false)
+bool(true)
+int(1024)
+string(32) "950b7457d1deb6332f2fc5d42f3129d6"
+-- Opening file in rt --
+int(0)
+int(0)
+int(0)
+bool(false)
+int(2)
+int(0)
+int(2)
+bool(false)
+bool(true)
+int(1024)
+string(32) "950b7457d1deb6332f2fc5d42f3129d6"
+-- Opening file in r+ --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+int(2)
+bool(false)
+int(200)
+int(202)
+bool(false)
+bool(true)
+int(1024)
+string(32) "950b7457d1deb6332f2fc5d42f3129d6"
+-- Opening file in r+b --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+int(2)
+bool(false)
+int(200)
+int(202)
+bool(false)
+bool(true)
+int(1024)
+string(32) "950b7457d1deb6332f2fc5d42f3129d6"
+-- Opening file in r+t --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+int(2)
+bool(false)
+int(200)
+int(202)
+bool(false)
+bool(true)
+int(1024)
+string(32) "950b7457d1deb6332f2fc5d42f3129d6"
+-- Opening file in a --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+bool(true)
+int(1624)
+string(32) "59ce5bf03b69069d00d6354bdc969ff6"
+-- Opening file in ab --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+bool(true)
+int(1624)
+string(32) "59ce5bf03b69069d00d6354bdc969ff6"
+-- Opening file in at --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+bool(true)
+int(1624)
+string(32) "59ce5bf03b69069d00d6354bdc969ff6"
+-- Opening file in a+ --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+bool(true)
+int(1624)
+string(32) "59ce5bf03b69069d00d6354bdc969ff6"
+-- Opening file in a+b --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+bool(true)
+int(1624)
+string(32) "59ce5bf03b69069d00d6354bdc969ff6"
+-- Opening file in a+t --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+bool(true)
+int(1624)
+string(32) "59ce5bf03b69069d00d6354bdc969ff6"
+-- Opening file in x --
+int(0)
+int(400)
+int(400)
+bool(false)
+bool(true)
+int(400)
+string(32) "f255efe87ebdf755e515868cea9ad24b"
+-- Opening file in xb --
+int(0)
+int(400)
+int(400)
+bool(false)
+bool(true)
+int(400)
+string(32) "f255efe87ebdf755e515868cea9ad24b"
+-- Opening file in xt --
+int(0)
+int(400)
+int(400)
+bool(false)
+bool(true)
+int(400)
+string(32) "f255efe87ebdf755e515868cea9ad24b"
+-- Opening file in x+ --
+int(0)
+int(400)
+int(400)
+bool(false)
+bool(true)
+int(400)
+string(32) "f255efe87ebdf755e515868cea9ad24b"
+-- Opening file in x+b --
+int(0)
+int(400)
+int(400)
+bool(false)
+bool(true)
+int(400)
+string(32) "f255efe87ebdf755e515868cea9ad24b"
+-- Opening file in x+t --
+int(0)
+int(400)
+int(400)
+bool(false)
+bool(true)
+int(400)
+string(32) "f255efe87ebdf755e515868cea9ad24b"
+
+-- Testing fwrite() with file having content of type text --
+-- Opening file in r --
+int(0)
+int(0)
+int(0)
+bool(false)
+int(2)
+int(0)
+int(2)
+bool(false)
+bool(true)
+int(1024)
+string(32) "e486000c4c8452774f746a27658d87fa"
+-- Opening file in rb --
+int(0)
+int(0)
+int(0)
+bool(false)
+int(2)
+int(0)
+int(2)
+bool(false)
+bool(true)
+int(1024)
+string(32) "e486000c4c8452774f746a27658d87fa"
+-- Opening file in rt --
+int(0)
+int(0)
+int(0)
+bool(false)
+int(2)
+int(0)
+int(2)
+bool(false)
+bool(true)
+int(1024)
+string(32) "e486000c4c8452774f746a27658d87fa"
+-- Opening file in r+ --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+int(2)
+bool(false)
+int(200)
+int(202)
+bool(false)
+bool(true)
+int(1024)
+string(32) "3bdaf80dae28bc24bb304daa5ffee16c"
+-- Opening file in r+b --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+int(2)
+bool(false)
+int(200)
+int(202)
+bool(false)
+bool(true)
+int(1024)
+string(32) "3bdaf80dae28bc24bb304daa5ffee16c"
+-- Opening file in r+t --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+int(2)
+bool(false)
+int(200)
+int(202)
+bool(false)
+bool(true)
+int(1024)
+string(32) "3bdaf80dae28bc24bb304daa5ffee16c"
+-- Opening file in a --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+bool(true)
+int(1624)
+string(32) "dbd9dffd809d82e299bc1e5c55087f3b"
+-- Opening file in ab --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+bool(true)
+int(1624)
+string(32) "dbd9dffd809d82e299bc1e5c55087f3b"
+-- Opening file in at --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+bool(true)
+int(1624)
+string(32) "dbd9dffd809d82e299bc1e5c55087f3b"
+-- Opening file in a+ --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+bool(true)
+int(1624)
+string(32) "dbd9dffd809d82e299bc1e5c55087f3b"
+-- Opening file in a+b --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+bool(true)
+int(1624)
+string(32) "dbd9dffd809d82e299bc1e5c55087f3b"
+-- Opening file in a+t --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+bool(true)
+int(1624)
+string(32) "dbd9dffd809d82e299bc1e5c55087f3b"
+-- Opening file in x --
+int(0)
+int(400)
+int(400)
+bool(false)
+bool(true)
+int(400)
+string(32) "c2244282eeca7c2d32d0dacf21e19432"
+-- Opening file in xb --
+int(0)
+int(400)
+int(400)
+bool(false)
+bool(true)
+int(400)
+string(32) "c2244282eeca7c2d32d0dacf21e19432"
+-- Opening file in xt --
+int(0)
+int(400)
+int(400)
+bool(false)
+bool(true)
+int(400)
+string(32) "c2244282eeca7c2d32d0dacf21e19432"
+-- Opening file in x+ --
+int(0)
+int(400)
+int(400)
+bool(false)
+bool(true)
+int(400)
+string(32) "c2244282eeca7c2d32d0dacf21e19432"
+-- Opening file in x+b --
+int(0)
+int(400)
+int(400)
+bool(false)
+bool(true)
+int(400)
+string(32) "c2244282eeca7c2d32d0dacf21e19432"
+-- Opening file in x+t --
+int(0)
+int(400)
+int(400)
+bool(false)
+bool(true)
+int(400)
+string(32) "c2244282eeca7c2d32d0dacf21e19432"
+
+-- Testing fwrite() with file having content of type text_with_new_line --
+-- Opening file in r --
+int(0)
+int(0)
+int(0)
+bool(false)
+int(2)
+int(0)
+int(2)
+bool(false)
+bool(true)
+int(1024)
+string(32) "b09c8026a64a88d36d4c2f17983964bb"
+-- Opening file in rb --
+int(0)
+int(0)
+int(0)
+bool(false)
+int(2)
+int(0)
+int(2)
+bool(false)
+bool(true)
+int(1024)
+string(32) "b09c8026a64a88d36d4c2f17983964bb"
+-- Opening file in rt --
+int(0)
+int(0)
+int(0)
+bool(false)
+int(2)
+int(0)
+int(2)
+bool(false)
+bool(true)
+int(1024)
+string(32) "b09c8026a64a88d36d4c2f17983964bb"
+-- Opening file in r+ --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+int(2)
+bool(false)
+int(200)
+int(202)
+bool(false)
+bool(true)
+int(1024)
+string(32) "b188d7c8aa229cbef067e5970f2daba9"
+-- Opening file in r+b --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+int(2)
+bool(false)
+int(200)
+int(202)
+bool(false)
+bool(true)
+int(1024)
+string(32) "b188d7c8aa229cbef067e5970f2daba9"
+-- Opening file in r+t --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+int(2)
+bool(false)
+int(200)
+int(202)
+bool(false)
+bool(true)
+int(1024)
+string(32) "991652c76db8d17c790c702ac0a6dc5f"
+-- Opening file in a --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+bool(true)
+int(1624)
+string(32) "3f0a483fe8a2f405677844e0b1af6cf4"
+-- Opening file in ab --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+bool(true)
+int(1624)
+string(32) "3f0a483fe8a2f405677844e0b1af6cf4"
+-- Opening file in at --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+bool(true)
+int(1690)
+string(32) "656648355b64df6fded53b12fb355ab8"
+-- Opening file in a+ --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+bool(true)
+int(1624)
+string(32) "3f0a483fe8a2f405677844e0b1af6cf4"
+-- Opening file in a+b --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+bool(true)
+int(1624)
+string(32) "3f0a483fe8a2f405677844e0b1af6cf4"
+-- Opening file in a+t --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+bool(true)
+int(1690)
+string(32) "656648355b64df6fded53b12fb355ab8"
+-- Opening file in x --
+int(0)
+int(400)
+int(400)
+bool(false)
+bool(true)
+int(400)
+string(32) "fa6c79b925c2fc754b9d063c6de1d8df"
+-- Opening file in xb --
+int(0)
+int(400)
+int(400)
+bool(false)
+bool(true)
+int(400)
+string(32) "fa6c79b925c2fc754b9d063c6de1d8df"
+-- Opening file in xt --
+int(0)
+int(400)
+int(400)
+bool(false)
+bool(true)
+int(444)
+string(32) "c96531f6b4c8d9e829c25b87f96ea86e"
+-- Opening file in x+ --
+int(0)
+int(400)
+int(400)
+bool(false)
+bool(true)
+int(400)
+string(32) "fa6c79b925c2fc754b9d063c6de1d8df"
+-- Opening file in x+b --
+int(0)
+int(400)
+int(400)
+bool(false)
+bool(true)
+int(400)
+string(32) "fa6c79b925c2fc754b9d063c6de1d8df"
+-- Opening file in x+t --
+int(0)
+int(400)
+int(400)
+bool(false)
+bool(true)
+int(444)
+string(32) "c96531f6b4c8d9e829c25b87f96ea86e"
+
+-- Testing fwrite() with file having content of type alphanumeric --
+-- Opening file in r --
+int(0)
+int(0)
+int(0)
+bool(false)
+int(2)
+int(0)
+int(2)
+bool(false)
+bool(true)
+int(1024)
+string(32) "3fabd48d8eaa65c14e0d93d6880c560c"
+-- Opening file in rb --
+int(0)
+int(0)
+int(0)
+bool(false)
+int(2)
+int(0)
+int(2)
+bool(false)
+bool(true)
+int(1024)
+string(32) "3fabd48d8eaa65c14e0d93d6880c560c"
+-- Opening file in rt --
+int(0)
+int(0)
+int(0)
+bool(false)
+int(2)
+int(0)
+int(2)
+bool(false)
+bool(true)
+int(1024)
+string(32) "3fabd48d8eaa65c14e0d93d6880c560c"
+-- Opening file in r+ --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+int(2)
+bool(false)
+int(200)
+int(202)
+bool(false)
+bool(true)
+int(1024)
+string(32) "5d4ec23a3d9dd447e2f702d9e0e114d9"
+-- Opening file in r+b --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+int(2)
+bool(false)
+int(200)
+int(202)
+bool(false)
+bool(true)
+int(1024)
+string(32) "5d4ec23a3d9dd447e2f702d9e0e114d9"
+-- Opening file in r+t --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+int(2)
+bool(false)
+int(200)
+int(202)
+bool(false)
+bool(true)
+int(1024)
+string(32) "5d4ec23a3d9dd447e2f702d9e0e114d9"
+-- Opening file in a --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+bool(true)
+int(1624)
+string(32) "ea0c0bfa0b10aa8e614fd33ffe295cb9"
+-- Opening file in ab --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+bool(true)
+int(1624)
+string(32) "ea0c0bfa0b10aa8e614fd33ffe295cb9"
+-- Opening file in at --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+bool(true)
+int(1624)
+string(32) "ea0c0bfa0b10aa8e614fd33ffe295cb9"
+-- Opening file in a+ --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+bool(true)
+int(1624)
+string(32) "ea0c0bfa0b10aa8e614fd33ffe295cb9"
+-- Opening file in a+b --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+bool(true)
+int(1624)
+string(32) "ea0c0bfa0b10aa8e614fd33ffe295cb9"
+-- Opening file in a+t --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+bool(true)
+int(1624)
+string(32) "ea0c0bfa0b10aa8e614fd33ffe295cb9"
+-- Opening file in x --
+int(0)
+int(400)
+int(400)
+bool(false)
+bool(true)
+int(400)
+string(32) "b2a123e1d84e6a03c8520aff7689219e"
+-- Opening file in xb --
+int(0)
+int(400)
+int(400)
+bool(false)
+bool(true)
+int(400)
+string(32) "b2a123e1d84e6a03c8520aff7689219e"
+-- Opening file in xt --
+int(0)
+int(400)
+int(400)
+bool(false)
+bool(true)
+int(400)
+string(32) "b2a123e1d84e6a03c8520aff7689219e"
+-- Opening file in x+ --
+int(0)
+int(400)
+int(400)
+bool(false)
+bool(true)
+int(400)
+string(32) "b2a123e1d84e6a03c8520aff7689219e"
+-- Opening file in x+b --
+int(0)
+int(400)
+int(400)
+bool(false)
+bool(true)
+int(400)
+string(32) "b2a123e1d84e6a03c8520aff7689219e"
+-- Opening file in x+t --
+int(0)
+int(400)
+int(400)
+bool(false)
+bool(true)
+int(400)
+string(32) "b2a123e1d84e6a03c8520aff7689219e"
+Done
\ No newline at end of file
diff --git a/ext/standard/tests/file/fwrite_variation.phpt b/ext/standard/tests/file/fwrite_variation.phpt
new file mode 100644 (file)
index 0000000..87bbf47
--- /dev/null
@@ -0,0 +1,1008 @@
+--TEST--
+Test fwrite() function : usage variations
+--SKIPIF--
+<?php
+if( substr(PHP_OS, 0, 3) == 'WIN' ) {
+   die('skip...Not valid for Windows');
+}
+?>
+--FILE--
+<?php
+/*
+ Prototype: int fwrite ( resource $handle,string string, [, int $length] );
+ Description: fwrite() writes the contents of string to the file stream pointed to by handle.
+              If the length arquement is given,writing will stop after length bytes have been
+              written or the end of string reached, whichever comes first.
+              fwrite() returns the number of bytes written or FALSE on error
+*/
+
+
+echo "*** Testing fwrite() various  operations ***\n";
+
+// include the file.inc for Function: function delete_file($filename)
+include ("file.inc");
+
+/*
+ Test fwrite with file opened in mode : a,ab,at,a+,a+b,a+t,r,rb,rt,r+,r+b,r+t
+ File having content of type numeric, text,text_with_new_line & alphanumeric
+*/
+
+$file_modes = array("r","rb","rt","r+", "r+b", "r+t","a","ab","at","a+","a+b",
+                    "a+t","x","xb","xt","x+","x+b","x+t");
+$file_content_types = array("numeric","text","text_with_new_line","alphanumeric");
+
+
+foreach($file_content_types as $file_content_type) {
+  echo "\n-- Testing fwrite() with file having content of type ". $file_content_type ." --\n";
+
+  /* open the file using $files_modes and perform fwrite() on it */
+  foreach($file_modes as $file_mode) {
+    echo "-- Opening file in $file_mode --\n";
+
+    $filename = dirname(__FILE__)."/fwrite_variation1.tmp"; // this is name of the file
+    if ( ! strstr( $file_mode, "x" ) ) {
+      create_files ( dirname(__FILE__), 1, $file_content_type, 0755, 1, "w", "fwrite_variation");
+    }
+
+    $file_handle = fopen($filename, $file_mode);
+    if(!$file_handle) {
+      echo "Error: failed to fopen() file: $filename!";
+      exit();
+    }
+
+    $data_to_be_written="";
+    fill_buffer($data_to_be_written,$file_content_type,1024);  //get the data of size 1024
+
+    /*  Write the in to the file, verify it by checking the file pointer position, eof position, 
+        filesize & by displaying the content */
+    switch($file_mode) {
+      case "r":
+      case "rb":
+      case "rt":
+        var_dump( ftell($file_handle) );  // expected: 0
+        var_dump( fwrite($file_handle, $data_to_be_written )); 
+        var_dump( ftell($file_handle) );  // expected: 0
+        var_dump( feof($file_handle) );  // expected: false 
+  
+        // move the file pointer to end of the file and try fwrite()
+        fseek($file_handle, SEEK_END, 0);
+        var_dump( ftell($file_handle) );  // expecting 1024
+        var_dump( fwrite($file_handle, $data_to_be_written) ); // fwrite to fail
+        var_dump( ftell($file_handle) );  //check that file pointer points at eof, expected: 1024
+        var_dump( feof($file_handle) );  // ensure that  feof() points to eof, expected: true
+
+       // ensure that file content/size didn't change.
+        var_dump( fclose($file_handle) );
+        clearstatcache();//clears file status cache
+        var_dump( filesize($filename) );  // expected: 1024
+        var_dump(md5(file_get_contents($filename))); // hash the output
+       delete_file($filename); // delete file with name fwrite_variation1.tmp
+       break;
+
+      case "r+b":
+      case "r+":
+      case "r+t":
+        /*overwrite first 400 bytes in the file*/
+        var_dump( ftell($file_handle) );  // expected : 0
+        var_dump( fwrite($file_handle, $data_to_be_written, 400));
+        var_dump( ftell($file_handle) );  // expected: 400
+        var_dump( feof($file_handle) );  //Expecting bool(false)
+
+       /*overwrite data in middle of the file*/
+        fseek($file_handle, SEEK_SET, 1024/2 ); 
+       var_dump( ftell($file_handle));  // expected: 1024/2
+       var_dump( fwrite($file_handle, $data_to_be_written, 200) );
+        var_dump( ftell($file_handle) );
+       var_dump( feof($file_handle) );  //Expecting bool(false)
+
+        /* write at the end of the file */
+        fseek($file_handle, SEEK_END, 0); 
+       var_dump( ftell($file_handle) );  // expected: 1024
+        var_dump( feof($file_handle) );
+       var_dump( fwrite($file_handle, $data_to_be_written, 200) );
+        var_dump( ftell($file_handle) );
+       var_dump( feof($file_handle) );  //Expecting bool(false)
+
+       /* display the file content, check the file size  */
+        var_dump( fclose($file_handle) );
+        clearstatcache();//clears file status cache
+        var_dump( filesize($filename) );
+        var_dump(md5(file_get_contents($filename)));
+        delete_file($filename); // delete file with name fwrite_variation1.tmp
+        break;
+
+      case "a":
+      case "ab":
+      case "at":
+      case "a+":
+      case "a+b":
+      case "a+t":
+        // append the data to the file, starting from current position of the file pointer
+        var_dump( ftell($file_handle) ); // expected: 1024
+        var_dump( fwrite($file_handle,$data_to_be_written,400) );
+        var_dump( ftell($file_handle) ); // expected: 1024 + 400
+        var_dump( feof($file_handle) );  // expected : true
+
+        /*overwrite data in middle of the file*/
+        fseek($file_handle, SEEK_SET, (1024 + 400)/2 );
+        var_dump( ftell($file_handle));  // expected: (1024 + 400)/2
+        var_dump( fwrite($file_handle, $data_to_be_written, 200) );
+        var_dump( ftell($file_handle) ); 
+        var_dump( feof($file_handle) );  //Expecting bool(false)
+        
+        /* check the filesize and display file content */
+        // close the file, get the size and content of the file.
+        var_dump( fclose($file_handle) );
+        clearstatcache();//clears file status cache
+        var_dump( filesize($filename) );
+        var_dump(md5(file_get_contents($filename)));
+        // delete the file created
+        delete_file($filename); // delete file with name fwrite_variation.tmp
+        break;
+
+      case "x":
+      case "xb":
+      case "xt":
+      case "x+":
+      case "x+b":
+      case "x+t":
+        // write data to the file
+        var_dump( ftell($file_handle) );
+        var_dump( fwrite($file_handle,$data_to_be_written,400));
+        var_dump( ftell($file_handle) );
+        var_dump( feof($file_handle) );  // expected: true
+
+        //check the filesize and content
+        // close the file, get the size and content of the file.
+        var_dump( fclose($file_handle) );
+        clearstatcache();//clears file status cache
+        var_dump( filesize($filename) );
+        var_dump(md5(file_get_contents($filename)));
+        // delete the file created
+        delete_file($filename); // delete file with name fwrite_variation.tmp
+        break;
+    } //end of switch
+  } // end of inner foreach loop
+} // end of outer foreach loop
+
+echo "Done\n";
+?>
+--EXPECTF--
+*** Testing fwrite() various  operations ***
+
+-- Testing fwrite() with file having content of type numeric --
+-- Opening file in r --
+int(0)
+int(0)
+int(0)
+bool(false)
+int(2)
+int(0)
+int(2)
+bool(false)
+bool(true)
+int(1024)
+string(32) "950b7457d1deb6332f2fc5d42f3129d6"
+-- Opening file in rb --
+int(0)
+int(0)
+int(0)
+bool(false)
+int(2)
+int(0)
+int(2)
+bool(false)
+bool(true)
+int(1024)
+string(32) "950b7457d1deb6332f2fc5d42f3129d6"
+-- Opening file in rt --
+int(0)
+int(0)
+int(0)
+bool(false)
+int(2)
+int(0)
+int(2)
+bool(false)
+bool(true)
+int(1024)
+string(32) "950b7457d1deb6332f2fc5d42f3129d6"
+-- Opening file in r+ --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+int(2)
+bool(false)
+int(200)
+int(202)
+bool(false)
+bool(true)
+int(1024)
+string(32) "950b7457d1deb6332f2fc5d42f3129d6"
+-- Opening file in r+b --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+int(2)
+bool(false)
+int(200)
+int(202)
+bool(false)
+bool(true)
+int(1024)
+string(32) "950b7457d1deb6332f2fc5d42f3129d6"
+-- Opening file in r+t --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+int(2)
+bool(false)
+int(200)
+int(202)
+bool(false)
+bool(true)
+int(1024)
+string(32) "950b7457d1deb6332f2fc5d42f3129d6"
+-- Opening file in a --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+bool(true)
+int(1624)
+string(32) "59ce5bf03b69069d00d6354bdc969ff6"
+-- Opening file in ab --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+bool(true)
+int(1624)
+string(32) "59ce5bf03b69069d00d6354bdc969ff6"
+-- Opening file in at --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+bool(true)
+int(1624)
+string(32) "59ce5bf03b69069d00d6354bdc969ff6"
+-- Opening file in a+ --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+bool(true)
+int(1624)
+string(32) "59ce5bf03b69069d00d6354bdc969ff6"
+-- Opening file in a+b --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+bool(true)
+int(1624)
+string(32) "59ce5bf03b69069d00d6354bdc969ff6"
+-- Opening file in a+t --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+bool(true)
+int(1624)
+string(32) "59ce5bf03b69069d00d6354bdc969ff6"
+-- Opening file in x --
+int(0)
+int(400)
+int(400)
+bool(false)
+bool(true)
+int(400)
+string(32) "f255efe87ebdf755e515868cea9ad24b"
+-- Opening file in xb --
+int(0)
+int(400)
+int(400)
+bool(false)
+bool(true)
+int(400)
+string(32) "f255efe87ebdf755e515868cea9ad24b"
+-- Opening file in xt --
+int(0)
+int(400)
+int(400)
+bool(false)
+bool(true)
+int(400)
+string(32) "f255efe87ebdf755e515868cea9ad24b"
+-- Opening file in x+ --
+int(0)
+int(400)
+int(400)
+bool(false)
+bool(true)
+int(400)
+string(32) "f255efe87ebdf755e515868cea9ad24b"
+-- Opening file in x+b --
+int(0)
+int(400)
+int(400)
+bool(false)
+bool(true)
+int(400)
+string(32) "f255efe87ebdf755e515868cea9ad24b"
+-- Opening file in x+t --
+int(0)
+int(400)
+int(400)
+bool(false)
+bool(true)
+int(400)
+string(32) "f255efe87ebdf755e515868cea9ad24b"
+
+-- Testing fwrite() with file having content of type text --
+-- Opening file in r --
+int(0)
+int(0)
+int(0)
+bool(false)
+int(2)
+int(0)
+int(2)
+bool(false)
+bool(true)
+int(1024)
+string(32) "e486000c4c8452774f746a27658d87fa"
+-- Opening file in rb --
+int(0)
+int(0)
+int(0)
+bool(false)
+int(2)
+int(0)
+int(2)
+bool(false)
+bool(true)
+int(1024)
+string(32) "e486000c4c8452774f746a27658d87fa"
+-- Opening file in rt --
+int(0)
+int(0)
+int(0)
+bool(false)
+int(2)
+int(0)
+int(2)
+bool(false)
+bool(true)
+int(1024)
+string(32) "e486000c4c8452774f746a27658d87fa"
+-- Opening file in r+ --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+int(2)
+bool(false)
+int(200)
+int(202)
+bool(false)
+bool(true)
+int(1024)
+string(32) "3bdaf80dae28bc24bb304daa5ffee16c"
+-- Opening file in r+b --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+int(2)
+bool(false)
+int(200)
+int(202)
+bool(false)
+bool(true)
+int(1024)
+string(32) "3bdaf80dae28bc24bb304daa5ffee16c"
+-- Opening file in r+t --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+int(2)
+bool(false)
+int(200)
+int(202)
+bool(false)
+bool(true)
+int(1024)
+string(32) "3bdaf80dae28bc24bb304daa5ffee16c"
+-- Opening file in a --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+bool(true)
+int(1624)
+string(32) "dbd9dffd809d82e299bc1e5c55087f3b"
+-- Opening file in ab --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+bool(true)
+int(1624)
+string(32) "dbd9dffd809d82e299bc1e5c55087f3b"
+-- Opening file in at --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+bool(true)
+int(1624)
+string(32) "dbd9dffd809d82e299bc1e5c55087f3b"
+-- Opening file in a+ --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+bool(true)
+int(1624)
+string(32) "dbd9dffd809d82e299bc1e5c55087f3b"
+-- Opening file in a+b --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+bool(true)
+int(1624)
+string(32) "dbd9dffd809d82e299bc1e5c55087f3b"
+-- Opening file in a+t --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+bool(true)
+int(1624)
+string(32) "dbd9dffd809d82e299bc1e5c55087f3b"
+-- Opening file in x --
+int(0)
+int(400)
+int(400)
+bool(false)
+bool(true)
+int(400)
+string(32) "c2244282eeca7c2d32d0dacf21e19432"
+-- Opening file in xb --
+int(0)
+int(400)
+int(400)
+bool(false)
+bool(true)
+int(400)
+string(32) "c2244282eeca7c2d32d0dacf21e19432"
+-- Opening file in xt --
+int(0)
+int(400)
+int(400)
+bool(false)
+bool(true)
+int(400)
+string(32) "c2244282eeca7c2d32d0dacf21e19432"
+-- Opening file in x+ --
+int(0)
+int(400)
+int(400)
+bool(false)
+bool(true)
+int(400)
+string(32) "c2244282eeca7c2d32d0dacf21e19432"
+-- Opening file in x+b --
+int(0)
+int(400)
+int(400)
+bool(false)
+bool(true)
+int(400)
+string(32) "c2244282eeca7c2d32d0dacf21e19432"
+-- Opening file in x+t --
+int(0)
+int(400)
+int(400)
+bool(false)
+bool(true)
+int(400)
+string(32) "c2244282eeca7c2d32d0dacf21e19432"
+
+-- Testing fwrite() with file having content of type text_with_new_line --
+-- Opening file in r --
+int(0)
+int(0)
+int(0)
+bool(false)
+int(2)
+int(0)
+int(2)
+bool(false)
+bool(true)
+int(1024)
+string(32) "b09c8026a64a88d36d4c2f17983964bb"
+-- Opening file in rb --
+int(0)
+int(0)
+int(0)
+bool(false)
+int(2)
+int(0)
+int(2)
+bool(false)
+bool(true)
+int(1024)
+string(32) "b09c8026a64a88d36d4c2f17983964bb"
+-- Opening file in rt --
+int(0)
+int(0)
+int(0)
+bool(false)
+int(2)
+int(0)
+int(2)
+bool(false)
+bool(true)
+int(1024)
+string(32) "b09c8026a64a88d36d4c2f17983964bb"
+-- Opening file in r+ --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+int(2)
+bool(false)
+int(200)
+int(202)
+bool(false)
+bool(true)
+int(1024)
+string(32) "b188d7c8aa229cbef067e5970f2daba9"
+-- Opening file in r+b --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+int(2)
+bool(false)
+int(200)
+int(202)
+bool(false)
+bool(true)
+int(1024)
+string(32) "b188d7c8aa229cbef067e5970f2daba9"
+-- Opening file in r+t --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+int(2)
+bool(false)
+int(200)
+int(202)
+bool(false)
+bool(true)
+int(1024)
+string(32) "b188d7c8aa229cbef067e5970f2daba9"
+-- Opening file in a --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+bool(true)
+int(1624)
+string(32) "3f0a483fe8a2f405677844e0b1af6cf4"
+-- Opening file in ab --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+bool(true)
+int(1624)
+string(32) "3f0a483fe8a2f405677844e0b1af6cf4"
+-- Opening file in at --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+bool(true)
+int(1624)
+string(32) "3f0a483fe8a2f405677844e0b1af6cf4"
+-- Opening file in a+ --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+bool(true)
+int(1624)
+string(32) "3f0a483fe8a2f405677844e0b1af6cf4"
+-- Opening file in a+b --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+bool(true)
+int(1624)
+string(32) "3f0a483fe8a2f405677844e0b1af6cf4"
+-- Opening file in a+t --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+bool(true)
+int(1624)
+string(32) "3f0a483fe8a2f405677844e0b1af6cf4"
+-- Opening file in x --
+int(0)
+int(400)
+int(400)
+bool(false)
+bool(true)
+int(400)
+string(32) "fa6c79b925c2fc754b9d063c6de1d8df"
+-- Opening file in xb --
+int(0)
+int(400)
+int(400)
+bool(false)
+bool(true)
+int(400)
+string(32) "fa6c79b925c2fc754b9d063c6de1d8df"
+-- Opening file in xt --
+int(0)
+int(400)
+int(400)
+bool(false)
+bool(true)
+int(400)
+string(32) "fa6c79b925c2fc754b9d063c6de1d8df"
+-- Opening file in x+ --
+int(0)
+int(400)
+int(400)
+bool(false)
+bool(true)
+int(400)
+string(32) "fa6c79b925c2fc754b9d063c6de1d8df"
+-- Opening file in x+b --
+int(0)
+int(400)
+int(400)
+bool(false)
+bool(true)
+int(400)
+string(32) "fa6c79b925c2fc754b9d063c6de1d8df"
+-- Opening file in x+t --
+int(0)
+int(400)
+int(400)
+bool(false)
+bool(true)
+int(400)
+string(32) "fa6c79b925c2fc754b9d063c6de1d8df"
+
+-- Testing fwrite() with file having content of type alphanumeric --
+-- Opening file in r --
+int(0)
+int(0)
+int(0)
+bool(false)
+int(2)
+int(0)
+int(2)
+bool(false)
+bool(true)
+int(1024)
+string(32) "3fabd48d8eaa65c14e0d93d6880c560c"
+-- Opening file in rb --
+int(0)
+int(0)
+int(0)
+bool(false)
+int(2)
+int(0)
+int(2)
+bool(false)
+bool(true)
+int(1024)
+string(32) "3fabd48d8eaa65c14e0d93d6880c560c"
+-- Opening file in rt --
+int(0)
+int(0)
+int(0)
+bool(false)
+int(2)
+int(0)
+int(2)
+bool(false)
+bool(true)
+int(1024)
+string(32) "3fabd48d8eaa65c14e0d93d6880c560c"
+-- Opening file in r+ --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+int(2)
+bool(false)
+int(200)
+int(202)
+bool(false)
+bool(true)
+int(1024)
+string(32) "5d4ec23a3d9dd447e2f702d9e0e114d9"
+-- Opening file in r+b --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+int(2)
+bool(false)
+int(200)
+int(202)
+bool(false)
+bool(true)
+int(1024)
+string(32) "5d4ec23a3d9dd447e2f702d9e0e114d9"
+-- Opening file in r+t --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+int(2)
+bool(false)
+int(200)
+int(202)
+bool(false)
+bool(true)
+int(1024)
+string(32) "5d4ec23a3d9dd447e2f702d9e0e114d9"
+-- Opening file in a --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+bool(true)
+int(1624)
+string(32) "ea0c0bfa0b10aa8e614fd33ffe295cb9"
+-- Opening file in ab --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+bool(true)
+int(1624)
+string(32) "ea0c0bfa0b10aa8e614fd33ffe295cb9"
+-- Opening file in at --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+bool(true)
+int(1624)
+string(32) "ea0c0bfa0b10aa8e614fd33ffe295cb9"
+-- Opening file in a+ --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+bool(true)
+int(1624)
+string(32) "ea0c0bfa0b10aa8e614fd33ffe295cb9"
+-- Opening file in a+b --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+bool(true)
+int(1624)
+string(32) "ea0c0bfa0b10aa8e614fd33ffe295cb9"
+-- Opening file in a+t --
+int(0)
+int(400)
+int(400)
+bool(false)
+int(400)
+int(200)
+int(600)
+bool(false)
+bool(true)
+int(1624)
+string(32) "ea0c0bfa0b10aa8e614fd33ffe295cb9"
+-- Opening file in x --
+int(0)
+int(400)
+int(400)
+bool(false)
+bool(true)
+int(400)
+string(32) "b2a123e1d84e6a03c8520aff7689219e"
+-- Opening file in xb --
+int(0)
+int(400)
+int(400)
+bool(false)
+bool(true)
+int(400)
+string(32) "b2a123e1d84e6a03c8520aff7689219e"
+-- Opening file in xt --
+int(0)
+int(400)
+int(400)
+bool(false)
+bool(true)
+int(400)
+string(32) "b2a123e1d84e6a03c8520aff7689219e"
+-- Opening file in x+ --
+int(0)
+int(400)
+int(400)
+bool(false)
+bool(true)
+int(400)
+string(32) "b2a123e1d84e6a03c8520aff7689219e"
+-- Opening file in x+b --
+int(0)
+int(400)
+int(400)
+bool(false)
+bool(true)
+int(400)
+string(32) "b2a123e1d84e6a03c8520aff7689219e"
+-- Opening file in x+t --
+int(0)
+int(400)
+int(400)
+bool(false)
+bool(true)
+int(400)
+string(32) "b2a123e1d84e6a03c8520aff7689219e"
+Done