File indexing completed on 2024-11-17 04:49:34

0001 /*
0002  * Copyright (c) 2019 Alexander Potashev <aspotashev@gmail.com>
0003  *
0004  * This program is free software; you can redistribute it and/or
0005  * modify it under the terms of the GNU General Public License as
0006  * published by the Free Software Foundation; either version 2 of
0007  * the License or (at your option) version 3 or any later version
0008  * accepted by the membership of KDE e.V. (or its successor approved
0009  * by the membership of KDE e.V.), which shall act as a proxy
0010  * defined in Section 14 of version 3 of the license.
0011  *
0012  * This program is distributed in the hope that it will be useful,
0013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0015  * GNU General Public License for more details.
0016  *
0017  * You should have received a copy of the GNU General Public License
0018  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
0019  */
0020 
0021 #include <QTest>
0022 
0023 #include "helpers.h"
0024 #include "model/task.h"
0025 #include "model/tasksmodel.h"
0026 #include "taskview.h"
0027 #include "widgets/taskswidget.h"
0028 
0029 class PlannerParserTest : public QObject
0030 {
0031     Q_OBJECT
0032 
0033 private Q_SLOTS:
0034     void testEmpty();
0035     void testAtTopLevel();
0036     void testAtSubTask();
0037 };
0038 
0039 void PlannerParserTest::testEmpty()
0040 {
0041     auto *taskView = createTaskView(this, false);
0042     QVERIFY(taskView);
0043 
0044     taskView->importPlanner(QFINDTESTDATA("data/kitchen.planner"));
0045 
0046     auto *model = taskView->storage()->tasksModel();
0047 
0048     QCOMPARE(model->getAllItems().size(), 21);
0049 
0050     QCOMPARE(model->topLevelItemCount(), 4);
0051     QCOMPARE(dynamic_cast<Task *>(model->topLevelItem(0))->name(), QStringLiteral("Initiation"));
0052 
0053     auto *closureTask = dynamic_cast<Task *>(model->topLevelItem(3));
0054     QCOMPARE(closureTask->name(), QStringLiteral("Closure"));
0055     QCOMPARE(closureTask->childCount(), 3);
0056 }
0057 
0058 void PlannerParserTest::testAtTopLevel()
0059 {
0060     auto *taskView = createTaskView(this, false);
0061     QVERIFY(taskView);
0062 
0063     Task *task1 = taskView->addTask(QStringLiteral("1"));
0064     QVERIFY(task1);
0065     taskView->tasksWidget()->setCurrentIndex(taskView->storage()->tasksModel()->index(task1, 0));
0066 
0067     taskView->importPlanner(QFINDTESTDATA("data/kitchen.planner"));
0068 
0069     auto *model = taskView->storage()->tasksModel();
0070 
0071     QCOMPARE(model->getAllItems().size(), 22);
0072 
0073     QCOMPARE(model->topLevelItemCount(), 5);
0074     QCOMPARE(dynamic_cast<Task *>(model->topLevelItem(0))->name(), QStringLiteral("1"));
0075     QCOMPARE(dynamic_cast<Task *>(model->topLevelItem(1))->name(), QStringLiteral("Initiation"));
0076 
0077     auto *closureTask = dynamic_cast<Task *>(model->topLevelItem(4));
0078     QCOMPARE(closureTask->name(), QStringLiteral("Closure"));
0079     QCOMPARE(closureTask->childCount(), 3);
0080 }
0081 
0082 void PlannerParserTest::testAtSubTask()
0083 {
0084     auto *taskView = createTaskView(this, false);
0085     QVERIFY(taskView);
0086 
0087     Task *task1 = taskView->addTask(QStringLiteral("1"));
0088     QVERIFY(task1);
0089     Task *task2 = taskView->addTask(QStringLiteral("2"), QString(), 0, 0, QVector<int>(0, 0), task1);
0090     QVERIFY(task2);
0091     taskView->tasksWidget()->setCurrentIndex(taskView->storage()->tasksModel()->index(task2, 0));
0092 
0093     taskView->importPlanner(QFINDTESTDATA("data/kitchen.planner"));
0094 
0095     auto *model = taskView->storage()->tasksModel();
0096 
0097     QCOMPARE(model->getAllItems().size(), 23);
0098 
0099     QCOMPARE(model->topLevelItemCount(), 1);
0100     QCOMPARE(task1->childCount(), 5);
0101     QCOMPARE(dynamic_cast<Task *>(task1->child(0))->name(), QStringLiteral("2"));
0102     QCOMPARE(dynamic_cast<Task *>(task1->child(1))->name(), QStringLiteral("Initiation"));
0103 
0104     auto *closureTask = dynamic_cast<Task *>(task1->child(4));
0105     QCOMPARE(closureTask->name(), QStringLiteral("Closure"));
0106     QCOMPARE(closureTask->childCount(), 3);
0107 }
0108 
0109 QTEST_MAIN(PlannerParserTest)
0110 
0111 #include "plannerparsertest.moc"