tilia-vobject 4.0.0.pre.alpha2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (193) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +19 -0
  3. data/.rubocop.yml +32 -0
  4. data/.simplecov +4 -0
  5. data/.travis.yml +3 -0
  6. data/CHANGELOG.sabre.md +626 -0
  7. data/CONTRIBUTING.md +25 -0
  8. data/Gemfile +17 -0
  9. data/Gemfile.lock +68 -0
  10. data/LICENSE +27 -0
  11. data/LICENSE.sabre +27 -0
  12. data/README.md +63 -0
  13. data/Rakefile +17 -0
  14. data/bin/vobject +7 -0
  15. data/lib/tilia/v_object/birthday_calendar_generator.rb +142 -0
  16. data/lib/tilia/v_object/cli.rb +582 -0
  17. data/lib/tilia/v_object/component/available.rb +107 -0
  18. data/lib/tilia/v_object/component/v_alarm.rb +114 -0
  19. data/lib/tilia/v_object/component/v_availability.rb +128 -0
  20. data/lib/tilia/v_object/component/v_calendar.rb +468 -0
  21. data/lib/tilia/v_object/component/v_card.rb +457 -0
  22. data/lib/tilia/v_object/component/v_event.rb +127 -0
  23. data/lib/tilia/v_object/component/v_free_busy.rb +81 -0
  24. data/lib/tilia/v_object/component/v_journal.rb +75 -0
  25. data/lib/tilia/v_object/component/v_time_zone.rb +51 -0
  26. data/lib/tilia/v_object/component/v_todo.rb +147 -0
  27. data/lib/tilia/v_object/component.rb +591 -0
  28. data/lib/tilia/v_object/date_time_parser.rb +486 -0
  29. data/lib/tilia/v_object/document.rb +218 -0
  30. data/lib/tilia/v_object/element_list.rb +18 -0
  31. data/lib/tilia/v_object/eof_exception.rb +8 -0
  32. data/lib/tilia/v_object/free_busy_data.rb +149 -0
  33. data/lib/tilia/v_object/free_busy_generator.rb +465 -0
  34. data/lib/tilia/v_object/i_tip/broker.rb +909 -0
  35. data/lib/tilia/v_object/i_tip/i_tip_exception.rb +9 -0
  36. data/lib/tilia/v_object/i_tip/message.rb +109 -0
  37. data/lib/tilia/v_object/i_tip/same_organizer_for_all_components_exception.rb +13 -0
  38. data/lib/tilia/v_object/i_tip.rb +10 -0
  39. data/lib/tilia/v_object/node.rb +192 -0
  40. data/lib/tilia/v_object/parameter.rb +327 -0
  41. data/lib/tilia/v_object/parse_exception.rb +7 -0
  42. data/lib/tilia/v_object/parser/json.rb +149 -0
  43. data/lib/tilia/v_object/parser/mime_dir.rb +543 -0
  44. data/lib/tilia/v_object/parser/parser.rb +61 -0
  45. data/lib/tilia/v_object/parser/xml/element/key_value.rb +60 -0
  46. data/lib/tilia/v_object/parser/xml/element.rb +11 -0
  47. data/lib/tilia/v_object/parser/xml.rb +322 -0
  48. data/lib/tilia/v_object/parser.rb +10 -0
  49. data/lib/tilia/v_object/property/binary.rb +96 -0
  50. data/lib/tilia/v_object/property/boolean.rb +57 -0
  51. data/lib/tilia/v_object/property/flat_text.rb +52 -0
  52. data/lib/tilia/v_object/property/float_value.rb +107 -0
  53. data/lib/tilia/v_object/property/i_calendar/cal_address.rb +49 -0
  54. data/lib/tilia/v_object/property/i_calendar/date.rb +15 -0
  55. data/lib/tilia/v_object/property/i_calendar/date_time.rb +330 -0
  56. data/lib/tilia/v_object/property/i_calendar/duration.rb +65 -0
  57. data/lib/tilia/v_object/property/i_calendar/period.rb +124 -0
  58. data/lib/tilia/v_object/property/i_calendar/recur.rb +173 -0
  59. data/lib/tilia/v_object/property/i_calendar.rb +14 -0
  60. data/lib/tilia/v_object/property/integer_value.rb +60 -0
  61. data/lib/tilia/v_object/property/text.rb +352 -0
  62. data/lib/tilia/v_object/property/time.rb +85 -0
  63. data/lib/tilia/v_object/property/unknown.rb +30 -0
  64. data/lib/tilia/v_object/property/uri.rb +78 -0
  65. data/lib/tilia/v_object/property/utc_offset.rb +56 -0
  66. data/lib/tilia/v_object/property/v_card/date.rb +31 -0
  67. data/lib/tilia/v_object/property/v_card/date_and_or_time.rb +343 -0
  68. data/lib/tilia/v_object/property/v_card/date_time.rb +22 -0
  69. data/lib/tilia/v_object/property/v_card/language_tag.rb +41 -0
  70. data/lib/tilia/v_object/property/v_card/time_stamp.rb +74 -0
  71. data/lib/tilia/v_object/property/v_card.rb +13 -0
  72. data/lib/tilia/v_object/property.rb +532 -0
  73. data/lib/tilia/v_object/reader.rb +73 -0
  74. data/lib/tilia/v_object/recur/event_iterator.rb +417 -0
  75. data/lib/tilia/v_object/recur/no_instances_exception.rb +11 -0
  76. data/lib/tilia/v_object/recur/r_date_iterator.rb +138 -0
  77. data/lib/tilia/v_object/recur/r_rule_iterator.rb +717 -0
  78. data/lib/tilia/v_object/recur.rb +10 -0
  79. data/lib/tilia/v_object/settings.rb +32 -0
  80. data/lib/tilia/v_object/splitter/i_calendar.rb +95 -0
  81. data/lib/tilia/v_object/splitter/splitter_interface.rb +31 -0
  82. data/lib/tilia/v_object/splitter/v_card.rb +56 -0
  83. data/lib/tilia/v_object/splitter.rb +9 -0
  84. data/lib/tilia/v_object/string_util.rb +58 -0
  85. data/lib/tilia/v_object/time_zone_data/exchange_zones.rb +96 -0
  86. data/lib/tilia/v_object/time_zone_data/lotus_zones.rb +104 -0
  87. data/lib/tilia/v_object/time_zone_data/php_zones.rb +49 -0
  88. data/lib/tilia/v_object/time_zone_data/windows_zones.rb +121 -0
  89. data/lib/tilia/v_object/time_zone_data.rb +10 -0
  90. data/lib/tilia/v_object/time_zone_util.rb +213 -0
  91. data/lib/tilia/v_object/uuid_util.rb +51 -0
  92. data/lib/tilia/v_object/v_card_converter.rb +354 -0
  93. data/lib/tilia/v_object/version.rb +9 -0
  94. data/lib/tilia/v_object/writer.rb +56 -0
  95. data/lib/tilia/v_object.rb +45 -0
  96. data/lib/tilia/vobject.rb +1 -0
  97. data/resources/schema/xcal.rng +1192 -0
  98. data/resources/schema/xcard.rng +388 -0
  99. data/test/test_helper.rb +56 -0
  100. data/test/v_object/attach_issue_test.rb +19 -0
  101. data/test/v_object/birthday_calendar_generator_test.rb +463 -0
  102. data/test/v_object/cli_mock.rb +19 -0
  103. data/test/v_object/cli_test.rb +460 -0
  104. data/test/v_object/component/available_test.rb +59 -0
  105. data/test/v_object/component/v_alarm_test.rb +160 -0
  106. data/test/v_object/component/v_availability_test.rb +388 -0
  107. data/test/v_object/component/v_calendar_test.rb +646 -0
  108. data/test/v_object/component/v_card_test.rb +258 -0
  109. data/test/v_object/component/v_event_test.rb +85 -0
  110. data/test/v_object/component/v_free_busy_test.rb +59 -0
  111. data/test/v_object/component/v_journal_test.rb +85 -0
  112. data/test/v_object/component/v_time_zone_test.rb +47 -0
  113. data/test/v_object/component/v_todo_test.rb +172 -0
  114. data/test/v_object/component_test.rb +419 -0
  115. data/test/v_object/date_time_parser_test.rb +526 -0
  116. data/test/v_object/document_test.rb +71 -0
  117. data/test/v_object/element_list_test.rb +27 -0
  118. data/test/v_object/em_client_test.rb +53 -0
  119. data/test/v_object/empty_parameter_test.rb +65 -0
  120. data/test/v_object/empty_value_issue_test.rb +25 -0
  121. data/test/v_object/fake_component.rb +21 -0
  122. data/test/v_object/free_busy_data_test.rb +285 -0
  123. data/test/v_object/free_busy_generator_test.rb +637 -0
  124. data/test/v_object/google_colon_escaping_test.rb +27 -0
  125. data/test/v_object/i_calendar/attach_parse_test.rb +24 -0
  126. data/test/v_object/i_tip/broker_attendee_reply_test.rb +1042 -0
  127. data/test/v_object/i_tip/broker_delete_event_test.rb +175 -0
  128. data/test/v_object/i_tip/broker_new_event_test.rb +440 -0
  129. data/test/v_object/i_tip/broker_process_message_test.rb +153 -0
  130. data/test/v_object/i_tip/broker_process_reply_test.rb +402 -0
  131. data/test/v_object/i_tip/broker_tester.rb +71 -0
  132. data/test/v_object/i_tip/broker_update_event_test.rb +763 -0
  133. data/test/v_object/i_tip/evolution_test.rb +2644 -0
  134. data/test/v_object/i_tip/message_test.rb +25 -0
  135. data/test/v_object/issue153.vcf +352 -0
  136. data/test/v_object/issue153_test.rb +12 -0
  137. data/test/v_object/issue26_test.rb +25 -0
  138. data/test/v_object/issue36_work_around_test.rb +37 -0
  139. data/test/v_object/issue40_test.rb +26 -0
  140. data/test/v_object/issue64.vcf +351 -0
  141. data/test/v_object/issue64_test.rb +17 -0
  142. data/test/v_object/issue96_test.rb +22 -0
  143. data/test/v_object/issue_undefined_index_test.rb +24 -0
  144. data/test/v_object/j_cal_test.rb +150 -0
  145. data/test/v_object/j_card_test.rb +192 -0
  146. data/test/v_object/line_folding_issue_test.rb +19 -0
  147. data/test/v_object/mock_document.rb +6 -0
  148. data/test/v_object/parameter_test.rb +109 -0
  149. data/test/v_object/parser/json_test.rb +370 -0
  150. data/test/v_object/parser/mime_dir_test.rb +14 -0
  151. data/test/v_object/parser/quoted_printable_test.rb +78 -0
  152. data/test/v_object/parser/xml_test.rb +2563 -0
  153. data/test/v_object/property/binary_test.rb +12 -0
  154. data/test/v_object/property/boolean_test.rb +18 -0
  155. data/test/v_object/property/compound_test.rb +43 -0
  156. data/test/v_object/property/float_test.rb +20 -0
  157. data/test/v_object/property/i_calendar/cal_address_test.rb +26 -0
  158. data/test/v_object/property/i_calendar/date_time_test.rb +303 -0
  159. data/test/v_object/property/i_calendar/duration_test.rb +14 -0
  160. data/test/v_object/property/i_calendar/recur_test.rb +39 -0
  161. data/test/v_object/property/text_test.rb +81 -0
  162. data/test/v_object/property/v_card/date_and_or_time_test.rb +205 -0
  163. data/test/v_object/property/v_card/language_tag_test.rb +35 -0
  164. data/test/v_object/property_test.rb +338 -0
  165. data/test/v_object/reader_test.rb +403 -0
  166. data/test/v_object/recur/event_iterator/by_month_in_daily_test.rb +52 -0
  167. data/test/v_object/recur/event_iterator/by_set_pos_hang_test.rb +55 -0
  168. data/test/v_object/recur/event_iterator/expand_floating_times_test.rb +109 -0
  169. data/test/v_object/recur/event_iterator/fifth_tuesday_problem_test.rb +45 -0
  170. data/test/v_object/recur/event_iterator/incorrect_expand_test.rb +53 -0
  171. data/test/v_object/recur/event_iterator/infinite_loop_problem_test.rb +75 -0
  172. data/test/v_object/recur/event_iterator/issue48_test.rb +43 -0
  173. data/test/v_object/recur/event_iterator/issue50_test.rb +123 -0
  174. data/test/v_object/recur/event_iterator/main_test.rb +1222 -0
  175. data/test/v_object/recur/event_iterator/missing_overridden_test.rb +55 -0
  176. data/test/v_object/recur/event_iterator/no_instances_test.rb +32 -0
  177. data/test/v_object/recur/event_iterator/override_first_event_test.rb +106 -0
  178. data/test/v_object/recur/r_date_iterator_test.rb +44 -0
  179. data/test/v_object/recur/r_rule_iterator_test.rb +608 -0
  180. data/test/v_object/recurrence_iterator/UntilRespectsTimezoneTest.ics +39 -0
  181. data/test/v_object/slash_r_test.rb +15 -0
  182. data/test/v_object/splitter/i_calendar_test.rb +299 -0
  183. data/test/v_object/splitter/v_card_test.rb +173 -0
  184. data/test/v_object/string_util_test.rb +37 -0
  185. data/test/v_object/test_case.rb +42 -0
  186. data/test/v_object/time_zone_util_test.rb +271 -0
  187. data/test/v_object/uuid_util_test.rb +18 -0
  188. data/test/v_object/v_card21_test.rb +43 -0
  189. data/test/v_object/v_card_converter_test.rb +419 -0
  190. data/test/v_object/version_test.rb +15 -0
  191. data/test/v_object/writer_test.rb +33 -0
  192. data/tilia-vobject.gemspec +17 -0
  193. metadata +308 -0
@@ -0,0 +1,299 @@
1
+ require 'test_helper'
2
+ require 'stringio'
3
+
4
+ module Tilia
5
+ module VObject
6
+ class ICalendarTest < Minitest::Test
7
+ def setup
8
+ @version = Tilia::VObject::Version::VERSION
9
+ end
10
+
11
+ def create_stream(data)
12
+ stream = StringIO.new
13
+ stream.write(data)
14
+ stream.rewind
15
+ stream
16
+ end
17
+
18
+ def test_i_calendar_import_valid_event
19
+ data = <<EOT
20
+ BEGIN:VCALENDAR
21
+ BEGIN:VEVENT
22
+ UID:foo
23
+ DTSTAMP:20140122T233226Z
24
+ DTSTART:20140101T070000Z
25
+ END:VEVENT
26
+ END:VCALENDAR
27
+ EOT
28
+ temp_file = create_stream(data)
29
+
30
+ objects = Tilia::VObject::Splitter::ICalendar.new(temp_file)
31
+
32
+ to_return = ''
33
+ while object = objects.next
34
+ to_return += object.serialize
35
+ end
36
+ assert_equal([], Tilia::VObject::Reader.read(to_return).validate)
37
+ end
38
+
39
+ def test_i_calendar_import_wrong_type
40
+ data = <<EOT
41
+ BEGIN:VCARD
42
+ UID:foo1
43
+ END:VCARD
44
+ BEGIN:VCARD
45
+ UID:foo2
46
+ END:VCARD
47
+ EOT
48
+ temp_file = create_stream(data)
49
+
50
+ assert_raises(Tilia::VObject::ParseException) { Tilia::VObject::Splitter::ICalendar.new(temp_file) }
51
+ end
52
+
53
+ def test_i_calendar_import_end_of_data
54
+ data = <<EOT
55
+ BEGIN:VCALENDAR
56
+ BEGIN:VEVENT
57
+ UID:foo
58
+ DTSTAMP:20140122T233226Z
59
+ END:VEVENT
60
+ END:VCALENDAR
61
+ EOT
62
+ temp_file = create_stream(data)
63
+
64
+ objects = Tilia::VObject::Splitter::ICalendar.new(temp_file)
65
+
66
+ to_return = ''
67
+ while object = objects.next
68
+ to_return += object.serialize
69
+ end
70
+
71
+ assert_nil(objects.next)
72
+ end
73
+
74
+ def test_i_calendar_import_invalid_event
75
+ data = <<EOT
76
+ EOT
77
+ temp_file = create_stream(data)
78
+ assert_raises(Tilia::VObject::ParseException) { objects = Tilia::VObject::Splitter::ICalendar.new(temp_file) }
79
+ end
80
+
81
+ def test_i_calendar_import_multiple_valid_events
82
+ event = []
83
+ event << <<EOT
84
+ BEGIN:VEVENT
85
+ UID:foo1
86
+ DTSTAMP:20140122T233226Z
87
+ DTSTART:20140101T050000Z
88
+ END:VEVENT
89
+ EOT
90
+
91
+ event << <<EOT
92
+ BEGIN:VEVENT
93
+ UID:foo2
94
+ DTSTAMP:20140122T233226Z
95
+ DTSTART:20140101T060000Z
96
+ END:VEVENT
97
+ EOT
98
+
99
+ data = <<EOT
100
+ BEGIN:VCALENDAR
101
+ #{event[0]}
102
+ #{event[1]}
103
+ END:VCALENDAR
104
+ EOT
105
+ temp_file = create_stream(data)
106
+
107
+ objects = Tilia::VObject::Splitter::ICalendar.new(temp_file)
108
+
109
+ to_return = ''
110
+ i = 0
111
+ while object = objects.next
112
+ # event[i] already includes \n
113
+ expected = <<EOT
114
+ BEGIN:VCALENDAR
115
+ VERSION:2.0
116
+ PRODID:-//Tilia//Tilia VObject #{@version}//EN
117
+ CALSCALE:GREGORIAN
118
+ #{event[i]}END:VCALENDAR
119
+ EOT
120
+
121
+ to_return += object.serialize
122
+ expected = expected.gsub("\n", "\r\n")
123
+ assert_equal(expected, object.serialize)
124
+ i += 1
125
+ end
126
+ assert_equal([], Tilia::VObject::Reader.read(to_return).validate)
127
+ end
128
+
129
+ def test_i_calendar_import_event_without_uid
130
+ data = <<EOT
131
+ BEGIN:VCALENDAR
132
+ VERSION:2.0
133
+ PRODID:-//Sabre//Sabre VObject @version//EN
134
+ CALSCALE:GREGORIAN
135
+ BEGIN:VEVENT
136
+ DTSTART:20140101T040000Z
137
+ DTSTAMP:20140122T233226Z
138
+ END:VEVENT
139
+ END:VCALENDAR
140
+
141
+ EOT
142
+ temp_file = create_stream(data)
143
+
144
+ objects = Tilia::VObject::Splitter::ICalendar.new(temp_file)
145
+
146
+ to_return = ''
147
+ while object = objects.next
148
+ to_return += object.serialize
149
+ end
150
+
151
+ assert_nil(objects.next)
152
+
153
+ messages = Tilia::VObject::Reader.read(to_return).validate
154
+
155
+ if messages.any?
156
+ messages = messages.map { |i| i['message'] }
157
+ fail("Validation errors: #{messages.join("\n")}")
158
+ else
159
+ assert_equal([], messages)
160
+ end
161
+ end
162
+
163
+ def test_i_calendar_import_multiple_vtimezones_and_multiple_valid_events
164
+ timezones = <<EOT
165
+ BEGIN:VTIMEZONE
166
+ TZID:Europe/Berlin
167
+ BEGIN:DAYLIGHT
168
+ TZOFFSETFROM:+0100
169
+ RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
170
+ DTSTART:19810329T020000
171
+ TZNAME:MESZ
172
+ TZOFFSETTO:+0200
173
+ END:DAYLIGHT
174
+ BEGIN:STANDARD
175
+ TZOFFSETFROM:+0200
176
+ RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
177
+ DTSTART:19961027T030000
178
+ TZNAME:MEZ
179
+ TZOFFSETTO:+0100
180
+ END:STANDARD
181
+ END:VTIMEZONE
182
+ BEGIN:VTIMEZONE
183
+ TZID:Europe/London
184
+ BEGIN:DAYLIGHT
185
+ TZOFFSETFROM:+0000
186
+ RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
187
+ DTSTART:19810329T010000
188
+ TZNAME:GMT+01:00
189
+ TZOFFSETTO:+0100
190
+ END:DAYLIGHT
191
+ BEGIN:STANDARD
192
+ TZOFFSETFROM:+0100
193
+ RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
194
+ DTSTART:19961027T020000
195
+ TZNAME:GMT
196
+ TZOFFSETTO:+0000
197
+ END:STANDARD
198
+ END:VTIMEZONE
199
+ EOT
200
+
201
+ event = []
202
+ event << <<EOT
203
+ BEGIN:VEVENT
204
+ UID:foo1
205
+ DTSTAMP:20140122T232710Z
206
+ DTSTART:20140101T010000Z
207
+ END:VEVENT
208
+ EOT
209
+
210
+ event << <<EOT
211
+ BEGIN:VEVENT
212
+ UID:foo2
213
+ DTSTAMP:20140122T232710Z
214
+ DTSTART:20140101T020000Z
215
+ END:VEVENT
216
+ EOT
217
+
218
+ event << <<EOT
219
+ BEGIN:VEVENT
220
+ UID:foo3
221
+ DTSTAMP:20140122T232710Z
222
+ DTSTART:20140101T030000Z
223
+ END:VEVENT
224
+ EOT
225
+
226
+ data = <<EOT
227
+ BEGIN:VCALENDAR
228
+ #{timezones}
229
+ #{event[0]}
230
+ #{event[1]}
231
+ #{event[2]}
232
+ END:VCALENDAR
233
+ EOT
234
+ temp_file = create_stream(data)
235
+
236
+ objects = Tilia::VObject::Splitter::ICalendar.new(temp_file)
237
+
238
+ to_return = ''
239
+ i = 0
240
+ while object = objects.next
241
+ # newlines are part of the variables
242
+ expected = <<EOT
243
+ BEGIN:VCALENDAR
244
+ VERSION:2.0
245
+ PRODID:-//Tilia//Tilia VObject #{@version}//EN
246
+ CALSCALE:GREGORIAN
247
+ #{timezones}#{event[i]}END:VCALENDAR
248
+ EOT
249
+ expected = expected.gsub("\n", "\r\n")
250
+
251
+ assert_equal(expected, object.serialize)
252
+ to_return += object.serialize
253
+ i += 1
254
+ end
255
+
256
+ assert_equal([], Tilia::VObject::Reader.read(to_return).validate)
257
+ end
258
+
259
+ def test_i_calendar_import_with_out_vtimezones
260
+ data = <<EOT
261
+ BEGIN:VCALENDAR
262
+ VERSION:2.0
263
+ PRODID:-//Apple Inc.//Mac OS X 10.8//EN
264
+ CALSCALE:GREGORIAN
265
+ BEGIN:VEVENT
266
+ CREATED:20120605T072109Z
267
+ UID:D6716295-C10F-4B20-82F9-E1A3026C7DCF
268
+ DTEND;VALUE=DATE:20120717
269
+ TRANSP:TRANSPARENT
270
+ SUMMARY:Start Vorbereitung
271
+ DTSTART;VALUE=DATE:20120716
272
+ DTSTAMP:20120605T072115Z
273
+ SEQUENCE:2
274
+ BEGIN:VALARM
275
+ X-WR-ALARMUID:A99EDA6A-35EB-4446-B8BC-CDA3C60C627D
276
+ UID:A99EDA6A-35EB-4446-B8BC-CDA3C60C627D
277
+ TRIGGER:-PT15H
278
+ X-APPLE-DEFAULT-ALARM:TRUE
279
+ ATTACH;VALUE=URI:Basso
280
+ ACTION:AUDIO
281
+ END:VALARM
282
+ END:VEVENT
283
+ END:VCALENDAR
284
+ EOT
285
+ temp_file = create_stream(data)
286
+
287
+ objects = Tilia::VObject::Splitter::ICalendar.new(temp_file)
288
+
289
+ to_return = ''
290
+ while object = objects.next
291
+ to_return += object.serialize
292
+ end
293
+
294
+ messages = Tilia::VObject::Reader.read(to_return).validate
295
+ assert_equal([], messages)
296
+ end
297
+ end
298
+ end
299
+ end
@@ -0,0 +1,173 @@
1
+ require 'test_helper'
2
+ require 'stringio'
3
+
4
+ module Tilia
5
+ module VObject
6
+ class VCardTest < Minitest::Test
7
+ def create_stream(data)
8
+ stream = StringIO.new
9
+ stream.write(data)
10
+ stream.rewind
11
+ stream
12
+ end
13
+
14
+ def test_v_card_import_valid_v_card
15
+ data = <<EOT
16
+ BEGIN:VCARD
17
+ UID:foo
18
+ END:VCARD
19
+ EOT
20
+ temp_file = create_stream(data)
21
+
22
+ objects = Tilia::VObject::Splitter::VCard.new(temp_file)
23
+
24
+ count = 0
25
+ count += 1 while objects.next
26
+ assert_equal(1, count)
27
+ end
28
+
29
+ def test_v_card_import_wrong_type
30
+ event = []
31
+ event << <<EOT
32
+ BEGIN:VEVENT
33
+ UID:foo1
34
+ DTSTAMP:20140122T233226Z
35
+ DTSTART:20140101T050000Z
36
+ END:VEVENT
37
+ EOT
38
+
39
+ event << <<EOT
40
+ BEGIN:VEVENT
41
+ UID:foo2
42
+ DTSTAMP:20140122T233226Z
43
+ DTSTART:20140101T060000Z
44
+ END:VEVENT
45
+ EOT
46
+
47
+ data = <<EOT
48
+ BEGIN:VCALENDAR
49
+ #{event[0]}
50
+ #{event[1]}
51
+ END:VCALENDAR
52
+ EOT
53
+ temp_file = create_stream(data)
54
+
55
+ splitter = Tilia::VObject::Splitter::VCard.new(temp_file)
56
+
57
+ assert_raises(Tilia::VObject::ParseException) do
58
+ while object = splitter.next
59
+ end
60
+ end
61
+ end
62
+
63
+ def test_v_card_import_valid_v_cards_with_categories
64
+ data = <<EOT
65
+ BEGIN:VCARD
66
+ UID:card-in-foo1-and-foo2
67
+ CATEGORIES:foo1,foo2
68
+ END:VCARD
69
+ BEGIN:VCARD
70
+ UID:card-in-foo1
71
+ CATEGORIES:foo1
72
+ END:VCARD
73
+ BEGIN:VCARD
74
+ UID:card-in-foo3
75
+ CATEGORIES:foo3
76
+ END:VCARD
77
+ BEGIN:VCARD
78
+ UID:card-in-foo1-and-foo3
79
+ CATEGORIES:foo1\,foo3
80
+ END:VCARD
81
+ EOT
82
+ temp_file = create_stream(data)
83
+
84
+ splitter = Tilia::VObject::Splitter::VCard.new(temp_file)
85
+
86
+ count = 0
87
+ count += 1 while splitter.next
88
+ assert_equal(4, count)
89
+ end
90
+
91
+ def test_v_card_import_end_of_data
92
+ data = <<EOT
93
+ BEGIN:VCARD
94
+ UID:foo
95
+ END:VCARD
96
+ EOT
97
+ temp_file = create_stream(data)
98
+
99
+ objects = Tilia::VObject::Splitter::VCard.new(temp_file)
100
+ object = objects.next
101
+
102
+ assert_nil(objects.next)
103
+ end
104
+
105
+ def test_v_card_import_check_invalid_argument_exception
106
+ data = <<EOT
107
+ BEGIN:FOO
108
+ END:FOO
109
+ EOT
110
+ temp_file = create_stream(data)
111
+
112
+ objects = Tilia::VObject::Splitter::VCard.new(temp_file)
113
+ assert_raises(Tilia::VObject::ParseException) do
114
+ while object = objects.next
115
+ end
116
+ end
117
+ end
118
+
119
+ def test_v_card_import_multiple_valid_v_cards
120
+ data = <<EOT
121
+ BEGIN:VCARD
122
+ UID:foo
123
+ END:VCARD
124
+ BEGIN:VCARD
125
+ UID:foo
126
+ END:VCARD
127
+ EOT
128
+ temp_file = create_stream(data)
129
+
130
+ objects = Tilia::VObject::Splitter::VCard.new(temp_file)
131
+
132
+ count = 0
133
+ count += 1 while objects.next
134
+ assert_equal(2, count)
135
+ end
136
+
137
+ def test_import_multiple_separated_with_new_lines
138
+ data = <<EOT
139
+ BEGIN:VCARD
140
+ UID:foo
141
+ END:VCARD
142
+
143
+
144
+ BEGIN:VCARD
145
+ UID:foo
146
+ END:VCARD
147
+
148
+
149
+ EOT
150
+ temp_file = create_stream(data)
151
+ objects = Tilia::VObject::Splitter::VCard.new(temp_file)
152
+
153
+ count = 0
154
+ count += 1 while objects.next
155
+ assert_equal(2, count)
156
+ end
157
+
158
+ def test_v_card_import_v_card_without_uid
159
+ data = <<EOT
160
+ BEGIN:VCARD
161
+ END:VCARD
162
+ EOT
163
+ temp_file = create_stream(data)
164
+
165
+ objects = Tilia::VObject::Splitter::VCard.new(temp_file)
166
+
167
+ count = 0
168
+ count += 1 while objects.next
169
+ assert_equal(1, count)
170
+ end
171
+ end
172
+ end
173
+ end
@@ -0,0 +1,37 @@
1
+ require 'test_helper'
2
+
3
+ module Tilia
4
+ module VObject
5
+ class StringUtilTest < Minitest::Test
6
+ def test_non_utf8
7
+ string = Tilia::VObject::StringUtil.utf8?((0xbf).chr)
8
+ refute(string)
9
+ end
10
+
11
+ def test_is_utf8
12
+ string = Tilia::VObject::StringUtil.utf8?('I 💚 SabreDAV')
13
+ assert(string)
14
+ end
15
+
16
+ def test_utf8_control_char
17
+ string = Tilia::VObject::StringUtil.utf8?((0x00).chr)
18
+ refute(string)
19
+ end
20
+
21
+ def test_convert_to_utf8non_utf8
22
+ string = Tilia::VObject::StringUtil.convert_to_utf8("asdf\xbf")
23
+ assert_equal('asdf¿', string)
24
+ end
25
+
26
+ def test_convert_to_utf8_is_utf8
27
+ string = Tilia::VObject::StringUtil.convert_to_utf8('I 💚 SabreDAV')
28
+ assert_equal('I 💚 SabreDAV', string)
29
+ end
30
+
31
+ def test_convert_to_utf8_control_char
32
+ string = Tilia::VObject::StringUtil.convert_to_utf8((0x00).chr)
33
+ assert_equal('', string)
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,42 @@
1
+ module Tilia
2
+ module VObject
3
+ class TestCase < Minitest::Test
4
+ # This method tests wether two vcards or icalendar objects are
5
+ # semantically identical.
6
+ #
7
+ # It supports objects being supplied as strings, streams or
8
+ # Sabre\VObject\Component instances.
9
+ #
10
+ # PRODID is removed from both objects as this is often changes and would
11
+ # just get in the way.
12
+ #
13
+ # CALSCALE will automatically get removed if it's set to GREGORIAN.
14
+ def assert_v_obj_equals(expected, actual, message = '')
15
+ get_obj = lambda do |input|
16
+ input = input.readlines.join("\n") if input.respond_to?(:readlines)
17
+
18
+ input = Tilia::VObject::Reader.read(input) if input.is_a?(String)
19
+
20
+ unless input.is_a?(Tilia::VObject::Component)
21
+ fail ArgumentError, 'Input must be a string, stream or VObject component'
22
+ end
23
+
24
+ input.delete('PRODID')
25
+ if input.is_a?(Tilia::VObject::Component::VCalendar) && input['CALSCALE'].to_s == 'GREGORIAN'
26
+ input.delete('CALSCALE')
27
+ end
28
+ input
29
+ end
30
+
31
+ expected = get_obj.call(expected)
32
+ actual = get_obj.call(actual)
33
+
34
+ assert_equal(
35
+ expected.serialize,
36
+ actual.serialize,
37
+ message
38
+ )
39
+ end
40
+ end
41
+ end
42
+ end