File: test.rb

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 (209 lines) | stat: -rwxr-xr-x 6,028 bytes parent folder | download
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#!/usr/bin/ruby -I../ruby

require 'Buffy'
require 'test/unit'
require 'pp'

class TC_Buffy_Config < Test::Unit::TestCase
	def setup
		@config = Buffy::Config.new("test-config.txt")
	end

	# def teardown
	# end

	# Test Config
	def test_config
		assert_not_nil(@config)

		assert_equal(@config.view.read, false)
		assert_equal(@config.view.empty, false)
		assert_equal(@config.view.important, true)
		assert_equal(@config.general.interval, 600)

		locations = @config.locations
		assert_equal(locations.size, 4)

		programs = @config.mailPrograms
		assert_equal(programs.size, 3)

		assert_equal(@config.selectedMailProgram.name, "mutt")
        @config.selectMailProgram("Test")
        assert_equal(@config.selectedMailProgram.name, "Test")

		folder = @config.folder("foo")
		assert_equal(folder.forceview, true)
		assert_equal(folder.forcehide, false)
        folder.setForceHide(true)
        assert_equal(folder.forceview, false)
        assert_equal(folder.forcehide, true)

		folder = @config.folder("bar")
		assert_equal(folder.forceview, false)
		assert_equal(folder.forcehide, true)
        folder.setForceView(true)
        assert_equal(folder.forceview, true)
        assert_equal(folder.forcehide, false)
	end
end

class TC_Buffy_Maildir < Test::Unit::TestCase
	# Check an empty maildir
	def test_empty
		test = Buffy::MailFolder.accessFolder("maildir/empty")
		assert_equal(test.valid, true)
		assert_equal(test.name, "empty")
		assert_equal(test.path, "maildir/empty")
		assert_equal(test.type, "Maildir")

		assert_equal(test.getMsgTotal, -1)
		assert_equal(test.getMsgUnread, -1)
		assert_equal(test.getMsgNew, -1)
		assert_equal(test.getMsgFlagged, -1)
		assert_equal(test.changed, true)

		test.updateStatistics
		assert_equal(test.getMsgTotal, 0)
		assert_equal(test.getMsgUnread, 0)
		assert_equal(test.getMsgNew, 0)
		assert_equal(test.getMsgFlagged, 0)
		assert_equal(test.changed, false)

		folders = Buffy::MailFolder::enumerateFolders "maildir/empty"
		assert_equal(folders.length, 1)
	end

	# Check a non empty maildir
	def test_nonempty
		test = Buffy::MailFolder.accessFolder "maildir/test"
		assert_equal(test.valid, true)
		assert_equal(test.name, "test")
		assert_equal(test.path, "maildir/test")
		assert_equal(test.type, "Maildir")

		assert_equal(test.getMsgTotal, -1)
		assert_equal(test.getMsgUnread, -1)
		assert_equal(test.getMsgNew, -1)
		assert_equal(test.getMsgFlagged, -1)
		assert_equal(test.changed, true)

		test.updateStatistics
		assert_equal(test.getMsgTotal, 3)
		assert_equal(test.getMsgUnread, 0)
		assert_equal(test.getMsgNew, 0)
		assert_equal(test.getMsgFlagged, 1)
		assert_equal(test.changed, false)

		folders = Buffy::MailFolder::enumerateFolders "maildir/test"
		assert_equal(folders.length, 1)
	end

	# Check a maildir whose root is a broken symlink
	def test_broken
		test = Buffy::MailFolder.accessFolder "maildir/broken"
		assert_equal(test.valid, false)

		folders = Buffy::MailFolder::enumerateFolders "maildir/broken"
		assert_equal(folders.length, 0)
	end

	# Check a maildir whose cur, new and tmp directories are broken symlinks
	def test_broken1
		test = Buffy::MailFolder.accessFolder "maildir/broken1"
		assert_equal(test.valid, false)

		folders = Buffy::MailFolder::enumerateFolders "maildir/broken1"
		assert_equal(folders.length, 0)
	end

	# Check a maildir whose root is a symlink pointing to a nonexisting directory
	def test_loop
		test = Buffy::MailFolder.accessFolder "maildir/loop"
		assert_equal(test.valid, false)

		folders = Buffy::MailFolder.enumerateFolders "maildir/loop"
		assert_equal(folders.length, 0)
	end

	# Check a maildir which has a submaildir that is a symlink pointing up
	def test_loop1
		test = Buffy::MailFolder.accessFolder "maildir/loop1"
		assert_equal(test.valid, true)

		folders = Buffy::MailFolder.enumerateFolders "maildir/loop1"
		assert_equal(folders.length, 1)
	end

	# Check maildir enumeration
	def test_enumeration
		folders = Buffy::MailFolder.enumerateFolders "maildir"
		assert_equal(folders.length, 4)
	end
end

class TC_Buffy_Mailbox < Test::Unit::TestCase
	# Check an empty mailbox
	def test_empty
		test = Buffy::MailFolder.accessFolder "mbox/empty.mbox"
		assert_equal(test.valid, true)
		assert_equal(test.name, "empty.mbox")
		assert_equal(test.path, "mbox/empty.mbox")
		assert_equal(test.type, "Mailbox")

		assert_equal(test.getMsgTotal, -1)
		assert_equal(test.getMsgUnread, -1)
		assert_equal(test.getMsgNew, -1)
		assert_equal(test.getMsgFlagged, -1)
		assert_equal(test.changed, true)

		test.updateStatistics
		assert_equal(test.getMsgTotal, 0)
		assert_equal(test.getMsgUnread, 0)
		assert_equal(test.getMsgNew, 0)
		assert_equal(test.getMsgFlagged, 0)
		assert_equal(test.changed, false)

		folders = Buffy::MailFolder.enumerateFolders "mbox/empty.mbox"
		assert_equal(folders.length, 1)
	end

	# Check a non empty mailbox
	def test_nonempty
		test = Buffy::MailFolder.accessFolder "mbox/test.mbox"
		assert_equal(test.valid, true)
		assert_equal(test.name, "test.mbox")
		assert_equal(test.path, "mbox/test.mbox")
		assert_equal(test.type, "Mailbox")

		assert_equal(test.getMsgTotal, -1)
		assert_equal(test.getMsgUnread, -1)
		assert_equal(test.getMsgNew, -1)
		assert_equal(test.getMsgFlagged, -1)
		assert_equal(test.changed, true)

		test.updateStatistics
		assert_equal(test.getMsgTotal, 3)
		assert_equal(test.getMsgUnread, 0)
		assert_equal(test.getMsgNew, 0)
		assert_equal(test.getMsgFlagged, 1)
		assert_equal(test.changed, false)

		folders = Buffy::MailFolder.enumerateFolders "mbox/test.mbox"
		assert_equal(folders.length, 1)
	end

	# Check a mailbox whose root is a broken symlink
	def test_broken
		test = Buffy::MailFolder.accessFolder "mbox/broken.mbox"
		assert_equal(test.valid(), false)

		folders = Buffy::MailFolder.enumerateFolders "mbox/broken.mbox"
		assert_equal(folders.length, 0)
	end

	# Check enumeration of a directory with mailboxes
	def test_enumeration
		folders = Buffy::MailFolder::enumerateFolders "mbox"
		assert_equal(folders.length, 2)
	end
end