aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/cal-util/test-recur.c
diff options
context:
space:
mode:
authorDamon Chaplin <damon@helixcode.com>2000-10-05 08:02:56 +0800
committerDamon Chaplin <damon@src.gnome.org>2000-10-05 08:02:56 +0800
commitaca022a441730b3707c26a6385d8e3c7c492e2cf (patch)
treeda6feb8a311526555f04fbb1ca23d3be50341633 /calendar/cal-util/test-recur.c
parent8fee89d2fb528f546ba2215a0b343068f7afdd3b (diff)
downloadgsoc2013-evolution-aca022a441730b3707c26a6385d8e3c7c492e2cf.tar
gsoc2013-evolution-aca022a441730b3707c26a6385d8e3c7c492e2cf.tar.gz
gsoc2013-evolution-aca022a441730b3707c26a6385d8e3c7c492e2cf.tar.bz2
gsoc2013-evolution-aca022a441730b3707c26a6385d8e3c7c492e2cf.tar.lz
gsoc2013-evolution-aca022a441730b3707c26a6385d8e3c7c492e2cf.tar.xz
gsoc2013-evolution-aca022a441730b3707c26a6385d8e3c7c492e2cf.tar.zst
gsoc2013-evolution-aca022a441730b3707c26a6385d8e3c7c492e2cf.zip
when the user types in a new event, don't create it until the user hits
2000-10-05 Damon Chaplin <damon@helixcode.com> * gui/e-day-view.c: * gui/e-week-view.c: when the user types in a new event, don't create it until the user hits Return or switches focus. Removed the editing_new_event flags. * cal-util/test-recur.c: rewritten to work on ics files. Now I can start testing the recurrence code. * cal-util/cal-recur.c: a few fixes. * gui/e-day-view.c (e_day_view_check_if_new_event_fits): fixed to return TRUE for long events, not FALSE. svn path=/trunk/; revision=5729
Diffstat (limited to 'calendar/cal-util/test-recur.c')
-rw-r--r--calendar/cal-util/test-recur.c345
1 files changed, 84 insertions, 261 deletions
diff --git a/calendar/cal-util/test-recur.c b/calendar/cal-util/test-recur.c
index f3b75eb94f..01a1719903 100644
--- a/calendar/cal-util/test-recur.c
+++ b/calendar/cal-util/test-recur.c
@@ -28,311 +28,134 @@
*/
#include <config.h>
-#include <string.h>
-#include <time.h>
-#include <glib.h>
-#include "cal-recur.h"
-
-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_END 999
-
-static void
-test_yearly ()
-{
- 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, 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);
+#include <stdio.h>
+#include <gtk/gtk.h>
+#include <cal-util/cal-recur.h>
- 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);
+static void usage (void);
+static icalcomponent* scan_vcs_file (char *filename);
+static char* get_line (char *s,
+ size_t size,
+ void *data);
+static void generate_occurrences (icalcomponent *comp);
+static gboolean occurrence_cb (CalComponent *comp,
+ time_t instance_start,
+ time_t instance_end,
+ gpointer data);
-
- 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 ()
+int
+main (int argc,
+ char *argv[])
{
- CalObjTime event_start, interval_start, interval_end;
- CalObjRecurrence recur;
+ gchar *filename;
+ icalcomponent *icalcomp;
- set_time (&event_start, 2000, 0, 1, 0, 0, 0);
+ gtk_init (&argc, &argv);
- /* 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);
+ if (argc != 2)
+ usage ();
- 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);
+ filename = argv[1];
-}
-
-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);
+ icalcomp = scan_vcs_file (filename);
+ if (icalcomp)
+ generate_occurrences (icalcomp);
+ return 0;
}
-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 ()
+usage (void)
{
- 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);
+ g_print ("Usage: test-recur <filename>\n");
+ exit (1);
}
-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 ()
+static icalcomponent*
+scan_vcs_file (char *filename)
{
- 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);
-}
+ FILE *fp;
+ icalcomponent *icalcomp;
+ icalparser *parser;
-int
-main (int argc, char *argv[])
-{
+ g_print ("Opening file: %s\n", filename);
+ fp = fopen (filename, "r");
- test_yearly ();
- test_monthly ();
- test_weekly ();
- test_daily ();
- test_hourly ();
- test_minutely ();
- test_secondly ();
+ if (!fp) {
+ g_print ("Can't open file: %s\n", filename);
+ return NULL;
+ }
- return 0;
-}
+ parser = icalparser_new ();
+ icalparser_set_gen_data (parser, fp);
+ icalcomp = icalparser_parse (parser, get_line);
+ icalparser_free (parser);
-static void
-set_time (CalObjTime *cotime, gint year, gint month, gint day,
- gint hour, gint minute, gint second)
-{
- cotime->year = year;
- cotime->month = month;
- cotime->day = day;
- cotime->hour = hour;
- cotime->minute = minute;
- cotime->second = second;
+ return icalcomp;
}
-static GList*
-build_list (gint first, ...)
+/* Callback used from icalparser_parse() */
+static char *
+get_line (char *s,
+ size_t size,
+ void *data)
{
- 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;
+ return fgets (s, size, (FILE*) data);
}
static void
-do_test (gchar *description,
- CalObjTime *event_start,
- CalObjRecurrence *recur,
- CalObjTime *interval_start,
- CalObjTime *interval_end)
+generate_occurrences (icalcomponent *icalcomp)
{
- GArray *occs;
+ icalcomponent *tmp_icalcomp;
+ CalComponent *comp;
- 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));
+ for (tmp_icalcomp = icalcomponent_get_first_component (icalcomp, ICAL_ANY_COMPONENT);
+ tmp_icalcomp;
+ tmp_icalcomp = icalcomponent_get_next_component (icalcomp, ICAL_ANY_COMPONENT)) {
+ icalcomponent_kind kind;
- occs = cal_obj_expand_recurrence (event_start, recur,
- interval_start, interval_end);
- display_occs (occs);
- g_array_free (occs, TRUE);
-}
+ kind = icalcomponent_isa (tmp_icalcomp);
+ if (!(kind == ICAL_VEVENT_COMPONENT
+ || kind == ICAL_VTODO_COMPONENT
+ || kind == ICAL_VJOURNAL_COMPONENT))
+ continue;
-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" };
+ comp = cal_component_new ();
- month = cotime->month;
- if (month < 0 || month > 12)
- month = 12;
+ if (!cal_component_set_icalcomponent (comp, tmp_icalcomp))
+ continue;
- sprintf (buffer, "%s %2i %02i:%02i:%02i %4i",
- months[month], cotime->day,
- cotime->hour, cotime->minute, cotime->second,
- cotime->year);
+ g_print ("#############################################################################\n");
+ g_print ("%s\n\n", icalcomponent_as_ical_string (tmp_icalcomp));
- return buffer;
+ cal_recur_generate_instances (comp, -1, -1,
+ occurrence_cb, NULL);
+ }
}
-static void
-display_occs (GArray *occs)
-{
- CalObjTime *occ;
- gint len, i;
- struct tm t;
- len = occs->len;
- for (i = 0; i < len; i++) {
- occ = &g_array_index (occs, CalObjTime, i);
+static gboolean
+occurrence_cb (CalComponent *comp,
+ time_t instance_start,
+ time_t instance_end,
+ gpointer data)
+{
+ char start[32], finish[32];
- t.tm_sec = occ->second;
- t.tm_min = occ->minute;
- t.tm_hour = occ->hour;
- t.tm_mday = occ->day;
- t.tm_mon = occ->month;
- t.tm_year = occ->year - 1900;
- t.tm_isdst = -1;
+ strcpy (start, ctime (&instance_start));
+ start[24] = '\0';
+ strcpy (finish, ctime (&instance_end));
+ finish[24] = '\0';
- mktime (&t);
+ g_print ("%s - %s\n", start, finish);
- g_print ("%s", asctime (&t));
- }
+ return TRUE;
}