Warning, file /education/khipu/tests/persistancefiletest.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /************************************************************************************* 0002 * Copyright (C) 2013 by Punit Mehta <punit9462@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 * 0006 * as published by the Free Software Foundation; either version 2 * 0007 * of the License, or (at your option) any later version. * 0008 * * 0009 * This program 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 * 0012 * GNU General Public License for more details. * 0013 * * 0014 * You should have received a copy of the GNU General Public License * 0015 * along with this program; if not, write to the Free Software * 0016 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * 0017 *************************************************************************************/ 0018 0019 #include <persistancefiletest.h> 0020 0021 //Qt includes 0022 #include <qtest_kde.h> 0023 0024 //Analitza includes 0025 #include <analitzaplot/plotsfactory.h> 0026 #include <analitzaplot/plotitem.h> 0027 #include <analitzaplot/functiongraph.h> 0028 #include <analitzaplot/plotsmodel.h> 0029 0030 //libkhipu includes 0031 #include <datastore.h> 0032 #include <spacesmodel.h> 0033 #include <spaceitem.h> 0034 #include <mainwindow.h> 0035 0036 using namespace Analitza; 0037 0038 QTEST_KDEMAIN( PersistanceFileTest , GUI) 0039 0040 Q_DECLARE_METATYPE (Analitza::Dimension); 0041 0042 PersistanceFileTest::PersistanceFileTest(QObject *parent) 0043 : QObject(parent) 0044 { 0045 } 0046 0047 PersistanceFileTest::~PersistanceFileTest() 0048 { 0049 } 0050 0051 void PersistanceFileTest::initTestCase() 0052 {} 0053 0054 void PersistanceFileTest::cleanupTestCase() 0055 {} 0056 0057 void PersistanceFileTest::testCorrect_data() 0058 { 0059 QTest::addColumn<QString>("spacename"); 0060 QTest::addColumn<Analitza::Dimension>("spacedimension"); 0061 0062 QTest::addColumn<QString>("plotname"); 0063 QTest::addColumn<QString>("plotequation"); 0064 QTest::addColumn<QColor>("plotcolor"); 0065 0066 QTest::newRow("1") << "space-1" << Analitza::Dim2D << "sin curve" << "x->sin(x)" << QColor(Qt::black); 0067 QTest::newRow("2") << "space-2" << Analitza::Dim2D << "cos curve" << "x->cos(x)" << QColor(Qt::blue); 0068 QTest::newRow("3") << "space-3" << Analitza::Dim2D << "tan curve" << "x->tan(x)" << QColor(Qt::green); 0069 QTest::newRow("4") << "space-4" << Analitza::Dim2D << "line-2d" << "t->vector{t,t}" << QColor(Qt::red); 0070 QTest::newRow("5") << "space-5" << Analitza::Dim3D << "line-3d" << "t->vector{t, t, t}" << QColor(Qt::yellow); 0071 QTest::newRow("6") << "space-6" << Analitza::Dim3D << "para-3d" << "t->vector{t,sin(t),cos(t)}" << QColor(Qt::white); 0072 } 0073 0074 void PersistanceFileTest::testCorrect() 0075 { 0076 QFETCH(QString,spacename); 0077 QFETCH(Analitza::Dimension,spacedimension); 0078 0079 QFETCH(QString,plotname); 0080 QFETCH(QString,plotequation); 0081 QFETCH(QColor,plotcolor); 0082 0083 MainWindow window; 0084 DataStore* document=window.getDocument(); 0085 0086 document->spacesModel()->addSpace(spacedimension,spacename,QString()); 0087 0088 FunctionGraph *item=nullptr; 0089 Analitza::PlotBuilder req = Analitza::PlotsFactory::self()->requestPlot(Analitza::Expression(plotequation),spacedimension); 0090 QVERIFY(req.canDraw()); 0091 item = req.create(QColor(plotcolor),plotname); 0092 document->plotsModel()->addPlot(item); 0093 0094 //save data in a file 0095 const QUrl testFile = QUrl::fromLocalFile(QDir::tempPath().append("/.test.khipu")); 0096 0097 QVERIFY(window.saveFile(testFile)); 0098 0099 // clear the models and verify them 0100 QVERIFY(document->spacesModel()->removeRow(0)); 0101 QVERIFY(document->plotsModel()->removeRow(0)); 0102 0103 // open file 0104 QVERIFY(window.openFile(testFile)); 0105 0106 SpaceItem *space=document->spacesModel()->space(0); 0107 QVERIFY(space!=nullptr); 0108 0109 QModelIndex ind = document->spacesModel()->index(0); 0110 window.createPlot(ind); 0111 0112 PlotItem* plotitem=document->plotsModel()->data(document->plotsModel()->index(0),PlotsModel::PlotRole).value<PlotItem*>(); 0113 QVERIFY(plotitem!=nullptr); 0114 0115 //testing the data 0116 QCOMPARE(space->name(),spacename); 0117 QCOMPARE(space->dimension(),spacedimension); 0118 0119 QCOMPARE(plotitem->name(),plotname); 0120 QCOMPARE(plotitem->expression(),Analitza::Expression(plotequation)); 0121 QCOMPARE(plotitem->color(),plotcolor); 0122 0123 //clearing the model and verify again 0124 QVERIFY(document->spacesModel()->removeRow(0)); 0125 QVERIFY(document->plotsModel()->removeRow(0)); 0126 0127 delete document; 0128 }