ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/t/io_common
Revision: 1.1
Committed: Wed Mar 28 22:28:48 2012 UTC (12 years, 8 months ago) by root
Branch: MAIN
Log Message:
*** empty log message ***

File Contents

# Content
1 #! perl
2
3 $| = 1;
4
5 BEGIN {
6 print "1..24\n";
7 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 $cv = AE::cv;
19 my $ok = shift;
20 my $f = "ae_" . shift;
21 $f->(@_, my $cv = AE::cv);
22 my @res = $cv->recv;
23
24 print !@res != !$ok ? "not " : "", "ok ", $t++, " # $f (@_) = (@res)\n";
25
26 wantarray ? @res : $res[0]
27 }
28
29 our $TMP = "/tmp";
30 our $DIR = "$TMP/ae_io_testdir_$$~";
31
32 t 1, mkdir => $DIR, 0777
33 or do { print "Bail out! Cannot mkdir $DIR, skipping test.\n"; exit 0 };
34 t 0, mkdir => $DIR, 0777;
35
36 #############################################################################
37 # create file
38
39 my $fh = t 1, open => "$DIR/test", O_CREAT | O_EXCL | O_WRONLY, 0666;
40 t 0, open => "$DIR/test", O_CREAT | O_EXCL | O_WRONLY, 0666;
41
42 t 0, rmdir => $DIR;
43
44 t 1, write => $fh, "test1";
45 t 1, write => $fh, "test2";
46 t 1, write => $fh, "";
47
48 t 1, stat => $fh;
49 print -s _ != 10 ? "not " : "", "ok ", $t++, " # stat size\n";
50
51 t 1, close => $fh;
52
53 t 1, stat => "$DIR/test";
54 print -s _ != 10 ? "not " : "", "ok ", $t++, " # stat size\n";
55
56 t 1, lstat => "$DIR/test";
57 print -s _ != 10 ? "not " : "", "ok ", $t++, " # lstat size\n";
58
59 t 1, rename => "$DIR/test", "$DIR/test2";
60
61 #############################################################################
62 # test file
63
64 my $fh = t 1, open => "$DIR/test2", O_RDONLY, 0;
65
66 print +(t 1, read => $fh, 6) ne "test1t" ? "not " : "", "ok ", $t++, " # read 6\n";
67 print +(t 1, read => $fh, 7) ne "est2" ? "not " : "", "ok ", $t++, " # read 7\n";
68 print +(t 1, read => $fh, 8) ne "" ? "not " : "", "ok ", $t++, " # read 8\n";
69
70 t 1, close => $fh;
71
72 print +(t 1, load => "$DIR/test2") ne "test1test2" ? "not " : "", "ok ", $t++, " # load\n";
73
74 #############################################################################
75 # cleanup
76
77 t 0, unlink => "$DIR/test";
78 t 1, unlink => "$DIR/test2";
79
80 t 1, rmdir => $DIR;
81
82 1
83