Changeset View
Changeset View
Standalone View
Standalone View
agents/sendlateragent/autotests/sendlaterutiltest.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | Copyright (C) 2014-2020 Laurent Montel <montel@kde.org> | ||||
3 | | ||||
4 | This program is free software; you can redistribute it and/or | ||||
5 | modify it under the terms of the GNU General Public | ||||
6 | License as published by the Free Software Foundation; either | ||||
7 | version 2 of the License, or (at your option) any later version. | ||||
8 | | ||||
9 | This program is distributed in the hope that it will be useful, | ||||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
12 | General Public License for more details. | ||||
13 | | ||||
14 | You should have received a copy of the GNU General Public License | ||||
15 | along with this program; see the file COPYING. If not, write to | ||||
16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||||
17 | Boston, MA 02110-1301, USA. | ||||
18 | */ | ||||
19 | | ||||
20 | #include "sendlaterutiltest.h" | ||||
21 | #include "sendlaterutil.h" | ||||
22 | | ||||
23 | #include <MessageComposer/SendLaterInfo> | ||||
24 | | ||||
25 | #include <QTest> | ||||
26 | #include <QDateTime> | ||||
27 | #include <KConfigGroup> | ||||
28 | #include <KSharedConfig> | ||||
29 | #include <QStandardPaths> | ||||
30 | #include <sendlaterinfo.h> | ||||
31 | | ||||
32 | SendLaterUtilTest::SendLaterUtilTest(QObject *parent) | ||||
33 | : QObject(parent) | ||||
34 | { | ||||
35 | QStandardPaths::setTestModeEnabled(true); | ||||
36 | } | ||||
37 | void SendLaterUtilTest::shouldRestoreFromSettings() | ||||
38 | { | ||||
39 | MessageComposer::SendLaterInfo info; | ||||
40 | const QString to = QStringLiteral("kde.org"); | ||||
41 | info.setTo(to); | ||||
42 | info.setItemId(Akonadi::Item::Id(42)); | ||||
43 | info.setSubject(QStringLiteral("Subject")); | ||||
44 | info.setRecurrence(true); | ||||
45 | info.setRecurrenceEachValue(5); | ||||
46 | info.setRecurrenceUnit(MessageComposer::SendLaterInfo::Years); | ||||
47 | const QDate date(2014, 1, 1); | ||||
48 | #if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) | ||||
49 | info.setDateTime(QDateTime(date)); | ||||
50 | info.setLastDateTimeSend(QDateTime(date)); | ||||
51 | #else | ||||
52 | info.setDateTime(QDateTime(date.startOfDay())); | ||||
53 | info.setLastDateTimeSend(QDateTime(date.startOfDay())); | ||||
54 | #endif | ||||
55 | SendLaterUtil::writeSendLaterInfo(KSharedConfig::openConfig(), &info); | ||||
56 | | ||||
57 | KConfigGroup grp(KSharedConfig::openConfig(), SendLaterUtil::sendLaterPattern().arg(42)); | ||||
58 | std::unique_ptr<MessageComposer::SendLaterInfo> restoreInfo{SendLaterUtil::readSendLaterInfo(grp)}; | ||||
59 | QCOMPARE(info, *restoreInfo); | ||||
60 | } | ||||
61 | | ||||
62 | QTEST_MAIN(SendLaterUtilTest) |