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

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 "testobjectstore.h"
0013 
0014 #include <QtTest>
0015 
0016 #include <datasource.h>
0017 #include <datavector.h>
0018 #include <objectstore.h>
0019 #include <scalar.h>
0020 #include <vector.h>
0021 
0022 using namespace Kst;
0023 
0024 void TestObjectStore::cleanupTestCase() {
0025 }
0026 
0027 void TestObjectStore::testObjectStore() {
0028   ObjectStore store;
0029   QVERIFY(store.isEmpty());
0030 
0031   ScalarPtr sc = kst_cast<Scalar>(store.createObject<Scalar>());
0032   QVERIFY(sc);  // scalar was created
0033   ScalarPtr sc2 = kst_cast<Scalar>(store.createObject<Scalar>());
0034   QVERIFY(sc2);
0035   QCOMPARE(store.getObjects<Scalar>().count(), 2);
0036   QCOMPARE(store.getObjects<Vector>().count(), 0);
0037 
0038   QVERIFY(sc == kst_cast<Scalar>(store.retrieveObject(sc->Name()))); // can retrieve the object from the store
0039 
0040   VectorPtr vec = kst_cast<Vector>(store.createObject<Vector>());
0041   QVERIFY(vec);
0042   QVERIFY(store.getObjects<Scalar>().count() > 2);  // to account for the vector's stats scalars
0043   QCOMPARE(store.getObjects<Vector>().count(), 1);
0044 
0045   QCOMPARE(store.getObjects<DataSource>().count(), 0);
0046   QCOMPARE(store.getObjects<DataVector>().count(), 0);
0047   QCOMPARE(store.dataSourceList().count(), 0);
0048 
0049   store.clear();
0050   QVERIFY(store.isEmpty());
0051   QVERIFY(sc);  // make sure objects didn't get deleted while references were held
0052   QVERIFY(sc2);
0053   QVERIFY(vec);
0054 
0055   QPointer<Scalar> p(sc);
0056   ScalarPtr tempSc = sc;
0057   sc = 0L;
0058   QVERIFY(p);
0059   tempSc = 0L;
0060   QVERIFY(!p);  // make sure object gets deleted when last reference is gone
0061 }
0062 
0063 #ifdef KST_USE_QTEST_MAIN
0064 QTEST_MAIN(TestObjectStore)
0065 #endif
0066 
0067 // vim: ts=2 sw=2 et