diff options
author | Milan Crha <mcrha@redhat.com> | 2019-05-11 09:21:50 -0400 |
---|---|---|
committer | Allen Winter <allen.winter@kdab.com> | 2019-05-11 09:28:59 -0400 |
commit | 53beb0a86a0c23286dd08f07f4edffdfa9189e1b (patch) | |
tree | 6dcf2bef2e3629b71353989a0c6a9e4e9d08ed3c | |
parent | 9a08148f7db5f570ab3d7f81b3423c963873cfb4 (diff) | |
download | libical-git-53beb0a86a0c23286dd08f07f4edffdfa9189e1b.tar.gz |
improve testing for icalproperty_get_datetime_with_compoment()
when using BUILTIN_TZDATA (and encountering the location fallback)
-rw-r--r-- | src/libical/icalproperty.c | 2 | ||||
-rw-r--r-- | src/test/CMakeLists.txt | 2 | ||||
-rwxr-xr-x | src/test/libical-glib/component.py | 6 | ||||
-rw-r--r-- | src/test/regression.c | 41 |
4 files changed, 40 insertions, 11 deletions
diff --git a/src/libical/icalproperty.c b/src/libical/icalproperty.c index f78533c7..64b50268 100644 --- a/src/libical/icalproperty.c +++ b/src/libical/icalproperty.c @@ -1103,7 +1103,7 @@ struct icaltimetype icalproperty_get_datetime_with_component(icalproperty *prop, if (tz == NULL) tz = icaltimezone_get_builtin_timezone_from_tzid(tzid); - if (!icaltimezone_get_builtin_tzdata() && tz == NULL) + if (tz == NULL) tz = icaltimezone_get_builtin_timezone(tzid); if (tz != NULL) diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt index b1179c2c..db478dcc 100644 --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -22,7 +22,7 @@ endif() set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}) set(TEST_DATADIR "\"${CMAKE_SOURCE_DIR}/test-data\"") -add_definitions(-DTEST_DATADIR=${TEST_DATADIR}) +add_definitions(-DTEST_DATADIR=${TEST_DATADIR} -DTEST_ZONEDIR="${CMAKE_SOURCE_DIR}/zoneinfo") macro(setprops _name) if(UNIX) diff --git a/src/test/libical-glib/component.py b/src/test/libical-glib/component.py index d8443d4e..3f0be729 100755 --- a/src/test/libical-glib/component.py +++ b/src/test/libical-glib/component.py @@ -24,6 +24,9 @@ gi.require_version('ICalGLib', '3.0') from gi.repository import ICalGLib +import os +import sys + event_str1 = \ "BEGIN:VEVENT\n" \ "UID:event-uid-123\n" \ @@ -306,6 +309,9 @@ def main(): prop = comp.get_first_property(ICalGLib.PropertyKind.DTSTART_PROPERTY) prop.remove_parameter_by_kind(ICalGLib.ParameterKind.TZID_PARAMETER) tz = ICalGLib.Timezone.get_builtin_timezone("Europe/Prague") + + ICalGLib.Timezone.set_tzid_prefix(tz.get_tzid().replace("Europe/Prague", "")) + prop.set_parameter(ICalGLib.Parameter.new_tzid(tz.get_tzid())) itt = prop.get_datetime_with_component(comp) diff --git a/src/test/regression.c b/src/test/regression.c index 3bee1ccd..f1ae757a 100644 --- a/src/test/regression.c +++ b/src/test/regression.c @@ -37,6 +37,8 @@ #include <assert.h> #include <stdlib.h> +#define TESTS_TZID_PREFIX "/softwarestudio.org/tests/" + /* For GNU libc, strcmp appears to be a macro, so using strcmp in assert results in incomprehansible assertion messages. This eliminates the problem */ @@ -2623,10 +2625,10 @@ void test_convenience() #if ADD_TESTS_BROKEN_BUILTIN_TZDATA ok("Start is 1997-08-01 12:00:00 Europe/Rome", - (0 == strcmp("1997-08-01 12:00:00 /softwarestudio.org/Europe/Rome", + (0 == strcmp("1997-08-01 12:00:00 " TESTS_TZID_PREFIX "Europe/Rome", ictt_as_string(icalcomponent_get_dtstart(c))))); ok("End is 1997-08-01 13:30:00 Europe/Rome", - (0 == strcmp("1997-08-01 13:30:00 /softwarestudio.org/Europe/Rome", + (0 == strcmp("1997-08-01 13:30:00 " TESTS_TZID_PREFIX "Europe/Rome", ictt_as_string(icalcomponent_get_dtend(c))))); #endif ok("Duration is 90 m", (duration == 90)); @@ -4462,7 +4464,7 @@ void test_set_date_datetime_value(void) void test_timezone_from_builtin(void) { - const char *strcomp = + const char *strcomp_fmt = "BEGIN:VCALENDAR\r\n" "BEGIN:VTIMEZONE\r\n" "TZID:my_zone\r\n" @@ -4477,12 +4479,31 @@ void test_timezone_from_builtin(void) "BEGIN:VEVENT\r\n" "UID:0\r\n" "DTSTART;TZID=my_zone:20180101T010000\r\n" - "DTEND;TZID=/softwarestudio.org/America/New_York:20180101T030000\r\n" + "DTEND;TZID=%s:20180101T030000\r\n" "DUE;TZID=Europe/Berlin:20180101T030000\r\n" "END:VEVENT\r\n" "END:VCALENDAR\r\n"; icalcomponent *comp, *subcomp; + icaltimezone *zone; struct icaltimetype dtstart, dtend, due; + char *strcomp, *tzidprefix, *prevslash = NULL, *prevprevslash = NULL, *p; + int len; + + zone = icaltimezone_get_builtin_timezone("America/New_York"); + tzidprefix = strdup(icaltimezone_get_tzid (zone)); + p = tzidprefix; + while(p = strchr(p + 1, '/'), p) { + prevprevslash = prevslash; + prevslash = p; + } + if(prevprevslash) + prevprevslash[1] = 0; + + icaltimezone_set_tzid_prefix(tzidprefix); + + len = strlen(strcomp_fmt) + strlen(icaltimezone_get_tzid(zone)) + 2; + strcomp = (char *) malloc(len + 1); + snprintf(strcomp, len, strcomp_fmt, icaltimezone_get_tzid(zone)); comp = icalcomponent_new_from_string(strcomp); ok("icalcomponent_new_from_string()", (comp != NULL)); @@ -4497,7 +4518,11 @@ void test_timezone_from_builtin(void) ok("DTEND is America/New_York", (strcmp(icaltimezone_get_location((icaltimezone *) dtend.zone), "America/New_York") == 0)); ok("DUE is Europe/Berlin", (strcmp(icaltimezone_get_location((icaltimezone *) due.zone), "Europe/Berlin") == 0)); + icaltimezone_set_tzid_prefix(TESTS_TZID_PREFIX); + icalcomponent_free(comp); + free(tzidprefix); + free(strcomp); } int main(int argc, char *argv[]) @@ -4515,8 +4540,8 @@ int main(int argc, char *argv[]) int do_header = 0; int failed_count = 0; - set_zone_directory("../../zoneinfo"); - icaltimezone_set_tzid_prefix("/softwarestudio.org/"); + set_zone_directory(TEST_ZONEDIR); + icaltimezone_set_tzid_prefix(TESTS_TZID_PREFIX); test_start(0); @@ -4636,9 +4661,7 @@ int main(int argc, char *argv[]) test_run("Test kind_to_string", test_kind_to_string, do_test, do_header); test_run("Test string_to_kind", test_string_to_kind, do_test, do_header); test_run("Test set DATE/DATE-TIME VALUE", test_set_date_datetime_value, do_test, do_header); - if (!icaltimezone_get_builtin_tzdata()) { - test_run("Test timezone from builtin", test_timezone_from_builtin, do_test, do_header); - } + test_run("Test timezone from builtin", test_timezone_from_builtin, do_test, do_header); /** OPTIONAL TESTS go here... **/ |