ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/t/io_common
Revision: 1.6
Committed: Wed Apr 4 02:18:30 2012 UTC (12 years, 3 months ago) by root
Branch: MAIN
Changes since 1.5: +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.5 print "1..37\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 root 1.6 my $f = "io_" . shift;
20 root 1.1 $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 root 1.5 t 1, write => $fh, "tes--";
44 root 1.1 t 1, write => $fh, "test2";
45     t 1, write => $fh, "";
46    
47 root 1.5 t 1, seek => $fh, 3, 0;
48     t 1, write => $fh, "t1";
49    
50 root 1.1 t 1, stat => $fh;
51     print -s _ != 10 ? "not " : "", "ok ", $t++, " # stat size\n";
52    
53     t 1, close => $fh;
54    
55     t 1, stat => "$DIR/test";
56     print -s _ != 10 ? "not " : "", "ok ", $t++, " # stat size\n";
57    
58     t 1, lstat => "$DIR/test";
59     print -s _ != 10 ? "not " : "", "ok ", $t++, " # lstat size\n";
60    
61     t 1, rename => "$DIR/test", "$DIR/test2";
62    
63     #############################################################################
64 root 1.3 # test dir
65    
66     t 0, readdir => "$DIR/nonexistent";
67     my $res = t 1, readdir => $DIR;
68     print @$res != 1 ? "not " : "", "ok ", $t++, " # res count\n";
69     print $res->[0] ne "test2" ? "not " : "", "ok ", $t++, " # res data (@$res)\n";
70    
71     #############################################################################
72 root 1.1 # test file
73    
74 root 1.2 $fh = t 1, open => "$DIR/test2", O_RDONLY, 0;
75 root 1.1
76     print +(t 1, read => $fh, 6) ne "test1t" ? "not " : "", "ok ", $t++, " # read 6\n";
77     print +(t 1, read => $fh, 7) ne "est2" ? "not " : "", "ok ", $t++, " # read 7\n";
78     print +(t 1, read => $fh, 8) ne "" ? "not " : "", "ok ", $t++, " # read 8\n";
79    
80     t 1, close => $fh;
81    
82     print +(t 1, load => "$DIR/test2") ne "test1test2" ? "not " : "", "ok ", $t++, " # load\n";
83    
84     #############################################################################
85     # cleanup
86    
87     t 0, unlink => "$DIR/test";
88     t 1, unlink => "$DIR/test2";
89    
90     t 1, rmdir => $DIR;
91    
92     1
93