From 5fbb6351fc1ec8292a8314fb2cadd84bba0dab5d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Mikko=20Kein=C3=A4nen?= Date: Wed, 24 Nov 2010 01:37:44 +0200 Subject: [PATCH 1/1] Still experimenting with unit testing code. --- src/dataobjects/emufrontfile.cpp | 6 ++ src/dataobjects/emufrontfile.h | 1 + src/dataobjects/emufrontfileobject.h | 2 +- src/dataobjects/emufrontobject.cpp | 2 + src/dataobjects/platform.cpp | 10 +++ src/dataobjects/platform.h | 1 + testing/EmuFrontTesting/platformtest.cpp | 100 +++++++++++++++++++++++++----- testing/EmuFrontTesting/platformtest.h | 18 ++++-- 8 files changed, 120 insertions(+), 20 deletions(-) diff --git a/src/dataobjects/emufrontfile.cpp b/src/dataobjects/emufrontfile.cpp index 858b22d..5635b3e 100644 --- a/src/dataobjects/emufrontfile.cpp +++ b/src/dataobjects/emufrontfile.cpp @@ -18,6 +18,7 @@ // along with EmuFront. If not, see . #include "emufrontfile.h" +#include EmuFrontFile::EmuFrontFile() : EmuFrontObject() { } @@ -30,6 +31,11 @@ EmuFrontFile::EmuFrontFile(const EmuFrontFile &eff) : EmuFrontObject(eff), checkSum(eff.checkSum), size(eff.size), type(eff.type) {} +EmuFrontFile::~EmuFrontFile() +{ + qDebug() << "EmuFrontFile " << name << " dying."; +} + QString EmuFrontFile::getCheckSum() const { return checkSum; } diff --git a/src/dataobjects/emufrontfile.h b/src/dataobjects/emufrontfile.h index 428309a..96bb14f 100644 --- a/src/dataobjects/emufrontfile.h +++ b/src/dataobjects/emufrontfile.h @@ -29,6 +29,7 @@ public: EmuFrontFile(int type); EmuFrontFile(int id, QString name, QString checksum, int size, int type); EmuFrontFile(const EmuFrontFile &); + ~EmuFrontFile(); QString getCheckSum() const; void setCheckSum(QString); int getSize() const; diff --git a/src/dataobjects/emufrontfileobject.h b/src/dataobjects/emufrontfileobject.h index a18b340..9df9c65 100644 --- a/src/dataobjects/emufrontfileobject.h +++ b/src/dataobjects/emufrontfileobject.h @@ -38,7 +38,7 @@ public: { this->file = file; } protected: - EmuFrontFile *file; + EmuFrontFile *file; // TODO: Should we have stack object instead of a pointer }; #endif // EMUFRONTFILEOBJECT_H diff --git a/src/dataobjects/emufrontobject.cpp b/src/dataobjects/emufrontobject.cpp index 1b94837..977bcc4 100644 --- a/src/dataobjects/emufrontobject.cpp +++ b/src/dataobjects/emufrontobject.cpp @@ -18,6 +18,7 @@ // along with EmuFront. If not, see . #include "emufrontobject.h" +#include EmuFrontObject::EmuFrontObject() : id(-1), name("") { @@ -36,6 +37,7 @@ EmuFrontObject::EmuFrontObject(int id, QString name) EmuFrontObject::~EmuFrontObject() { + qDebug() << "EmuFrontObject " << name << " dying."; } EmuFrontObject& EmuFrontObject::operator =(const EmuFrontObject &ob) diff --git a/src/dataobjects/platform.cpp b/src/dataobjects/platform.cpp index 8be339d..490a349 100644 --- a/src/dataobjects/platform.cpp +++ b/src/dataobjects/platform.cpp @@ -18,6 +18,7 @@ // along with EmuFront. If not, see . #include "platform.h" +#include Platform::Platform() : EmuFrontFileObject() { } @@ -34,3 +35,12 @@ Platform::Platform(const Platform &p) { } +Platform::~Platform() +{ + if (file) { + qDebug() << "file: " << file->getName(); + } + qDebug() << "Platform " << name << " @ " + << this << "dying."; +} + diff --git a/src/dataobjects/platform.h b/src/dataobjects/platform.h index 994e9b4..186946a 100644 --- a/src/dataobjects/platform.h +++ b/src/dataobjects/platform.h @@ -29,6 +29,7 @@ public: Platform(int id, QString name); Platform(int id, QString name, EmuFrontFile*); Platform(const Platform &); + ~Platform(); }; #endif // PLATFORM_H diff --git a/testing/EmuFrontTesting/platformtest.cpp b/testing/EmuFrontTesting/platformtest.cpp index f0971fb..2a4d932 100644 --- a/testing/EmuFrontTesting/platformtest.cpp +++ b/testing/EmuFrontTesting/platformtest.cpp @@ -1,49 +1,119 @@ #include "platformtest.h" -#include "../../src/dataobjects/platform.h" -#include "../../src/dataobjects/emufrontfile.h" -Q_DECLARE_METATYPE(EmuFrontFile) -Q_DECLARE_METATYPE(Platform) + +void PlatformTest::init() +{ + qDebug() << "Creating efA and efB."; + //efA = new EmuFrontFile(1, "a", "qa", 1, 2); + //efB = new EmuFrontFile(2, "b", "qaa", 2, 3); +} void PlatformTest::initTestCase() { qDebug() << "Initializing PlatformTest."; - EmuFrontFile *efile = new EmuFrontFile(1, "zzz.png", "2hxxxx", 2, 1); +} + +void PlatformTest::cleanup() +{ + qDebug() << "cleanup"; + // The following objects have already been deleted + //delete efA; + //delete efB; + //efA = 0; + //efB = 0; } void PlatformTest::cleanupTestCase() { qDebug() << "Cleaning up PlatformTest."; - delete efile; } -void PlatformTest::equals_data() +/*void PlatformTest::equals_data() { + qDebug() << "Arranging data for equals."; + QTest::addColumn("platform1"); QTest::addColumn("platform2"); + qDebug() << "Done columns"; + efA = new EmuFrontFile(1, "a", "qa", 1, 2); + efB = new EmuFrontFile(2, "b", "qaa", 2, 3); + qDebug() << "efA" << efA->getName(); + qDebug() << "efB" << efB->getName(); + QTest::newRow("id and name") - << Platform(1, "test", efile) - << Platform(1, "test", efile); + << Platform(1, "test", efA) + << Platform(1, "test", efB); + + qDebug() << "Done first row"; + efA = new EmuFrontFile(1, "a", "qa", 1, 2); + efB = new EmuFrontFile(2, "b", "qaa", 2, 3); + qDebug() << "efA" << efA->getName(); + qDebug() << "efB" << efB->getName(); + QTest::newRow("id, name and filename") - << Platform(2, "test", efile) - << Platform(2, "test", efile); + << Platform(2, "test", efA) + << Platform(2, "test", efB); + qDebug() << "Done 2nd row"; } void PlatformTest::equals() { + qDebug() << "Entering equals"; QFETCH(Platform, platform1); QFETCH(Platform, platform2); QVERIFY(platform1 == platform2); + qDebug() << "Leaving equals"; +}*/ + +void PlatformTest::equals2() +{ + qDebug() << "Starting equals2"; + EmuFrontFile *efA = new EmuFrontFile(1, "a", "qa", 1, 2); + EmuFrontFile *efB = new EmuFrontFile(2, "b", "qaa", 2, 3); + Platform p1(1, "test"); + Platform p2(1, "test"); + QVERIFY(p1 == p2); + + qDebug() << "efA" << efA->getName(); + qDebug() << "efB" << efB->getName(); + + Platform p5(1, "test", efA); + // The following cannot be done, efA dies with p5: + // and pointer from p6 would keep pointing to memory area where + // efA no longer exists: + //Platform p6(1, "test", efA); + Platform p6(1, "test", efA); + + qDebug() << "efA" << efA->getName(); + qDebug() << "efB" << efB->getName(); + + + qDebug() << "Entering QVERIFY"; + QVERIFY(p5 == p6); + + qDebug() << "efA" << efA->getName(); + qDebug() << "efB" << efB->getName(); + + QVERIFY(p5 == p6); + + qDebug() << "efA" << efA->getName(); + qDebug() << "efB" << efB->getName(); + + qDebug() << "Leaving QVERIFY"; + qDebug() << "Leaving equals2"; + efA->deleteLater(); + efB->deleteLater(); } /* Platforms are equal if the following fields match: - id (int) - name (QString) + - filename (QString) */ -void PlatformTest::notEquals() +/*void PlatformTest::notEquals() { - Platform p1(1, "testa", efile); - Platform p2(1, "test", efile); + Platform p1(1, "testa"); + Platform p2(1, "test"); // This should return true QVERIFY(p1 != p2); -} +}*/ diff --git a/testing/EmuFrontTesting/platformtest.h b/testing/EmuFrontTesting/platformtest.h index 7e50e9b..ed57e9c 100644 --- a/testing/EmuFrontTesting/platformtest.h +++ b/testing/EmuFrontTesting/platformtest.h @@ -3,22 +3,32 @@ #include #include +#include "../../src/dataobjects/platform.h" +#include "../../src/dataobjects/emufrontfile.h" -class EmuFrontFile; +//Q_DECLARE_METATYPE(EmuFrontFile) +//Q_DECLARE_METATYPE(Platform) class PlatformTest : public QObject { Q_OBJECT private slots: + void init(); + void cleanup(); void initTestCase(); void cleanupTestCase(); - void notEquals(); - void equals(); - void equals_data(); + void equals2(); + // void equals(); + // void equals_data(); private: + //EmuFrontFile *ef; +/* EmuFrontFile *efile; + */ + //EmuFrontFile *efA; + //EmuFrontFile *efB; }; -- 1.7.9.5