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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
|
#!/usr/bin/perl -w
use strict;
use Gnome2::VFS;
use Test::More;
# $Header: /cvsroot/gtk2-perl/gtk2-perl-xs/Gnome2-VFS/t/GnomeVFSOps.t,v 1.16 2005/09/28 14:04:32 kaffeetisch Exp $
plan -d "$ENV{ HOME }/.gnome" ?
(tests => 48) :
(skip_all => "You have no ~/.gnome");
Gnome2::VFS -> init();
###############################################################################
use Cwd qw(cwd);
use constant TMP => cwd() . "/tmp";
unless (-e TMP) {
mkdir(TMP) or die ("Urgh, couldn't create the scratch directory: $!");
}
###############################################################################
my ($result, $handle);
foreach ([Gnome2::VFS -> open(cwd() . "/" . $0, "read")],
[Gnome2::VFS::URI -> new(cwd() . "/" . $0) -> open("read")],
[Gnome2::VFS -> create(TMP . "/blaaaaaaaaa", "write", 1, 0777)],
[Gnome2::VFS::URI -> new(TMP . "/bleeeeeeeee") -> create("write", 1, 0666)]) {
($result, $handle) = @{$_};
is($result, "ok");
isa_ok($handle, "Gnome2::VFS::Handle");
is($handle -> close(), "ok");
}
###############################################################################
is(Gnome2::VFS -> move(TMP . "/blaaaaaaaaa", TMP . "/bla", 0), "ok");
is(Gnome2::VFS::URI -> new(TMP . "/bleeeeeeeee") -> move(Gnome2::VFS::URI -> new(TMP . "/ble"), 0), "ok");
is_deeply([Gnome2::VFS -> check_same_fs(TMP . "/bla", TMP . "/ble")], ["ok", 1]);
is_deeply([Gnome2::VFS::URI -> new(TMP . "/bla") -> check_same_fs(Gnome2::VFS::URI -> new(TMP . "/ble"))], ["ok", 1]);
is(Gnome2::VFS -> create_symbolic_link(Gnome2::VFS::URI -> new(TMP . "/bli"), "/usr/bin/perl"), "ok");
is(Gnome2::VFS -> set_file_info(TMP . "/bla",
{ permissions => [qw/user-read user-write/] },
qw/permissions/), "ok");
is(Gnome2::VFS -> unlink(TMP . "/bla"), "ok");
is(Gnome2::VFS -> unlink(TMP . "/bli"), "ok");
my $uri = Gnome2::VFS::URI -> new(TMP . "/ble");
is($uri -> set_file_info({ permissions => [qw/user-read user-write/] },
qw/permissions/), "ok");
ok($uri -> exists());
is($uri -> unlink(), "ok");
###############################################################################
($result, $handle) = Gnome2::VFS -> create(TMP . "/blu", "write", 1, 0644);
is($result, "ok");
is_deeply([$handle -> write("blaaa!", 6)], ["ok", 6]);
($result, $handle) = Gnome2::VFS -> open(TMP . "/blu", "read");
is($result, "ok");
is_deeply([$handle -> read(6)], ["ok", 6, "blaaa!"]);
is_deeply([$handle -> tell()], ["ok", 6]);
is($handle -> seek("start", 2), "ok");
is_deeply([$handle -> read(4)], ["ok", 4, "aaa!"]);
is($handle -> truncate(0), "error-not-supported");
SKIP: {
skip "forget_cache is new in 2.12", 1
unless Gnome2::VFS -> CHECK_VERSION(2, 12, 0);
is($handle -> forget_cache(0, 0), "ok");
}
is($handle -> close(), "ok");
###############################################################################
is(Gnome2::VFS -> truncate(TMP . "/blu", 5), "ok");
is(Gnome2::VFS::URI -> new(TMP . "/blu") -> truncate(4), "ok");
($result, $handle) = Gnome2::VFS -> open(TMP . "/blu", [qw(read write random)]);
is($result, "ok");
my $info;
($result, $info) = Gnome2::VFS -> get_file_info(TMP . "/blu", qw(default));
is($result, "ok");
is($info -> { size }, 4);
($result, $info) = Gnome2::VFS::URI -> new(TMP . "/blu") -> get_file_info(qw(get-mime-type));
is($result, "ok");
ok(defined($info -> { mime_type }));
($result, $info) = $handle -> get_file_info(qw(default));
is($result, "ok");
isa_ok($info -> { permissions }, "Gnome2::VFS::FilePermissions");
is($handle -> close(), "ok");
is(Gnome2::VFS -> unlink(TMP . "/blu"), "ok");
###############################################################################
# FIXME: any way to reliably test this? (currently needs FAM and some luck.)
# my $monitor;
# ($result, $monitor) = Gnome2::VFS::Monitor -> add(TMP, qw(directory), sub {
# my ($handle, $monitor_uri, $info_uri, $event_type) = @_;
# isa_ok($handle, "Gnome2::VFS::Monitor::Handle");
# is($monitor_uri, "file://" . TMP);
# is($info_uri, "file://" . TMP . "/ulb");
# ok($event_type eq "created" or $event_type eq "deleted");
# });
# is($result, "ok");
# isa_ok($monitor, "Gnome2::VFS::Monitor::Handle");
###############################################################################
is(Gnome2::VFS -> make_directory(TMP . "/ulb", 0755), "ok");
is(Gnome2::VFS -> remove_directory(TMP . "/ulb"), "ok");
$uri = Gnome2::VFS::URI -> new(TMP . "/ulb");
is($uri -> make_directory(0755), "ok");
is($uri -> remove_directory(), "ok");
###############################################################################
# shortly enter the main loop so that the monitor receives the events.
# Glib::Idle -> add(sub {
# Gtk2 -> main_quit();
# return 0;
# });
# use Gtk2 -init;
# Gtk2 -> main();
# is($monitor -> cancel(), "ok");
###############################################################################
Gnome2::VFS -> shutdown();
###############################################################################
rmdir(TMP) or die("Urgh, couldn't delete the scratch directory: $!\n");
|