import zend standard tests
[hiphop-php.git] / hphp / test / zend / bad / ext-standard-file / fopen_variation15.php
blob9bc9448ae21b92eac6e2a99b9d82ded3f0900fd9
1 <?php
2 /* Prototype : resource fopen(string filename, string mode [, bool use_include_path [, resource context]])
3 * Description: Open a file or a URL and return a file pointer
4 * Source code: ext/standard/file.c
5 * Alias to functions:
6 */
8 echo "*** Testing fopen() : variation ***\n";
10 // fopen with interesting windows paths.
11 $includePathDir = getcwd().'/fopen15.includeDir';
12 $testDir = 'fopen15.tmpDir';
13 $absTestDir = getcwd().'/'.$testDir;
14 $file = "fopen_variation15.tmp";
15 $absFile = $absTestDir.'/'.$file;
17 mkdir($testDir);
18 mkdir($includePathDir);
19 set_include_path($includePathDir);
21 $files = array("file://$testDir/$file",
22 "file://./$testDir/$file",
23 "file://$absTestDir/$file"
26 runtest($files);
28 chdir($testDir);
29 $files = array("file://../$testDir/$file",
30 "file://$absTestDir/$file"
32 runtest($files);
33 chdir("..");
34 rmdir($testDir);
35 rmdir($includePathDir);
37 function runtest($fileURIs) {
38 global $absFile;
39 $iteration = 0;
40 foreach($fileURIs as $fileURI) {
41 echo "--- READ: $fileURI ---\n";
43 $readData = "read:$iteration";
44 $writeData = "write:$iteration";
46 // create the file and test read
47 $h = fopen($absFile, 'w');
48 fwrite($h, $readData);
49 fclose($h);
51 $h = fopen($fileURI, 'r', true);
52 if ($h !== false) {
53 if (fread($h, 4096) != $readData) {
54 echo "contents not correct\n";
56 else {
57 echo "test passed\n";
59 fclose($h);
61 unlink($absFile);
63 echo "--- WRITE: $fileURI ---\n";
64 // create the file to test write
65 $h = fopen($fileURI, 'w', true);
66 if ($h !== false) {
67 fwrite($h, $writeData);
68 fclose($h);
70 $h = fopen($absFile, 'r');
71 if ($h !== false) {
72 if (fread($h, 4096) != $writeData) {
73 echo "contents not correct\n";
75 else {
76 echo "test passed\n";
78 fclose($h);
80 unlink($absFile);
87 ===DONE===