| 1 |
/* This file is part of the KDE project |
| 2 |
SPDX-FileCopyrightText: 2022 Dag Andersen <[email protected]> |
| 3 |
|
| 4 |
SPDX-License-Identifier: LGPL-2.0-or-later |
| 5 |
*/ |
| 6 |
|
| 7 |
// clazy:excludeall=qstring-arg |
| 8 |
#include "ReportsTester.h" |
| 9 |
|
| 10 |
#include <kptpart.h> |
| 11 |
#include <kptmaindocument.h> |
| 12 |
#include <ReportGeneratorOdt.h> |
| 13 |
|
| 14 |
#include <ExtraProperties.h> |
| 15 |
|
| 16 |
#include <QTest> |
| 17 |
#include <QTemporaryFile> |
| 18 |
|
| 19 |
#include <tests/debug.cpp> |
| 20 |
|
| 21 |
using namespace KPlato; |
| 22 |
|
| 23 |
void ReportsTester::init() |
| 24 |
{ |
| 25 |
part = nullptr; |
| 26 |
} |
| 27 |
|
| 28 |
void ReportsTester::cleanup() |
| 29 |
{ |
| 30 |
delete part; |
| 31 |
part = nullptr; |
| 32 |
} |
| 33 |
|
| 34 |
void ReportsTester::loadDocument(const QString &file) |
| 35 |
{ |
| 36 |
QVERIFY(QFile::exists(file)); |
| 37 |
|
| 38 |
part = new Part(nullptr); |
| 39 |
MainDocument *doc = new MainDocument(part, false); |
| 40 |
part->setDocument(doc); |
| 41 |
doc->setProgressEnabled(false); |
| 42 |
doc->setProperty(NOUI, true); // avoid possible error message |
| 43 |
doc->setUrl(QUrl::fromUserInput(file)); |
| 44 |
QVERIFY(doc->openLocalFile(file)); |
| 45 |
} |
| 46 |
|
| 47 |
void ReportsTester::testReportGeneration() |
| 48 |
{ |
| 49 |
QString file = QFINDTESTDATA("data/Project 1.plan"); |
| 50 |
loadDocument(file); |
| 51 |
QString templateFile = QFINDTESTDATA("data/TaskStatus.odt"); |
| 52 |
QVERIFY(QFile::exists(templateFile)); |
| 53 |
|
| 54 |
auto project = part->document()->project(); |
| 55 |
auto scheduleManager = project->scheduleManagers().value(0); |
| 56 |
ReportGeneratorOdt report; |
| 57 |
report.setProject(project); |
| 58 |
report.setScheduleManager(scheduleManager); |
| 59 |
report.setTemplateFile(templateFile); |
| 60 |
QTemporaryFile tmp(QDir::currentPath() + QDir::separator() + QStringLiteral("taskstatusreport-XXXXXX.odt")); |
| 61 |
QVERIFY(tmp.open()); |
| 62 |
const auto reportFile = tmp.fileName(); |
| 63 |
qDebug()<<reportFile; |
| 64 |
tmp.close(); |
| 65 |
report.setReportFile(reportFile); |
| 66 |
QVERIFY(report.initiate()); |
| 67 |
QVERIFY(report.createReport()); |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
QTEST_MAIN(ReportsTester) |