1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
#!/usr/bin/perl
use Fcntl;
use Test;
use POSIX qw(ENOENT EACCES EBADF);
use FindBin;
use lib "$FindBin::Bin";
use aio_test_common;
BEGIN { plan tests => 13 }
IO::AIO::min_parallel 2;
my $tempdir = tempdir();
my $some_dir = "$tempdir/some_dir";
my $some_file = "$some_dir/some_file";
my $some_link = "$some_dir/some_link";
# create a file in a non-existent directory
aio_open $some_file, O_RDWR|O_CREAT|O_TRUNC, 0, sub {
ok((!defined $_[0]) && $! == ENOENT);
};
pcb;
# now actually make that file
ok(mkdir $some_dir);
aio_open $some_file, O_RDWR|O_CREAT|O_TRUNC, 0644, sub {
my $fh = shift;
ok(defined $fh);
print $fh "contents.";
ok(-e $some_file);
close $fh;
};
pcb;
# test error on unlinking nonexistent file
aio_unlink "$some_dir/notfound.txt", sub {
ok($_[0] < 0);
ok($! == ENOENT);
};
pcb;
# write to file open for reading
ok(open(F, $some_file)) or die $!;
aio_write *F, 0, 10, "foobarbaz.", 0, sub {
my $written = shift;
ok($written < 0);
ok($! == EBADF);
};
pcb;
close F;
aio_symlink "\\test\\", $some_link, sub {
ok (!$_[0]);
ok ("\\test\\" eq readlink $some_link);
};
pcb;
unlink $some_link;
# test unlinking and rmdir
aio_unlink $some_file, sub {
ok (!shift);
};
pcb;
aio_rmdir $some_dir, sub {
ok (!shift);
};
pcb;
|