File indexing completed on 2024-04-14 14:08:51

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 <dictionarycollectiontest.h>
0020 
0021 //Qt includes
0022 #include <qtest_kde.h>
0023 #include <QTreeView>
0024 #include <QItemSelectionModel>
0025 
0026 //Analitza includes
0027 #include <analitzaplot/plotitem.h>
0028 #include <analitzaplot/plotsmodel.h>
0029 
0030 //libkhipu includes
0031 #include <dictionarycollection.h>
0032 #include <dashboard.h>
0033 #include <datastore.h>
0034 #include <spacesmodel.h>
0035 
0036 using namespace Analitza;
0037 
0038 QTEST_KDEMAIN( DictionaryCollectionTest, GUI)
0039 
0040 Q_DECLARE_METATYPE (Analitza::Dimension);
0041 
0042 Q_DECLARE_METATYPE (PlotItem*);
0043 
0044 DictionaryCollectionTest::DictionaryCollectionTest(QObject *parent)
0045     : QObject(parent)
0046 {
0047 }
0048 
0049 DictionaryCollectionTest::~DictionaryCollectionTest()
0050 {
0051 }
0052 
0053 void DictionaryCollectionTest::initTestCase()
0054 {}
0055 
0056 void DictionaryCollectionTest::cleanupTestCase()
0057 {}
0058 
0059 void DictionaryCollectionTest::testCorrect_data()
0060 {
0061     QTest::addColumn<QString>("dictionaryname");
0062     QTest::newRow("1") << "3Ds";
0063     QTest::newRow("2") << "basic_curves";
0064     QTest::newRow("3") << "conics";
0065     QTest::newRow("4") << "polar";
0066 }
0067 
0068 void DictionaryCollectionTest::testCorrect()
0069 {
0070     QFETCH(QString,dictionaryname);
0071 
0072     Dashboard *dashboard = new Dashboard(0);
0073     DictionaryCollection *testWidget = new DictionaryCollection(0);
0074     testWidget->setDashboardWidget(dashboard);
0075     testWidget->setDictionaryDataMap();
0076     testWidget->setDefaultDictionaries();
0077 
0078     QStringList values=dashboard->dictionaryDataMap().values();
0079     QCOMPARE(values.size(),4);
0080     QVERIFY(testWidget->conains(dictionaryname));
0081     QCOMPARE(testWidget->totalDictionaries(),4);
0082 }
0083 
0084 void DictionaryCollectionTest::testIncorrect_data()
0085 {
0086     QTest::addColumn<QString>("dictionaryname");
0087     QTest::newRow("1") << "dictionary1";
0088     QTest::newRow("2") << "test";
0089     QTest::newRow("3") << "wrong_name";
0090     QTest::newRow("4") << "";
0091     QTest::newRow("5") << "incorrect";
0092 }
0093 
0094 void DictionaryCollectionTest::testIncorrect()
0095 {
0096     QFETCH(QString,dictionaryname);
0097 
0098     Dashboard *dashboard = new Dashboard(0);
0099     DictionaryCollection *testWidget = new DictionaryCollection(0);
0100     testWidget->setDashboardWidget(dashboard);
0101     testWidget->setDictionaryDataMap();
0102     testWidget->setDefaultDictionaries();
0103 
0104     QStringList values=dashboard->dictionaryDataMap().values();
0105 
0106     // This will always 4.Since the correct dictionaries are always there.
0107     QCOMPARE(values.size(),4);
0108     QCOMPARE(testWidget->totalDictionaries(),4);
0109 
0110     QVERIFY(!testWidget->conains(dictionaryname));
0111 }
0112 
0113 void DictionaryCollectionTest::testAddPlot_data()
0114 {
0115     QTest::addColumn<QString>("dictionaryname");
0116     QTest::addColumn<QString>("plotname1");
0117     QTest::addColumn<QString>("ploteqn1");
0118 
0119     QTest::newRow("1") << "3Ds";
0120 }
0121 
0122 void DictionaryCollectionTest::testAddPlot()
0123 {
0124     QFETCH(QString,dictionaryname);
0125 
0126     Dashboard *dashboard = new Dashboard(0);
0127     DataStore *document = new DataStore(0);
0128     document->spacesModel()->addSpace(Dim3D);
0129     document->setCurrentSpace(0);
0130     DictionaryCollection *testWidget = new DictionaryCollection(0);
0131 
0132     testWidget->setDashboardWidget(dashboard);
0133     testWidget->setDictionaryDataMap();
0134     testWidget->setDefaultDictionaries();
0135     testWidget->setDocument(document);
0136 
0137     //setting the plot-dictionary model based on the name of the dictionary.
0138     testWidget->setDictionaryData(testWidget->indexOf(dictionaryname));
0139 
0140     //test index
0141     QModelIndex ind=testWidget->dictionaryPlotsView()->model()->index(0,0);
0142 
0143     //selecting the plot on the view.
0144     testWidget->dictionaryPlotsView()->selectionModel()->setCurrentIndex(ind,QItemSelectionModel::Select);
0145 
0146     //add plot in the space
0147     testWidget->addPlotClicked();
0148 
0149     //check for the correctness of the added plot
0150     QCOMPARE(document->plotsModel()->rowCount(),1);
0151 
0152     PlotItem* plotitem=document->plotsModel()->data(document->plotsModel()->index(0),PlotsModel::PlotRole).value<PlotItem*>();
0153     QVERIFY(plotitem!=0);
0154 
0155     QCOMPARE(plotitem->name(),QString("plane2"));
0156     QCOMPARE(plotitem->expression(),Analitza::Expression("(x, y, z)->(x+y+z)-5"));
0157 }
0158 
0159 #include "dictionarycollectiontest.moc"
0160 
0161 #include "moc_dictionarycollectiontest.cpp"