File indexing completed on 2024-05-12 16:39:23

0001 /* This file is part of the KDE project
0002    Copyright (C) 2009 Dag Andersen <danders@get2net.dk>
0003 
0004    This library is free software; you can redistribute it and/or
0005    modify it under the terms of the GNU Library General Public
0006    License as published by the Free Software Foundation; either
0007    version 2 of the License, or (at your option) any later version.
0008 
0009    This library is distributed in the hope that it will be useful,
0010    but WITHOUT ANY WARRANTY; without even the implied warranty of
0011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012    Library General Public License for more details.
0013 
0014    You should have received a copy of the GNU Library General Public License
0015    along with this library; see the file COPYING.LIB.  If not, write to
0016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017    Boston, MA 02110-1301, USA.
0018 */
0019 
0020 // clazy:excludeall=qstring-arg
0021 #include "InsertFileTester.h"
0022 
0023 #include "kptcommand.h"
0024 #include "kptmaindocument.h"
0025 #include "kptcalendar.h"
0026 #include "kptresource.h"
0027 #include "kpttask.h"
0028 #include "kptnode.h"
0029 
0030 #include <QTest>
0031 
0032 #include <QUrl>
0033 #include <QFileInfo>
0034 
0035 namespace KPlato
0036 {
0037 
0038 
0039 void InsertFileTester::testVersion_0_6()
0040 {
0041     Part part;
0042     QFileInfo file("version-0-6.kplato");
0043     QVERIFY(file.exists());
0044 
0045     bool res = part.openUrl(QUrl::fromLocalFile(file.absoluteFilePath()));
0046     QVERIFY(res);
0047 
0048     Project &p = part.getProject();
0049 
0050     QCOMPARE(p.name(), QString("P1"));
0051     QCOMPARE(p.leader(), QString("pp"));
0052 
0053     QCOMPARE(p.numChildren(), 2);
0054     QCOMPARE(p.numResourceGroups(), 1);
0055     QCOMPARE(p.resourceList().count(), 1);
0056     QCOMPARE(p.allCalendars().count(), 2);
0057 
0058     Node *n = p.childNode(0);
0059     QCOMPARE(n->type(), (int)Node::Type_Task);
0060     QCOMPARE(n->name(), QString("T1"));
0061 
0062     n = p.childNode(1);
0063     QCOMPARE(n->type(), (int)Node::Type_Task);
0064     QCOMPARE(n->name(), QString("T2"));
0065 
0066 }
0067 
0068 void InsertFileTester::testProject_stats1()
0069 {
0070     Part part;
0071     QFileInfo file("project_stats1.kplato");
0072     QVERIFY(file.exists());
0073 
0074     bool res = part.openUrl(QUrl::fromLocalFile(file.absoluteFilePath()));
0075     QVERIFY(res);
0076 
0077     Project &p = part.getProject();
0078 
0079     QCOMPARE(p.name(), QString("P1"));
0080     QCOMPARE(p.leader(), QString("Robin"));
0081 
0082     QCOMPARE(p.numChildren(), 1);
0083     QCOMPARE(p.numResourceGroups(), 1);
0084     QCOMPARE(p.resourceList().count(), 1);
0085     QCOMPARE(p.allCalendars().count(), 1);
0086 
0087     Node *n = p.childNode(0);
0088     QCOMPARE(n->type(), (int)Node::Type_Task);
0089     QCOMPARE(n->name(), QString("T1"));
0090 
0091 }
0092 
0093 void InsertFileTester::testPert1()
0094 {
0095     Part part;
0096     QFileInfo file("pert1.kplato");
0097     QVERIFY(file.exists());
0098 
0099     bool res = part.openUrl(QUrl::fromLocalFile(file.absoluteFilePath()));
0100     QVERIFY(res);
0101 
0102     Project &p = part.getProject();
0103 
0104     QCOMPARE(p.name(), QString("PERT 1"));
0105     QCOMPARE(p.leader(), QString("PM"));
0106 
0107     QCOMPARE(p.numChildren(), 7);
0108     QCOMPARE(p.numResourceGroups(), 0);
0109     QCOMPARE(p.resourceList().count(), 0);
0110     QCOMPARE(p.allCalendars().count(), 1);
0111 
0112     Node *n = p.childNode(0);
0113     QCOMPARE(n->type(), (int)Node::Type_Task);
0114     QCOMPARE(n->name(), QString("a"));
0115 
0116     n = p.childNode(1);
0117     QCOMPARE(n->type(), (int)Node::Type_Task);
0118     QCOMPARE(n->name(), QString("b"));
0119 
0120     n = p.childNode(2);
0121     QCOMPARE(n->type(), (int)Node::Type_Task);
0122     QCOMPARE(n->name(), QString("c"));
0123 
0124     n = p.childNode(3);
0125     QCOMPARE(n->type(), (int)Node::Type_Task);
0126     QCOMPARE(n->name(), QString("d"));
0127 
0128     n = p.childNode(4);
0129     QCOMPARE(n->type(), (int)Node::Type_Task);
0130     QCOMPARE(n->name(), QString("e"));
0131 
0132     n = p.childNode(5);
0133     QCOMPARE(n->type(), (int)Node::Type_Task);
0134     QCOMPARE(n->name(), QString("f"));
0135 
0136     n = p.childNode(6);
0137     QCOMPARE(n->type(), (int)Node::Type_Task);
0138     QCOMPARE(n->name(), QString("g"));
0139 }
0140 
0141 } //namespace KPlato
0142 
0143 QTEST_MAIN(KPlato::InsertFileTester)