File: GnomeVFSDirectory.t

package info (click to toggle)
libgnome2-vfs-perl 1.080-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 468 kB
  • ctags: 71
  • sloc: perl: 1,195; ansic: 446; makefile: 53
file content (105 lines) | stat: -rw-r--r-- 3,254 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/perl -w
use strict;
use Glib qw(TRUE FALSE);
use Gnome2::VFS;

use Test::More;

# $Header: /cvsroot/gtk2-perl/gtk2-perl-xs/Gnome2-VFS/t/GnomeVFSDirectory.t,v 1.8 2006/09/01 15:39:56 kaffeetisch Exp $

plan -d "$ENV{ HOME }/.gnome" ?
  (tests => 38) :
  (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::Directory -> open(TMP, qw(default))],
         [Gnome2::VFS::Directory -> open_from_uri(Gnome2::VFS::URI -> new(TMP), qw(default))]) {
  ($result, $handle) = @{$_};

  is($result, "ok");
  isa_ok($handle, "Gnome2::VFS::Directory::Handle");

  is($handle -> close(), "ok");
}

###############################################################################

my $info;

$handle = Gnome2::VFS::Directory -> open(TMP, qw(default));

($result, $info) = $handle -> read_next();
is($result, "ok");
ok($info -> { name } eq "." || $info -> { name } eq "..");
is($info -> { type }, "directory");

$handle -> close();

###############################################################################

my $callback = sub {
  my ($node, $info, $will_loop) = @_;

  ok(-e TMP . "/" . $node);
  is($info -> { name }, $node);
  ok($will_loop == 0 || $will_loop == 1);

  return (TRUE, FALSE);
};

Gnome2::VFS -> create(TMP . "/bla", "write", TRUE, 0644);
Gnome2::VFS -> create(TMP . "/blu", "write", TRUE, 0644);

is(Gnome2::VFS::Directory -> visit(TMP,
                                   qw(default),
                                   qw(default),
                                   $callback), "ok");

is(Gnome2::VFS::Directory -> visit_uri(Gnome2::VFS::URI -> new(TMP),
                                       qw(default),
                                       qw(default),
                                       $callback), "ok");

is(Gnome2::VFS::Directory -> visit_files(TMP,
                                         [qw(bla blu)],
                                         qw(default),
                                         qw(default),
                                         $callback), "ok");

is(Gnome2::VFS::Directory -> visit_files_at_uri(Gnome2::VFS::URI -> new(TMP),
                                                [qw(bla blu)],
                                                qw(default),
                                                qw(default),
                                                $callback), "ok");

Gnome2::VFS -> unlink(TMP . "/blu");
Gnome2::VFS -> unlink(TMP . "/bla");

###############################################################################

my @infos;

($result, @infos) = Gnome2::VFS::Directory -> list_load(TMP, qw(default));
ok(-e TMP . "/" . $infos[0] -> { name });

###############################################################################

Gnome2::VFS -> shutdown();

###############################################################################

rmdir(TMP) or die("Urgh, couldn't delete the scratch directory: $!\n");