ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/t/io_common
Revision: 1.7
Committed: Thu Apr 5 03:13:27 2012 UTC (12 years, 2 months ago) by root
Branch: MAIN
Changes since 1.6: +7 -3 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 #! perl
2
3 $| = 1;
4
5 # not tested: symlink, readlink, link, utime, chown, chmod
6
7 BEGIN {
8 print "1..38\n";
9 print "ok 1 # MODEL=$AnyEvent::IO::MODEL\n";
10 }
11 use AnyEvent;
12 use AnyEvent::IO qw(:DEFAULT :flags);
13 BEGIN {
14 print "ok 2 # MODEL=$AnyEvent::IO::MODEL\n";
15 }
16
17 our $t = 3;
18
19 sub t {
20 my $ok = shift;
21 my $f = "aio_" . shift;
22 $f->(@_, my $cv = AE::cv);
23 my @res = $cv->recv;
24
25 print !@res != !$ok ? "not " : "", "ok ", $t++, " # $f (@_) = (@res)\n";
26
27 wantarray ? @res : $res[0]
28 }
29
30 our $TMP = "/tmp";
31 our $DIR = "$TMP/ae_io_testdir_$$~";
32
33 t 1, mkdir => $DIR, 0777
34 or do { print "Bail out! Cannot mkdir $DIR, skipping test.\n"; exit 0 };
35 t 0, mkdir => $DIR, 0777;
36
37 #############################################################################
38 # create file
39
40 my $fh = t 1, open => "$DIR/test", O_CREAT | O_EXCL | O_WRONLY, 0666;
41 t 0, open => "$DIR/test", O_CREAT | O_EXCL | O_WRONLY, 0666;
42
43 t 0, rmdir => $DIR;
44
45 t 1, write => $fh, "tes--";
46 t 1, write => $fh, "test2truncate";
47 t 1, write => $fh, "";
48
49 t 1, seek => $fh, 3, 0;
50 t 1, write => $fh, "t1";
51
52 t 1, truncate => $fh, 5+5;
53
54 t 1, stat => $fh;
55 print -s _ != 10 ? "not " : "", "ok ", $t++, " # stat size\n";
56
57 t 1, close => $fh;
58
59 t 1, stat => "$DIR/test";
60 print -s _ != 10 ? "not " : "", "ok ", $t++, " # stat size\n";
61
62 t 1, lstat => "$DIR/test";
63 print -s _ != 10 ? "not " : "", "ok ", $t++, " # lstat size\n";
64
65 t 1, rename => "$DIR/test", "$DIR/test2";
66
67 #############################################################################
68 # test dir
69
70 t 0, readdir => "$DIR/nonexistent";
71 my $res = t 1, readdir => $DIR;
72 print @$res != 1 ? "not " : "", "ok ", $t++, " # res count\n";
73 print $res->[0] ne "test2" ? "not " : "", "ok ", $t++, " # res data (@$res)\n";
74
75 #############################################################################
76 # test file
77
78 $fh = t 1, open => "$DIR/test2", O_RDONLY, 0;
79
80 print +(t 1, read => $fh, 6) ne "test1t" ? "not " : "", "ok ", $t++, " # read 6\n";
81 print +(t 1, read => $fh, 7) ne "est2" ? "not " : "", "ok ", $t++, " # read 7\n";
82 print +(t 1, read => $fh, 8) ne "" ? "not " : "", "ok ", $t++, " # read 8\n";
83
84 t 1, close => $fh;
85
86 print +(t 1, load => "$DIR/test2") ne "test1test2" ? "not " : "", "ok ", $t++, " # load\n";
87
88 #############################################################################
89 # cleanup
90
91 t 0, unlink => "$DIR/test";
92 t 1, unlink => "$DIR/test2";
93
94 t 1, rmdir => $DIR;
95
96 1
97