File indexing completed on 2024-05-19 04:34:06

0001 /***************************************************************************
0002  *                                                                         *
0003  *   copyright : (C) 2007 The University of Toronto                        *
0004  *                                                                         *
0005  *   This program is free software; you can redistribute it and/or modify  *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  *                                                                         *
0010  ***************************************************************************/
0011 
0012 #include "testdatamatrix.h"
0013 
0014 #include <QtTest>
0015 
0016 #include "datamatrix.h"
0017 #include "datasource.h"
0018 #include "math_kst.h"
0019 #include "datacollection.h"
0020 #include "objectstore.h"
0021 #include "datasourcepluginmanager.h"
0022 
0023 #include <QXmlStreamAttributes>
0024 
0025 static Kst::ObjectStore _store;
0026 
0027 void TestDataMatrix::cleanupTestCase() {
0028   _store.clear();
0029 }
0030 
0031 
0032 void TestDataMatrix::testDataMatrix() {
0033   bool ok = true;
0034 
0035   QStringList _plugins = Kst::DataSourcePluginManager::pluginList();
0036 
0037   //basic default constructor values
0038   Kst::DataMatrixPtr m1 = Kst::kst_cast<Kst::DataMatrix>(_store.createObject<Kst::DataMatrix>());
0039   QCOMPARE(m1->sampleCount(), 0);
0040   QCOMPARE(m1->minValue(), 0.0);
0041   QCOMPARE(m1->maxValue(), 0.0);
0042   QCOMPARE(m1->value(0, 0, &ok), 0.0);
0043   QVERIFY(!ok);
0044   QCOMPARE(m1->value(10, 10, &ok), 0.0); //should be outside the boundaries.
0045   QVERIFY(!ok);
0046   QCOMPARE(m1->meanValue(), 0.0);
0047 
0048   if (!_plugins.contains("QImage Source Reader"))
0049     QSKIP("...couldn't find plugin.", SkipAll);
0050 
0051   //These tests assume that the image kst.png exists in src/images
0052   QString imageFile = QDir::currentPath() + QDir::separator() + QString("src") +
0053                       QDir::separator() + QString("images") + QDir::separator() + QString("kst.png");
0054 
0055   if (!QFile::exists(imageFile)) {
0056     QSKIP("...unable to perform test.  Image file missing.", SkipAll);
0057   }
0058 
0059   printf("Opening image = %s for test.\n", imageFile.toLatin1().data());
0060 
0061   Kst::DataSourcePtr dsp = Kst::DataSourcePluginManager::loadSource(&_store, imageFile);
0062   dsp->internalUpdate();
0063 
0064   QVERIFY(dsp);
0065   QVERIFY(dsp->isValid());
0066 
0067   m1->change(dsp, "GRAY", 0, 0, -1, -1, false, false, 1, 0, 0, 1, 1);
0068 
0069   m1->writeLock();
0070   m1->internalUpdate();
0071   m1->unlock();
0072 
0073   QCOMPARE(m1->xNumSteps(), 32);
0074   QCOMPARE(m1->yNumSteps(), 32);
0075   QCOMPARE(m1->xStepSize(), 1.0);
0076   QCOMPARE(m1->yStepSize(), 1.0);
0077   QCOMPARE(m1->minX(), 0.0);
0078   QCOMPARE(m1->minY(), 0.0);
0079 
0080   QCOMPARE(m1->minValue(), 0.0);
0081   QCOMPARE(m1->maxValue(), 255.0);
0082 
0083   QCOMPARE(m1->minValuePositive(), 7.0);
0084 
0085   QCOMPARE(m1->sampleCount(), 1024);
0086 
0087   QCOMPARE(m1->value(0, 0, &ok), 0.0);
0088   QVERIFY(ok);
0089   QCOMPARE(m1->value(25, 3, &ok), 81.0);
0090   QVERIFY(ok);
0091 }
0092 
0093 #ifdef KST_USE_QTEST_MAIN
0094 QTEST_MAIN(TestDataMatrix)
0095 #endif
0096 
0097 // vim: ts=2 sw=2 et