summaryrefslogtreecommitdiff
path: root/src/test/regression.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/regression.c')
-rw-r--r--src/test/regression.c434
1 files changed, 371 insertions, 63 deletions
diff --git a/src/test/regression.c b/src/test/regression.c
index 24997d8d..8c4c5d84 100644
--- a/src/test/regression.c
+++ b/src/test/regression.c
@@ -2,28 +2,23 @@
FILE: regression.c
CREATOR: eric 03 April 1999
- (C) COPYRIGHT 1999 Eric Busboom <eric@civicknowledge.com>
+ SPDX-FileCopyrightText: 1999 Eric Busboom <eric@civicknowledge.com>
- This library is free software; you can redistribute it and/or modify
- it under the terms of either:
-
- The LGPL as published by the Free Software Foundation, version
- 2.1, available at: https://www.gnu.org/licenses/lgpl-2.1.html
-
- Or:
-
- The Mozilla Public License Version 2.0. You may obtain a copy of
- the License at https://www.mozilla.org/MPL/
+ SPDX-License-Identifier: LGPL-2.1-only OR MPL-2.0
The original author is Eric Busboom
The original code is regression.c
======================================================================*/
//krazy:skip
+
+# define NO_DEPRECATION_WARNINGS // do not complain about our own deprecated usage
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "regression.h"
+#include "libical/astime.h"
+#include "test-malloc.h"
#include "libical/ical.h"
#include "libicalss/icalss.h"
#include "libicalvcal/icalvcal.h"
@@ -186,9 +181,9 @@ void test_values(void)
str_is("icalvalue_as_ical_string()", icalvalue_as_ical_string(v), "cap://value/2");
- copy = icalvalue_new_clone(v);
+ copy = icalvalue_clone(v);
- str_is("icalvalue_new_clone()", icalvalue_as_ical_string(copy), "cap://value/2");
+ str_is("icalvalue_clone()", icalvalue_as_ical_string(copy), "cap://value/2");
icalvalue_free(v);
icalvalue_free(copy);
@@ -199,8 +194,8 @@ void test_values(void)
ok("icalvalue_set_boolean(2)", (2 == icalvalue_get_boolean(v)));
str_is("icalvalue_as_ical_string()", icalvalue_as_ical_string(v), "TRUE");
- copy = icalvalue_new_clone(v);
- str_is("icalvalue_new_clone()", icalvalue_as_ical_string(copy), "TRUE");
+ copy = icalvalue_clone(v);
+ str_is("icalvalue_clone()", icalvalue_as_ical_string(copy), "TRUE");
icalvalue_free(v);
icalvalue_free(copy);
@@ -211,8 +206,8 @@ void test_values(void)
str_is("icalvalue_set_x(test2)", icalvalue_get_x(v), "test2");
str_is("icalvalue_as_ical_string()", icalvalue_as_ical_string(v), "test2");
- copy = icalvalue_new_clone(v);
- str_is("icalvalue_new_clone()", icalvalue_as_ical_string(copy), "test2");
+ copy = icalvalue_clone(v);
+ str_is("icalvalue_clone()", icalvalue_as_ical_string(copy), "test2");
icalvalue_free(v);
icalvalue_free(copy);
@@ -222,8 +217,8 @@ void test_values(void)
icalvalue_set_datetime(v, icaltime_from_timet_with_zone(1023404802 - 3600, 0, NULL));
str_is("icalvalue_set_datetime()", icalvalue_as_ical_string(v), "20020606T220642");
- copy = icalvalue_new_clone(v);
- str_is("icalvalue_new_clone()", icalvalue_as_ical_string(v), "20020606T220642");
+ copy = icalvalue_clone(v);
+ str_is("icalvalue_clone()", icalvalue_as_ical_string(v), "20020606T220642");
icalvalue_free(v);
icalvalue_free(copy);
@@ -319,12 +314,12 @@ void test_properties(void)
}
str_is("icalproperty_as_ical_string()", icalproperty_as_ical_string(prop), test_ical_str_good);
- clone = icalproperty_new_clone(prop);
+ clone = icalproperty_clone(prop);
if (VERBOSE) {
printf("Clone:\n %s\n", icalproperty_as_ical_string(prop));
}
- str_is("icalproperty_new_clone()", icalproperty_as_ical_string(prop), test_ical_str_good);
+ str_is("icalproperty_clone()", icalproperty_as_ical_string(prop), test_ical_str_good);
icalproperty_free(clone);
icalproperty_free(prop);
@@ -801,7 +796,7 @@ void test_memory(void)
ok("final buffer size == 806", (bufsize == 806));
- free(f);
+ icalmemory_free_buffer(f);
bufsize = 4;
@@ -890,7 +885,7 @@ void test_memory(void)
if (VERBOSE)
printf("Char-by-Char buffer: %s\n", f);
- free(f);
+ icalmemory_free_buffer(f);
for (i = 0; i < 100; i++) {
f = icalmemory_tmp_buffer(bufsize);
@@ -955,7 +950,7 @@ void test_dirset(void)
/* Change the dtstart and dtend times in the component
pointed to by Itr */
- clone = icalcomponent_new_clone(itr);
+ clone = icalcomponent_clone(itr);
assert(icalerrno == ICAL_NO_ERROR);
assert(clone != 0);
@@ -1027,7 +1022,7 @@ void test_compare(void)
icalvalue *v1, *v2;
v1 = icalvalue_new_caladdress("cap://value/1");
- v2 = icalvalue_new_clone(v1);
+ v2 = icalvalue_clone(v1);
ok("compare value and clone", (icalvalue_compare(v1, v2) == ICAL_XLICCOMPARETYPE_EQUAL));
@@ -1140,7 +1135,15 @@ void test_restriction(void)
icalproperty_vanew_dtend(atime,
icalparameter_new_tzid("America/New_York"),
(void *)0),
- icalproperty_new_location("1CP Conference Room 4350"), (void *)0), (void *)0);
+ icalproperty_new_location("1CP Conference Room 4350"),
+ icalcomponent_vanew(ICAL_VALARM_COMPONENT,
+ icalproperty_new_action(ICAL_ACTION_EMAIL),
+ icalproperty_new_repeat(0),
+ icalcomponent_vanew(ICAL_VLOCATION_COMPONENT,
+ (void *)0),
+ (void *)0),
+ (void *)0),
+ (void *)0);
valid = icalrestriction_check(comp);
(void)icalcomponent_as_ical_string(comp);
@@ -1192,7 +1195,7 @@ void test_calendar(void)
c = icalcalendar_get_properties(calendar);
- error = icalfileset_add_component(c, icalcomponent_new_clone(comp));
+ error = icalfileset_add_component(c, icalcomponent_clone(comp));
ok("Adding Clone Component to dirset", (error == ICAL_NO_ERROR));
@@ -1209,17 +1212,17 @@ void print_occur(struct icalrecurrencetype recur, struct icaltimetype start)
struct icaltimetype next;
icalrecur_iterator *ritr;
- time_t tt = icaltime_as_timet(start);
+ icaltime_t tt = icaltime_as_timet(start);
printf("#### %s\n", icalrecurrencetype_as_string(&recur));
- printf("#### %s\n", ctime(&tt));
+ printf("#### %s\n", icalctime(&tt));
ritr = icalrecur_iterator_new(recur, start);
for (next = icalrecur_iterator_next(ritr);
!icaltime_is_null_time(next);
next = icalrecur_iterator_next(ritr)) {
tt = icaltime_as_timet(next);
- printf(" %s", ctime(&tt));
+ printf(" %s", icalctime(&tt));
}
icalrecur_iterator_free(ritr);
@@ -1229,7 +1232,7 @@ void test_recur(void)
{
struct icalrecurrencetype rt;
struct icaltimetype start;
- time_t array[25];
+ icaltime_t array[25];
int i;
rt = icalrecurrencetype_from_string(
@@ -1250,27 +1253,111 @@ void test_recur(void)
for (i = 0; i < 25 && array[i] != 0; i++) {
if (VERBOSE) {
- printf(" %s", ctime(&(array[i])));
+ printf(" %s", icalctime(&(array[i])));
}
}
/* test_increment();*/
}
+void test_recur_encode_by_day()
+{
+ struct icalrecurrencetype rt;
+ int ii;
+
+ rt = icalrecurrencetype_from_string("FREQ=WEEKLY;BYDAY=WE");
+ ok("Is weekly recurrence", (rt.freq == ICAL_WEEKLY_RECURRENCE));
+ ok("The by_day[0] is set", (rt.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX));
+ ok("The by_day[1] is not set", (rt.by_day[1] == ICAL_RECURRENCE_ARRAY_MAX));
+ ok("The day of week is Wednesday", (icalrecurrencetype_day_day_of_week(rt.by_day[0]) == ICAL_WEDNESDAY_WEEKDAY));
+ ok("The position is 0", (icalrecurrencetype_day_position(rt.by_day[0]) == 0));
+ ok("Encoded value matches", (icalrecurrencetype_encode_day(ICAL_WEDNESDAY_WEEKDAY, 0) == rt.by_day[0]));
+
+ rt = icalrecurrencetype_from_string("FREQ=MONTHLY;BYDAY=2FR");
+ ok("Is monthly recurrence", (rt.freq == ICAL_MONTHLY_RECURRENCE));
+ ok("The by_day[0] is set", (rt.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX));
+ ok("The by_day[1] is not set", (rt.by_day[1] == ICAL_RECURRENCE_ARRAY_MAX));
+ ok("The day of week is Friday", (icalrecurrencetype_day_day_of_week(rt.by_day[0]) == ICAL_FRIDAY_WEEKDAY));
+ ok("The position is 2", (icalrecurrencetype_day_position(rt.by_day[0]) == 2));
+ ok("Encoded value matches", (icalrecurrencetype_encode_day(ICAL_FRIDAY_WEEKDAY, 2) == rt.by_day[0]));
+
+ rt = icalrecurrencetype_from_string("FREQ=YEARLY;BYDAY=-3MO");
+ ok("Is yearly recurrence", (rt.freq == ICAL_YEARLY_RECURRENCE));
+ ok("The by_day[0] is set", (rt.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX));
+ ok("The by_day[1] is not set", (rt.by_day[1] == ICAL_RECURRENCE_ARRAY_MAX));
+ ok("The day of week is Monday", (icalrecurrencetype_day_day_of_week(rt.by_day[0]) == ICAL_MONDAY_WEEKDAY));
+ ok("The position is -3", (icalrecurrencetype_day_position(rt.by_day[0]) == -3));
+ ok("Encoded value matches", (icalrecurrencetype_encode_day(ICAL_MONDAY_WEEKDAY, -3) == rt.by_day[0]));
+
+ for (ii = -5; ii <= 5; ii++) {
+ icalrecurrencetype_weekday wd;
+
+ for (wd = ICAL_SUNDAY_WEEKDAY; wd <= ICAL_SATURDAY_WEEKDAY; wd++) {
+ short encoded;
+
+ if (VERBOSE)
+ printf(" Trying weekday %d and position %d\n", wd, ii);
+
+ encoded = icalrecurrencetype_encode_day(wd, ii);
+
+ ok("Decoded day of week matches", (icalrecurrencetype_day_day_of_week(encoded) == wd));
+ ok("Decoded position matches", (icalrecurrencetype_day_position(encoded) == ii));
+ }
+ }
+}
+
+void test_recur_encode_by_month()
+{
+ struct icalrecurrencetype rt;
+ int ii, jj;
+
+ rt = icalrecurrencetype_from_string("FREQ=WEEKLY;BYMONTH=2");
+ ok("Is weekly recurrence", (rt.freq == ICAL_WEEKLY_RECURRENCE));
+ ok("The by_month[0] is set", (rt.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX));
+ ok("The by_month[1] is not set", (rt.by_month[1] == ICAL_RECURRENCE_ARRAY_MAX));
+ ok("The month is 2", (icalrecurrencetype_month_month(rt.by_month[0]) == 2));
+ ok("Is not leap month", (icalrecurrencetype_month_is_leap(rt.by_month[0]) == 0));
+ ok("Encoded value matches", (icalrecurrencetype_encode_month(2, 0) == rt.by_month[0]));
+
+ rt = icalrecurrencetype_from_string("FREQ=MONTHLY;BYMONTH=3L");
+ if (rt.freq != ICAL_NO_RECURRENCE) {
+ ok("Is monthly recurrence", (rt.freq == ICAL_MONTHLY_RECURRENCE));
+ ok("The by_month[0] is set", (rt.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX));
+ ok("The by_month[1] is not set", (rt.by_month[1] == ICAL_RECURRENCE_ARRAY_MAX));
+ ok("The month is 3", (icalrecurrencetype_month_month(rt.by_month[0]) == 3));
+ ok("Is leap month", (icalrecurrencetype_month_is_leap(rt.by_month[0]) != 0));
+ ok("Encoded value matches", (icalrecurrencetype_encode_month(3, 1) == rt.by_month[0]));
+ }
+
+ for (ii = 0; ii <= 1; ii++) {
+ for (jj = 1; jj <= 12; jj++) {
+ short encoded;
+
+ if (VERBOSE)
+ printf(" Trying month %d as %sleap\n", jj, ii ? "" : "not ");
+
+ encoded = icalrecurrencetype_encode_month(jj, ii);
+
+ ok("Decoded month matches", (icalrecurrencetype_month_month(encoded) == jj));
+ ok("Decoded is-leap matches", ((icalrecurrencetype_month_is_leap(encoded) ? 1 : 0) == ii));
+ }
+ }
+}
+
void test_expand_recurrence(void)
{
- time_t arr[10];
- time_t now = 931057385;
+ icaltime_t arr[10];
+ icaltime_t now = 931057385;
int i, numfound = 0;
icalrecur_expand_recurrence("FREQ=MONTHLY;BYDAY=MO,WE", now, 5, arr);
if (VERBOSE)
- printf("Start %s", ctime(&now));
+ printf("Start %s", icalctime(&now));
for (i = 0; i < 5; i++) {
numfound++;
if (VERBOSE)
- printf("i=%d %s\n", i, ctime(&arr[i]));
+ printf("i=%d %s\n", i, icalctime(&arr[i]));
}
int_is("Get an array of 5 items", numfound, 5);
}
@@ -1299,7 +1386,7 @@ void icalrecurrencetype_test(void)
struct icalrecurrencetype r = icalvalue_get_recur(v);
struct icaltimetype t = icaltime_from_timet_with_zone(time(0), 0, NULL);
struct icaltimetype next;
- time_t tt;
+ icaltime_t tt;
struct icalrecur_iterator_impl *itr =
(struct icalrecur_iterator_impl *)icalrecur_iterator_new(r, t);
@@ -1309,7 +1396,7 @@ void icalrecurrencetype_test(void)
next = icalrecur_iterator_next(itr);
tt = icaltime_as_timet(next);
- printf("%s", ctime(&tt));
+ printf("%s", icalctime(&tt));
} while (!icaltime_is_null_time(next));
@@ -1323,7 +1410,7 @@ void test_recur_parameter_bug(void)
{
static const char test_icalcomp_str[] =
"BEGIN:VEVENT\r\n"
- "RRULE;X-EVOLUTION-ENDDATE=20030209T081500:FREQ=DAILY;COUNT=10;INTERVAL=6\r\n"
+ "RRULE;X-EVOLUTION-ENDDATE=20030209T081500:FREQ=DAILY;INTERVAL=6;COUNT=10\r\n"
"END:VEVENT\r\n";
icalcomponent *icalcomp;
@@ -1675,8 +1762,8 @@ void do_test_time(const char *zone)
{
struct icaltimetype ictt, icttutc, icttzone, icttdayl,
icttla, icttny, icttphoenix, icttlocal, icttnorm;
- time_t tt, tt2, tt_p200;
- time_t offset_tz;
+ icaltime_t tt, tt2, tt_p200;
+ icaltime_t offset_tz;
icalvalue *v;
short day_of_week, start_day_of_week, day_of_year;
icaltimezone *azone, *utczone;
@@ -1689,7 +1776,7 @@ void do_test_time(const char *zone)
/* Test new API */
if (VERBOSE) {
- printf("\n---> From time_t \n");
+ printf("\n---> From icaltime_t \n");
}
tt = 1025127869; /* stick with a constant... Wed, 26 Jun 2002 21:44:29 GMT */
@@ -1699,7 +1786,7 @@ void do_test_time(const char *zone)
}
ictt = icaltime_from_timet_with_zone(tt, 0, NULL);
- str_is("Floating time from time_t", ictt_as_string(ictt), "2002-06-26 21:44:29 (floating)");
+ str_is("Floating time from icaltime_t", ictt_as_string(ictt), "2002-06-26 21:44:29 (floating)");
ictt = icaltime_from_timet_with_zone(tt, 0, azone);
#if ADD_TESTS_REQUIRING_INVESTIGATION
@@ -1777,7 +1864,7 @@ void do_test_time(const char *zone)
tt = icaltime_as_timet(ictt);
- ok("test icaltime -> time_t for 20001103T183030Z", (tt == 973276230));
+ ok("test icaltime -> icaltime_t for 20001103T183030Z", (tt == 973276230));
/* Fri Nov 3 10:30:30 PST 2000 in PST
Fri Nov 3 18:30:30 PST 2000 in UTC */
@@ -1802,7 +1889,7 @@ void do_test_time(const char *zone)
/** add test case here.. **/
if (VERBOSE) {
- printf("\n As time_t \n");
+ printf("\n As icaltime_t \n");
}
tt2 = icaltime_as_timet(ictt);
@@ -1822,7 +1909,7 @@ void do_test_time(const char *zone)
printf("20001103T183030 : %s\n", ictt_as_string(icttlocal));
}
- offset_tz = (time_t) (-icaltimezone_get_utc_offset_of_utc_time(azone, &ictt, 0));
+ offset_tz = (icaltime_t) (-icaltimezone_get_utc_offset_of_utc_time(azone, &ictt, 0));
if (VERBOSE)
printf("offset_tz : %ld\n", (long)offset_tz);
@@ -1920,7 +2007,7 @@ void do_test_time(const char *zone)
icaltimezone_get_builtin_timezone("America/Phoenix"));
if (VERBOSE) {
- printf("Orig (ctime): %s\n", ical_timet_string(tt));
+ printf("Orig (icalctime): %s\n", ical_timet_string(tt));
printf("Orig (ical) : %s\n", ictt_as_string(ictt));
printf("UTC : %s\n", ictt_as_string(icttutc));
printf("Los Angeles : %s\n", ictt_as_string(icttla));
@@ -1933,7 +2020,7 @@ void do_test_time(const char *zone)
if (VERBOSE) {
printf("\n Daylight Savings \n");
- printf("Orig (ctime): %s\n", ical_timet_string(tt));
+ printf("Orig (icalctime): %s\n", ical_timet_string(tt));
printf("Orig (ical) : %s\n", ictt_as_string(ictt));
printf("NY : %s\n", ictt_as_string(icttny));
}
@@ -1961,7 +2048,7 @@ void do_test_time(const char *zone)
icaltimezone_get_builtin_timezone("America/Los_Angeles"));
if (VERBOSE) {
- printf("\nOrig (ctime): %s\n", ical_timet_string(tt));
+ printf("\nOrig (icalctime): %s\n", ical_timet_string(tt));
printf("Orig (ical) : %s\n", ictt_as_string(ictt));
printf("LA : %s\n", ictt_as_string(icttla));
}
@@ -2163,7 +2250,7 @@ void test_icalset(void)
icalcomponent *clone;
- clone = icalcomponent_new_clone(c);
+ clone = icalcomponent_clone(c);
(void)icalset_add_component(d, clone);
@@ -2178,12 +2265,12 @@ void test_overlaps(void)
{
icalcomponent *cset, *c;
icalset *set;
- time_t tm1 = 973378800; /*Sat Nov 4 23:00:00 UTC 2000,
+ icaltime_t tm1 = 973378800; /*Sat Nov 4 23:00:00 UTC 2000,
Sat Nov 4 15:00:00 PST 2000 */
- time_t tm2 = 973382400; /*Sat Nov 5 00:00:00 UTC 2000
+ icaltime_t tm2 = 973382400; /*Sat Nov 5 00:00:00 UTC 2000
Sat Nov 4 16:00:00 PST 2000 */
- time_t hh = 1800; /* one half hour */
+ icaltime_t hh = 1800; /* one half hour */
icalfileset_options options = { O_RDONLY, 0644, 0, NULL };
set = icalset_new(ICAL_FILE_SET, TEST_DATADIR "/overlaps.ics", &options);
@@ -2594,7 +2681,7 @@ void test_recur_parser(void)
const char *str;
str =
- "FREQ=YEARLY;UNTIL=20000131T090000Z;BYDAY=-1TU,3WE,-4FR,SA,SU;BYYEARDAY=34,65,76,78;BYMONTH=1,2,3,4,8";
+ "FREQ=YEARLY;BYMONTH=1,2,3,4,8;BYYEARDAY=34,65,76,78;BYDAY=-1TU,3WE,-4FR,SA,SU;UNTIL=20000131T090000Z";
rt = icalrecurrencetype_from_string(str);
str_is(str, icalrecurrencetype_as_string(&rt), str);
@@ -2609,10 +2696,19 @@ void test_recur_parser(void)
icalerror_restore("BADARG", es);
ok("COUNT + UNTIL not allowed", rt.freq == ICAL_NO_RECURRENCE);
+ /* Try to parse a RRULE with illegal BY* part combination */
str = "FREQ=DAILY;COUNT=3;BYDAY=-1TU,3WE,-4FR,SA,SU;BYYEARDAY=34,65,76,78;BYMONTH=1,2,3,4,8";
+ es = icalerror_supress("MALFORMEDDATA");
+ rt = icalrecurrencetype_from_string(str);
+ icalerror_restore("MALFORMEDDATA", es);
+ ok("DAILY + BYYEARDAY not allowed", rt.freq == ICAL_NO_RECURRENCE);
+
+ /* Parse the same RRULE but ignore invalid BY* parts */
+ ical_set_invalid_rrule_handling_setting(ICAL_RRULE_IGNORE_INVALID);
rt = icalrecurrencetype_from_string(str);
- str_is(str, icalrecurrencetype_as_string(&rt), str);
+ str_is(str, icalrecurrencetype_as_string(&rt),
+ "FREQ=DAILY;BYMONTH=1,2,3,4,8;BYDAY=-1TU,3WE,-4FR,SA,SU;COUNT=3");
/* Try to parse an RRULE value with UNTIL + COUNT */
str = "FREQ=YEARLY;UNTIL=20000131T090000Z;COUNT=3";
@@ -2621,7 +2717,89 @@ void test_recur_parser(void)
rt = icalrecurrencetype_from_string(str);
icalerror_restore("MALFORMEDDATA", es);
ok(str, rt.freq == ICAL_NO_RECURRENCE);
- free(v);
+ icalmemory_free_buffer(v);
+}
+
+static int test_juldat_caldat_instance(long year, int month, int day) {
+
+ struct icaltimetype t;
+ struct ut_instant originalInstant;
+
+ memset(&t, 0, sizeof(t));
+ t.year = year;
+ t.month = month;
+ t.day = day;
+
+ memset(&originalInstant, 0, sizeof(originalInstant));
+ originalInstant.year = year;
+ originalInstant.month = month;
+ originalInstant.day = day;
+
+ juldat(&originalInstant);
+ caldat(&originalInstant);
+
+ if (icaltime_day_of_week(t) != originalInstant.weekday + 1)
+ return -1;
+
+ if (icaltime_start_doy_week(t, 1) != originalInstant.day_of_year - originalInstant.weekday)
+ return -1;
+
+ if (icaltime_week_number(t) != (originalInstant.day_of_year - originalInstant.weekday) / 7)
+ return -1;
+
+ return 0;
+}
+
+/*
+ * This test verifies the caldat_int and juldat_int functions. The functions are reworked versions
+ * of the original caldat and juldat functions but avoid using floating point arithmetic. As the
+ * new functions are not exported, the test cannot access them directly. It therefore checks the
+ * output of the icaltime_day_of_week, icaltime_start_doy_week and icaltime_week_number functions
+ * which are based on the functions to be tested.
+ */
+void test_juldat_caldat() {
+
+ int i;
+ int failed = 0;
+
+ ok("juldat and caldat return the expected values for specified min input values", test_juldat_caldat_instance(-4713, 1, 1) == 0);
+ ok("juldat and caldat return the expected values for specified max input values", test_juldat_caldat_instance(+32767, 12, 31) == 0);
+
+ ok("juldat and caldat return the expected values before end of julian calendar", test_juldat_caldat_instance(1582, 10, 4) == 0);
+ ok("juldat and caldat return the expected values at end of julian calendar", test_juldat_caldat_instance(1582, 10, 5) == 0);
+ ok("juldat and caldat return the expected values before introduction of gregorian calendar", test_juldat_caldat_instance(1582, 10, 14) == 0);
+ ok("juldat and caldat return the expected values at introduction of gregorian calendar", test_juldat_caldat_instance(1582, 10, 15) == 0);
+ ok("juldat and caldat return the expected values after introduction of gregorian calendar", test_juldat_caldat_instance(1582, 10, 16) == 0);
+
+ for (i = 0; i < 2582; i++) {
+
+ long y = i;
+
+ failed |= (test_juldat_caldat_instance(y, 1, 1) != 0);
+ failed |= (test_juldat_caldat_instance(y, 2, 28) != 0);
+
+ // Not every year has a leap day, but juldat_int/caldat_int should still produce
+ // the same output as the original implementation.
+ failed |= (test_juldat_caldat_instance(y, 2, 29) != 0);
+ failed |= (test_juldat_caldat_instance(y, 3, 1) != 0);
+ failed |= (test_juldat_caldat_instance(y, 12, 31) != 0);
+ }
+ ok("juldat and caldat return the expected values for random input values", failed == 0);
+
+ failed = 0;
+ for (i = 0; i < 10000; i++) {
+ /* coverity[dc.weak_crypto] */
+ long y = rand() % 2582;
+ int m = rand() % 12 + 1;
+
+ // Might produce some invalid dates, but juldat_int/caldat_int should still produce
+ // the same output as the original implementation.
+ int d = rand() % 31 + 1;
+
+ failed |= (test_juldat_caldat_instance(y, m, d) != 0);
+ }
+
+ ok("juldat and caldat return the expected values for random input values", failed == 0);
}
char *ical_strstr(const char *haystack, const char *needle)
@@ -2687,7 +2865,7 @@ void test_doy(void)
stm.tm_year = tt1.year - 1900;
stm.tm_isdst = -1;
- (void)mktime(&stm);
+ (void)icalmktime(&stm);
doy = icaltime_day_of_year(tt1);
@@ -3269,7 +3447,7 @@ void test_file_locks(void)
(void)icalfileset_add_component(fs, c);
- c2 = icalcomponent_new_clone(c);
+ c2 = icalcomponent_clone(c);
(void)icalfileset_add_component(fs, c2);
@@ -3305,7 +3483,7 @@ void test_file_locks(void)
icalcomponent_set_duration(c, d);
icalcomponent_set_summary(c, "Child");
- c2 = icalcomponent_new_clone(c);
+ c2 = icalcomponent_clone(c);
icalcomponent_set_summary(c2, "Child");
(void)icalfileset_add_component(fs, c2);
@@ -3338,7 +3516,7 @@ void test_file_locks(void)
icalcomponent_set_duration(c, d);
icalcomponent_set_summary(c, "Parent");
- c2 = icalcomponent_new_clone(c);
+ c2 = icalcomponent_clone(c);
icalcomponent_set_summary(c2, "Parent");
(void)icalfileset_add_component(fs, c2);
@@ -4195,6 +4373,86 @@ void test_comma_in_quoted_value(void)
icalcomponent_free(c);
}
+void test_geo_props(void)
+{
+ int estate;
+ icalcomponent *c;
+ icalproperty *p;
+
+ c = icalparser_parse_string("BEGIN:VEVENT\n" "GEO:49.42612;7.75473\n" "END:VEVENT\n");
+ ok("icalparser_parse_string()", (c != NULL));
+ if (!c) {
+ exit(EXIT_FAILURE);
+ }
+ if (VERBOSE)
+ printf("%s", icalcomponent_as_ical_string(c));
+ p = icalcomponent_get_first_property(c, ICAL_GEO_PROPERTY);
+ str_is("icalproperty_get_value_as_string() works",
+ icalproperty_get_value_as_string(p), "49.42612;7.75473");
+ icalcomponent_free(c);
+
+ c = icalparser_parse_string("BEGIN:VEVENT\n" "GEO:-0;+0\n" "END:VEVENT\n");
+ ok("icalparser_parse_string()", (c != NULL));
+ if (!c) {
+ exit(EXIT_FAILURE);
+ }
+ if (VERBOSE)
+ printf("%s", icalcomponent_as_ical_string(c));
+ p = icalcomponent_get_first_property(c, ICAL_GEO_PROPERTY);
+ str_is("icalproperty_get_value_as_string() works",
+ icalproperty_get_value_as_string(p), "-0;+0");
+ icalcomponent_free(c);
+
+ /* failure situations */
+ estate = icalerror_get_errors_are_fatal();
+ icalerror_set_errors_are_fatal(0);
+ c = icalparser_parse_string("BEGIN:VEVENT\n" "GEO:-0a;+0\n" "END:VEVENT\n");
+ if (!c) {
+ exit(EXIT_FAILURE);
+ }
+ if (VERBOSE)
+ printf("%s", icalcomponent_as_ical_string(c));
+ p = icalcomponent_get_first_property(c, ICAL_GEO_PROPERTY);
+ ok("expected fail icalcomponent_get_first_property()", (p == NULL));
+ icalcomponent_free(c);
+
+ c = icalparser_parse_string("BEGIN:VEVENT\n" "GEO:16.815151515151515151;+0\n" "END:VEVENT\n");
+ if (!c) {
+ exit(EXIT_FAILURE);
+ }
+ if (VERBOSE)
+ printf("%s", icalcomponent_as_ical_string(c));
+ p = icalcomponent_get_first_property(c, ICAL_GEO_PROPERTY);
+ ok("expected fail icalcomponent_get_first_property()", (p == NULL));
+ icalcomponent_free(c);
+
+ icalerror_set_errors_are_fatal(estate);
+}
+
+void test_zoneinfo_stuff(void)
+{
+#if defined(HAVE_SETENV)
+ setenv("TZDIR", TEST_DATADIR, 1);
+#else
+ char tzdir[256] = {0};
+ strncat(tzdir, "TZDIR=" TEST_DATADIR, 255);
+ putenv(tzdir);
+#endif
+ icaltzutil_set_zone_directory(NULL); /*resets to empty */
+ str_is("icaltzutil_get_zone_directory by TZDIR", icaltzutil_get_zone_directory(), TEST_DATADIR);
+ icaltzutil_set_zone_directory("foo");
+ str_is("icaltzutil_get_zone_directory", icaltzutil_get_zone_directory(), "foo");
+
+ /* reset the environment */
+#if defined(HAVE_SETENV)
+ unsetenv("TZDIR");
+#else
+ strcpy(tzdir, "TZDIR=");
+ putenv(tzdir);
+#endif
+ icaltzutil_set_zone_directory(NULL);
+}
+
void test_tzid_with_utc_time(void)
{
const char *strcomp =
@@ -4459,7 +4717,7 @@ void test_timezone_from_builtin(void)
comp = icaltimezone_get_component(zone);
strcomp = icalcomponent_as_ical_string_r(comp);
comp = icalcomponent_new_from_string(strcomp);
- free(strcomp);
+ icalmemory_free_buffer(strcomp);
ok("VTIMEZONE icalcomponent_new_from_string()", (comp != NULL));
@@ -4513,6 +4771,39 @@ void test_icalvalue_decode_ical_string(void)
ok("Properly decoded", (strcmp(buff, "a\\") == 0));
}
+static int test_icalarray_sort_compare_char(const void* p1, const void* p2) {
+
+ char c1 = *((char*)p1);
+ char c2 = *((char*)p2);
+
+ return (c1 < c2) ? -1 : ((c1 > c2) ? 1 : 0);
+}
+
+void test_icalarray_sort(void)
+{
+ /* this test is based on the work from the PDCLib project */
+
+ char presort[] = { "shreicnyjqpvozxmbt" };
+ char sorted1[] = { "bcehijmnopqrstvxyz" };
+ unsigned int i;
+
+ icalarray * array = icalarray_new(1, 2);
+
+ for (i = 0; i < sizeof(presort)-1; i++) {
+ icalarray_append(array, &presort[i]);
+ }
+
+ icalarray_sort(array, test_icalarray_sort_compare_char);
+
+ for (i = 0; i < sizeof(presort)-1; i++) {
+ void* pItem = icalarray_element_at(array, i);
+ char c = *((char*)pItem);
+ ok("icalarray_sort - item sorted as expected", c == sorted1[i]);
+ }
+
+ icalarray_free(array);
+}
+
void test_icalcomponent_normalize(void)
{
const char *calStr1 =
@@ -4808,7 +5099,6 @@ static void test_implicit_dtend_duration(void)
int_is("icaltime_compare(start, end)", 0, icaltime_compare(start, end));
icalcomponent_free(c);
-
c = icalcomponent_vanew(
ICAL_VCALENDAR_COMPONENT,
icalcomponent_vanew(
@@ -4993,7 +5283,7 @@ void test_icaltime_as_timet(void)
ok("icaltime_from_string translates 19970717T235959Z to 869183999", icaltime_as_timet(icaltime_from_string("19970717T235959Z")) == 869183999);
ok("icaltime_from_string translates 20241202T235959Z to 1733183999", icaltime_as_timet(icaltime_from_string("20241202T235959Z")) == 1733183999);
ok("icaltime_from_string translates 20371231T235959Z to 2145916799", icaltime_as_timet(icaltime_from_string("20371231T235959Z")) == 2145916799);
-#if (SIZEOF_TIME_T > 4)
+#if (SIZEOF_ICALTIME_T > 4)
ok("icaltime_from_string translates 20520419T235959Z to 2597183999", icaltime_as_timet(icaltime_from_string("20520419T235959Z")) == 2597183999);
ok("icaltime_from_string translates 20790905T235959Z to 3461183999", icaltime_as_timet(icaltime_from_string("20790905T235959Z")) == 3461183999);
ok("icaltime_from_string translates 21000101T235959Z to 4102531199", icaltime_as_timet(icaltime_from_string("21000101T235959Z")) == 4102531199);
@@ -5064,6 +5354,17 @@ int main(int argc, char *argv[])
int do_header = 0;
int failed_count = 0;
+#if !defined(MEMORY_CONSISTENCY)
+ // With MEMORY_CONSISTENCY we are building the entire library using the
+ // test_* functions; therefore, no need to set them here again.
+
+ // We specify special versions of malloc et al. that perform some extra verifications.
+ // Most notably they ensure, that memory allocated with icalmemory_new_buffer() is freed
+ // using icalmemory_free() rather than using free() directly and vice versa. Failing to
+ // do so would cause the test to fail with assertions or access violations.
+ icalmemory_set_mem_alloc_funcs(&test_malloc, &test_realloc, &test_free);
+#endif
+
set_zone_directory(TEST_ZONEDIR);
icaltimezone_set_tzid_prefix(TESTS_TZID_PREFIX);
@@ -5106,6 +5407,7 @@ int main(int argc, char *argv[])
test_run("Test time parser functions", test_time_parser, do_test, do_header);
test_run("Test icaltime_as_timet", test_icaltime_as_timet, do_test, do_header);
test_run("Test time", test_time, do_test, do_header);
+ test_run("Test calculation of DOY and WD", test_juldat_caldat, do_test, do_header);
test_run("Test day of Year", test_doy, do_test, do_header);
test_run("Test duration", test_duration, do_test, do_header);
test_run("Test period", test_period, do_test, do_header);
@@ -5113,6 +5415,8 @@ int main(int argc, char *argv[])
test_run("Test day of year of week start", test_start_of_week, do_test, do_header);
test_run("Test recur parser", test_recur_parser, do_test, do_header);
test_run("Test recur", test_recur, do_test, do_header);
+ test_run("Test recur encode by_day", test_recur_encode_by_day, do_test, do_header);
+ test_run("Test recur encode by_month", test_recur_encode_by_month, do_test, do_header);
test_run("Test Recurring Events File", test_recur_file, do_test, do_header);
test_run("Test parameter bug", test_recur_parameter_bug, do_test, do_header);
test_run("Test Array Expansion", test_expand_recurrence, do_test, do_header);
@@ -5179,6 +5483,7 @@ int main(int argc, char *argv[])
do_header);
test_run("Test comma in quoted value of x property", test_comma_in_quoted_value, do_test,
do_header);
+ test_run("Test setting/unsetting zoneinfo dir", test_zoneinfo_stuff, do_test, do_header);
test_run("Test TZID with UTC time", test_tzid_with_utc_time, do_test, do_header);
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);
@@ -5186,12 +5491,15 @@ int main(int argc, char *argv[])
test_run("Test timezone from builtin", test_timezone_from_builtin, do_test, do_header);
test_run("Test icalvalue_decode_ical_string", test_icalvalue_decode_ical_string, do_test, do_header);
+ test_run("Test icalarray_sort", test_icalarray_sort, do_test, do_header);
+
test_run("Test icalcomponent_normalize", test_icalcomponent_normalize, do_test, do_header);
test_run("Test builtin compat TZID", test_builtin_compat_tzid, do_test, do_header);
test_run("Test VCC vCard parse", test_vcc_vcard_parse, do_test, do_header);
test_run("Test implicit DTEND and DURATION for VEVENT and VTODO", test_implicit_dtend_duration, do_test, do_header);
test_run("Test icalvalue resets timezone on set", test_icalvalue_resets_timezone_on_set, do_test, do_header);
test_run("Test removing TZID from DUE with icalcomponent_set_due", test_remove_tzid_from_due, do_test, do_header);
+ test_run("Test geo precision", test_geo_props, do_test, do_header);
test_run("Test commas in x-property", test_comma_in_xproperty, do_test, do_header);
test_run("Test icalcomponent_vanew with lastmodified property", test_icalcomponent_with_lastmodified, do_test, do_header);