File indexing completed on 2024-04-28 05:11:29
0001 /* 0002 SPDX-FileCopyrightText: 2010 Casey Link <unnamedrambler@gmail.com> 0003 SPDX-FileCopyrightText: 2009-2010 Klaralvdalens Datakonsult AB, a KDAB Group company <info@kdab.net> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #include "testfreebusyganttproxymodel.h" 0009 #include "freebusyganttproxymodel.h" 0010 0011 #include <CalendarSupport/FreeBusyItem> 0012 #include <CalendarSupport/FreeBusyItemModel> 0013 0014 #include <KCalendarCore/Attendee> 0015 #include <KGanttGraphicsView> 0016 0017 #include <QAbstractItemModelTester> 0018 #include <QStandardPaths> 0019 #include <QTest> 0020 #include <QTimeZone> 0021 QTEST_MAIN(FreeBusyGanttProxyModelTest) 0022 0023 using namespace IncidenceEditorNG; 0024 0025 void FreeBusyGanttProxyModelTest::initTestCase() 0026 { 0027 qputenv("TZ", "UTC"); 0028 QStandardPaths::setTestModeEnabled(true); 0029 } 0030 0031 void FreeBusyGanttProxyModelTest::testModelValidity() 0032 { 0033 auto fbModel = new CalendarSupport::FreeBusyItemModel(); 0034 auto ganttModel = new FreeBusyGanttProxyModel(); 0035 ganttModel->setSourceModel(fbModel); 0036 auto modelTest = new QAbstractItemModelTester(ganttModel); 0037 0038 Q_UNUSED(modelTest) 0039 0040 QVERIFY(ganttModel->rowCount() == 0); 0041 0042 const QDateTime dt1(QDate(2010, 8, 24), QTime(7, 0, 0), QTimeZone::utc()); 0043 const QDateTime dt2(QDate(2010, 8, 24), QTime(16, 0, 0), QTimeZone::utc()); 0044 KCalendarCore::Attendee a1(QStringLiteral("fred"), QStringLiteral("fred@example.com")); 0045 KCalendarCore::FreeBusy::Ptr fb1(new KCalendarCore::FreeBusy()); 0046 0047 fb1->addPeriod(dt1, KCalendarCore::Duration(60 * 60)); 0048 fb1->addPeriod(dt2, KCalendarCore::Duration(60 * 60)); 0049 0050 CalendarSupport::FreeBusyItem::Ptr item1(new CalendarSupport::FreeBusyItem(a1, nullptr)); 0051 item1->setFreeBusy(fb1); 0052 0053 const QDateTime dt3(QDate(2010, 8, 25), QTime(7, 0, 0), QTimeZone::utc()); 0054 const QDateTime dt4(QDate(2010, 8, 25), QTime(16, 0, 0), QTimeZone::utc()); 0055 KCalendarCore::Attendee a2(QStringLiteral("joe"), QStringLiteral("joe@example.com")); 0056 KCalendarCore::FreeBusy::Ptr fb2(new KCalendarCore::FreeBusy()); 0057 0058 fb2->addPeriod(dt3, KCalendarCore::Duration(60 * 60)); 0059 fb2->addPeriod(dt4, KCalendarCore::Duration(60 * 60)); 0060 0061 CalendarSupport::FreeBusyItem::Ptr item2(new CalendarSupport::FreeBusyItem(a2, nullptr)); 0062 item2->setFreeBusy(fb2); 0063 0064 fbModel->addItem(item1); 0065 fbModel->addItem(item2); 0066 0067 QCOMPARE(ganttModel->rowCount(), 2); 0068 0069 QModelIndex parent0 = ganttModel->index(0, 0); 0070 QModelIndex parent1 = ganttModel->index(1, 0); 0071 QModelIndex parent2 = ganttModel->index(2, 0); 0072 QVERIFY(parent0.isValid()); 0073 QVERIFY(parent1.isValid()); 0074 QVERIFY(parent2.isValid() == false); 0075 0076 QModelIndex source_parent0 = fbModel->index(0, 0); 0077 QCOMPARE(parent0.data(), source_parent0.data()); 0078 QCOMPARE(parent0.data(KGantt::ItemTypeRole).toInt(), (int)KGantt::TypeMulti); 0079 0080 QModelIndex source_parent1 = fbModel->index(1, 0); 0081 QCOMPARE(parent1.data(), source_parent1.data()); 0082 QCOMPARE(parent1.data(KGantt::ItemTypeRole).toInt(), (int)KGantt::TypeMulti); 0083 0084 QModelIndex child0_0 = ganttModel->index(0, 0, parent0); 0085 QModelIndex child0_1 = ganttModel->index(1, 0, parent0); 0086 QVERIFY(child0_0.isValid()); 0087 QVERIFY(child0_1.isValid()); 0088 0089 QCOMPARE(child0_0.data(KGantt::ItemTypeRole).toInt(), (int)KGantt::TypeTask); 0090 QCOMPARE(child0_0.data(KGantt::StartTimeRole).toDateTime(), dt1); 0091 QCOMPARE(child0_1.data(KGantt::ItemTypeRole).toInt(), (int)KGantt::TypeTask); 0092 QCOMPARE(child0_1.data(KGantt::StartTimeRole).toDateTime(), dt2); 0093 0094 QModelIndex child1_0 = ganttModel->index(0, 0, parent1); 0095 QModelIndex child1_1 = ganttModel->index(1, 0, parent1); 0096 QVERIFY(child1_0.isValid()); 0097 QVERIFY(child1_1.isValid()); 0098 0099 QCOMPARE(child1_0.data(KGantt::ItemTypeRole).toInt(), (int)KGantt::TypeTask); 0100 QCOMPARE(child1_0.data(KGantt::StartTimeRole).toDateTime(), dt3); 0101 QCOMPARE(child1_1.data(KGantt::ItemTypeRole).toInt(), (int)KGantt::TypeTask); 0102 QCOMPARE(child1_1.data(KGantt::StartTimeRole).toDateTime(), dt4); 0103 delete fbModel; 0104 delete ganttModel; 0105 delete modelTest; 0106 } 0107 0108 #include "moc_testfreebusyganttproxymodel.cpp"