Skip to content
This repository has been archived by the owner on Nov 11, 2021. It is now read-only.

Commit

Permalink
Add another unit test for recurrence interval calculation
Browse files Browse the repository at this point in the history
This one is related to weekly recurrence with day-of-week semantics.
  • Loading branch information
Chris Adams committed Oct 17, 2019
1 parent 6fa6ee8 commit 2dd640e
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 1 deletion.
4 changes: 3 additions & 1 deletion kcalcore.pro
@@ -1,3 +1,5 @@
TEMPLATE = subdirs
SUBDIRS += \
kcalcore
kcalcore \
kcalcore/tests
OTHER_FILES += rpm/kcalcore-qt5.spec
2 changes: 2 additions & 0 deletions kcalcore/tests/tests.pro
@@ -0,0 +1,2 @@
TEMPLATE=subdirs
SUBDIRS+=testtimesininterval.pro
54 changes: 54 additions & 0 deletions kcalcore/tests/testtimesininterval.cpp
Expand Up @@ -3,6 +3,7 @@
Copyright (C) 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.net>
Author: Sergio Martins <sergio.martins@kdab.com>
Copyright (C) 2019 Open Mobile Platform LLC
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
Expand All @@ -19,6 +20,7 @@
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/

#include "testtimesininterval.h"
#include "../event.h"

Expand Down Expand Up @@ -183,3 +185,55 @@ void TimesInIntervalTest::testDailyRecurrenceDtStart()

QCOMPARE(expectedEventOccurrences.size(), 0);
}

//Test that the recurrence dtStart is used for calculation and not the interval start date
void TimesInIntervalTest::testWeeklyDayOfWeekRecurrenceDtStart()
{
// Create an all-day event which occurs every weekday of every week,
// starting from Friday the 11th of October.
KCalCore::Event::Ptr event = KCalCore::Event::Ptr(new KCalCore::Event());
event->startUpdates();
event->setUid("event");
event->setLocation(QStringLiteral("Test location"));
event->setAllDay(true);
event->setDescription(QStringLiteral("Test description"));
event->setDtStart(KDateTime::fromString(QStringLiteral("2019-10-11T00:00:00+10:00")));
event->setDtEnd(KDateTime::fromString(QStringLiteral("2019-10-12T00:00:00+10:00")));
event->setSummary(QStringLiteral("Test event summary"));
event->setCategories(QStringList() << QStringLiteral("Category One"));

RecurrenceRule * const rule = new RecurrenceRule();
rule->setRecurrenceType(RecurrenceRule::rWeekly);
rule->setStartDt(event->dtStart());
rule->setFrequency(1);
rule->setByDays(QList<RecurrenceRule::WDayPos>() << RecurrenceRule::WDayPos(0, 1) // monday
<< RecurrenceRule::WDayPos(0, 2) // tuesday
<< RecurrenceRule::WDayPos(0, 3) // wednesday
<< RecurrenceRule::WDayPos(0, 4) // thursday
<< RecurrenceRule::WDayPos(0, 5)); // friday

event->recurrence()->addRRule(rule);
event->endUpdates();

// Expand the events and within a wider interval, but ensure that the
// expansion does not include e.g. Wednesday the 9th of October.
const int days = 7;
const DateTimeList timesInInterval = event->recurrence()->timesInInterval(
event->dtStart().addDays(-days),
event->dtEnd().addDays(days));

QList<KDateTime> expectedEventOccurrences;
for (int i = 0; i <= days; ++i) {
// skip the saturday and sunday as those should not be expected
if (i != 1 && i != 2) {
expectedEventOccurrences << event->dtStart().addDays(i);
}
}

QCOMPARE(expectedEventOccurrences.size(), timesInInterval.size());
foreach (const KDateTime &dt, timesInInterval) {
QCOMPARE(expectedEventOccurrences.removeAll(dt), 1);
}

QCOMPARE(expectedEventOccurrences.size(), 0);
}
1 change: 1 addition & 0 deletions kcalcore/tests/testtimesininterval.h
Expand Up @@ -34,6 +34,7 @@ class TimesInIntervalTest : public QObject
void testSubDailyRecurrence2();
void testSubDailyRecurrenceIntervalLimits();
void testDailyRecurrenceDtStart();
void testWeeklyDayOfWeekRecurrenceDtStart();
};

#endif
19 changes: 19 additions & 0 deletions kcalcore/tests/testtimesininterval.pro
@@ -0,0 +1,19 @@
TEMPLATE = app
TARGET = tst_timesininterval

QT += testlib
CONFIG += link_pkgconfig
PKGCONFIG += libical uuid

DEPENDPATH += . $$PWD/.. $$PWD/../versit $$PWD/../klibport $$PWD/../kdedate
INCLUDEPATH += . $$PWD/.. $$PWD/../versit $$PWD/../klibport $$PWD/../kdedate /usr/include/libical

QMAKE_LIBDIR += $$PWD/..
LIBS += -lkcalcoren-qt5

HEADERS += testtimesininterval.h
SOURCES += testtimesininterval.cpp

target.path = /opt/tests/kcalcore-qt5/

INSTALLS += target
13 changes: 13 additions & 0 deletions rpm/kcalcore-qt5.spec
Expand Up @@ -29,6 +29,14 @@ Requires: %{name} = %{version}-%{release}
This package contains the files necessary to develop
applications using kcalcore

%package tests
Summary: Unit tests for kcalcore
Group: Development/Libraries
Requires: %{name} = %{version}-%{release}

%description tests
This package contains unit tests for kcalcore.

%prep
%setup -q -n %{name}-%{version}

Expand All @@ -53,3 +61,8 @@ rm -rf %{buildroot}
%{_includedir}/kcalcoren-qt5/*
%{_libdir}/libkcalcoren-qt5.so
%{_libdir}/pkgconfig/*.pc

%files tests
%defattr(-,root,root,-)
/opt/tests/kcalcore-qt5/tst_timesininterval
%dir /opt/tests/kcalcore-qt5

0 comments on commit 2dd640e

Please sign in to comment.