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

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 "testdatasource.h"
0013 
0014 #include <QtTest>
0015 
0016 #include <QDir>
0017 #include <QFile>
0018 #include <QSettings>
0019 #include <QTemporaryFile>
0020 
0021 #include "math_kst.h"
0022 #include "kst_inf.h"
0023 
0024 #include "datacollection.h"
0025 #include "objectstore.h"
0026 
0027 #include "datavector.h"
0028 #include "datamatrix.h"
0029 #include "datasourcepluginmanager.h"
0030 
0031 #include "colorsequence.h"
0032 
0033 #define STRINGIFY(x) #x
0034 #define TOSTRING(x) STRINGIFY(x)
0035 
0036 
0037 
0038 static Kst::ObjectStore _store;
0039 
0040 void TestDataSource::initTestCase() {
0041   Kst::DataSourcePluginManager::init();
0042   _plugins = Kst::DataSourcePluginManager::pluginList();
0043 
0044   Kst::ColorSequence::self();
0045 }
0046 
0047 
0048 void TestDataSource::cleanupTestCase() {
0049   _store.clear();
0050 }
0051 
0052 
0053 void TestDataSource::testAscii() {
0054   if (!_plugins.contains("ASCII File Reader"))
0055     QSKIP("...couldn't find plugin.", SkipAll);
0056 
0057   {
0058     QTemporaryFile tf;
0059     tf.open();
0060     QTextStream ts(&tf);
0061     ts << ";" << endl;
0062     ts << " ;" << endl;
0063     ts << "#;" << endl;
0064     ts << "c comment comment" << endl;
0065     ts << "\t!\t!\t!\t!" << endl;
0066     ts << "2.0" << endl;
0067     ts << "1" << endl;
0068     ts << ".2" << endl;
0069     ts.flush();
0070 
0071     Kst::DataSourcePtr dsp = Kst::DataSourcePluginManager::loadSource(&_store, tf.fileName());
0072 
0073     QVERIFY(dsp);
0074     QVERIFY(dsp->isValid());
0075     QVERIFY(dsp->hasConfigWidget());
0076     QCOMPARE(dsp->fileType(), QLatin1String("ASCII file"));
0077     QVERIFY(dsp->vector().isValid("INDEX"));
0078     QVERIFY(dsp->vector().isValid("1"));
0079     QVERIFY(!dsp->vector().isValid("0"));
0080     QVERIFY(!dsp->vector().isValid("2"));
0081     QCOMPARE(dsp->vector().dataInfo(QString::null).samplesPerFrame, 1);
0082     QCOMPARE(dsp->vector().dataInfo("INDEX").samplesPerFrame, 1);
0083     QCOMPARE(dsp->vector().dataInfo("1").samplesPerFrame, 1);
0084     QCOMPARE(dsp->vector().dataInfo(QString::null).frameCount, 3);
0085     QCOMPARE(dsp->vector().dataInfo("1").frameCount, 3);
0086     QCOMPARE(dsp->vector().dataInfo("INDEX").frameCount, 3);
0087     QCOMPARE(dsp->fileName(), tf.fileName());
0088     QCOMPARE(dsp->vector().list().count(), 2);
0089     QVERIFY(dsp->vector().isListComplete());
0090     QVERIFY(!dsp->isEmpty());
0091 
0092     Kst::DataVectorPtr rvp = Kst::kst_cast<Kst::DataVector>(_store.createObject<Kst::DataVector>());
0093 
0094     rvp->writeLock();
0095     rvp->change(dsp, "1", 0, -1, 0, false, false);
0096     rvp->internalUpdate();
0097     rvp->unlock();
0098     QVERIFY(rvp->isValid());
0099     QCOMPARE(rvp->length(), 3);
0100     QCOMPARE(rvp->value()[0], 2.0);
0101     QCOMPARE(rvp->value()[1], 1.0);
0102     QCOMPARE(rvp->value()[2], 0.2);
0103 
0104     rvp = Kst::kst_cast<Kst::DataVector>(_store.createObject<Kst::DataVector>());
0105 
0106     rvp->writeLock();
0107     rvp->change(dsp, "INDEX", 0, -1, 0, false, false);
0108     rvp->internalUpdate();
0109     rvp->unlock();
0110 
0111     QVERIFY(rvp->isValid());
0112     QCOMPARE(rvp->length(), 3);
0113     QCOMPARE(rvp->value()[0], 0.0);
0114     QCOMPARE(rvp->value()[1], 1.0);
0115     QCOMPARE(rvp->value()[2], 2.0);
0116 
0117     tf.close();
0118   }
0119 
0120   {
0121     QTemporaryFile tf;
0122     tf.open();
0123     QTextStream ts(&tf);
0124     ts << "2e-1 \t .1415" << endl;
0125     ts << "nan -.4e-2" << endl;
0126     ts << "inf\t1" << endl;
0127     ts << "0.000000000000000000000000000000000000000000000000 0" << endl;
0128 
0129     Kst::DataSourcePtr dsp = Kst::DataSourcePluginManager::loadSource(&_store, tf.fileName());
0130 
0131     QVERIFY(dsp);
0132     QVERIFY(dsp->isValid());
0133     QVERIFY(dsp->hasConfigWidget());
0134     QCOMPARE(dsp->fileType(), QLatin1String("ASCII file"));
0135     QVERIFY(dsp->vector().isValid("INDEX"));
0136     QVERIFY(dsp->vector().isValid("1"));
0137     QVERIFY(!dsp->vector().isValid("0"));
0138     QVERIFY(dsp->vector().isValid("2"));
0139     QVERIFY(!dsp->vector().isValid("3"));
0140     QCOMPARE(dsp->vector().dataInfo(QString::null).samplesPerFrame, 1);
0141     QCOMPARE(dsp->vector().dataInfo("INDEX").samplesPerFrame, 1);
0142     QCOMPARE(dsp->vector().dataInfo("1").samplesPerFrame, 1);
0143     QCOMPARE(dsp->vector().dataInfo("2").samplesPerFrame, 1);
0144     QCOMPARE(dsp->vector().dataInfo(QString::null).frameCount, 4);
0145     QCOMPARE(dsp->vector().dataInfo("1").frameCount, 4);
0146     QCOMPARE(dsp->vector().dataInfo("2").frameCount, 4);
0147     QCOMPARE(dsp->vector().dataInfo("INDEX").frameCount, 4);
0148     QCOMPARE(dsp->vector().list().count(), 3);
0149     QVERIFY(!dsp->isEmpty());
0150 
0151     Kst::DataVectorPtr rvp = Kst::kst_cast<Kst::DataVector>(_store.createObject<Kst::DataVector>());
0152 
0153     rvp->writeLock();
0154     rvp->change(dsp, "1", 0, -1, 0, false, false);
0155     rvp->internalUpdate();
0156     rvp->unlock();
0157 
0158     QVERIFY(rvp->isValid());
0159     QCOMPARE(rvp->length(), 4);
0160     QCOMPARE(rvp->value()[0], 0.2);
0161     QVERIFY(rvp->value()[1] != rvp->value()[1]);
0162 
0163     QVERIFY(rvp->value()[2] == INF);
0164 
0165     QCOMPARE(rvp->value()[3], 0.0);
0166 
0167     rvp = Kst::kst_cast<Kst::DataVector>(_store.createObject<Kst::DataVector>());
0168 
0169     rvp->writeLock();
0170     rvp->change(dsp, "2", 0, -1, 0, false, false);
0171     rvp->writeLock();
0172     rvp->internalUpdate();
0173     rvp->unlock();
0174 
0175     QVERIFY(rvp->isValid());
0176     QCOMPARE(rvp->length(), 4);
0177     QCOMPARE(rvp->value()[0], 0.1415);
0178     QCOMPARE(rvp->value()[1], -0.004);
0179     QCOMPARE(rvp->value()[2], 1.0);
0180     QCOMPARE(rvp->value()[3], 0.0);
0181 
0182     tf.close();
0183   }
0184 
0185   {
0186     QTemporaryFile tf;
0187     tf.open();
0188     QTextStream ts(&tf);
0189     ts << "2 4" << endl;
0190 
0191     Kst::DataSourcePtr dsp = Kst::DataSourcePluginManager::loadSource(&_store, tf.fileName());
0192 
0193     QVERIFY(dsp);
0194     QVERIFY(dsp->isValid());
0195     QVERIFY(dsp->hasConfigWidget());
0196     QCOMPARE(dsp->fileType(), QLatin1String("ASCII file"));
0197     QVERIFY(dsp->vector().isValid("INDEX"));
0198     QVERIFY(dsp->vector().isValid("1"));
0199     QVERIFY(!dsp->vector().isValid("0"));
0200     QVERIFY(dsp->vector().isValid("2"));
0201     QVERIFY(!dsp->vector().isValid("3"));
0202     QCOMPARE(dsp->vector().dataInfo(QString::null).samplesPerFrame, 1);
0203     QCOMPARE(dsp->vector().dataInfo("INDEX").samplesPerFrame, 1);
0204     QCOMPARE(dsp->vector().dataInfo("1").samplesPerFrame, 1);
0205     QCOMPARE(dsp->vector().dataInfo("2").samplesPerFrame, 1);
0206     QCOMPARE(dsp->vector().dataInfo(QString::null).frameCount, 1);
0207     QCOMPARE(dsp->vector().dataInfo("1").frameCount, 1);
0208     QCOMPARE(dsp->vector().dataInfo("2").frameCount, 1);
0209     QCOMPARE(dsp->vector().dataInfo("INDEX").frameCount, 1);
0210     QCOMPARE(dsp->vector().list().count(), 3);
0211     QVERIFY(!dsp->isEmpty());
0212 
0213 
0214     Kst::DataVectorPtr rvp = Kst::kst_cast<Kst::DataVector>(_store.createObject<Kst::DataVector>());
0215 
0216     rvp->writeLock();
0217     rvp->change(dsp, "1", 0, -1, 0, false, false);
0218     rvp->internalUpdate();
0219     rvp->unlock();
0220 
0221     QVERIFY(rvp->isValid());
0222     QCOMPARE(rvp->length(), 1); // Are we allowed to have vectors of 1?
0223     QCOMPARE(rvp->value()[0], 2.0);
0224 
0225     rvp = Kst::kst_cast<Kst::DataVector>(_store.createObject<Kst::DataVector>());
0226 
0227     rvp->writeLock();
0228     rvp->change(dsp, "2", 0, -1, 0, false, false);
0229     rvp->internalUpdate();
0230     rvp->unlock();
0231 
0232     QVERIFY(rvp->isValid());
0233     QCOMPARE(rvp->length(), 1);
0234     QCOMPARE(rvp->value()[0], 4.0);
0235 
0236     tf.close();
0237   }
0238 
0239   {
0240     QTemporaryFile tf;
0241     tf.open();
0242     QTextStream ts(&tf);
0243     ts << ";" << endl;
0244 
0245     Kst::DataSourcePtr dsp = Kst::DataSourcePluginManager::loadSource(&_store, tf.fileName());
0246 
0247     QVERIFY(dsp);
0248     QVERIFY(dsp->hasConfigWidget());
0249     QCOMPARE(dsp->fileType(), QLatin1String("ASCII file"));
0250     tf.close();
0251   }
0252 
0253   {
0254     QTemporaryFile tf;
0255     tf.open();
0256     QTextStream ts(&tf);
0257     for (int i = 0; i < 39000; ++i) {
0258       ts << i << " " <<  i + 100 << " " << i + 1000 << endl;
0259     }
0260 
0261     Kst::DataSourcePtr dsp = Kst::DataSourcePluginManager::loadSource(&_store, tf.fileName());
0262     dsp->internalUpdate();
0263 
0264     QVERIFY(dsp);
0265     QVERIFY(dsp->isValid());
0266     QVERIFY(dsp->hasConfigWidget());
0267     QCOMPARE(dsp->fileType(), QLatin1String("ASCII file"));
0268     QCOMPARE(dsp->vector().dataInfo(QString::null).frameCount, 39000);
0269     QCOMPARE(dsp->vector().dataInfo("1").frameCount, 39000);
0270     QCOMPARE(dsp->vector().dataInfo("2").frameCount, 39000);
0271     QCOMPARE(dsp->vector().dataInfo("3").frameCount, 39000);
0272     QCOMPARE(dsp->vector().dataInfo("INDEX").frameCount, 39000);
0273     QCOMPARE(dsp->vector().list().count(), 4);
0274     QVERIFY(!dsp->isEmpty());
0275 
0276     Kst::DataVectorPtr rvp = Kst::kst_cast<Kst::DataVector>(_store.createObject<Kst::DataVector>());
0277 
0278     rvp->writeLock();
0279     rvp->change(dsp, "1", 0, -1, 0, false, false);
0280     rvp->internalUpdate();
0281     rvp->unlock();
0282     QVERIFY(rvp->isValid());
0283     QCOMPARE(rvp->length(), 39000);
0284 
0285     rvp = Kst::kst_cast<Kst::DataVector>(_store.createObject<Kst::DataVector>());
0286 
0287     rvp->writeLock();
0288     rvp->change(dsp, "2", 0, -1, 10, true, false);
0289     rvp->internalUpdate();
0290     rvp->unlock();
0291 
0292     QVERIFY(rvp->isValid());
0293     QCOMPARE(rvp->length(), 3900);
0294     QCOMPARE(rvp->value()[0], 100.0);
0295     QCOMPARE(rvp->value()[1], 110.0);
0296     QCOMPARE(rvp->value()[2], 120.0);
0297     QCOMPARE(rvp->value()[3898], 39080.0);
0298 
0299     rvp = Kst::kst_cast<Kst::DataVector>(_store.createObject<Kst::DataVector>());
0300 
0301     rvp->writeLock();
0302     rvp->change(dsp, "3", 0, -1, 10, true, true);
0303     rvp->internalUpdate();
0304     rvp->unlock();
0305 
0306     QVERIFY(rvp->isValid());
0307     QCOMPARE(rvp->length(), 3900);
0308     QCOMPARE(rvp->value()[0], 1004.5);
0309     QCOMPARE(rvp->value()[1], 1014.5);
0310     QCOMPARE(rvp->value()[2], 1024.5);
0311     QCOMPARE(rvp->value()[3898], 39984.5);
0312 
0313     QFile::remove(dsp->fileName());
0314     tf.close();
0315 
0316     rvp->writeLock();
0317     rvp->reload();
0318     rvp->unlock();
0319 #ifndef Q_WS_WIN32
0320     // Win32 you can't erase a file that's open
0321     QVERIFY(!rvp->isValid());
0322 #endif
0323   }
0324 }
0325 
0326 
0327 void TestDataSource::testDirfile() {
0328   if (!_plugins.contains("DirFile Reader"))
0329     QSKIP("...couldn't find plugin.", SkipAll);
0330 
0331   //These tests assume that the dirfile was generated with dirfile_maker
0332 
0333   {
0334     QString fifteen = QDir::currentPath() + QDir::separator() + QString("tests") +
0335                       QDir::separator() + QString("dirfile_testcase") +
0336                       QDir::separator() + QString("15count");
0337     if (!QFile::exists(fifteen + QDir::separator() + "format")) {
0338       QSKIP("...unable to perform test.  Datafile missing", SkipAll);
0339     }
0340     printf("Opening dirfile = %s for test.\n", fifteen.toLatin1().data());
0341 
0342     Kst::DataSourcePtr dsp = Kst::DataSourcePluginManager::loadSource(&_store, fifteen);
0343     dsp->internalUpdate();
0344 
0345     QVERIFY(dsp);
0346     QVERIFY(dsp->isValid());
0347     QVERIFY(!dsp->hasConfigWidget());
0348     QCOMPARE(dsp->fileType(), QLatin1String("Directory of Binary Files"));
0349     QVERIFY(dsp->vector().isValid("INDEX"));
0350     QCOMPARE(dsp->vector().dataInfo("INDEX").frameCount, 17);
0351     QVERIFY(dsp->vector().isValid("cos"));
0352     QVERIFY(dsp->vector().isValid("fcount"));
0353     QVERIFY(dsp->vector().isValid("scount"));
0354     QVERIFY(dsp->vector().isValid("sine"));
0355     QVERIFY(dsp->vector().isValid("ssine"));
0356     QVERIFY(!dsp->vector().isValid("foo"));
0357 
0358     //TODO test samples per frame?
0359 
0360     QCOMPARE(dsp->fileName(), fifteen);
0361     QCOMPARE(dsp->vector().list().count(), 6);
0362     QVERIFY(dsp->vector().isListComplete());
0363 
0364     QVERIFY(!dsp->isEmpty());
0365 
0366   {
0367     //Skip FIVE frames...
0368 
0369     Kst::DataVectorPtr rvp = Kst::kst_cast<Kst::DataVector>(_store.createObject<Kst::DataVector>());
0370 
0371     rvp->writeLock();
0372     rvp->change(dsp, "INDEX", 0, -1, 5, true, false);
0373     rvp->internalUpdate();
0374     rvp->unlock();
0375 
0376     //We should have length equal to three...  items {0, 5, 10}
0377     //NOTE: The last item, index #14, does not fit in the skip boundary...
0378     QCOMPARE(3, rvp->length());
0379     QCOMPARE(0.0, rvp->value(0));
0380     QCOMPARE(5.0, rvp->value(1));
0381     QCOMPARE(10.0, rvp->value(2));
0382 
0383     QCOMPARE(15, rvp->numFrames());
0384     QCOMPARE(0, rvp->startFrame());
0385 
0386     QCOMPARE(-1, rvp->reqNumFrames());
0387     QCOMPARE(0, rvp->reqStartFrame());
0388 
0389     QCOMPARE(true, rvp->readToEOF());
0390     QCOMPARE(false, rvp->countFromEOF());
0391     QCOMPARE(true, rvp->doSkip());
0392     QCOMPARE(5, rvp->skip());
0393     QCOMPARE(false, rvp->doAve());
0394   }
0395   {
0396     //Skip FIVE frames start at 3...
0397     Kst::DataVectorPtr rvp = Kst::kst_cast<Kst::DataVector>(_store.createObject<Kst::DataVector>());
0398 
0399     rvp->writeLock();
0400     rvp->change(dsp, "INDEX", 3, -1, 5, true, false);
0401     rvp->internalUpdate();
0402     rvp->unlock();
0403 
0404     //We should have length equal to two...  items {5, 10}
0405     QCOMPARE(2, rvp->length());
0406     QCOMPARE(5.0, rvp->value(0));
0407     QCOMPARE(10.0, rvp->value(1));
0408 
0409     QCOMPARE(10, rvp->numFrames());
0410     QCOMPARE(5, rvp->startFrame());
0411 
0412     QCOMPARE(-1, rvp->reqNumFrames());
0413     QCOMPARE(3, rvp->reqStartFrame());
0414 
0415     QCOMPARE(true, rvp->readToEOF());
0416     QCOMPARE(false, rvp->countFromEOF());
0417     QCOMPARE(true, rvp->doSkip());
0418     QCOMPARE(5, rvp->skip());
0419     QCOMPARE(false, rvp->doAve());
0420   }
0421   {
0422     //Skip FIVE frames 11 from end...
0423     Kst::DataVectorPtr rvp = Kst::kst_cast<Kst::DataVector>(_store.createObject<Kst::DataVector>());
0424 
0425     rvp->writeLock();
0426     rvp->change(dsp, "INDEX", 0, 11, 5, true, false);
0427     rvp->internalUpdate();
0428     rvp->unlock();
0429 
0430     //We should have length equal to two...  items {0, 5}
0431     QCOMPARE(2, rvp->length());
0432     QCOMPARE(0.0, rvp->value(0));
0433     QCOMPARE(5.0, rvp->value(1));
0434 
0435     QCOMPARE(10, rvp->numFrames());
0436     QCOMPARE(0, rvp->startFrame());
0437 
0438     QCOMPARE(11, rvp->reqNumFrames());
0439     QCOMPARE(0, rvp->reqStartFrame());
0440 
0441     QCOMPARE(false, rvp->readToEOF());
0442     QCOMPARE(false, rvp->countFromEOF());
0443     QCOMPARE(true, rvp->doSkip());
0444     QCOMPARE(5, rvp->skip());
0445     QCOMPARE(false, rvp->doAve());
0446   }
0447   {
0448     //Skip FIVE frames and countFromEOF()...
0449     Kst::DataVectorPtr rvp = Kst::kst_cast<Kst::DataVector>(_store.createObject<Kst::DataVector>());
0450 
0451     rvp->writeLock();
0452     rvp->change(dsp, "INDEX", -1, 10, 5, true, false);
0453     rvp->internalUpdate();
0454     rvp->unlock();
0455 
0456     //We should have length equal to two...  items {5, 10}
0457     QCOMPARE(2, rvp->length());
0458     QCOMPARE(10.0, rvp->value(0));
0459     QCOMPARE(15.0, rvp->value(1));
0460 
0461     QCOMPARE(10, rvp->numFrames());
0462     QCOMPARE(10, rvp->startFrame());
0463 
0464     QCOMPARE(10, rvp->reqNumFrames());
0465     QCOMPARE(-1, rvp->reqStartFrame());
0466 
0467     QCOMPARE(false, rvp->readToEOF());
0468     QCOMPARE(true, rvp->countFromEOF());
0469     QCOMPARE(true, rvp->doSkip());
0470     QCOMPARE(5, rvp->skip());
0471     QCOMPARE(false, rvp->doAve());
0472   }
0473   }
0474 }
0475 
0476 
0477 void TestDataSource::testCDF() {
0478   return; //FIXME remove when we actually have some tests for this datasource.
0479 
0480   if (!_plugins.contains("CDF File Reader"))
0481     QSKIP("...couldn't find plugin.", SkipAll);
0482 }
0483 
0484 
0485 void TestDataSource::testFrame() {
0486   return; //FIXME remove when we actually have some tests for this datasource.
0487 
0488   if (!_plugins.contains("Frame Reader"))
0489     QSKIP("...couldn't find plugin.", SkipAll);
0490 }
0491 
0492 
0493 void TestDataSource::testIndirect() {
0494   return; //FIXME remove when we actually have some tests for this datasource.
0495 
0496   if (!_plugins.contains("Indirect File Reader"))
0497     QSKIP("...couldn't find plugin.", SkipAll);
0498 }
0499 
0500 
0501 void TestDataSource::testLFI() {
0502   return; //FIXME remove when we actually have some tests for this datasource.
0503 
0504   if (!_plugins.contains("LFIIO Reader"))
0505     QSKIP("...couldn't find plugin.", SkipAll);
0506 }
0507 
0508 
0509 void TestDataSource::testPlanck() {
0510   return; //FIXME remove when we actually have some tests for this datasource.
0511 
0512   if (!_plugins.contains("PLANCK Plugin"))
0513     QSKIP("...couldn't find plugin.", SkipAll);
0514 }
0515 
0516 
0517 void TestDataSource::testStdin() {
0518 }
0519 
0520 void TestDataSource::testQImageSource() {
0521   bool ok = true;
0522 
0523   if (!_plugins.contains("QImage Source Reader"))
0524     QSKIP("...couldn't find plugin.", SkipAll);
0525 
0526   //These tests assume that the image kst.png exists in src/images
0527   QString imageFile = QString(TOSTRING(KST_SRC_DIR)) + QDir::separator() + QString("src") +
0528                       QDir::separator() + QString("images") + QDir::separator() + QString("kst.png");
0529 
0530   if (!QFile::exists(imageFile)) {
0531     QSKIP("...unable to perform test.  Image file missing.", SkipAll);
0532   }
0533 
0534   printf("Opening image = %s for test.\n", imageFile.toLatin1().data());
0535 
0536   Kst::DataSourcePtr dsp = Kst::DataSourcePluginManager::loadSource(&_store, imageFile);
0537   dsp->internalUpdate();
0538 
0539   QVERIFY(dsp);
0540   QVERIFY(dsp->isValid());
0541   QVERIFY(!dsp->hasConfigWidget());
0542   QCOMPARE(dsp->fileType(), QLatin1String("QImage image"));
0543   QVERIFY(dsp->vector().isValid("INDEX"));
0544   QCOMPARE(dsp->vector().dataInfo("INDEX").frameCount, 1024);
0545   QVERIFY(dsp->vector().isValid("RED"));
0546   QVERIFY(dsp->vector().isValid("BLUE"));
0547   QVERIFY(dsp->vector().isValid("GREEN"));
0548   QVERIFY(dsp->vector().isValid("GRAY"));
0549   QVERIFY(!dsp->vector().isValid("foo"));
0550 
0551   //TODO test samples per frame?
0552 
0553   QCOMPARE(dsp->fileName(), imageFile);
0554   QCOMPARE(dsp->vector().list().count(), 5);
0555   QVERIFY(dsp->vector().isListComplete());
0556 
0557   QVERIFY(!dsp->isEmpty());
0558 
0559   QVERIFY(dsp->matrix().isValid("RED"));
0560   QVERIFY(dsp->matrix().isValid("BLUE"));
0561   QVERIFY(dsp->matrix().isValid("GREEN"));
0562   QVERIFY(dsp->matrix().isValid("GRAY"));
0563   QVERIFY(!dsp->matrix().isValid("foo"));
0564 
0565   {
0566     Kst::DataMatrixPtr matrix = Kst::kst_cast<Kst::DataMatrix>(_store.createObject<Kst::DataMatrix>());
0567     matrix->change(dsp, "GRAY", 0, 0,
0568         -1, -1, false,
0569         false, 0, 0, 0, 1, 1);
0570 
0571     matrix->writeLock();
0572     matrix->internalUpdate();
0573     matrix->unlock();
0574 
0575 
0576     QCOMPARE(matrix->xNumSteps(), 32);
0577     QCOMPARE(matrix->yNumSteps(), 32);
0578     QCOMPARE(matrix->xStepSize(), 1.0);
0579     QCOMPARE(matrix->yStepSize(), 1.0);
0580     QCOMPARE(matrix->minX(), 0.0);
0581     QCOMPARE(matrix->minY(), 0.0);
0582 
0583     QCOMPARE(matrix->minValue(), 0.0);
0584     QCOMPARE(matrix->maxValue(), 255.0);
0585 
0586     QCOMPARE(matrix->minValuePositive(), 7.0);
0587 
0588     QCOMPARE(matrix->sampleCount(), 1024);
0589 
0590     QCOMPARE(matrix->value(0, 0, &ok), 0.0);
0591     QVERIFY(ok);
0592     QCOMPARE(matrix->value(25, 3, &ok), 81.0);
0593     QVERIFY(ok);
0594   }
0595   {
0596     Kst::DataVectorPtr rvp = Kst::kst_cast<Kst::DataVector>(_store.createObject<Kst::DataVector>());
0597 
0598     rvp->writeLock();
0599     rvp->change(dsp, "INDEX", 0, -1, 1, false, false);
0600     rvp->internalUpdate();
0601     rvp->unlock();
0602 
0603     QCOMPARE(1024, rvp->length());
0604     QCOMPARE(0.0, rvp->value(0));
0605     QCOMPARE(1.0, rvp->value(1));
0606     QCOMPARE(2.0, rvp->value(2));
0607     QCOMPARE(1023.0, rvp->value(1023));
0608 
0609     QCOMPARE(1024, rvp->numFrames());
0610     QCOMPARE(0, rvp->startFrame());
0611 
0612     QCOMPARE(-1, rvp->reqNumFrames());
0613     QCOMPARE(0, rvp->reqStartFrame());
0614 
0615     QCOMPARE(true, rvp->readToEOF());
0616     QCOMPARE(false, rvp->countFromEOF());
0617     QCOMPARE(false, rvp->doSkip());
0618     QCOMPARE(0, rvp->skip());
0619     QCOMPARE(false, rvp->doAve());
0620   }
0621 }
0622 
0623 
0624 void TestDataSource::testFITSImage() {
0625   bool ok = true;
0626 
0627   if (!_plugins.contains("FITS Image Source Reader"))
0628     QSKIP("...couldn't find plugin.", SkipAll);
0629 
0630   //These tests assume that the fits image test.fits exists in tests/fitsimage_testcase
0631   QString imageFile = QDir::currentPath() + QDir::separator() + QString("tests") +
0632                       QDir::separator() + QString("fitsimage_testcase") + QDir::separator() + QString("test.fits");
0633 
0634   if (!QFile::exists(imageFile)) {
0635     QSKIP("...unable to perform test.  Image file missing.", SkipAll);
0636   }
0637 
0638   printf("Opening image = %s for test.\n", imageFile.toLatin1().data());
0639 
0640   Kst::DataSourcePtr dsp = Kst::DataSourcePluginManager::loadSource(&_store, imageFile);
0641   dsp->internalUpdate();
0642 
0643   QVERIFY(dsp);
0644   QVERIFY(dsp->isValid());
0645   QVERIFY(!dsp->hasConfigWidget());
0646   QCOMPARE(dsp->fileType(), QLatin1String("FITS image"));
0647   QVERIFY(dsp->vector().isValid("INDEX"));
0648   QCOMPARE(dsp->vector().dataInfo("INDEX").frameCount, 58800);
0649   QVERIFY(dsp->vector().isValid("1"));
0650   QVERIFY(!dsp->vector().isValid("foo"));
0651 
0652   //TODO test samples per frame?
0653 
0654   QCOMPARE(dsp->fileName(), imageFile);
0655   QCOMPARE(dsp->vector().list().count(), 2);
0656   QVERIFY(dsp->vector().isListComplete());
0657 
0658   QVERIFY(!dsp->isEmpty());
0659 
0660   QVERIFY(dsp->matrix().isValid("1"));
0661   QVERIFY(!dsp->matrix().isValid("foo"));
0662 
0663   {
0664     Kst::DataMatrixPtr matrix = Kst::kst_cast<Kst::DataMatrix>(_store.createObject<Kst::DataMatrix>());
0665     matrix->change(dsp, "1", 0, 0,
0666         -1, -1, false, false, 0, 0, 0, 1, 1);
0667 
0668     matrix->writeLock();
0669     matrix->internalUpdate();
0670     matrix->unlock();
0671 
0672     QCOMPARE(matrix->xNumSteps(), 280);
0673     QCOMPARE(matrix->yNumSteps(), 210);
0674 
0675     QCOMPARE(matrix->xStepSize(), 1.0);
0676     QCOMPARE(matrix->yStepSize(), 1.0);
0677     QCOMPARE(matrix->minX(), 0.0);
0678     QCOMPARE(matrix->minY(), 0.0);
0679 
0680     QCOMPARE(matrix->minValue(), -86.297431945800781);
0681     QCOMPARE(matrix->maxValue(), 487.873565673828125);
0682 
0683     QCOMPARE(matrix->minValuePositive(), 0.000308976683300);
0684 
0685     QCOMPARE(matrix->sampleCount(), 58800);
0686 
0687     QCOMPARE(matrix->value(0, 0, &ok), 0.0);
0688     QVERIFY(!ok);
0689 
0690     QCOMPARE(matrix->value(12, 61, &ok), -17.691156387329102);
0691     QVERIFY(ok);
0692   }
0693   {
0694     Kst::DataVectorPtr rvp = Kst::kst_cast<Kst::DataVector>(_store.createObject<Kst::DataVector>());
0695 
0696     rvp->writeLock();
0697     rvp->change(dsp, "INDEX", 0, -1, 1, false, false);
0698     rvp->internalUpdate();
0699     rvp->unlock();
0700 
0701     QCOMPARE(58800, rvp->length());
0702     QCOMPARE(0.0, rvp->value(0));
0703     QCOMPARE(1.0, rvp->value(1));
0704     QCOMPARE(2.0, rvp->value(2));
0705     QCOMPARE(1023.0, rvp->value(1023));
0706 
0707     QCOMPARE(58800, rvp->numFrames());
0708     QCOMPARE(0, rvp->startFrame());
0709 
0710     QCOMPARE(-1, rvp->reqNumFrames());
0711     QCOMPARE(0, rvp->reqStartFrame());
0712 
0713     QCOMPARE(true, rvp->readToEOF());
0714     QCOMPARE(false, rvp->countFromEOF());
0715     QCOMPARE(false, rvp->doSkip());
0716     QCOMPARE(0, rvp->skip());
0717     QCOMPARE(false, rvp->doAve());
0718   }
0719 }
0720 
0721 #ifdef KST_USE_QTEST_MAIN
0722 QTEST_MAIN(TestDataSource)
0723 #endif
0724 
0725 // vim: ts=2 sw=2 et