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

File Contents

# Content
1 #! perl
2
3 $| = 1;
4
5 BEGIN {
6 print "1..31\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 $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 # test file
62
63 $fh = t 1, open => "$DIR/test2", O_RDONLY, 0;
64
65 print +(t 1, read => $fh, 6) ne "test1t" ? "not " : "", "ok ", $t++, " # read 6\n";
66 print +(t 1, read => $fh, 7) ne "est2" ? "not " : "", "ok ", $t++, " # read 7\n";
67 print +(t 1, read => $fh, 8) ne "" ? "not " : "", "ok ", $t++, " # read 8\n";
68
69 t 1, close => $fh;
70
71 print +(t 1, load => "$DIR/test2") ne "test1test2" ? "not " : "", "ok ", $t++, " # load\n";
72
73 #############################################################################
74 # cleanup
75
76 t 0, unlink => "$DIR/test";
77 t 1, unlink => "$DIR/test2";
78
79 t 1, rmdir => $DIR;
80
81 1
82