File: testscalar.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 (152 lines) | stat: -rw-r--r-- 4,389 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/***************************************************************************
 *                                                                         *
 *   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 "testscalar.h"

#include <QtTest>

#include <QDomDocument>

#include <scalar.h>

#include <math_kst.h>
#include <kst_inf.h>

#include <datacollection.h>
#include <objectstore.h>
#include "updatemanager.h"

static Kst::ObjectStore _store;

double NOPOINT = NAN;

SListener::SListener() : QObject(), _trigger(0) {}
SListener::~SListener() {}
void SListener::trigger(qint64) { 
    _trigger++; 
}


QDomDocument TestScalar::makeDOMDocument(const QString& tag, const QString& val, bool orphan) {
  QDomDocument loadTest("scalardocument");
  QDomElement scalardoc, child;
  QDomText text;

  scalardoc = loadTest.createElement("scalar");

  child = loadTest.createElement("tag");
  text = loadTest.createTextNode(tag);
  child.appendChild(text);
  scalardoc.appendChild(child);

  child = loadTest.createElement("value");
  text = loadTest.createTextNode(val);
  child.appendChild(text);
  scalardoc.appendChild(child);

  if (orphan) {
    child = loadTest.createElement("orphan");
    scalardoc.appendChild(child);
  }

  loadTest.appendChild(scalardoc);

  return loadTest;
}


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


void TestScalar::testScalar() {
  Kst::ScalarPtr sp = Kst::kst_cast<Kst::Scalar>(_store.createObject<Kst::Scalar>());
  QCOMPARE(sp->value(), 0.0);
  *sp = 3.1415;
  QVERIFY(sp->displayable());
  QCOMPARE(sp->value(), 3.1415);
  sp->setValue(2.1415);
  QCOMPARE(sp->value(), 2.1415);
  sp->setValue(NOPOINT);
  QVERIFY(sp->value() != sp->value());
  sp->setValue(INF );

  QVERIFY(sp->value() == INF);

  QCOMPARE((*sp = 2.0).value(), 2.0);
  SListener *listener = new SListener;
  Kst::UpdateManager::self()->setStore(&_store);
  QObject::connect(Kst::UpdateManager::self(), SIGNAL(objectsUpdated(qint64)), listener, SLOT(trigger(qint64)));

  *sp = 3.1415;
  Kst::UpdateManager::self()->doUpdates(true);
  QCOMPARE(listener->_trigger, 1);

  sp->setValue(3.1415);
  QCOMPARE(listener->_trigger, 1);
  Kst::UpdateManager::self()->doUpdates(true);
  QCOMPARE(listener->_trigger, 2);

  *sp = 1.1415;
  Kst::UpdateManager::self()->doUpdates(true);
  QCOMPARE(listener->_trigger, 3);

  Kst::ScalarPtr sp2 = Kst::kst_cast<Kst::Scalar>(_store.createObject<Kst::Scalar>());

  QVERIFY(sp->displayable());
  QVERIFY(sp2->displayable());

  // FIXME: This constructor is no longer used - test using the factory
//   QDomNode n;
//   QDomElement e;
//   n = makeDOMDocument("load1", "2.14159265").firstChild();
//   e = n.toElement();
// 
//   Kst::ScalarPtr sp3 = new Kst::Scalar(&_store, e);
//   QCOMPARE(sp3->orphan(), false);
//   QCOMPARE(sp3->value(), 2.14159265);
//   QCOMPARE(sp3->tag().tagString(), QLatin1String("load1"));
//   QVERIFY(sp3->displayable());
// 
//   n = makeDOMDocument("55.4232", "55.4232", true).firstChild();
//   e = n.toElement();
//   Kst::ScalarPtr sp4 = new Kst::Scalar(&_store, e);
//   QVERIFY(sp4->orphan());
//   QCOMPARE(sp4->value(), 55.4232);
//   QCOMPARE(sp4->tag().tagString(), QLatin1String("55.4232"));
//   QVERIFY(!sp4->displayable());
// 
//   n = makeDOMDocument("load2", "NAN").firstChild();
//   e = n.toElement();
//   sp4 = new Kst::Scalar(&_store, e);
//   QVERIFY(sp4->value() != sp4->value());
// 
//   n = makeDOMDocument("load3", "INF").firstChild();
//   e = n.toElement();
//   sp4 = new Kst::Scalar(&_store, e);
// 
//   QVERIFY(sp4->value() == INF);
// 
//   n = makeDOMDocument("load4", "-INF").firstChild();
//   e = n.toElement();
//   sp4 = new Kst::Scalar(&_store, e);
// 
//   QVERIFY(sp4->value() == -INF);

  delete listener;
}

#ifdef KST_USE_QTEST_MAIN
QTEST_MAIN(TestScalar)
#endif

// vim: ts=2 sw=2 et