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