File: testdatamatrix.cpp

package info (click to toggle)
kst 2.0.8-6
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 30,748 kB
  • sloc: cpp: 97,086; ansic: 13,364; python: 2,970; sh: 761; yacc: 184; lex: 143; makefile: 141; javascript: 122; perl: 30; xml: 30
file content (97 lines) | stat: -rw-r--r-- 3,019 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/***************************************************************************
 *                                                                         *
 *   copyright : (C) 2007 The University of Toronto                        *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include "testdatamatrix.h"

#include <QtTest>

#include "datamatrix.h"
#include "datasource.h"
#include "math_kst.h"
#include "datacollection.h"
#include "objectstore.h"
#include "datasourcepluginmanager.h"

#include <QXmlStreamAttributes>

static Kst::ObjectStore _store;

void TestDataMatrix::cleanupTestCase() {
  _store.clear();
}


void TestDataMatrix::testDataMatrix() {
  bool ok = true;

  QStringList _plugins = Kst::DataSourcePluginManager::pluginList();

  //basic default constructor values
  Kst::DataMatrixPtr m1 = Kst::kst_cast<Kst::DataMatrix>(_store.createObject<Kst::DataMatrix>());
  QCOMPARE(m1->sampleCount(), 0);
  QCOMPARE(m1->minValue(), 0.0);
  QCOMPARE(m1->maxValue(), 0.0);
  QCOMPARE(m1->value(0, 0, &ok), 0.0);
  QVERIFY(!ok);
  QCOMPARE(m1->value(10, 10, &ok), 0.0); //should be outside the boundaries.
  QVERIFY(!ok);
  QCOMPARE(m1->meanValue(), 0.0);

  if (!_plugins.contains("QImage Source Reader"))
    QSKIP("...couldn't find plugin.", SkipAll);

  //These tests assume that the image kst.png exists in src/images
  QString imageFile = QDir::currentPath() + QDir::separator() + QString("src") +
                      QDir::separator() + QString("images") + QDir::separator() + QString("kst.png");

  if (!QFile::exists(imageFile)) {
    QSKIP("...unable to perform test.  Image file missing.", SkipAll);
  }

  printf("Opening image = %s for test.\n", imageFile.toLatin1().data());

  Kst::DataSourcePtr dsp = Kst::DataSourcePluginManager::loadSource(&_store, imageFile);
  dsp->internalUpdate();

  QVERIFY(dsp);
  QVERIFY(dsp->isValid());

  m1->change(dsp, "GRAY", 0, 0, -1, -1, false, false, 1, 0, 0, 1, 1);

  m1->writeLock();
  m1->internalUpdate();
  m1->unlock();

  QCOMPARE(m1->xNumSteps(), 32);
  QCOMPARE(m1->yNumSteps(), 32);
  QCOMPARE(m1->xStepSize(), 1.0);
  QCOMPARE(m1->yStepSize(), 1.0);
  QCOMPARE(m1->minX(), 0.0);
  QCOMPARE(m1->minY(), 0.0);

  QCOMPARE(m1->minValue(), 0.0);
  QCOMPARE(m1->maxValue(), 255.0);

  QCOMPARE(m1->minValuePositive(), 7.0);

  QCOMPARE(m1->sampleCount(), 1024);

  QCOMPARE(m1->value(0, 0, &ok), 0.0);
  QVERIFY(ok);
  QCOMPARE(m1->value(25, 3, &ok), 81.0);
  QVERIFY(ok);
}

#ifdef KST_USE_QTEST_MAIN
QTEST_MAIN(TestDataMatrix)
#endif

// vim: ts=2 sw=2 et