ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/t/io_common
Revision: 1.9
Committed: Fri Apr 13 15:24:57 2012 UTC (12 years, 8 months ago) by root
Branch: MAIN
CVS Tags: rel-7_02, rel-7_05, rel-7_07, rel-7_04, rel-7_16, rel-7_15, rel-7_14, rel-7_13, rel-7_12, rel-7_11, rel-7_03, rel-7_08, rel-7_09, rel-7_01, HEAD
Changes since 1.8: +3 -1 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..37\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 use File::Spec;
31
32 our $TMP = File::Spec->tmpdir;
33 our $DIR = "$TMP/ae_io_testdir_$$~";
34
35 t 1, mkdir => $DIR, 0777
36 or do { print "Bail out! Cannot mkdir $DIR, skipping test.\n"; exit 0 };
37 t 0, mkdir => $DIR, 0777;
38
39 #############################################################################
40 # create file
41
42 my $fh = t 1, open => "$DIR/test", O_CREAT | O_EXCL | O_WRONLY, 0666;
43 t 0, open => "$DIR/test", O_CREAT | O_EXCL | O_WRONLY, 0666;
44
45 t 0, rmdir => $DIR;
46
47 t 1, write => $fh, "tes--";
48 t 1, write => $fh, "test2";
49 t 1, write => $fh, "";
50
51 t 1, seek => $fh, 3, 0;
52 t 1, write => $fh, "t1";
53
54 #t 1, truncate => $fh, 5+5; # not available on windows
55
56 t 1, stat => $fh;
57 print -s _ != 10 ? "not " : "", "ok ", $t++, " # stat size\n";
58
59 t 1, close => $fh;
60
61 t 1, stat => "$DIR/test";
62 print -s _ != 10 ? "not " : "", "ok ", $t++, " # stat size (", -s _,")\n";
63
64 t 1, lstat => "$DIR/test";
65 print -s _ != 10 ? "not " : "", "ok ", $t++, " # lstat size\n";
66
67 t 1, rename => "$DIR/test", "$DIR/test2";
68
69 #############################################################################
70 # test dir
71
72 t 0, readdir => "$DIR/nonexistent";
73 my $res = t 1, readdir => $DIR;
74 print @$res != 1 ? "not " : "", "ok ", $t++, " # res count\n";
75 print $res->[0] ne "test2" ? "not " : "", "ok ", $t++, " # res data (@$res)\n";
76
77 #############################################################################
78 # test file
79
80 $fh = t 1, open => "$DIR/test2", O_RDONLY, 0;
81
82 print +(t 1, read => $fh, 6) ne "test1t" ? "not " : "", "ok ", $t++, " # read 6\n";
83 print +(t 1, read => $fh, 7) ne "est2" ? "not " : "", "ok ", $t++, " # read 7\n";
84 print +(t 1, read => $fh, 8) ne "" ? "not " : "", "ok ", $t++, " # read 8\n";
85
86 t 1, close => $fh;
87
88 print +(t 1, load => "$DIR/test2") ne "test1test2" ? "not " : "", "ok ", $t++, " # load\n";
89
90 #############################################################################
91 # cleanup
92
93 t 0, unlink => "$DIR/test";
94 t 1, unlink => "$DIR/test2";
95
96 t 1, rmdir => $DIR;
97
98 1
99