File: testobjectstore.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 (67 lines) | stat: -rw-r--r-- 2,298 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
/***************************************************************************
 *                                                                         *
 *   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 "testobjectstore.h"

#include <QtTest>

#include <datasource.h>
#include <datavector.h>
#include <objectstore.h>
#include <scalar.h>
#include <vector.h>

using namespace Kst;

void TestObjectStore::cleanupTestCase() {
}

void TestObjectStore::testObjectStore() {
  ObjectStore store;
  QVERIFY(store.isEmpty());

  ScalarPtr sc = kst_cast<Scalar>(store.createObject<Scalar>());
  QVERIFY(sc);  // scalar was created
  ScalarPtr sc2 = kst_cast<Scalar>(store.createObject<Scalar>());
  QVERIFY(sc2);
  QCOMPARE(store.getObjects<Scalar>().count(), 2);
  QCOMPARE(store.getObjects<Vector>().count(), 0);

  QVERIFY(sc == kst_cast<Scalar>(store.retrieveObject(sc->Name()))); // can retrieve the object from the store

  VectorPtr vec = kst_cast<Vector>(store.createObject<Vector>());
  QVERIFY(vec);
  QVERIFY(store.getObjects<Scalar>().count() > 2);  // to account for the vector's stats scalars
  QCOMPARE(store.getObjects<Vector>().count(), 1);

  QCOMPARE(store.getObjects<DataSource>().count(), 0);
  QCOMPARE(store.getObjects<DataVector>().count(), 0);
  QCOMPARE(store.dataSourceList().count(), 0);

  store.clear();
  QVERIFY(store.isEmpty());
  QVERIFY(sc);  // make sure objects didn't get deleted while references were held
  QVERIFY(sc2);
  QVERIFY(vec);

  QPointer<Scalar> p(sc);
  ScalarPtr tempSc = sc;
  sc = 0L;
  QVERIFY(p);
  tempSc = 0L;
  QVERIFY(!p);  // make sure object gets deleted when last reference is gone
}

#ifdef KST_USE_QTEST_MAIN
QTEST_MAIN(TestObjectStore)
#endif

// vim: ts=2 sw=2 et