Imported Upstream version 0.48
[platform/upstream/libical.git] / src / java / testjni.java
1 package net.cp.jlibical;
2
3 import java.lang.String;
4
5 public class testjni
6 {
7         static final String content = "BEGIN:VCALENDAR\nVERSION:2.1\nBEGIN:VEVENT\nUID:abcd12345\nDTSTART:20020307T180000Z\nDTEND:20020307T190000Z\nSUMMARY:Important Meeting\nEND:VEVENT\nEND:VCALENDAR";
8         public static void main(String[] args)
9         {
10                 // VAGENDA test case
11
12                 ICalProperty calidProp = new ICalProperty(ICalProperty.ICalPropertyKind.ICAL_RELCALID_PROPERTY);
13                 ICalProperty ownerProp = new ICalProperty(ICalProperty.ICalPropertyKind.ICAL_OWNER_PROPERTY);
14
15                 calidProp.set_relcalid("1212");
16                 ownerProp.set_owner("Bill Smith");
17
18                 VAgenda vAgenda = new VAgenda();
19                 vAgenda.add_property(calidProp);
20                 vAgenda.add_property(ownerProp);
21
22                 System.out.println("VAgenda:\n" + vAgenda.as_ical_string());
23
24                 // VEVENT test case
25
26                 ICalProperty summProp  = new ICalProperty(ICalProperty.ICalPropertyKind.ICAL_SUMMARY_PROPERTY);
27                 ICalProperty startProp = new ICalProperty(ICalProperty.ICalPropertyKind.ICAL_DTSTART_PROPERTY);
28                 ICalProperty endProp   = new ICalProperty(ICalProperty.ICalPropertyKind.ICAL_DTEND_PROPERTY);
29
30                 ICalProperty locationProp = new ICalProperty(ICalProperty.ICalPropertyKind.ICAL_LOCATION_PROPERTY);
31                 ICalProperty descProp = new ICalProperty(ICalProperty.ICalPropertyKind.ICAL_DESCRIPTION_PROPERTY);
32
33                 ICalTimeType starttime = new ICalTimeType();
34                 starttime.setYear(2001);
35                 starttime.setMonth(12);
36                 starttime.setDay(21);
37                 starttime.setHour(18);
38                 starttime.setMinute(0);
39                 starttime.setSecond(0);
40                 starttime.setIs_utc(true);
41                 System.out.println("done creating starttime");
42
43                 ICalTimeType endtime = new ICalTimeType();
44                 endtime.setYear(2002);
45                 endtime.setMonth(1);
46                 endtime.setDay(1);
47                 endtime.setHour(8);
48                 endtime.setMinute(0);
49                 endtime.setSecond(0);
50                 endtime.setIs_utc(true);
51                 System.out.println("done creating endtime");
52
53
54                 // START - get, set_exdate
55                 ICalProperty property_tma = new ICalProperty(ICalProperty.ICalPropertyKind.ICAL_EXDATE_PROPERTY);
56                 property_tma.set_exdate(starttime);
57                 ICalTimeType starttime_return = property_tma.get_exdate();
58                 System.out.println("****** property - exdate ******");
59                 System.out.println("setYear=" + starttime_return.getYear());
60                 System.out.println("setMonth=" + starttime_return.getMonth());
61                 System.out.println("setDay=" + starttime_return.getDay());
62                 System.out.println("setHour=" + starttime_return.getHour());
63                 System.out.println("setMinute=" + starttime_return.getMinute());
64                 System.out.println("setSecond=" + starttime_return.getSecond());
65                 System.out.println("******* property - exdate *****");
66
67                 // END - get, set exdate
68
69                 // START - get, set exrule
70                 ICalProperty property_exrule_tma = new ICalProperty(ICalProperty.ICalPropertyKind.ICAL_EXRULE_PROPERTY);
71                 ICalRecurrenceType exrule_tma = new ICalRecurrenceType();
72                 exrule_tma.setUntil(starttime);
73                 exrule_tma.setFreq(ICalRecurrenceType.ICalRecurrenceTypeFrequency.ICAL_MINUTELY_RECURRENCE);
74                 exrule_tma.setWeek_start(ICalRecurrenceType.ICalRecurrenceTypeWeekday.ICAL_SUNDAY_WEEKDAY);
75                 short test_tma[] = {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};
76
77                 exrule_tma.setBy_second(test_tma);
78                 exrule_tma.setBy_minute(test_tma);
79                 property_exrule_tma.set_exrule(exrule_tma);
80
81                 ICalRecurrenceType recurence_tma_return = property_exrule_tma.get_exrule();
82                 System.out.println("****** property - exrule ******");
83                 System.out.println("setFreq=" + recurence_tma_return.getFreq());
84                 System.out.println("setWeek_start=" + recurence_tma_return.getWeek_start());
85                 System.out.println("setBy_second[30]=" + recurence_tma_return.getBy_secondIndexed(30));
86                 System.out.println("setBy_minute[28]=" + recurence_tma_return.getBy_minuteIndexed(28));
87                 System.out.println("****** property - exrule ******");
88
89                 // END - get, set exrule
90
91                 // START - get, set recurrenceid
92                 ICalProperty property_recurrenceid_tma = new ICalProperty(ICalProperty.ICalPropertyKind.ICAL_RECURRENCEID_PROPERTY);
93                 property_recurrenceid_tma.set_recurrenceid(starttime);
94                 ICalTimeType recurrenceid_return = property_recurrenceid_tma.get_recurrenceid();
95                 System.out.println("****** property - recurrenceid ******");
96                 System.out.println("setYear=" + recurrenceid_return.getYear());
97                 System.out.println("setMonth=" + recurrenceid_return.getMonth());
98                 System.out.println("setDay=" + recurrenceid_return.getDay());
99                 System.out.println("setHour=" + recurrenceid_return.getHour());
100                 System.out.println("setMinute=" + recurrenceid_return.getMinute());
101                 System.out.println("setSecond=" + recurrenceid_return.getSecond());
102                 System.out.println("******* property - recurrenceid *****");
103
104                 // END - get, set recurrenceid
105
106                 // START - get, set rrule
107                 ICalProperty property_rrule_tma = new ICalProperty(ICalProperty.ICalPropertyKind.ICAL_RRULE_PROPERTY);
108                 ICalRecurrenceType rrule_tma = new ICalRecurrenceType();
109                 rrule_tma.setUntil(starttime);
110                 rrule_tma.setFreq(ICalRecurrenceType.ICalRecurrenceTypeFrequency.ICAL_MINUTELY_RECURRENCE);
111                 rrule_tma.setWeek_start(ICalRecurrenceType.ICalRecurrenceTypeWeekday.ICAL_SUNDAY_WEEKDAY);
112                 short test_hour_tma[] = {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};
113                 rrule_tma.setBy_hour(test_hour_tma);
114                 property_rrule_tma.set_rrule(rrule_tma);
115
116                 ICalRecurrenceType rrule_tma_return = property_rrule_tma.get_rrule();
117                 System.out.println("****** property - rrule ******");
118                 System.out.println("setFreq=" + rrule_tma_return.getFreq());
119                 System.out.println("setWeek_start=" + rrule_tma_return.getWeek_start());
120                 System.out.println("setBy_hour[11]=" + rrule_tma_return.getBy_hourIndexed(11));
121                 System.out.println("****** property - rrule ******");
122                 // END - get, set rrule
123
124                 // START - get, set freebusy
125                 ICalProperty property_freebusy_tma = new ICalProperty(ICalProperty.ICalPropertyKind.ICAL_FREEBUSY_PROPERTY);
126                 ICalPeriodType period_tma = new ICalPeriodType();
127                 ICalDurationType duration_tma = new ICalDurationType();
128                 duration_tma.setDays((long) 0);
129                 duration_tma.setHours((long) 10);
130                 duration_tma.setMinutes((long) 15);
131
132                 period_tma.setStart(starttime);
133                 period_tma.setEnd(endtime);
134                 period_tma.setDuration(duration_tma);
135
136                 property_freebusy_tma.set_freebusy(period_tma);
137
138                 ICalPeriodType period_tma_return = property_freebusy_tma.get_freebusy();
139                 ICalTimeType start_tma_return = period_tma_return.getStart();
140                 ICalTimeType end_tma_return = period_tma_return.getEnd();
141                 ICalDurationType duration_tma_return = period_tma_return.getDuration();
142
143                 System.out.println("****** property - freebusy - start ******");
144                 System.out.println("setYear=" + start_tma_return.getYear());
145                 System.out.println("setMonth=" + start_tma_return.getMonth());
146                 System.out.println("setDay=" + start_tma_return.getDay());
147                 System.out.println("setHour=" + start_tma_return.getHour());
148                 System.out.println("setMinute=" + start_tma_return.getMinute());
149                 System.out.println("setSecond=" + start_tma_return.getSecond());
150                 System.out.println("******* property - freebusy - start *****");
151
152                 System.out.println("****** property - freebusy - end ******");
153                 System.out.println("setYear=" + end_tma_return.getYear());
154                 System.out.println("setMonth=" + end_tma_return.getMonth());
155                 System.out.println("setDay=" + end_tma_return.getDay());
156                 System.out.println("setHour=" + end_tma_return.getHour());
157                 System.out.println("setMinute=" + end_tma_return.getMinute());
158                 System.out.println("setSecond=" + end_tma_return.getSecond());
159                 System.out.println("******* property - freebusy - end *****");
160
161                 System.out.println("****** property - freebusy - duration ******");
162                 System.out.println("setYear=" + duration_tma_return.getDays());
163                 System.out.println("setMonth=" + duration_tma_return.getHours());
164                 System.out.println("setDay=" + duration_tma_return.getMinutes());
165                 System.out.println("******* property - freebusy - duration *****");
166
167                 // END - get, set freebusy
168
169                 // START - get, set dtstamp
170                 ICalProperty property_dtstamp_tma = new ICalProperty(ICalProperty.ICalPropertyKind.ICAL_DTSTAMP_PROPERTY);
171                 property_dtstamp_tma.set_dtstamp(starttime);
172                 ICalTimeType dtstamp_tma_return = property_dtstamp_tma.get_dtstamp();
173                 System.out.println("****** property - dtstamp ******");
174                 System.out.println("setYear=" + dtstamp_tma_return.getYear());
175                 System.out.println("setMonth=" + dtstamp_tma_return.getMonth());
176                 System.out.println("setDay=" + dtstamp_tma_return.getDay());
177                 System.out.println("setHour=" + dtstamp_tma_return.getHour());
178                 System.out.println("setMinute=" + dtstamp_tma_return.getMinute());
179                 System.out.println("setSecond=" + dtstamp_tma_return.getSecond());
180                 System.out.println("******* property - dtstamp *****");
181                 // END - get, set dtstamp
182                 // START - get, set attendee
183                 ICalProperty property_attendee_tma = new ICalProperty(ICalProperty.ICalPropertyKind.ICAL_ATTENDEE_PROPERTY);
184                 property_attendee_tma.set_attendee("John");
185                 String attendee_tma_return = property_attendee_tma.get_attendee();
186                 System.out.println("****** property - attendee ******");
187                 System.out.println("setAttendee=" + attendee_tma_return);
188                 System.out.println("****** property - attendee ******");
189                 // END - get, set attendee
190                 // START - get, set comment
191                 ICalProperty property_comment_tma = new ICalProperty(ICalProperty.ICalPropertyKind.ICAL_COMMENT_PROPERTY);
192                 property_comment_tma.set_comment("John");
193                 String comment_tma_return = property_comment_tma.get_comment();
194                 System.out.println("****** property - comment ******");
195                 System.out.println("setComment=" + comment_tma_return);
196                 System.out.println("****** property - comment ******");
197                 // END - get, set comment
198                 // START - get, set organizer
199                 ICalProperty property_organizer_tma = new ICalProperty(ICalProperty.ICalPropertyKind.ICAL_ORGANIZER_PROPERTY);
200                 property_organizer_tma.set_organizer("John");
201                 String organizer_tma_return = property_organizer_tma.get_organizer();
202                 System.out.println("****** property - organizer ******");
203                 System.out.println("setOrganizer=" + organizer_tma_return);
204                 System.out.println("****** property - organizer ******");
205                 // END - get, set organizer
206
207                 summProp.set_summary("New Year's Eve Party, and more");
208                 System.out.println("done setting summProp");
209                 startProp.set_dtstart(starttime);
210                 System.out.println("done setting startProp");
211                 endProp.set_dtend(endtime);
212                 System.out.println("done setting endProp");
213                 locationProp.set_location("Bothin, Marin County, CA, USA");
214                 System.out.println("done setting locationProp\n");
215                 descProp.set_description("Drive carefully; come to have fun!");
216                 System.out.println("done setting descProp\n");
217
218                 VEvent vEvent = new VEvent();
219                 vEvent.add_property(summProp);
220                 vEvent.add_property(startProp);
221                 vEvent.add_property(endProp);
222                 vEvent.add_property(locationProp);
223                 vEvent.add_property(descProp);
224
225                 ICalTimeType sTime = vEvent.get_dtstart();
226                 ICalTimeType eTime = vEvent.get_dtend();
227
228                 //System.out.println("VEvent:\n" + vEvent.as_ical_string());
229                 System.out.println("Summary: \n" + vEvent.get_summary());
230                 System.out.println("DTSTART: \n" + sTime.getYear() + sTime.getMonth() + sTime.getDay() +
231                                                    sTime.getHour() + sTime.getMinute() + sTime.getSecond());
232                 System.out.println("DTEND: \n"   + eTime.getYear() + eTime.getMonth() + eTime.getDay() +
233                                                    eTime.getHour() + eTime.getMinute() + eTime.getSecond());
234                 System.out.println("Location: \n" + vEvent.get_location());
235                 System.out.println("Description: \n" +vEvent.get_description());
236
237                 VComponent ic = new VComponent(content);
238                 if (ic == null)
239                         System.err.println("Failed to parse component");
240                 System.out.println("VComponent:\n" + ic.as_ical_string());
241
242                 // component is wrapped within BEGIN:VCALENDAR END:VCALENDAR
243                 // we need to unwrap it.
244                 VEvent sub_ic = (VEvent)ic.get_first_component(VComponent.ICalComponentKind.ICAL_VEVENT_COMPONENT);
245                 if (sub_ic == null)
246                         System.out.println("Failed to get subcomponent");
247                 while (sub_ic != null)
248                 {
249                         System.out.println("subcomponent:\n" + sub_ic.as_ical_string());
250                         sub_ic = (VEvent)ic.get_next_component(VComponent.ICalComponentKind.ICAL_VEVENT_COMPONENT);
251                 }
252
253                 // START - get, set recurrenceid
254                 ICalTimeType time_tma = new ICalTimeType();
255                 time_tma.setYear(2002);
256                 time_tma.setMonth(2);
257                 time_tma.setDay(2);
258                 time_tma.setHour(2);
259                 time_tma.setMinute(2);
260                 time_tma.setSecond(2);
261                 time_tma.setIs_utc(true);
262
263                 ic.set_recurrenceid(time_tma);
264
265                 ICalTimeType time_tma_return = new ICalTimeType();
266                 time_tma_return = ic.get_recurrenceid();
267                 System.out.println("****** vcomponent - recurrenceid ******");
268                 System.out.println("setYear=" + time_tma_return.getYear());
269                 System.out.println("setMonth=" + time_tma_return.getMonth());
270                 System.out.println("setDay=" + time_tma_return.getDay());
271                 System.out.println("setHour=" + time_tma_return.getHour());
272                 System.out.println("setMinute=" + time_tma_return.getMinute());
273                 System.out.println("setSecond=" + time_tma_return.getSecond());
274                 System.out.println("****** vcomponent - recurrenceid ******");
275                 // END - get, set recurrenceid
276                 // START - get, set dtstamp
277                 ic.set_dtstamp(time_tma);
278                 ICalTimeType vcomponent_dtstamp_tma_return = ic.get_dtstamp();
279                 System.out.println("****** vcomponent - dtstamp ******");
280                 System.out.println("setYear=" + vcomponent_dtstamp_tma_return.getYear());
281                 System.out.println("setMonth=" + vcomponent_dtstamp_tma_return.getMonth());
282                 System.out.println("setDay=" + vcomponent_dtstamp_tma_return.getDay());
283                 System.out.println("setHour=" + vcomponent_dtstamp_tma_return.getHour());
284                 System.out.println("setMinute=" + vcomponent_dtstamp_tma_return.getMinute());
285                 System.out.println("setSecond=" + vcomponent_dtstamp_tma_return.getSecond());
286                 System.out.println("****** vcomponent - dtstamp ******");
287
288                 // END - get, set dtstamp
289
290                 // VTODO test cases
291
292                 ICalProperty statusProp = new ICalProperty(ICalProperty.ICalPropertyKind.ICAL_STATUS_PROPERTY);
293                 ICalProperty dueProp = new ICalProperty(ICalProperty.ICalPropertyKind.ICAL_DUE_PROPERTY);
294
295                 ICalTimeType duetime = new ICalTimeType();
296                 duetime.setYear(2002);
297                 duetime.setMonth(12);
298                 duetime.setDay(21);
299                 duetime.setHour(18);
300                 duetime.setMinute(0);
301                 duetime.setSecond(0);
302                 duetime.setIs_utc(true);
303                 System.out.println("done creating duetime");
304
305                 statusProp.set_status(ICalProperty.ICalPropertyStatus.ICAL_STATUS_COMPLETED);
306                 dueProp.set_due(duetime);
307
308                 VToDo vtodo = new VToDo();
309
310                 vtodo.add_property(statusProp);
311                 vtodo.add_property(dueProp);
312
313                 System.out.println("VToDo:\n" + vtodo.as_ical_string());
314
315                 // VALARM test cases
316
317                 VAlarm valarm = new VAlarm();
318                 System.out.println("created valarm");
319
320                 // 1. Create a ICAL_DURATION_PROPERTY using the TimePeriod.
321                 ICalDurationType duration = new ICalDurationType();
322                 duration.setDays((long) 0);
323                 duration.setHours((long) 0);
324                 duration.setMinutes((long) 15);
325                 System.out.println("created duration object");
326
327                 // Since we want to trigger before the event or task,
328                 // we always want to set this to 1. If we say this is not
329                 // a negative duration, that means the alarm will trigger
330                 // AFTER the event or task start or due date, which is useless.
331                 duration.setIs_neg(1);
332
333                 // 2. Create a ICalTriggerType oject and set the duration on it.
334                 ICalTriggerType trigger = new ICalTriggerType();
335                 trigger.setDuration(duration);
336                 System.out.println("set trigger to duration object");
337
338                 // 3. Create a trigger ICalProperty and set the trigger on it.
339                 ICalProperty triggerProp = new ICalProperty(ICalProperty.ICalPropertyKind.ICAL_TRIGGER_PROPERTY);
340                 System.out.println("created trigger property");
341                 triggerProp.set_trigger(trigger);
342                 System.out.println("set trigger property");
343                 trigger = triggerProp.get_trigger();
344                 System.out.println("get trigger property");
345
346                 // 4. set the trigger property on the Valarm object.
347                 valarm.add_property(triggerProp);
348                 System.out.println("VAlarm:\n" + valarm.as_ical_string());
349
350                 // 5. create attendee property
351                 String userEmail = "userid@domain";
352                 ICalProperty attendeeProp = new ICalProperty(ICalProperty.ICalPropertyKind.ICAL_ATTENDEE_PROPERTY);
353                 attendeeProp.set_attendee("MAILTO:" + userEmail);
354                 System.out.println("set attendee property");
355                 userEmail = attendeeProp.get_attendee();
356                 System.out.println("get attendee property");
357                 valarm.add_property(attendeeProp);
358                 System.out.println("VAlarm:\n" + valarm.as_ical_string());
359
360                 // START - get, set_role
361                 ICalParameter parameter_role_tma = new ICalParameter(ICalParameter.ICalParameterKind.ICAL_ROLE_PARAMETER);
362                 parameter_role_tma.set_role(ICalParameter.ICalParameterRole.ICAL_ROLE_REQPARTICIPANT);
363                 int role_tma_return = parameter_role_tma.get_role();
364                 System.out.println("******* parameter - role *****");
365                 System.out.println("setRole=" + role_tma_return);
366                 System.out.println("******* parameter - role *****");
367                 // END - get, set_role
368                 // START - get, set_partstat
369                 ICalParameter parameter_partstat_tma = new ICalParameter(ICalParameter.ICalParameterKind.ICAL_PARTSTAT_PARAMETER);
370                 parameter_partstat_tma.set_partstat(ICalParameter.ICalParameterPartStat.ICAL_PARTSTAT_DECLINED);
371                 int partstat_tma_return = parameter_partstat_tma.get_partstat();
372                 System.out.println("******* parameter - partstat *****");
373                 System.out.println("setPartstat=" + partstat_tma_return);
374                 System.out.println("******* parameter - partstat *****");
375                 // END - get, set_partstat
376         }
377 }