File indexing completed on 2024-03-24 03:43:20
0001 /************************************************************************************* 0002 * Copyright (C) 2007 by Aleix Pol <aleixpol@kde.org> * 0003 * Copyright (C) 2012 by Percy Camilo T. Aucahuasi <percy.camilo.ta@gmail.com> * 0004 * * 0005 * This program is free software; you can redistribute it and/or * 0006 * modify it under the terms of the GNU General Public License * 0007 * as published by the Free Software Foundation; either version 2 * 0008 * of the License, or (at your option) any later version. * 0009 * * 0010 * This program is distributed in the hope that it will be useful, * 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0013 * GNU General Public License for more details. * 0014 * * 0015 * You should have received a copy of the GNU General Public License * 0016 * along with this program; if not, write to the Free Software * 0017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * 0018 *************************************************************************************/ 0019 0020 #include "plotsdictionarymodeltest.h" 0021 #include <QTest> 0022 #include <QStandardPaths> 0023 #include <QDebug> 0024 #include <QDir> 0025 #include <analitzaplot/plotitem.h> 0026 #include <analitzaplot/plotsmodel.h> 0027 #include <analitzaplot/plotsdictionarymodel.h> 0028 0029 using namespace Analitza; 0030 0031 QTEST_MAIN( PlotsDictionaryModelTest ) 0032 0033 PlotsDictionaryModelTest::PlotsDictionaryModelTest(QObject *parent) 0034 : QObject(parent) 0035 {} 0036 0037 PlotsDictionaryModelTest::~PlotsDictionaryModelTest() 0038 {} 0039 0040 void PlotsDictionaryModelTest::testDictionaries() 0041 { 0042 PlotsDictionaryModel m; 0043 m.clear(); //we don't want the installed, we want the ones in the source directory 0044 QFileInfo f(QFINDTESTDATA("../data/plots/3Ds.plots")); 0045 QDir d(f.dir()); 0046 foreach(const QString& f, d.entryList(QStringList(QLatin1String("*.plots")), QDir::Files)) { 0047 m.createDictionary(d.filePath(f)); 0048 } 0049 0050 QVERIFY(m.rowCount()>0); 0051 PlotsModel* plot = m.plotModel(); 0052 0053 for(int i=0; i<m.rowCount(); i++) { 0054 QModelIndex idx = m.index(i, 0); 0055 QVariant v=idx.data(Qt::DisplayRole); 0056 QVERIFY(v.isValid()); 0057 QVERIFY(v.type()==QVariant::String); 0058 QVERIFY(!v.toString().isEmpty()); 0059 QVERIFY(!idx.data(PlotsDictionaryModel::ExpressionRole).toString().isEmpty()); 0060 0061 m.setCurrentRow(i); 0062 QCOMPARE(plot->rowCount(), 1); 0063 0064 QModelIndex plotIdx = plot->index(0,0); 0065 PlotItem* item = plotIdx.data(PlotsModel::PlotRole).value<PlotItem*>(); 0066 QVERIFY(item); 0067 QCOMPARE(idx.data(Qt::DisplayRole).toString(), item->name()); 0068 } 0069 } 0070 0071 0072 #include "moc_plotsdictionarymodeltest.cpp"