Playing around with my first unit test example.
authorMikko Keinänen <mikko.keinanen@gmail.com>
Tue, 23 Nov 2010 20:49:06 +0000 (22:49 +0200)
committerMikko Keinänen <mikko.keinanen@gmail.com>
Tue, 23 Nov 2010 20:49:06 +0000 (22:49 +0200)
src/dataobjects/emufrontfile.cpp
src/dataobjects/emufrontfile.h
testing/EmuFrontTesting/platformtest.cpp
testing/EmuFrontTesting/platformtest.h

index 3e46669..858b22d 100644 (file)
@@ -26,7 +26,7 @@ EmuFrontFile::EmuFrontFile(int type) : EmuFrontObject(), type(type) { }
 EmuFrontFile::EmuFrontFile(int id, QString name, QString checksum, int size, int type)
    : EmuFrontObject(id, name), checkSum(checksum), size(size), type(type) { }
 
-EmuFrontFile::EmuFrontFile(EmuFrontFile &eff)
+EmuFrontFile::EmuFrontFile(const EmuFrontFile &eff)
     : EmuFrontObject(eff), checkSum(eff.checkSum), size(eff.size), type(eff.type)
 {}
 
index 4986f7f..428309a 100644 (file)
@@ -28,7 +28,7 @@ public:
     EmuFrontFile();
     EmuFrontFile(int type);
     EmuFrontFile(int id, QString name, QString checksum, int size, int type);
-    EmuFrontFile(EmuFrontFile &);
+    EmuFrontFile(const EmuFrontFile &);
     QString getCheckSum() const;
     void setCheckSum(QString);
     int getSize() const;
index 011d987..f0971fb 100644 (file)
@@ -1,15 +1,49 @@
 #include "platformtest.h"
 #include "../../src/dataobjects/platform.h"
+#include "../../src/dataobjects/emufrontfile.h"
+
+Q_DECLARE_METATYPE(EmuFrontFile)
+Q_DECLARE_METATYPE(Platform)
+
+void PlatformTest::initTestCase()
+{
+    qDebug() << "Initializing PlatformTest.";
+    EmuFrontFile *efile = new EmuFrontFile(1, "zzz.png", "2hxxxx", 2, 1);
+}
+
+void PlatformTest::cleanupTestCase()
+{
+    qDebug() << "Cleaning up PlatformTest.";
+    delete efile;
+}
+
+void PlatformTest::equals_data()
+{
+    QTest::addColumn<Platform>("platform1");
+    QTest::addColumn<Platform>("platform2");
+    QTest::newRow("id and name")
+        << Platform(1, "test", efile)
+        << Platform(1, "test", efile);
+    QTest::newRow("id, name and filename")
+        << Platform(2, "test", efile)
+        << Platform(2, "test", efile);
+}
+
+void PlatformTest::equals()
+{
+    QFETCH(Platform, platform1);
+    QFETCH(Platform, platform2);
+    QVERIFY(platform1 == platform2);
+}
 
 /* Platforms are equal if the following fields match:
     - id (int)
     - name (QString)
-    - filename (QString)
 */
-void PlatformTest::equals()
+void PlatformTest::notEquals()
 {
-    Platform p1(1, "testa");
-    Platform p2(1, "test");
+    Platform p1(1, "testa", efile);
+    Platform p2(1, "test", efile);
     // This should return true
     QVERIFY(p1 != p2);
 }
index 623d598..7e50e9b 100644 (file)
@@ -4,12 +4,21 @@
 #include <QObject>
 #include <QtTest/QtTest>
 
+class EmuFrontFile;
+
 class PlatformTest : public QObject
 {
     Q_OBJECT
 
 private slots:
+    void initTestCase();
+    void cleanupTestCase();
+    void notEquals();
     void equals();
+    void equals_data();
+
+private:
+    EmuFrontFile *efile;
 
 };