ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/t/io_common
Revision: 1.4
Committed: Wed Mar 28 23:45:47 2012 UTC (12 years, 8 months ago) by root
Branch: MAIN
Changes since 1.3: +1 -1 lines
Log Message:
*** empty log message ***

File Contents

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