Still experimenting with unit testing code.
authorMikko Keinänen <mikko.keinanen@gmail.com>
Tue, 23 Nov 2010 23:37:44 +0000 (01:37 +0200)
committerMikko Keinänen <mikko.keinanen@gmail.com>
Tue, 23 Nov 2010 23:37:44 +0000 (01:37 +0200)
src/dataobjects/emufrontfile.cpp
src/dataobjects/emufrontfile.h
src/dataobjects/emufrontfileobject.h
src/dataobjects/emufrontobject.cpp
src/dataobjects/platform.cpp
src/dataobjects/platform.h
testing/EmuFrontTesting/platformtest.cpp
testing/EmuFrontTesting/platformtest.h

index 858b22d..5635b3e 100644 (file)
@@ -18,6 +18,7 @@
 // along with EmuFront.  If not, see <http://www.gnu.org/licenses/>.
 
 #include "emufrontfile.h"
+#include <QDebug>
 
 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; }
 
index 428309a..96bb14f 100644 (file)
@@ -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;
index a18b340..9df9c65 100644 (file)
@@ -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
index 1b94837..977bcc4 100644 (file)
@@ -18,6 +18,7 @@
 // along with EmuFront.  If not, see <http://www.gnu.org/licenses/>.
 
 #include "emufrontobject.h"
+#include <QDebug>
 
 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)
index 8be339d..490a349 100644 (file)
@@ -18,6 +18,7 @@
 // along with EmuFront.  If not, see <http://www.gnu.org/licenses/>.
 
 #include "platform.h"
+#include <QDebug>
 
 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.";
+}
+
index 994e9b4..186946a 100644 (file)
@@ -29,6 +29,7 @@ public:
     Platform(int id, QString name);
     Platform(int id, QString name, EmuFrontFile*);
     Platform(const Platform &);
+    ~Platform();
 };
 
 #endif // PLATFORM_H
index f0971fb..2a4d932 100644 (file)
 #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<Platform>("platform1");
     QTest::addColumn<Platform>("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);
-}
+}*/
index 7e50e9b..ed57e9c 100644 (file)
@@ -3,22 +3,32 @@
 
 #include <QObject>
 #include <QtTest/QtTest>
+#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;
 
 };