import zend standard tests
[hiphop-php.git] / hphp / test / zend / bad / ext-standard-file / touch_variation5.php
blob984c30223203cee37dc2c77e74dea864b5fa3733
1 <?php
2 /* Prototype : bool touch(string filename [, int time [, int atime]])
3 * Description: Set modification time of file
4 * Source code: ext/standard/filestat.c
5 * Alias to functions:
6 */
8 $workDir = "touchVar5.tmp";
9 $subDirOrFile = "aSubDirOrFile";
10 mkdir($workDir);
11 $cwd = getcwd();
13 $paths = array(
14 // relative
15 $workDir.'/'.$subDirOrFile,
16 './'.$workDir.'/'.$subDirOrFile,
17 $workDir.'/../'.$workDir.'/'.$subDirOrFile,
19 // relative bad path
20 $workDir.'/../BADDIR/'.$subDirOrFile,
21 'BADDIR/'.$subDirOrFile,
23 //absolute
24 $cwd.'/'.$workDir.'/'.$subDirOrFile,
25 $cwd.'/./'.$workDir.'/'.$subDirOrFile,
26 $cwd.'/'.$workDir.'/../'.$workDir.'/'.$subDirOrFile,
28 //absolute bad path
29 $cwd.'/BADDIR/'.$subDirOrFile,
31 //trailing separators
32 $workDir.'/'.$subDirOrFile.'/',
33 $cwd.'/'.$workDir.'/'.$subDirOrFile.'/',
35 // multiple separators
36 $workDir.'//'.$subDirOrFile,
37 $cwd.'//'.$workDir.'//'.$subDirOrFile,
41 echo "*** Testing touch() : variation ***\n";
43 echo "\n*** testing nonexisting paths ***\n";
44 test_nonexisting($paths);
46 echo "\n*** testing existing files ***\n";
47 test_existing($paths, false);
49 echo "\n*** testing existing directories ***\n";
50 test_existing($paths, true);
53 rmdir($workDir);
57 function test_nonexisting($paths) {
58 foreach($paths as $path) {
59 echo "--- testing $path ---\n";
61 if (is_dir($path) || is_file($path)) {
62 echo "FAILED: $path - exists\n";
64 else {
65 $res = touch($path);
66 if ($res === true) {
67 // something was created
68 if (file_exists($path)) {
69 // something found
70 if (is_dir($path)) {
71 echo "FAILED: $path - unexpected directory\n";
73 else {
74 echo "PASSED: $path - created\n";
75 unlink($path);
78 else {
79 // nothing found
80 echo "FAILED: $path - touch returned true, nothing there\n";
83 else {
84 // nothing created
85 if (file_exists($path)) {
86 //something found
87 echo "FAILED: $path - touch returned false, something there\n";
88 if (is_dir($path)) {
89 rmdir($path);
91 else {
92 unlink($path);
100 function test_existing($paths, $are_dirs) {
101 foreach($paths as $path) {
102 if ($are_dirs) {
103 $res = @mkdir($path);
104 if ($res == true) {
105 test_path($path);
106 rmdir($path);
109 else {
110 $h = @fopen($path,"w");
111 if ($h !== false) {
112 fclose($h);
113 test_path($path);
114 unlink($path);
121 function test_path($path) {
122 echo "--- testing $path ---\n";
123 $org_atime = get_atime($path);
124 clearstatcache();
125 $res = touch($path,0,0);
126 $next_atime = get_atime($path);
127 if ($next_atime == $org_atime) {
128 echo "FAILED: $path - access time not changed\n";
130 else {
131 echo "PASSED: $path - touched\n";
135 function get_atime($path) {
136 $temp = stat($path);
137 return $temp['atime'];
142 ===DONE===