Annotation of embedaddon/php/ext/standard/tests/file/touch_basic-win32.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test touch() function : basic functionality
3: --CREDITS--
4: Dave Kelsey <d_kelsey@uk.ibm.com>
5: --SKIPIF--
6: <?php
7: if (substr(PHP_OS, 0, 3) != 'WIN') {
8: die('skip.. only for Windows');
9: }
10: ?>
11: --FILE--
12: <?php
13: /* Prototype : proto bool touch(string filename [, int time [, int atime]])
14: * Description: Set modification time of file
15: * Source code: ext/standard/filestat.c
16: * Alias to functions:
17: */
18:
19: echo "*** Testing touch() : basic functionality ***\n";
20:
21: $filename = dirname(__FILE__)."/touch.dat";
22:
23: echo "\n--- testing touch creates a file ---\n";
24: @unlink($filename);
25: if (file_exists($filename)) {
26: die("touch_basic failed");
27: }
28: var_dump( touch($filename) );
29: if (file_exists($filename) == false) {
30: die("touch_basic failed");
31: }
32:
33: echo "\n --- testing touch doesn't alter file contents ---\n";
34: $testln = "Here is a test line";
35: $h = fopen($filename, "wb");
36: fwrite($h, $testln);
37: fclose($h);
38: touch($filename);
39: $h = fopen($filename, "rb");
40: echo fgets($h);
41: fclose($h);
42:
43: echo "\n\n --- testing touch alters the correct file metadata ---\n";
44: $init_meta = stat($filename);
45: clearstatcache();
46: sleep(1);
47: touch($filename);
48: $next_meta = stat($filename);
49: $type = array("dev", "ino", "mode", "nlink", "uid", "gid",
50: "rdev", "size", "atime", "mtime", "ctime",
51: "blksize", "blocks");
52:
53: for ($i = 0; $i < count($type); $i++) {
54: if ($init_meta[$i] != $next_meta[$i]) {
55: echo "stat data differs at $type[$i]\n";
56: }
57: }
58:
59:
60: // Initialise all required variables
61: $time = 10000;
62: $atime = 20470;
63:
64: // Calling touch() with all possible arguments
65: echo "\n --- testing touch using all parameters ---\n";
66: var_dump( touch($filename, $time, $atime) );
67: clearstatcache();
68: $init_meta = stat($filename);
69: echo "ctime=".$init_meta['ctime']."\n";
70: echo "mtime=".$init_meta['mtime']."\n";
71: echo "atime=".$init_meta['atime']."\n";
72:
73: unlink($filename);
74:
75: echo "Done";
76: ?>
77: --EXPECTF--
78: *** Testing touch() : basic functionality ***
79:
80: --- testing touch creates a file ---
81: bool(true)
82:
83: --- testing touch doesn't alter file contents ---
84: Here is a test line
85:
86: --- testing touch alters the correct file metadata ---
87: stat data differs at atime
88: stat data differs at mtime
89:
90: --- testing touch using all parameters ---
91: bool(true)
92: ctime=%d
93: mtime=10000
94: atime=20470
95: Done
96:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>