File: test.pl

package info (click to toggle)
libbuffy-bindings 0.11%2Bnmu1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 1,420 kB
  • ctags: 141
  • sloc: sh: 10,221; ruby: 168; python: 162; perl: 131; makefile: 119
file content (193 lines) | stat: -rwxr-xr-x 5,010 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
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#!/usr/bin/perl -w

use strict;
use warnings;
use lib qw(../perl/blib/arch ../perl);
use Test::More tests=>90;
use Buffy;

#
# Test Config
#

my $config = Buffy::Config->new("test-config.txt");
ok(defined $config);

ok(!$config->view()->read());
ok(!$config->view()->empty());
ok($config->view()->important());
is($config->general()->interval(), 600);

my $locations = $config->locations();
is($locations->size(), 4);

my $programs = $config->mailPrograms();
is($programs->size(), 3);

is($config->selectedMailProgram()->name(), "mutt");

$config->selectMailProgram("Test");
is($config->selectedMailProgram()->name(), "Test");

my $folder = Buffy::MailFolder::accessFolder("maildir/empty");
ok($folder->valid);
$config->mailProgram("test")->run($folder);

my $folder = $config->folder("foo");
ok($folder->forceview());
ok(!$folder->forcehide());
$folder->setForceHide(1);
ok(!$folder->forceview());
ok($folder->forcehide());

my $folder = $config->folder("bar");
ok(!$folder->forceview());
ok($folder->forcehide());
$folder->setForceView(1);
ok($folder->forceview());
ok(!$folder->forcehide());

#
# Test Maildir
#
my $test;
my $folders;

# Check an empty maildir
$test = Buffy::MailFolder::accessFolder("maildir/empty");
ok($test->valid);
is($test->name(), "empty");
is($test->path(), "maildir/empty");
is($test->type(), "Maildir");

is($test->getMsgTotal(), -1);
is($test->getMsgUnread(), -1);
is($test->getMsgNew(), -1);
is($test->getMsgFlagged(), -1);
ok($test->changed());

$test->updateStatistics();
is($test->getMsgTotal(), 0);
is($test->getMsgUnread(), 0);
is($test->getMsgNew(), 0);
is($test->getMsgFlagged(), 0);
ok(!$test->changed());

$folders = Buffy::MailFolder::enumerateFolders("maildir/empty");
is(scalar(@$folders), 1);

# Check a non empty maildir
$test = Buffy::MailFolder::accessFolder("maildir/test");
ok($test->valid());
is($test->name(), "test");
is($test->path(), "maildir/test");
is($test->type(), "Maildir");

is($test->getMsgTotal(), -1);
is($test->getMsgUnread(), -1);
is($test->getMsgNew(), -1);
is($test->getMsgFlagged(), -1);
ok($test->changed());

$test->updateStatistics();
is($test->getMsgTotal(), 3);
is($test->getMsgUnread(), 0);
is($test->getMsgNew(), 0);
is($test->getMsgFlagged(), 1);
ok(!$test->changed());

$folders = Buffy::MailFolder::enumerateFolders("maildir/test");
is(scalar(@$folders), 1);

# Check a maildir whose root is a broken symlink
$test = Buffy::MailFolder::accessFolder("maildir/broken");
ok(!$test->valid());

$folders = Buffy::MailFolder::enumerateFolders("maildir/broken");
is(scalar(@$folders), 0);

# Check a maildir whose cur, new and tmp directories are broken symlinks
$test = Buffy::MailFolder::accessFolder("maildir/broken1");
ok(!$test->valid());

$folders = Buffy::MailFolder::enumerateFolders("maildir/broken1");
is(scalar(@$folders), 0);

# Check a maildir whose root is a symlink pointing to a nonexisting directory
$test = Buffy::MailFolder::accessFolder("maildir/loop");
ok(!$test->valid());

$folders = Buffy::MailFolder::enumerateFolders("maildir/loop");
is(scalar(@$folders), 0);

# Check a maildir which has a submaildir that is a symlink pointing up
$test = Buffy::MailFolder::accessFolder("maildir/loop1");
ok($test->valid());

$folders = Buffy::MailFolder::enumerateFolders("maildir/loop1");
is(scalar(@$folders), 1);

# Check maildir enumeration
$folders = Buffy::MailFolder::enumerateFolders("maildir");
is(scalar(@$folders), 4);

#
# Test Mailbox
#

# Check an empty mailbox
$test = Buffy::MailFolder::accessFolder("mbox/empty.mbox");
ok($test->valid);
is($test->name(), "empty.mbox");
is($test->path(), "mbox/empty.mbox");
is($test->type(), "Mailbox");

is($test->getMsgTotal(), -1);
is($test->getMsgUnread(), -1);
is($test->getMsgNew(), -1);
is($test->getMsgFlagged(), -1);
ok($test->changed());

$test->updateStatistics();
is($test->getMsgTotal(), 0);
is($test->getMsgUnread(), 0);
is($test->getMsgNew(), 0);
is($test->getMsgFlagged(), 0);
ok(!$test->changed());

$folders = Buffy::MailFolder::enumerateFolders("mbox/empty.mbox");
is(scalar(@$folders), 1);

# Check a non empty mailbox
$test = Buffy::MailFolder::accessFolder("mbox/test.mbox");
ok($test->valid());
is($test->name(), "test.mbox");
is($test->path(), "mbox/test.mbox");
is($test->type(), "Mailbox");

is($test->getMsgTotal(), -1);
is($test->getMsgUnread(), -1);
is($test->getMsgNew(), -1);
is($test->getMsgFlagged(), -1);
ok($test->changed());

$test->updateStatistics();
is($test->getMsgTotal, 3);
is($test->getMsgUnread, 0);
is($test->getMsgNew, 0);
is($test->getMsgFlagged, 1);
ok(!$test->changed());

$folders = Buffy::MailFolder::enumerateFolders("mbox/test.mbox");
is(scalar(@$folders), 1);

# Check a mailbox whose root is a broken symlink
$test = Buffy::MailFolder::accessFolder("mbox/broken.mbox");
ok(!$test->valid());

$folders = Buffy::MailFolder::enumerateFolders("mbox/broken.mbox");
is(scalar(@$folders), 0);

# Check enumeration of a directory with mailboxes
$folders = Buffy::MailFolder::enumerateFolders("mbox");
is(scalar(@$folders), 2);