ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/t/io_common
Revision: 1.8
Committed: Fri Apr 13 08:34:08 2012 UTC (12 years, 1 month ago) by root
Branch: MAIN
CVS Tags: rel-7_0
Changes since 1.7: +4 -4 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 #! perl
2    
3     $| = 1;
4    
5 root 1.7 # not tested: symlink, readlink, link, utime, chown, chmod
6    
7 root 1.1 BEGIN {
8 root 1.8 print "1..37\n";
9 root 1.1 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 root 1.7 my $f = "aio_" . shift;
22 root 1.1 $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 root 1.5 t 1, write => $fh, "tes--";
46 root 1.8 t 1, write => $fh, "test2";
47 root 1.1 t 1, write => $fh, "";
48    
49 root 1.5 t 1, seek => $fh, 3, 0;
50     t 1, write => $fh, "t1";
51    
52 root 1.8 #t 1, truncate => $fh, 5+5; # not available on windows
53 root 1.7
54 root 1.1 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 root 1.8 print -s _ != 10 ? "not " : "", "ok ", $t++, " # stat size (", -s _,")\n";
61 root 1.1
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 root 1.3 # 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 root 1.1 # test file
77    
78 root 1.2 $fh = t 1, open => "$DIR/test2", O_RDONLY, 0;
79 root 1.1
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