Skip to content

Commit

Permalink
[mkcal] Add a test for alarms.
Browse files Browse the repository at this point in the history
  • Loading branch information
dcaliste committed Mar 12, 2020
1 parent 8a63fef commit ba6ebdd
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 2 deletions.
6 changes: 4 additions & 2 deletions tests/tests.pro
@@ -1,14 +1,16 @@
TEMPLATE = app
TARGET = tst_storage

QT += testlib
QT += testlib dbus
CONFIG += link_pkgconfig c++11

DEFINES += TIMED_SUPPORT

INCLUDEPATH += ../src
QMAKE_LIBDIR += ../src

LIBS += -lmkcal-qt5
PKGCONFIG += libkcalcoren-qt5 sqlite3
PKGCONFIG += libkcalcoren-qt5 sqlite3 timed-qt5

HEADERS += \
tst_storage.h
Expand Down
79 changes: 79 additions & 0 deletions tests/tst_storage.cpp
Expand Up @@ -27,6 +27,12 @@

#include "tst_storage.h"
#include "sqlitestorage.h"
#ifdef TIMED_SUPPORT
#include <timed-qt5/interface.h>
#include <QtCore/QMap>
#include <QtDBus/QDBusReply>
using namespace Maemo;
#endif

// random
const char *const NotebookId("12345678-9876-1111-2222-222222222222");
Expand Down Expand Up @@ -1672,6 +1678,79 @@ void tst_storage::tst_calendarProperties()
sqlite3_close(database);
}

void tst_storage::tst_alarms()
{
Notebook::Ptr notebook = Notebook::Ptr(new Notebook(QStringLiteral("Notebook for alarms"), QString()));
QVERIFY(m_storage->addNotebook(notebook));
const QString uid = notebook->uid();

const KDateTime dt = KDateTime::currentUtcDateTime().addSecs(300);
KCalCore::Event::Ptr ev = KCalCore::Event::Ptr(new KCalCore::Event);
ev->setDtStart(dt);
KCalCore::Alarm::Ptr alarm = ev->newAlarm();
alarm->setDisplayAlarm(QLatin1String("Testing alarm"));
alarm->setStartOffset(KCalCore::Duration(0));
alarm->setEnabled(true);
QVERIFY(m_calendar->addEvent(ev, uid));
QVERIFY(m_storage->save());

#if defined(TIMED_SUPPORT)
QMap<QString, QVariant> map;
map["APPLICATION"] = "libextendedkcal";
map["notebook"] = uid;

Timed::Interface timed;
QVERIFY(timed.isValid());
QDBusReply<QList<QVariant> > reply = timed.query_sync(map);
QVERIFY(reply.isValid());
QCOMPARE(reply.value().size(), 1);
#endif

QVERIFY(m_calendar->deleteIncidence(ev));
QVERIFY(m_storage->save());

#if defined(TIMED_SUPPORT)
reply = timed.query_sync(map);
QVERIFY(reply.isValid());
QCOMPARE(reply.value().size(), 0);
#endif

notebook = m_storage->notebook(uid);
QVERIFY(notebook);
notebook->setIsVisible(false);
QVERIFY(m_storage->updateNotebook(notebook));

// Adding an event in a non visible notebook should not add alarm.
QVERIFY(m_calendar->addEvent(ev, uid));
QVERIFY(m_storage->save());
#if defined(TIMED_SUPPORT)
reply = timed.query_sync(map);
QVERIFY(reply.isValid());
QCOMPARE(reply.value().size(), 0);
#endif

// Clearing calendar to be in a situation where the calendar
// object has just been created.
m_calendar->close();

// Switching the notebook to visible should activate all alarms.
notebook->setIsVisible(true);
QVERIFY(m_storage->updateNotebook(notebook));
#if defined(TIMED_SUPPORT)
reply = timed.query_sync(map);
QVERIFY(reply.isValid());
QCOMPARE(reply.value().size(), 1);
#endif

// Switching the notebook to non visible should deactivate all alarms.
notebook->setIsVisible(false);
QVERIFY(m_storage->updateNotebook(notebook));
#if defined(TIMED_SUPPORT)
reply = timed.query_sync(map);
QVERIFY(reply.isValid());
QCOMPARE(reply.value().size(), 0);
#endif
}

void tst_storage::openDb(bool clear)
{
Expand Down
1 change: 1 addition & 0 deletions tests/tst_storage.h
Expand Up @@ -68,6 +68,7 @@ private slots:
void tst_icalAllDay();
void tst_deleteAllEvents();
void tst_calendarProperties();
void tst_alarms();

private:
void openDb(bool clear = false);
Expand Down

0 comments on commit ba6ebdd

Please sign in to comment.