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

# 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 root 1.9 use File::Spec;
31    
32     our $TMP = File::Spec->tmpdir;
33 root 1.1 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 root 1.5 t 1, write => $fh, "tes--";
48 root 1.8 t 1, write => $fh, "test2";
49 root 1.1 t 1, write => $fh, "";
50    
51 root 1.5 t 1, seek => $fh, 3, 0;
52     t 1, write => $fh, "t1";
53    
54 root 1.8 #t 1, truncate => $fh, 5+5; # not available on windows
55 root 1.7
56 root 1.1 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 root 1.8 print -s _ != 10 ? "not " : "", "ok ", $t++, " # stat size (", -s _,")\n";
63 root 1.1
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 root 1.3 # 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 root 1.1 # test file
79    
80 root 1.2 $fh = t 1, open => "$DIR/test2", O_RDONLY, 0;
81 root 1.1
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