test: Add event_date_edit_tzid

This new test check that the tz data in the component is set correctly
after editing an event date end.

See https://gitlab.gnome.org/GNOME/gnome-calendar/-/issues/170
This commit is contained in:
Daniel Garcia Moreno
2023-11-09 20:59:59 +00:00
committed by Georges Basile Stavracas Neto
parent 20aa929966
commit 68c921bf60
4 changed files with 105 additions and 43 deletions
+4 -9
View File
@@ -216,17 +216,12 @@ static ECalComponentDateTime*
build_component_from_datetime (GcalEvent *self,
GDateTime *dt)
{
GcalApplication *application;
GcalContext *context;
ICalTime *itt;
gchar *tzid;
ICalTime *itt = NULL;
gchar *tzid = NULL;
if (!dt)
return NULL;
application = GCAL_APPLICATION (g_application_get_default ());
context = gcal_application_get_context (application);
itt = gcal_date_time_to_icaltime (dt);
if (self->all_day)
@@ -236,10 +231,10 @@ build_component_from_datetime (GcalEvent *self,
}
else
{
g_autoptr (GTimeZone) zone = NULL;
ICalTimezone *tz;
GTimeZone *zone;
zone = gcal_context_get_timezone (context);
zone = gcal_util_get_app_timezone_or_local ();
tz = gcal_timezone_to_icaltimezone (zone);
i_cal_time_set_timezone (itt, tz);
tzid = g_strdup (i_cal_timezone_get_tzid (tz));
+34 -19
View File
@@ -401,17 +401,13 @@ build_component_from_details (const gchar *summary,
GDateTime *initial_date,
GDateTime *final_date)
{
GcalApplication *application;
GcalContext *context;
ECalComponent *event;
ECalComponentDateTime *dt;
ECalComponentText *summ;
ICalTimezone *tz;
ICalTime *itt;
gboolean all_day;
ECalComponent *event = NULL;
ECalComponentDateTime *dt = NULL;
ECalComponentText *summ = NULL;
ICalTimezone *tz = NULL;
ICalTime *itt = NULL;
gboolean all_day = FALSE;
application = GCAL_APPLICATION (g_application_get_default ());
context = gcal_application_get_context (application);
event = e_cal_component_new ();
e_cal_component_set_new_vtype (event, E_CAL_COMPONENT_EVENT);
@@ -431,9 +427,8 @@ build_component_from_details (const gchar *summary,
}
else
{
GTimeZone *zone;
zone = gcal_context_get_timezone (context);
g_autoptr (GTimeZone) zone = NULL;
zone = gcal_util_get_app_timezone_or_local ();
tz = gcal_timezone_to_icaltimezone (zone);
}
@@ -515,16 +510,12 @@ icaltime_compare_with_current (const ICalTime *date1,
const ICalTime *date2,
time_t *current_time_t)
{
GcalApplication *application;
GcalContext *context;
GTimeZone *zone;
g_autoptr (GTimeZone) zone = NULL;
ICalTimezone *zone1, *zone2;
gint result = 0;
time_t start1, start2, diff1, diff2;
application = GCAL_APPLICATION (g_application_get_default ());
context = gcal_application_get_context (application);
zone = gcal_context_get_timezone (context);
zone = gcal_util_get_app_timezone_or_local ();
zone1 = i_cal_time_get_timezone (date1);
if (!zone1)
@@ -1328,3 +1319,27 @@ gcal_util_translate_time_string (const gchar *str)
return res;
}
/**
* gcal_util_get_app_timezone_or_local:
*
* Returns a new reference to the application context timezone. If
* g_application_get_default() returns null, because there's no default
* application, it'll return a new local timezone created with
* g_timezone_new_local().
*
* Returns: (transfer full): a #GTimeZone
*/
GTimeZone *
gcal_util_get_app_timezone_or_local ()
{
GcalApplication *application = NULL;
GcalContext *context = NULL;
application = GCAL_APPLICATION (g_application_get_default ());
if (!application)
return g_time_zone_new_local ();
context = gcal_application_get_context (application);
return g_time_zone_ref (gcal_context_get_timezone (context));
}
+2
View File
@@ -136,4 +136,6 @@ void gcal_utils_ask_recurrence_modification_type (GtkWidget
const gchar * gcal_util_translate_time_string (const gchar *str);
GTimeZone * gcal_util_get_app_timezone_or_local ();
#endif /* __GCAL_UTILS_H__ */
+65 -15
View File
@@ -48,15 +48,15 @@
"SUMMARY:Stub event\n" \
"UID:example@uid\n" \
"DTSTAMP:19970114T170000Z\n" \
"DTSTART:"dtstart"\n" \
"DTEND:"dtend"\n" \
"DTSTART"dtstart"\n" \
"DTEND"dtend"\n" \
"END:VEVENT\n"
#define EVENT_STRING_FOR_DATE_START(dtstart) \
EVENT_STRING_FOR_DATE(dtstart, "20180715T035959Z")
EVENT_STRING_FOR_DATE(dtstart, ":20180715T035959Z")
#define EVENT_STRING_FOR_DATE_END(dtend) \
EVENT_STRING_FOR_DATE("19970101T170000Z", dtend)
EVENT_STRING_FOR_DATE(":19970101T170000Z", dtend)
@@ -183,9 +183,9 @@ event_date_start (void)
GDateTime *datetime;
}
start_dates[] = {
{ EVENT_STRING_FOR_DATE_START ("20160229T000000Z"), g_date_time_new_utc (2016, 2, 29, 00, 00, 00.) },
{ EVENT_STRING_FOR_DATE_START ("20180228T170000Z"), g_date_time_new_utc (2018, 2, 28, 17, 00, 00.) },
{ EVENT_STRING_FOR_DATE_START ("20180714T170000Z"), g_date_time_new_utc (2018, 7, 14, 17, 00, 00.) },
{ EVENT_STRING_FOR_DATE_START (":20160229T000000Z"), g_date_time_new_utc (2016, 2, 29, 00, 00, 00.) },
{ EVENT_STRING_FOR_DATE_START (":20180228T170000Z"), g_date_time_new_utc (2018, 2, 28, 17, 00, 00.) },
{ EVENT_STRING_FOR_DATE_START (":20180714T170000Z"), g_date_time_new_utc (2018, 7, 14, 17, 00, 00.) },
};
guint i;
@@ -215,9 +215,9 @@ event_date_end (void)
GDateTime *datetime;
}
end_dates[] = {
{ EVENT_STRING_FOR_DATE_END ("20160229T000000Z"), g_date_time_new_utc (2016, 2, 29, 00, 00, 00.) },
{ EVENT_STRING_FOR_DATE_END ("20180228T170000Z"), g_date_time_new_utc (2018, 2, 28, 17, 00, 00.) },
{ EVENT_STRING_FOR_DATE_END ("20180714T170000Z"), g_date_time_new_utc (2018, 7, 14, 17, 00, 00.) },
{ EVENT_STRING_FOR_DATE_END (":20160229T000000Z"), g_date_time_new_utc (2016, 2, 29, 00, 00, 00.) },
{ EVENT_STRING_FOR_DATE_END (":20180228T170000Z"), g_date_time_new_utc (2018, 2, 28, 17, 00, 00.) },
{ EVENT_STRING_FOR_DATE_END (":20180714T170000Z"), g_date_time_new_utc (2018, 7, 14, 17, 00, 00.) },
};
guint i;
@@ -242,9 +242,9 @@ static void
event_date_singleday (void)
{
const gchar * const events[] = {
EVENT_STRING_FOR_DATE ("20160229T000000Z", "20160229T030000Z"),
EVENT_STRING_FOR_DATE ("20160229T000000Z", "20160301T000000Z"),
EVENT_STRING_FOR_DATE ("20160229T000000Z", "20160229T235959Z"),
EVENT_STRING_FOR_DATE (":20160229T000000Z", ":20160229T030000Z"),
EVENT_STRING_FOR_DATE (":20160229T000000Z", ":20160301T000000Z"),
EVENT_STRING_FOR_DATE (":20160229T000000Z", ":20160229T235959Z"),
};
guint i;
@@ -267,8 +267,8 @@ static void
event_date_multiday (void)
{
const gchar * const events[] = {
EVENT_STRING_FOR_DATE ("20160229T000000Z", "20160302T000001Z"),
EVENT_STRING_FOR_DATE ("20160229T020000Z", "20160310T004500Z"),
EVENT_STRING_FOR_DATE (":20160229T000000Z", ":20160302T000001Z"),
EVENT_STRING_FOR_DATE (":20160229T020000Z", ":20160310T004500Z"),
};
guint i;
@@ -287,6 +287,55 @@ event_date_multiday (void)
/*********************************************************************************************************************/
static void
event_date_edit_tzid (void)
{
struct {
const gchar *string;
const gchar *tz;
} events[] = {
{
EVENT_STRING_FOR_DATE (";TZID=Europe/Madrid:20170818T130000", ";TZID=Europe/Madrid:20170818T140000"),
"Europe/Madrid"
},
{
// https://gitlab.gnome.org/GNOME/gnome-calendar/-/issues/170
EVENT_STRING_FOR_DATE (";TZID=Europe/London:20170818T130000", ";TZID=Europe/London:20170818T140000"),
"Europe/London"
},
{
EVENT_STRING_FOR_DATE (";TZID=America/Costa_Rica:20170818T130000", ";TZID=America/Costa_Rica:20170818T140000"),
"America/Costa_Rica"
},
};
g_test_bug ("170");
for (size_t i = 0; i < G_N_ELEMENTS (events); i++)
{
g_autoptr (GDateTime) datetime = NULL;
g_autoptr (GTimeZone) timezone = NULL;
g_autoptr (GcalEvent) event = NULL;
g_autoptr (GError) error = NULL;
ECalComponentDateTime *dt_end = NULL;
event = create_event_for_string (events[i].string, &error);
g_assert_no_error (error);
// modify the event and check the tz in the result
timezone = g_time_zone_new_identifier (events[i].tz);
datetime = g_date_time_new (timezone, 2017, 8, 18, 15, 00, 00.);
gcal_event_set_date_end (event, datetime);
dt_end = e_cal_component_get_dtend (gcal_event_get_component (event));
g_assert_cmpstr (e_cal_component_datetime_get_tzid (dt_end), ==, "UTC");
e_cal_component_datetime_free (dt_end);
}
}
/*********************************************************************************************************************/
gint
main (gint argc,
gchar *argv[])
@@ -305,6 +354,7 @@ main (gint argc,
g_test_add_func ("/event/date/end", event_date_end);
g_test_add_func ("/event/date/singleday", event_date_singleday);
g_test_add_func ("/event/date/multiday", event_date_multiday);
g_test_add_func ("/event/date/edit-tzid", event_date_edit_tzid);
return g_test_run ();
}