fraser-vpim-rails 0.658
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +504 -0
- data/COPYING +58 -0
- data/README +182 -0
- data/lib/atom.rb +728 -0
- data/lib/plist.rb +22 -0
- data/lib/vpim/address.rb +219 -0
- data/lib/vpim/attachment.rb +102 -0
- data/lib/vpim/date.rb +222 -0
- data/lib/vpim/dirinfo.rb +277 -0
- data/lib/vpim/duration.rb +119 -0
- data/lib/vpim/enumerator.rb +32 -0
- data/lib/vpim/field.rb +614 -0
- data/lib/vpim/icalendar.rb +381 -0
- data/lib/vpim/maker/vcard.rb +16 -0
- data/lib/vpim/property/base.rb +193 -0
- data/lib/vpim/property/common.rb +315 -0
- data/lib/vpim/property/location.rb +38 -0
- data/lib/vpim/property/priority.rb +43 -0
- data/lib/vpim/property/recurrence.rb +69 -0
- data/lib/vpim/property/resources.rb +24 -0
- data/lib/vpim/repo.rb +181 -0
- data/lib/vpim/rfc2425.rb +367 -0
- data/lib/vpim/rrule.rb +589 -0
- data/lib/vpim/time.rb +40 -0
- data/lib/vpim/vcard.rb +1429 -0
- data/lib/vpim/version.rb +18 -0
- data/lib/vpim/vevent.rb +187 -0
- data/lib/vpim/view.rb +90 -0
- data/lib/vpim/vjournal.rb +58 -0
- data/lib/vpim/vpim.rb +65 -0
- data/lib/vpim/vtodo.rb +103 -0
- data/lib/vpim.rb +13 -0
- data/samples/README.mutt +93 -0
- data/samples/ab-query.rb +57 -0
- data/samples/cmd-itip.rb +156 -0
- data/samples/ex_cpvcard.rb +55 -0
- data/samples/ex_get_vcard_photo.rb +22 -0
- data/samples/ex_mkv21vcard.rb +34 -0
- data/samples/ex_mkvcard.rb +64 -0
- data/samples/ex_mkyourown.rb +29 -0
- data/samples/ics-dump.rb +210 -0
- data/samples/ics-to-rss.rb +84 -0
- data/samples/mutt-aliases-to-vcf.rb +45 -0
- data/samples/osx-wrappers.rb +86 -0
- data/samples/reminder.rb +203 -0
- data/samples/rrule.rb +71 -0
- data/samples/tabbed-file-to-vcf.rb +390 -0
- data/samples/vcf-dump.rb +86 -0
- data/samples/vcf-lines.rb +61 -0
- data/samples/vcf-to-ics.rb +22 -0
- data/samples/vcf-to-mutt.rb +121 -0
- data/test/test_all.rb +17 -0
- data/test/test_date.rb +120 -0
- data/test/test_dur.rb +41 -0
- data/test/test_field.rb +156 -0
- data/test/test_ical.rb +415 -0
- data/test/test_repo.rb +158 -0
- data/test/test_rrule.rb +1030 -0
- data/test/test_vcard.rb +973 -0
- data/test/test_view.rb +79 -0
- metadata +129 -0
data/test/test_ical.rb
ADDED
@@ -0,0 +1,415 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'vpim/icalendar'
|
4
|
+
require 'test/unit'
|
5
|
+
|
6
|
+
|
7
|
+
# Sorry for the donkey patching...
|
8
|
+
module Enumerable
|
9
|
+
def first
|
10
|
+
find{true}
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
include Vpim
|
15
|
+
|
16
|
+
Req_1 =<<___
|
17
|
+
BEGIN:VCALENDAR
|
18
|
+
METHOD:REQUEST
|
19
|
+
PRODID:-//Lotus Development Corporation//NONSGML Notes 6.0//EN
|
20
|
+
VERSION:2.0
|
21
|
+
X-LOTUS-CHARSET:UTF-8
|
22
|
+
BEGIN:VTIMEZONE
|
23
|
+
TZID:Pacific
|
24
|
+
BEGIN:STANDARD
|
25
|
+
DTSTART:19501029T020000
|
26
|
+
TZOFFSETFROM:-0700
|
27
|
+
TZOFFSETTO:-0800
|
28
|
+
RRULE:FREQ=YEARLY;BYMINUTE=0;BYHOUR=2;BYDAY=-1SU;BYMONTH=10
|
29
|
+
END:STANDARD
|
30
|
+
BEGIN:DAYLIGHT
|
31
|
+
DTSTART:19500402T020000
|
32
|
+
TZOFFSETFROM:-0800
|
33
|
+
TZOFFSETTO:-0700
|
34
|
+
RRULE:FREQ=YEARLY;BYMINUTE=0;BYHOUR=2;BYDAY=1SU;BYMONTH=4
|
35
|
+
END:DAYLIGHT
|
36
|
+
END:VTIMEZONE
|
37
|
+
BEGIN:VEVENT
|
38
|
+
ATTENDEE;ROLE=CHAIR;PARTSTAT=ACCEPTED;CN="Gary Pope/Certicom"
|
39
|
+
;RSVP=FALSE:mailto:gpope@certicom.com
|
40
|
+
ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION
|
41
|
+
;CN="Mike Harvey/Certicom";RSVP=TRUE:mailto:MHarvey@certicom.com
|
42
|
+
ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE
|
43
|
+
:mailto:rgallant@emilpost.certicom.com
|
44
|
+
ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION
|
45
|
+
;CN="Sam Roberts/Certicom";RSVP=TRUE:mailto:SRoberts@certicom.com
|
46
|
+
ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION
|
47
|
+
;CN="Tony Walters/Certicom";RSVP=TRUE:mailto:TWalters@certicom.com
|
48
|
+
CLASS:PUBLIC
|
49
|
+
DTEND;TZID="Pacific":20040415T130000
|
50
|
+
DTSTAMP:20040319T205045Z
|
51
|
+
DTSTART;TZID="Pacific":20040415T120000
|
52
|
+
ORGANIZER;CN="Gary Pope/Certicom":mailto:gpope@certicom.com
|
53
|
+
SEQUENCE:0
|
54
|
+
SUMMARY:hjold intyel
|
55
|
+
TRANSP:OPAQUE
|
56
|
+
UID:3E19204063C93D2388256E5C006BF8D9-Lotus_Notes_Generated
|
57
|
+
X-LOTUS-BROADCAST:FALSE
|
58
|
+
X-LOTUS-CHILD_UID:3E19204063C93D2388256E5C006BF8D9
|
59
|
+
X-LOTUS-NOTESVERSION:2
|
60
|
+
X-LOTUS-NOTICETYPE:I
|
61
|
+
X-LOTUS-UPDATE-SEQ:1
|
62
|
+
X-LOTUS-UPDATE-WISL:$S:1;$L:1;$B:1;$R:1;$E:1
|
63
|
+
END:VEVENT
|
64
|
+
END:VCALENDAR
|
65
|
+
___
|
66
|
+
|
67
|
+
Rep_1 =<<___
|
68
|
+
BEGIN:VCALENDAR
|
69
|
+
CALSCALE:GREGORIAN
|
70
|
+
PRODID:-//Apple Computer\, Inc//iCal 1.5//EN
|
71
|
+
VERSION:2.0
|
72
|
+
METHOD:REPLY
|
73
|
+
BEGIN:VEVENT
|
74
|
+
ATTENDEE;CN="Sam Roberts/Certicom";PARTSTAT=ACCEPTED;ROLE=REQ-PARTICIPAN
|
75
|
+
T;RSVP=TRUE:mailto:SRoberts@certicom.com
|
76
|
+
CLASS:PUBLIC
|
77
|
+
DTEND;TZID=Pacific:20040415T130000
|
78
|
+
DTSTAMP:20040319T205045Z
|
79
|
+
DTSTART;TZID=Pacific:20040415T120000
|
80
|
+
ORGANIZER;CN="Gary Pope/Certicom":mailto:gpope@certicom.com
|
81
|
+
SEQUENCE:0
|
82
|
+
SUMMARY:hjold intyel
|
83
|
+
TRANSP:OPAQUE
|
84
|
+
UID:3E19204063C93D2388256E5C006BF8D9-Lotus_Notes_Generated
|
85
|
+
X-LOTUS-BROADCAST:FALSE
|
86
|
+
X-LOTUS-CHILDUID:3E19204063C93D2388256E5C006BF8D9
|
87
|
+
X-LOTUS-NOTESVERSION:2
|
88
|
+
X-LOTUS-NOTICETYPE:I
|
89
|
+
X-LOTUS-UPDATE-SEQ:1
|
90
|
+
X-LOTUS-UPDATE-WISL:$S:1\;$L:1\;$B:1\;$R:1\;$E:1
|
91
|
+
END:VEVENT
|
92
|
+
END:VCALENDAR
|
93
|
+
___
|
94
|
+
|
95
|
+
class TestIcal < Test::Unit::TestCase
|
96
|
+
|
97
|
+
def assert_time(expected, actual, msg = nil)
|
98
|
+
assert_in_delta(expected, actual, 1, msg)
|
99
|
+
end
|
100
|
+
|
101
|
+
# Reported by Kyle Maxwell
|
102
|
+
def test_serialize_todo
|
103
|
+
icstodo =<<___
|
104
|
+
BEGIN:VCALENDAR
|
105
|
+
VERSION:2.0
|
106
|
+
BEGIN:VTODO
|
107
|
+
END:VTODO
|
108
|
+
END:VCALENDAR
|
109
|
+
___
|
110
|
+
|
111
|
+
cal = Icalendar.decode(icstodo)
|
112
|
+
assert_equal(icstodo, cal.to_s)
|
113
|
+
end
|
114
|
+
|
115
|
+
# Tracker #18920
|
116
|
+
def test_recurring_todos
|
117
|
+
icstodo =<<___
|
118
|
+
BEGIN:VCALENDAR
|
119
|
+
VERSION:2.0
|
120
|
+
BEGIN:VTODO
|
121
|
+
SUMMARY:todo
|
122
|
+
DTSTART:20040415T120000
|
123
|
+
RRULE:FREQ=WEEKLY;COUNT=2
|
124
|
+
END:VTODO
|
125
|
+
END:VCALENDAR
|
126
|
+
___
|
127
|
+
|
128
|
+
cal = Icalendar.decode(icstodo).first
|
129
|
+
todo = cal.todos.first
|
130
|
+
assert(todo)
|
131
|
+
assert_equal(todo.occurrences.to_a.size, 2)
|
132
|
+
end
|
133
|
+
|
134
|
+
def test_1
|
135
|
+
req = Icalendar.decode(Req_1).first
|
136
|
+
|
137
|
+
req.components { }
|
138
|
+
req.components(Icalendar::Vevent) { }
|
139
|
+
req.components(Icalendar::Vjournal) { }
|
140
|
+
assert_equal(1, req.components.size)
|
141
|
+
assert_equal(1, req.components(Icalendar::Vevent).size)
|
142
|
+
assert_equal(0, req.components(Icalendar::Vjournal).size)
|
143
|
+
|
144
|
+
assert_equal(req.protocol, 'REQUEST')
|
145
|
+
|
146
|
+
event = req.events.first
|
147
|
+
|
148
|
+
assert(event)
|
149
|
+
|
150
|
+
assert( event.attendee?('mailto:sroberts@certicom.com'))
|
151
|
+
assert(!event.attendee?('mailto:sroberts@uniserve.com'))
|
152
|
+
|
153
|
+
me = event.attendees('mailto:sroberts@certicom.com').first
|
154
|
+
|
155
|
+
assert(me)
|
156
|
+
assert(me == 'mailto:sroberts@certicom.com')
|
157
|
+
|
158
|
+
reply = Icalendar.create_reply
|
159
|
+
|
160
|
+
reply.push(event.accept(me))
|
161
|
+
|
162
|
+
# puts "Reply=>"
|
163
|
+
# puts reply.to_s
|
164
|
+
end
|
165
|
+
|
166
|
+
def test_hal1
|
167
|
+
# Hal was encoding raw strings, here's how to do it with the API.
|
168
|
+
|
169
|
+
cal = Icalendar.create
|
170
|
+
|
171
|
+
start = Time.now
|
172
|
+
|
173
|
+
event = Icalendar::Vevent.create(start,
|
174
|
+
'DTEND' => start + 60 * 60,
|
175
|
+
'SUMMARY' => "this is an event",
|
176
|
+
'RRULE' => 'freq=monthly;byday=2fr,4fr;count=5'
|
177
|
+
)
|
178
|
+
|
179
|
+
cal.push event
|
180
|
+
|
181
|
+
#puts cal.encode
|
182
|
+
end
|
183
|
+
|
184
|
+
# FIXME - test bad durations, like 'PT1D'
|
185
|
+
|
186
|
+
def test_event_duration
|
187
|
+
now = Time.now
|
188
|
+
event = Icalendar::Vevent.create(now)
|
189
|
+
assert_time(now, event.dtstart)
|
190
|
+
assert_nil(event.duration)
|
191
|
+
assert_nil(event.dtend)
|
192
|
+
|
193
|
+
event = Icalendar::Vevent.create(Date.new(2000, 1, 21),
|
194
|
+
'DURATION' => 'PT1H')
|
195
|
+
assert_equal(Time.gm(2000, 1, 21, 1), event.dtend)
|
196
|
+
|
197
|
+
event = Icalendar::Vevent.create(Date.new(2000, 1, 21),
|
198
|
+
'DTEND' => Date.new(2000, 1, 22))
|
199
|
+
assert_equal(24*60*60, event.duration)
|
200
|
+
end
|
201
|
+
|
202
|
+
def test_todo_duration
|
203
|
+
todo = Icalendar::Vtodo.create()
|
204
|
+
assert_nil(todo.dtstart)
|
205
|
+
assert_nil(todo.duration)
|
206
|
+
assert_nil(todo.due)
|
207
|
+
|
208
|
+
todo = Icalendar::Vtodo.create('DTSTART' => Date.new(2000, 1, 21),
|
209
|
+
'DURATION' => 'PT1H')
|
210
|
+
assert_equal(Time.gm(2000, 1, 21, 1), todo.due)
|
211
|
+
|
212
|
+
todo = Icalendar::Vtodo.create('DTSTART' => Date.new(2000, 1, 21),
|
213
|
+
'DUE' => Date.new(2000, 1, 22))
|
214
|
+
assert_equal(24*60*60, todo.duration)
|
215
|
+
end
|
216
|
+
|
217
|
+
def test_journal_create
|
218
|
+
vj = Icalendar::Vjournal.create('DESCRIPTION' => "description")
|
219
|
+
assert_equal("description", vj.description)
|
220
|
+
end
|
221
|
+
|
222
|
+
def TODO_test_occurrence_with_date_start
|
223
|
+
d = Date.new(2000, 1, 21)
|
224
|
+
event = Icalendar::Vevent.create(d)
|
225
|
+
d1 = event.occurences.to_a.first
|
226
|
+
assert_equal(d.class, d1.class)
|
227
|
+
end
|
228
|
+
|
229
|
+
def test_decode_duration_four_weeks
|
230
|
+
assert_equal 4*7*86400, Icalendar.decode_duration('P4W')
|
231
|
+
end
|
232
|
+
|
233
|
+
def test_decode_duration_negative_two_weeks
|
234
|
+
assert_equal(-2*7*86400, Icalendar.decode_duration('-P2W'))
|
235
|
+
end
|
236
|
+
|
237
|
+
def test_decode_duration_five_days
|
238
|
+
assert_equal 5*86400, Icalendar.decode_duration('P5D')
|
239
|
+
end
|
240
|
+
|
241
|
+
def test_decode_duration_one_hour
|
242
|
+
assert_equal 3600, Icalendar.decode_duration('PT1H')
|
243
|
+
end
|
244
|
+
|
245
|
+
def test_decode_duration_five_minutes
|
246
|
+
assert_equal 5*60, Icalendar.decode_duration('PT5M')
|
247
|
+
end
|
248
|
+
|
249
|
+
def test_decode_duration_ten_seconds
|
250
|
+
assert_equal 10, Icalendar.decode_duration('PT10S')
|
251
|
+
end
|
252
|
+
|
253
|
+
def test_decode_duration_with_leading_plus
|
254
|
+
assert_equal 10, Icalendar.decode_duration('+PT10S')
|
255
|
+
end
|
256
|
+
|
257
|
+
def test_decode_duration_with_composite_duration
|
258
|
+
assert_equal((15*86400+5*3600+20), Icalendar.decode_duration('P15DT5H0M20S'))
|
259
|
+
end
|
260
|
+
|
261
|
+
def test_create_with_prodid
|
262
|
+
prodid = "me//here/non-sgml"
|
263
|
+
cal = Icalendar.create2(prodid) do |cal|
|
264
|
+
assert_respond_to(cal, :push)
|
265
|
+
end
|
266
|
+
assert_equal(prodid, cal.producer)
|
267
|
+
end
|
268
|
+
|
269
|
+
def test_occurences
|
270
|
+
t0 = Time.now
|
271
|
+
vc = Icalendar.create2 do |vc|
|
272
|
+
vc.add_event do |ve|
|
273
|
+
ve.dtstart t0
|
274
|
+
end
|
275
|
+
end
|
276
|
+
ve = vc.components(Icalendar::Vevent).first
|
277
|
+
assert_time(t0, ve.occurences.select{true}.first)
|
278
|
+
ve.occurences do |t|
|
279
|
+
assert_time(t0, t)
|
280
|
+
end
|
281
|
+
|
282
|
+
vc = Icalendar.decode(<<__).first
|
283
|
+
BEGIN:VCALENDAR
|
284
|
+
BEGIN:VEVENT
|
285
|
+
END:VEVENT
|
286
|
+
END:VCALENDAR
|
287
|
+
__
|
288
|
+
ve = vc.components(Icalendar::Vevent).first
|
289
|
+
assert_raises(ArgumentError) { ve.occurences }
|
290
|
+
end
|
291
|
+
|
292
|
+
def test_each
|
293
|
+
vc = Icalendar.decode(<<__).first
|
294
|
+
BEGIN:VCALENDAR
|
295
|
+
BEGIN:VEVENT
|
296
|
+
END:VEVENT
|
297
|
+
BEGIN:VTODO
|
298
|
+
END:VTODO
|
299
|
+
BEGIN:VJOURNAL
|
300
|
+
END:VJOURNAL
|
301
|
+
BEGIN:VTIMEZONE
|
302
|
+
END:VTIMEZONE
|
303
|
+
BEGIN:X-UNKNOWN
|
304
|
+
END:X-UNKNOWN
|
305
|
+
END:VCALENDAR
|
306
|
+
__
|
307
|
+
count = Hash.new(0)
|
308
|
+
|
309
|
+
vc.each do |c| count[c.class] += 1 end
|
310
|
+
|
311
|
+
assert_equal(3, count.size)
|
312
|
+
count.each do |_,v| assert_equal(1, v) end
|
313
|
+
|
314
|
+
count = Hash.new(0)
|
315
|
+
vc.events do |c| count[c.class] += 1 end
|
316
|
+
vc.todos do |c| count[c.class] += 1 end
|
317
|
+
vc.journals do |c| count[c.class] += 1 end
|
318
|
+
assert_equal(3, count.size)
|
319
|
+
count.each do |_,v| assert_equal(1, v) end
|
320
|
+
|
321
|
+
assert_equal(3, vc.each.to_a.size)
|
322
|
+
assert_equal(1, vc.each.select{|c| Vpim::Icalendar::Vevent === c}.size)
|
323
|
+
assert_equal(1, vc.each.select{|c| Vpim::Icalendar::Vtodo === c}.size)
|
324
|
+
assert_equal(1, vc.each.select{|c| Vpim::Icalendar::Vjournal === c}.size)
|
325
|
+
|
326
|
+
assert_equal(1, vc.events.to_a.size)
|
327
|
+
assert_equal(1, vc.todos.to_a.size)
|
328
|
+
assert_equal(1, vc.journals.to_a.size)
|
329
|
+
|
330
|
+
vc.to_s # Shouldn't raise...
|
331
|
+
# TODO - encode isn't round-tripping, unknown components are lost, which is
|
332
|
+
# not good.
|
333
|
+
end
|
334
|
+
|
335
|
+
def test_calscale
|
336
|
+
req = Icalendar.decode(<<__).first
|
337
|
+
BEGIN:VCALENDAR
|
338
|
+
END:VCALENDAR
|
339
|
+
__
|
340
|
+
assert_equal("GREGORIAN", req.calscale)
|
341
|
+
req = Icalendar.decode(<<__).first
|
342
|
+
BEGIN:VCALENDAR
|
343
|
+
CALSCALE:GREGORIAN
|
344
|
+
END:VCALENDAR
|
345
|
+
__
|
346
|
+
assert_equal("GREGORIAN", req.calscale)
|
347
|
+
end
|
348
|
+
|
349
|
+
def test_version
|
350
|
+
req = Icalendar.decode(<<__).first
|
351
|
+
BEGIN:VCALENDAR
|
352
|
+
END:VCALENDAR
|
353
|
+
__
|
354
|
+
assert_raises(InvalidEncodingError) { req.version }
|
355
|
+
|
356
|
+
req = Icalendar.decode(<<__).first
|
357
|
+
BEGIN:VCALENDAR
|
358
|
+
VERSION:2.0
|
359
|
+
END:VCALENDAR
|
360
|
+
__
|
361
|
+
assert_equal(20, req.version)
|
362
|
+
end
|
363
|
+
|
364
|
+
def test_protocol
|
365
|
+
req = Icalendar.decode(<<__).first
|
366
|
+
BEGIN:VCALENDAR
|
367
|
+
METHOD:GET
|
368
|
+
END:VCALENDAR
|
369
|
+
__
|
370
|
+
assert(req.protocol?("get"))
|
371
|
+
assert(!req.protocol?("set"))
|
372
|
+
end
|
373
|
+
|
374
|
+
def test_transparency
|
375
|
+
transparency = Icalendar.decode(<<__).first.to_a.first.transparency
|
376
|
+
BEGIN:VCALENDAR
|
377
|
+
BEGIN:VEVENT
|
378
|
+
END:VEVENT
|
379
|
+
END:VCALENDAR
|
380
|
+
__
|
381
|
+
assert_equal("OPAQUE", transparency, "check default")
|
382
|
+
|
383
|
+
transparency = Icalendar.decode(<<__).first.to_a.first.transparency
|
384
|
+
BEGIN:VCALENDAR
|
385
|
+
BEGIN:VEVENT
|
386
|
+
TRANSP:Opaque
|
387
|
+
END:VEVENT
|
388
|
+
END:VCALENDAR
|
389
|
+
__
|
390
|
+
assert_equal("OPAQUE", transparency, "check opaque")
|
391
|
+
|
392
|
+
transparency = Icalendar.decode(<<__).first.to_a.first.transparency
|
393
|
+
BEGIN:VCALENDAR
|
394
|
+
BEGIN:VEVENT
|
395
|
+
TRANSP:TrANSPARENT
|
396
|
+
END:VEVENT
|
397
|
+
END:VCALENDAR
|
398
|
+
__
|
399
|
+
assert_equal("TRANSPARENT", transparency, "check transparent")
|
400
|
+
|
401
|
+
end
|
402
|
+
|
403
|
+
def test_event_maker_w_rrule
|
404
|
+
vc = Icalendar.create2 do |vc|
|
405
|
+
vc.add_event do |m|
|
406
|
+
m.add_rrule("freq=monthly")
|
407
|
+
m.set_rrule do |_| _.frequency = "daily" end
|
408
|
+
end
|
409
|
+
end
|
410
|
+
assert_no_match(/RRULE:FREQ=MONTHLY/, vc.to_s)
|
411
|
+
assert_match(/RRULE:FREQ=DAILY/, vc.to_s)
|
412
|
+
end
|
413
|
+
|
414
|
+
end
|
415
|
+
|
data/test/test_repo.rb
ADDED
@@ -0,0 +1,158 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'vpim/repo'
|
4
|
+
require 'vpim/agent/calendars'
|
5
|
+
require 'test/unit'
|
6
|
+
|
7
|
+
require 'pp'
|
8
|
+
|
9
|
+
module Enumerable
|
10
|
+
def count
|
11
|
+
self.inject(0){|i,_| i + 1}
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class TestRepo < Test::Unit::TestCase
|
16
|
+
Apple3 = Vpim::Repo::Apple3
|
17
|
+
Directory = Vpim::Repo::Directory
|
18
|
+
Agent = Vpim::Agent
|
19
|
+
Path = Agent::Path
|
20
|
+
NotFound = Agent::NotFound
|
21
|
+
|
22
|
+
def setup
|
23
|
+
@testdir = Dir.getwd + "/test" #File.dirname($0) doesn't work with rcov :-(
|
24
|
+
@caldir = @testdir + "/calendars"
|
25
|
+
@eventsz = Dir[@caldir + "/**/*.ics"].size
|
26
|
+
assert(@testdir)
|
27
|
+
assert(test(?d, @caldir), "no caldir "+@caldir)
|
28
|
+
end
|
29
|
+
|
30
|
+
def _test_each(repo, eventsz)
|
31
|
+
repo.each do |cal|
|
32
|
+
assert_equal(eventsz, cal.events.count, cal.name)
|
33
|
+
assert("", File.extname(cal.name))
|
34
|
+
assert_equal(cal.displayed, true)
|
35
|
+
cal.events do |c|
|
36
|
+
assert_instance_of(Vpim::Icalendar::Vevent, c)
|
37
|
+
end
|
38
|
+
cal.events.each do |c|
|
39
|
+
assert_instance_of(Vpim::Icalendar::Vevent, c)
|
40
|
+
end
|
41
|
+
assert_equal(0, cal.todos.count)
|
42
|
+
assert(cal.encode)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_apple3
|
47
|
+
repo = Apple3.new(@caldir)
|
48
|
+
|
49
|
+
assert_equal(1, repo.count)
|
50
|
+
|
51
|
+
_test_each(repo, @eventsz)
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_dir
|
55
|
+
assert(test(?d, @caldir))
|
56
|
+
|
57
|
+
repo = Directory.new(@caldir)
|
58
|
+
|
59
|
+
assert_equal(@eventsz, repo.count)
|
60
|
+
|
61
|
+
_test_each(repo, 1)
|
62
|
+
end
|
63
|
+
|
64
|
+
def assert_is_text_calendar(text)
|
65
|
+
lines = text.split("\n")
|
66
|
+
lines = lines.first, lines.last
|
67
|
+
assert_equal("BEGIN:VCALENDAR", lines.first.upcase, lines)
|
68
|
+
assert_equal("END:VCALENDAR", lines.last.upcase, lines)
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_agent_calendars
|
72
|
+
repo = Apple3.new(@caldir)
|
73
|
+
rest = Agent::Calendars.new(repo)
|
74
|
+
|
75
|
+
out1, form = rest.get(Path.new("http://host/here", "/here"))
|
76
|
+
assert_equal("text/html", form)
|
77
|
+
#puts(out1)
|
78
|
+
|
79
|
+
out1, form = rest.get(Path.new("http://host/here/weather%2fLeavenworth", "/here"))
|
80
|
+
assert_equal("text/html", form)
|
81
|
+
#puts(out1)
|
82
|
+
|
83
|
+
out2, form = rest.get(Path.new("http://host/here/weather%2fLeavenworth/calendar", "/here"))
|
84
|
+
assert_equal("text/calendar", form)
|
85
|
+
assert_is_text_calendar(out2)
|
86
|
+
|
87
|
+
#assert_equal(out1, out2)
|
88
|
+
|
89
|
+
assert_raise(Vpim::Agent::NotFound) do
|
90
|
+
rest.get(Path.new("http://host/here/weather%2fLeavenworth/an_unknown_protocol", "/here"))
|
91
|
+
end
|
92
|
+
assert_raise(Vpim::Agent::NotFound) do
|
93
|
+
rest.get(Path.new("http://host/here/no_such_calendar", "/here"))
|
94
|
+
end
|
95
|
+
|
96
|
+
assert_equal(["","/","/"], Vpim::Agent::Path.split_path("/%2F/%2F"))
|
97
|
+
assert_equal(["/","/"], Vpim::Agent::Path.split_path("%2F/%2F"))
|
98
|
+
assert_equal(["calendars", "weather/Leavenworth"],
|
99
|
+
Vpim::Agent::Path.split_path("calendars/weather%2FLeavenworth"))
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_agent_calendar_atom
|
103
|
+
repo = Apple3.new(@caldir)
|
104
|
+
rest = Agent::Calendars.new(repo)
|
105
|
+
|
106
|
+
out, form = rest.get(Path.new("http://host/here/weather%2fLeavenworth/atom", "/here"))
|
107
|
+
assert_equal("application/atom+xml", form)
|
108
|
+
#pp out
|
109
|
+
#assert_is_atom(out)
|
110
|
+
end
|
111
|
+
|
112
|
+
def _test_path_shift(url, shifts)
|
113
|
+
# last shift should be a nil
|
114
|
+
shifts << nil
|
115
|
+
|
116
|
+
# presence or absence of a trailing / should not affect shifting
|
117
|
+
["", "/"].each do |trailer|
|
118
|
+
path = Path.new(url + trailer)
|
119
|
+
shifts.each do |_|
|
120
|
+
assert_equal(_, path.shift)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_path_shift
|
126
|
+
_test_path_shift("http://host.ex", [])
|
127
|
+
_test_path_shift("http://host.ex/a", ["a"])
|
128
|
+
_test_path_shift("http://host.ex/a/b", ["a", "b"])
|
129
|
+
_test_path_shift("http://host.ex/a/b/c", ["a", "b", "c"])
|
130
|
+
end
|
131
|
+
|
132
|
+
def _test_path_prefix(base, parts, shifts, prefix)
|
133
|
+
path = Path.new(base+parts.join("/"))
|
134
|
+
shifts.times{ path.shift }
|
135
|
+
assert_equal(prefix, path.prefix)
|
136
|
+
end
|
137
|
+
|
138
|
+
def test_path_prefix
|
139
|
+
_test_path_prefix("http://host.ex/", [], 0, "/")
|
140
|
+
_test_path_prefix("http://host.ex/", ["a"], 0, "/")
|
141
|
+
_test_path_prefix("http://host.ex/", ["a"], 1, "/")
|
142
|
+
_test_path_prefix("http://host.ex/", ["a"], 2, "/a/")
|
143
|
+
_test_path_prefix("http://host.ex/", ["a"], 3, "/a/")
|
144
|
+
_test_path_prefix("http://host.ex/", ["a", "b"], 0, "/")
|
145
|
+
_test_path_prefix("http://host.ex/", ["a", "b"], 1, "/")
|
146
|
+
_test_path_prefix("http://host.ex/", ["a", "b"], 2, "/a/")
|
147
|
+
_test_path_prefix("http://host.ex/", ["a", "b"], 3, "/a/b/")
|
148
|
+
end
|
149
|
+
|
150
|
+
def test_atomize
|
151
|
+
repo = Apple3.new(@caldir)
|
152
|
+
cal = repo.find{true}
|
153
|
+
a = Vpim::Agent::Atomize.new(cal)
|
154
|
+
assert( a.get(Path.new("http://example.com/path")))
|
155
|
+
end
|
156
|
+
|
157
|
+
end
|
158
|
+
|