aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/cal-util/test-recur.c
diff options
context:
space:
mode:
authorDamon Chaplin <damon@helixcode.com>2000-06-16 14:59:18 +0800
committerDamon Chaplin <damon@src.gnome.org>2000-06-16 14:59:18 +0800
commit5ecbc259fa5b8f8c66c5a1eb85fd16fcfcf73b6c (patch)
treeac39306a9060a423a98dab6387434e05da242ebf /calendar/cal-util/test-recur.c
parent8f9d4477d4692e44583ea0aa085f4b9a07e1bffd (diff)
downloadgsoc2013-evolution-5ecbc259fa5b8f8c66c5a1eb85fd16fcfcf73b6c.tar
gsoc2013-evolution-5ecbc259fa5b8f8c66c5a1eb85fd16fcfcf73b6c.tar.gz
gsoc2013-evolution-5ecbc259fa5b8f8c66c5a1eb85fd16fcfcf73b6c.tar.bz2
gsoc2013-evolution-5ecbc259fa5b8f8c66c5a1eb85fd16fcfcf73b6c.tar.lz
gsoc2013-evolution-5ecbc259fa5b8f8c66c5a1eb85fd16fcfcf73b6c.tar.xz
gsoc2013-evolution-5ecbc259fa5b8f8c66c5a1eb85fd16fcfcf73b6c.tar.zst
gsoc2013-evolution-5ecbc259fa5b8f8c66c5a1eb85fd16fcfcf73b6c.zip
updated.
2000-06-16 Damon Chaplin <damon@helixcode.com> * cal-util/test-recur.c: updated. * cal-util/cal-recur.[hc]: mostly finished, though it depends on the iCalObject struct being updated to support more of iCalendar. svn path=/trunk/; revision=3591
Diffstat (limited to 'calendar/cal-util/test-recur.c')
-rw-r--r--calendar/cal-util/test-recur.c259
1 files changed, 241 insertions, 18 deletions
diff --git a/calendar/cal-util/test-recur.c b/calendar/cal-util/test-recur.c
index fd3059113e..83602bb0d6 100644
--- a/calendar/cal-util/test-recur.c
+++ b/calendar/cal-util/test-recur.c
@@ -35,41 +35,198 @@
static void set_time (CalObjTime *cotime, gint year, gint month, gint day,
gint hour, gint minute, gint second);
static void display_occs (GArray *occs);
+static GList* build_list (gint first, ...);
+static gchar* time_to_string (CalObjTime *cotime);
+static void do_test (gchar *description,
+ CalObjTime *event_start,
+ CalObjRecurrence *recur,
+ CalObjTime *interval_start,
+ CalObjTime *interval_end);
-#define LIST_ADD(list, num) \
- list = g_list_prepend (list, GINT_TO_POINTER (num));
+#define LIST_END 999
-int
-main (int argc, char *argv[])
+static void
+test_yearly ()
{
CalObjTime event_start, interval_start, interval_end;
CalObjRecurrence recur;
- GArray *occs;
set_time (&event_start, 2000, 0, 1, 0, 0, 0);
/* We set the interval to a wide range so we just test the event. */
- set_time (&interval_start, 1900, 0, 1, 0, 0, 0);
- set_time (&interval_end, 2100, 0, 1, 0, 0, 0);
+ set_time (&interval_start, 2000, 0, 1, 0, 0, 0);
+ set_time (&interval_end, 2010, 0, 1, 0, 0, 0);
+
+ memset (&recur, 0, sizeof (recur));
+ recur.type = CAL_RECUR_YEARLY;
+ recur.interval = 3;
+ recur.byweekno = build_list (3, 9, 24, LIST_END);
+ recur.byday = build_list (3, 0, 5, 0, LIST_END);
+ do_test ("YEARLY every 3 years in weeks 3, 9, 24 on Thu/Sat",
+ &event_start, &recur, &interval_start, &interval_end);
+
+ set_time (&interval_end, 2002, 0, 1, 0, 0, 0);
memset (&recur, 0, sizeof (recur));
recur.type = CAL_RECUR_YEARLY;
recur.interval = 1;
+ recur.bymonth = build_list (0, 6, LIST_END);
+ recur.byday = build_list (0, 0, 6, 0, LIST_END);
+ do_test ("YEARLY every year in Jan/Jul on Mon/Sun",
+ &event_start, &recur, &interval_start, &interval_end);
- LIST_ADD (recur.byweekno, 3)
- LIST_ADD (recur.byweekno, 9)
- LIST_ADD (recur.byweekno, 24)
- LIST_ADD (recur.byday, 0)
- LIST_ADD (recur.byday, 3)
- LIST_ADD (recur.byday, 0)
- LIST_ADD (recur.byday, 5)
+ memset (&recur, 0, sizeof (recur));
+ recur.type = CAL_RECUR_YEARLY;
+ recur.interval = 1;
+ recur.bymonthday = build_list (3, 7, LIST_END);
+ do_test ("YEARLY every year on 3rd & 7th of the month",
+ &event_start, &recur, &interval_start, &interval_end);
- occs = cal_obj_expand_recurrence (&event_start, &recur,
- &interval_start, &interval_end);
- display_occs (occs);
- g_array_free (occs, TRUE);
+
+ memset (&recur, 0, sizeof (recur));
+ recur.type = CAL_RECUR_YEARLY;
+ recur.interval = 1;
+ recur.byyearday = build_list (15, 126, 360, LIST_END);
+ do_test ("YEARLY every year on 15th, 126th & 360th day of the year",
+ &event_start, &recur, &interval_start, &interval_end);
+
+}
+
+
+static void
+test_monthly ()
+{
+ CalObjTime event_start, interval_start, interval_end;
+ CalObjRecurrence recur;
+
+ set_time (&event_start, 2000, 0, 1, 0, 0, 0);
+
+ /* We set the interval to a wide range so we just test the event. */
+ set_time (&interval_start, 2000, 0, 1, 0, 0, 0);
+ set_time (&interval_end, 2002, 0, 1, 0, 0, 0);
+
+ memset (&recur, 0, sizeof (recur));
+ recur.type = CAL_RECUR_MONTHLY;
+ recur.interval = 1;
+ do_test ("MONTHLY every month",
+ &event_start, &recur, &interval_start, &interval_end);
+
+}
+
+static void
+test_weekly ()
+{
+ CalObjTime event_start, interval_start, interval_end;
+ CalObjRecurrence recur;
+
+ set_time (&event_start, 2000, 0, 1, 0, 0, 0);
+
+ /* We set the interval to a wide range so we just test the event. */
+ set_time (&interval_start, 2000, 0, 1, 0, 0, 0);
+ set_time (&interval_end, 2002, 0, 1, 0, 0, 0);
+
+ memset (&recur, 0, sizeof (recur));
+ recur.type = CAL_RECUR_WEEKLY;
+ recur.interval = 1;
+ do_test ("WEEKLY every week",
+ &event_start, &recur, &interval_start, &interval_end);
+
+}
+
+static void
+test_daily ()
+{
+ CalObjTime event_start, interval_start, interval_end;
+ CalObjRecurrence recur;
+
+ set_time (&event_start, 2000, 0, 1, 0, 0, 0);
+
+ /* We set the interval to a wide range so we just test the event. */
+ set_time (&interval_start, 2000, 0, 1, 0, 0, 0);
+ set_time (&interval_end, 2000, 6, 1, 0, 0, 0);
+
+ memset (&recur, 0, sizeof (recur));
+ recur.type = CAL_RECUR_DAILY;
+ recur.interval = 1;
+ do_test ("DAILY every day",
+ &event_start, &recur, &interval_start, &interval_end);
+
+}
+
+static void
+test_hourly ()
+{
+ CalObjTime event_start, interval_start, interval_end;
+ CalObjRecurrence recur;
+
+ set_time (&event_start, 2000, 0, 1, 2, 15, 0);
+
+ /* We set the interval to a wide range so we just test the event. */
+ set_time (&interval_start, 2000, 0, 1, 0, 0, 0);
+ set_time (&interval_end, 2002, 0, 1, 0, 0, 0);
+
+ memset (&recur, 0, sizeof (recur));
+ recur.type = CAL_RECUR_HOURLY;
+ recur.interval = 3;
+ recur.bymonth = build_list (3, 11, LIST_END);
+ recur.byday = build_list (2, 0, 4, 0, LIST_END);
+ do_test ("HOURLY every 3 hours in Apr/Dec on Wed & Fri",
+ &event_start, &recur, &interval_start, &interval_end);
+}
+
+static void
+test_minutely ()
+{
+ CalObjTime event_start, interval_start, interval_end;
+ CalObjRecurrence recur;
+
+ set_time (&event_start, 2000, 0, 1, 0, 0, 0);
+
+ /* We set the interval to a wide range so we just test the event. */
+ set_time (&interval_start, 2000, 0, 1, 0, 0, 0);
+ set_time (&interval_end, 2000, 0, 2, 0, 0, 0);
+
+ memset (&recur, 0, sizeof (recur));
+ recur.type = CAL_RECUR_MINUTELY;
+ recur.interval = 45;
+ do_test ("MINUTELY every 45 minutes",
+ &event_start, &recur, &interval_start, &interval_end);
+}
+
+static void
+test_secondly ()
+{
+ CalObjTime event_start, interval_start, interval_end;
+ CalObjRecurrence recur;
+
+ set_time (&event_start, 2000, 0, 1, 0, 0, 0);
+
+ /* We set the interval to a wide range so we just test the event. */
+ set_time (&interval_start, 2000, 0, 1, 0, 0, 0);
+ set_time (&interval_end, 2000, 0, 2, 0, 0, 0);
+
+ memset (&recur, 0, sizeof (recur));
+ recur.type = CAL_RECUR_SECONDLY;
+ recur.interval = 15;
+ recur.byhour = build_list (2, 4, 6, LIST_END);
+ recur.byminute = build_list (0, 30, LIST_END);
+ do_test ("SECONDLY every 15 seconds at 2:00,2:30,4:00,4:30,6:00,6:30",
+ &event_start, &recur, &interval_start, &interval_end);
+}
+
+int
+main (int argc, char *argv[])
+{
+
+ test_yearly ();
+ test_monthly ();
+ test_weekly ();
+ test_daily ();
+ test_hourly ();
+ test_minutely ();
+ test_secondly ();
return 0;
}
@@ -88,6 +245,72 @@ set_time (CalObjTime *cotime, gint year, gint month, gint day,
}
+static GList*
+build_list (gint first, ...)
+{
+ va_list args;
+ GList *list;
+ gint num;
+
+ va_start (args, first);
+
+ list = g_list_prepend (NULL, GINT_TO_POINTER (first));
+
+ num = va_arg (args, gint);
+ while (num != LIST_END) {
+ list = g_list_prepend (list, GINT_TO_POINTER (num));
+ num = va_arg (args, gint);
+ }
+
+ list = g_list_reverse (list);
+
+ va_end (args);
+
+ return list;
+}
+
+
+static void
+do_test (gchar *description,
+ CalObjTime *event_start,
+ CalObjRecurrence *recur,
+ CalObjTime *interval_start,
+ CalObjTime *interval_end)
+{
+ GArray *occs;
+
+ g_print ("========================================================\n");
+ g_print ("%s\n", description);
+ g_print ("(From %s", time_to_string (interval_start));
+ g_print (" To %s)\n\n", time_to_string (interval_end));
+
+ occs = cal_obj_expand_recurrence (event_start, recur,
+ interval_start, interval_end);
+ display_occs (occs);
+ g_array_free (occs, TRUE);
+}
+
+
+static gchar*
+time_to_string (CalObjTime *cotime)
+{
+ static gchar buffer[64];
+ gint month;
+ gchar *months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
+ "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "XXX" };
+
+ month = cotime->month;
+ if (month < 0 || month > 12)
+ month = 12;
+
+ sprintf (buffer, "%s %2i %02i:%02i:%02i %4i",
+ months[month], cotime->day,
+ cotime->hour, cotime->minute, cotime->second,
+ cotime->year);
+
+ return buffer;
+}
+
static void
display_occs (GArray *occs)
{