Changeset View
Changeset View
Standalone View
Standalone View
src/freebusymodel/autotests/testfreeperiodmodel.cpp
Show All 16 Lines | 1 | /* | |||
---|---|---|---|---|---|
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | 17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
18 | 02110-1301, USA. | 18 | 02110-1301, USA. | ||
19 | */ | 19 | */ | ||
20 | 20 | | |||
21 | #include "testfreeperiodmodel.h" | 21 | #include "testfreeperiodmodel.h" | ||
22 | #include "modeltest.h" | 22 | #include "modeltest.h" | ||
23 | #include "../freeperiodmodel.h" | 23 | #include "../freeperiodmodel.h" | ||
24 | 24 | | |||
25 | #include <KCalCore/Period> | 25 | #include <KCalendarCore/Period> | ||
26 | #include <KCalCore/Duration> | 26 | #include <KCalendarCore/Duration> | ||
27 | 27 | | |||
28 | #include <QTest> | 28 | #include <QTest> | ||
29 | 29 | | |||
30 | using namespace CalendarSupport; | 30 | using namespace CalendarSupport; | ||
31 | 31 | | |||
32 | // Workaround QTBUG-51789 causing a crash when QtWebEngineWidgets | 32 | // Workaround QTBUG-51789 causing a crash when QtWebEngineWidgets | ||
33 | // is linked into a QCoreApplication. | 33 | // is linked into a QCoreApplication. | ||
34 | QTEST_GUILESS_MAIN(FreePeriodModelTest) | 34 | QTEST_GUILESS_MAIN(FreePeriodModelTest) | ||
35 | 35 | | |||
36 | void FreePeriodModelTest::testModelValidity() | 36 | void FreePeriodModelTest::testModelValidity() | ||
37 | { | 37 | { | ||
38 | FreePeriodModel *model = new FreePeriodModel(this); | 38 | FreePeriodModel *model = new FreePeriodModel(this); | ||
39 | new ModelTest(model, this); | 39 | new ModelTest(model, this); | ||
40 | 40 | | |||
41 | const QDateTime dt1(QDate(2010, 7, 24), QTime(7, 0, 0), Qt::UTC); | 41 | const QDateTime dt1(QDate(2010, 7, 24), QTime(7, 0, 0), Qt::UTC); | ||
42 | const QDateTime dt2(QDate(2010, 7, 24), QTime(10, 0, 0), Qt::UTC); | 42 | const QDateTime dt2(QDate(2010, 7, 24), QTime(10, 0, 0), Qt::UTC); | ||
43 | 43 | | |||
44 | KCalCore::Period::List list; | 44 | KCalendarCore::Period::List list; | ||
45 | 45 | | |||
46 | list << KCalCore::Period(dt1, KCalCore::Duration(60 * 60)); | 46 | list << KCalendarCore::Period(dt1, KCalendarCore::Duration(60 * 60)); | ||
47 | list << KCalCore::Period(dt2, KCalCore::Duration(60 * 60)); | 47 | list << KCalendarCore::Period(dt2, KCalendarCore::Duration(60 * 60)); | ||
48 | 48 | | |||
49 | QCOMPARE(model->rowCount(), 0); | 49 | QCOMPARE(model->rowCount(), 0); | ||
50 | model->slotNewFreePeriods(list); | 50 | model->slotNewFreePeriods(list); | ||
51 | QCOMPARE(model->rowCount(), 2); | 51 | QCOMPARE(model->rowCount(), 2); | ||
52 | } | 52 | } | ||
53 | 53 | | |||
54 | void FreePeriodModelTest::testSplitByDay() | 54 | void FreePeriodModelTest::testSplitByDay() | ||
55 | { | 55 | { | ||
56 | FreePeriodModel *model = new FreePeriodModel(this); | 56 | FreePeriodModel *model = new FreePeriodModel(this); | ||
57 | new ModelTest(model, this); | 57 | new ModelTest(model, this); | ||
58 | 58 | | |||
59 | const QDateTime startDt(QDate(2010, 7, 24), QTime(8, 0, 0), Qt::UTC); | 59 | const QDateTime startDt(QDate(2010, 7, 24), QTime(8, 0, 0), Qt::UTC); | ||
60 | const QDateTime endDt(QDate(2010, 7, 25), QTime(8, 0, 0), Qt::UTC); | 60 | const QDateTime endDt(QDate(2010, 7, 25), QTime(8, 0, 0), Qt::UTC); | ||
61 | 61 | | |||
62 | KCalCore::Period::List list; | 62 | KCalendarCore::Period::List list; | ||
63 | 63 | | |||
64 | // This period goes from 8am on the 24th to 8am on the 25th | 64 | // This period goes from 8am on the 24th to 8am on the 25th | ||
65 | list << KCalCore::Period(startDt, endDt); | 65 | list << KCalendarCore::Period(startDt, endDt); | ||
66 | 66 | | |||
67 | QCOMPARE(model->rowCount(), 0); | 67 | QCOMPARE(model->rowCount(), 0); | ||
68 | 68 | | |||
69 | // as part of adding the new periods | 69 | // as part of adding the new periods | ||
70 | // the model should split the above period into two | 70 | // the model should split the above period into two | ||
71 | // one from 8am-12 on the 24th, and the second from 00-08 on the 25th | 71 | // one from 8am-12 on the 24th, and the second from 00-08 on the 25th | ||
72 | model->slotNewFreePeriods(list); | 72 | model->slotNewFreePeriods(list); | ||
73 | 73 | | |||
74 | const QDateTime endPeriod1(QDate(2010, 7, 24), QTime(23, 59, 59, 999), Qt::UTC); | 74 | const QDateTime endPeriod1(QDate(2010, 7, 24), QTime(23, 59, 59, 999), Qt::UTC); | ||
75 | const QDateTime startPeriod2(QDate(2010, 7, 25), QTime(0, 0, 0, 0), Qt::UTC); | 75 | const QDateTime startPeriod2(QDate(2010, 7, 25), QTime(0, 0, 0, 0), Qt::UTC); | ||
76 | 76 | | |||
77 | QModelIndex index = model->index(0, 0); | 77 | QModelIndex index = model->index(0, 0); | ||
78 | KCalCore::Period period1 | 78 | KCalendarCore::Period period1 | ||
79 | = model->data(index, FreePeriodModel::PeriodRole).value<KCalCore::Period>(); | 79 | = model->data(index, FreePeriodModel::PeriodRole).value<KCalendarCore::Period>(); | ||
80 | index = model->index(1, 0); | 80 | index = model->index(1, 0); | ||
81 | KCalCore::Period period2 | 81 | KCalendarCore::Period period2 | ||
82 | = model->data(index, FreePeriodModel::PeriodRole).value<KCalCore::Period>(); | 82 | = model->data(index, FreePeriodModel::PeriodRole).value<KCalendarCore::Period>(); | ||
83 | 83 | | |||
84 | QCOMPARE(period1.start(), startDt); | 84 | QCOMPARE(period1.start(), startDt); | ||
85 | QCOMPARE(period1.end(), endPeriod1); | 85 | QCOMPARE(period1.end(), endPeriod1); | ||
86 | QCOMPARE(period2.start(), startPeriod2); | 86 | QCOMPARE(period2.start(), startPeriod2); | ||
87 | QCOMPARE(period2.end(), endDt); | 87 | QCOMPARE(period2.end(), endDt); | ||
88 | } | 88 | } |