| 1 |
/* This file is part of the KDE project |
| 2 |
SPDX-FileCopyrightText: 2009 Dag Andersen <[email protected]> |
| 3 |
|
| 4 |
SPDX-License-Identifier: LGPL-2.0-or-later |
| 5 |
*/ |
| 6 |
|
| 7 |
#include "MpxjImportTester.h" |
| 8 |
|
| 9 |
#include "ExtraProperties.h" |
| 10 |
#include "kptpart.h" |
| 11 |
#include "kptmaindocument.h" |
| 12 |
|
| 13 |
#include <QTest> |
| 14 |
|
| 15 |
#include <tests/debug.cpp> |
| 16 |
|
| 17 |
using namespace KPlato; |
| 18 |
|
| 19 |
Part *loadDocument(const QString &file) |
| 20 |
{ |
| 21 |
Part *part = new Part(nullptr); |
| 22 |
MainDocument *doc = new MainDocument(part, false); |
| 23 |
part->setDocument(doc); |
| 24 |
doc->setProgressEnabled(false); |
| 25 |
doc->setProperty(NOUI, true); // avoid possible error message |
| 26 |
doc->importDocument(QUrl::fromUserInput(file)); |
| 27 |
return part; |
| 28 |
} |
| 29 |
|
| 30 |
void MpxjImportTester::testGanttProject() |
| 31 |
{ |
| 32 |
QString file = QFINDTESTDATA("../../convert/testdata/ganttproject.gan"); |
| 33 |
QScopedPointer<Part> part(loadDocument(file)); |
| 34 |
auto project = part->document()->project(); |
| 35 |
|
| 36 |
auto schedule = project->schedules().values().value(0); |
| 37 |
QVERIFY(schedule); |
| 38 |
project->setCurrentSchedule(schedule->id()); |
| 39 |
|
| 40 |
// Debug::print(project, "GanttProject: -----------------", true); |
| 41 |
QEXPECT_FAIL("", "GanttProject importer does not set project description", Continue); |
| 42 |
QVERIFY(project->description().contains(QStringLiteral("This is a test of Gantt Project importer."))); |
| 43 |
|
| 44 |
QCOMPARE(project->allCalendars().count(), 1); |
| 45 |
QCOMPARE(project->allResourceGroups().count(), 0); |
| 46 |
QCOMPARE(project->resourceList().count(), 2); |
| 47 |
|
| 48 |
const auto nodes = project->allNodes(true); |
| 49 |
QCOMPARE(nodes.count(), 8); |
| 50 |
|
| 51 |
QVERIFY(nodes.value(0)->parentNode() == project); |
| 52 |
|
| 53 |
QVERIFY(nodes.value(1)->parentNode() == project); |
| 54 |
|
| 55 |
QVERIFY(nodes.value(2)->parentNode() == project); |
| 56 |
|
| 57 |
QVERIFY(nodes.value(3)->parentNode() == project); |
| 58 |
|
| 59 |
QVERIFY(nodes.value(4)->parentNode() == nodes.value(3)); |
| 60 |
|
| 61 |
QVERIFY(nodes.value(5)->parentNode() == nodes.value(3)); |
| 62 |
|
| 63 |
QVERIFY(nodes.value(6)->parentNode() == nodes.value(5)); |
| 64 |
|
| 65 |
QVERIFY(nodes.value(7)->parentNode() == project); |
| 66 |
|
| 67 |
const auto tasks = project->allTasks(); |
| 68 |
QCOMPARE(tasks.count(), 6); |
| 69 |
|
| 70 |
QCOMPARE(tasks.value(0)->priority(), 100); |
| 71 |
|
| 72 |
QCOMPARE(tasks.value(1)->priority(), 400); |
| 73 |
QVERIFY(tasks.value(1)->completion().isStarted()); |
| 74 |
QCOMPARE(tasks.value(1)->completion().percentFinished(), 30); |
| 75 |
|
| 76 |
QCOMPARE(tasks.value(2)->priority(), 500); |
| 77 |
QVERIFY(tasks.value(2)->completion().isFinished()); |
| 78 |
QCOMPARE(tasks.value(2)->completion().percentFinished(), 100); |
| 79 |
|
| 80 |
QCOMPARE(tasks.value(3)->priority(), 600); |
| 81 |
|
| 82 |
QCOMPARE(tasks.value(4)->priority(), 900); |
| 83 |
|
| 84 |
QCOMPARE(tasks.value(5)->priority(), 500); |
| 85 |
QCOMPARE(tasks.value(5)->type(), Node::Type_Milestone); |
| 86 |
|
| 87 |
QEXPECT_FAIL("", "GanttProject importer does not set task description", Continue); |
| 88 |
QVERIFY(tasks.value(5)->description().contains(QStringLiteral("This is a description"))); |
| 89 |
|
| 90 |
QVERIFY(tasks.value(0)->findParentRelation(tasks.value(1)) != nullptr); |
| 91 |
} |
| 92 |
|
| 93 |
void MpxjImportTester::testProjectLibre() |
| 94 |
{ |
| 95 |
QString file = QFINDTESTDATA("../../convert/testdata/projectlibre.pod"); |
| 96 |
QScopedPointer<Part> part(loadDocument(file)); |
| 97 |
auto project = part->document()->project(); |
| 98 |
auto schedule = project->schedules().values().value(0); |
| 99 |
QVERIFY(schedule); |
| 100 |
project->setCurrentSchedule(schedule->id()); |
| 101 |
|
| 102 |
// Debug::print(project, "ProjectLibre: -----------------", true); |
| 103 |
QCOMPARE(project->leader(), "Project Manager"); |
| 104 |
QEXPECT_FAIL("", "ProjectLibre importer does not set project description", Continue); |
| 105 |
QVERIFY(project->description().contains(QStringLiteral("This is the project description."))); |
| 106 |
|
| 107 |
QCOMPARE(project->allCalendars().count(), 3); // ProjectLibre generates 3 calendars by default |
| 108 |
QCOMPARE(project->allResourceGroups().count(), 1); |
| 109 |
QCOMPARE(project->resourceList().count(), 3); // ProjectLibre seems to generate an extra resource |
| 110 |
|
| 111 |
// Note: Groups come in arbitrary order |
| 112 |
auto r1 = project->resourceList().value(1); |
| 113 |
QCOMPARE(r1->name(), QStringLiteral("R1")); |
| 114 |
QCOMPARE(r1->parentGroups().count(), 1); |
| 115 |
QVERIFY(r1->parentGroups().value(0) == project->group(r1->parentGroups().value(0)->id())); |
| 116 |
|
| 117 |
const auto nodes = project->allNodes(true); |
| 118 |
QCOMPARE(nodes.count(), 7); |
| 119 |
|
| 120 |
QVERIFY(nodes.value(0)->parentNode() == project); |
| 121 |
|
| 122 |
QVERIFY(nodes.value(1)->parentNode() == project); |
| 123 |
|
| 124 |
QCOMPARE(nodes.value(2)->type(), Node::Type_Summarytask); |
| 125 |
QVERIFY(nodes.value(2)->parentNode() == project); |
| 126 |
|
| 127 |
QVERIFY(nodes.value(3)->parentNode() == nodes.value(2)); |
| 128 |
|
| 129 |
QCOMPARE(nodes.value(4)->type(), Node::Type_Summarytask); |
| 130 |
QVERIFY(nodes.value(4)->parentNode() == nodes.value(2)); |
| 131 |
|
| 132 |
QVERIFY(nodes.value(5)->parentNode() == nodes.value(4)); |
| 133 |
|
| 134 |
QVERIFY(nodes.value(6)->parentNode() == project); |
| 135 |
|
| 136 |
const auto tasks = project->allTasks(); |
| 137 |
QCOMPARE(tasks.count(), 5); |
| 138 |
|
| 139 |
QCOMPARE(tasks.value(0)->type(), Node::Type_Task); |
| 140 |
QCOMPARE(tasks.value(0)->priority(), 500); |
| 141 |
QVERIFY(tasks.value(0)->completion().isFinished()); |
| 142 |
QCOMPARE(tasks.value(0)->completion().percentFinished(), 100); |
| 143 |
|
| 144 |
QCOMPARE(tasks.value(1)->type(), Node::Type_Task); |
| 145 |
QCOMPARE(tasks.value(1)->priority(), 500); |
| 146 |
QVERIFY(tasks.value(1)->completion().isStarted()); |
| 147 |
QCOMPARE(tasks.value(1)->completion().percentFinished(), 30); |
| 148 |
|
| 149 |
QCOMPARE(tasks.value(2)->type(), Node::Type_Task); |
| 150 |
QCOMPARE(tasks.value(2)->priority(), 500); |
| 151 |
|
| 152 |
QCOMPARE(tasks.value(3)->type(), Node::Type_Task); |
| 153 |
QCOMPARE(tasks.value(3)->priority(), 500); |
| 154 |
|
| 155 |
QCOMPARE(tasks.value(4)->type(), Node::Type_Milestone); |
| 156 |
QCOMPARE(tasks.value(4)->priority(), 500); |
| 157 |
QVERIFY(tasks.value(4)->description().contains(QStringLiteral("This is a description"))); |
| 158 |
|
| 159 |
QVERIFY(tasks.value(2)->findChildRelation(tasks.value(3)) != nullptr); |
| 160 |
} |
| 161 |
|
| 162 |
QTEST_MAIN(MpxjImportTester) |