Playing around with qtestlibs data driven testing (Added MediaTypeTest
authorMikko Keinänen <mikko.keinanen@gmail.com>
Wed, 24 Nov 2010 22:15:17 +0000 (00:15 +0200)
committerMikko Keinänen <mikko.keinanen@gmail.com>
Wed, 24 Nov 2010 22:15:17 +0000 (00:15 +0200)
class). Added new constructor to EmuFrontFileObject with id and name
parameters.

src/dataobjects/emufrontfileobject.cpp
src/dataobjects/emufrontfileobject.h
src/dataobjects/mediatype.cpp
src/dataobjects/platform.cpp
testing/EmuFrontTesting/EmuFrontTesting.pro
testing/EmuFrontTesting/main.cpp
testing/EmuFrontTesting/mediatypetest.cpp [new file with mode: 0644]
testing/EmuFrontTesting/mediatypetest.h [new file with mode: 0644]
testing/EmuFrontTesting/platformtest.cpp
testing/EmuFrontTesting/platformtest.h

index 7928aac..7a5c8d7 100644 (file)
@@ -26,6 +26,9 @@ EmuFrontFileObject::EmuFrontFileObject()
 EmuFrontFileObject::EmuFrontFileObject(int id, QString name, EmuFrontFile *file)
     : EmuFrontObject(id, name), file(file) {}
 
+EmuFrontFileObject::EmuFrontFileObject(int id, QString name)
+    : EmuFrontObject(id, name), file(0) {}
+
 EmuFrontFileObject::EmuFrontFileObject(const EmuFrontFileObject &pl)
     : EmuFrontObject(pl)
 {
index 9df9c65..71a7894 100644 (file)
@@ -28,6 +28,7 @@ class EmuFrontFileObject : public EmuFrontObject
 public:
     EmuFrontFileObject();
     EmuFrontFileObject(int id, QString name, EmuFrontFile *file);
+    EmuFrontFileObject(int id, QString name);
     EmuFrontFileObject(const EmuFrontFileObject&);
     EmuFrontFileObject& operator=(const EmuFrontFileObject&);
     ~EmuFrontFileObject();
index 3f695a3..4908786 100644 (file)
 #include "mediatype.h"
 
 MediaType::MediaType() : EmuFrontFileObject()
-{
-}
+{ }
+
+MediaType::MediaType(int id, QString name)
+        : EmuFrontFileObject(id, name)
+{ }
 
 MediaType::MediaType(int id, QString name, EmuFrontFile *file)
         : EmuFrontFileObject(id, name, file)
-{
-}
+{ }
 
 MediaType::MediaType(const MediaType &mt)
         : EmuFrontFileObject(mt)
-{
-}
+{ }
index e0082d0..8928819 100644 (file)
@@ -18,7 +18,6 @@
 // along with EmuFront.  If not, see <http://www.gnu.org/licenses/>.
 
 #include "platform.h"
-#include <QDebug>
 
 Platform::Platform() : EmuFrontFileObject() { }
 
index 0a3340a..068cf85 100644 (file)
@@ -22,13 +22,17 @@ TEMPLATE = app
 SOURCES += main.cpp \
     platformtest.cpp \
     ../../src/dataobjects/platform.cpp \
+    ../../src/dataobjects/mediatype.cpp \
     ../../src/dataobjects/emufrontobject.cpp \
     ../../src/dataobjects/emufrontfileobject.cpp \
-    ../../src/dataobjects/emufrontfile.cpp
+    ../../src/dataobjects/emufrontfile.cpp \
+    mediatypetest.cpp
 
 HEADERS += \
     platformtest.h \
     ../../src/dataobjects/platform.h \
+    ../../src/dataobjects/mediatype.h \
     ../../src/dataobjects/emufrontobject.h \
     ../../src/dataobjects/emufrontfileobject.h \
-    ../../src/dataobjects/emufrontfile.h
+    ../../src/dataobjects/emufrontfile.h \
+    mediatypetest.h
index 5b9a1b1..dc0aaa0 100644 (file)
@@ -1,10 +1,14 @@
 #include "platformtest.h"
+#include "mediatypetest.h"
 
 int main(int argc, char *argv[])
 {
     PlatformTest plfTest;
     QTest::qExec(&plfTest, argc, argv);
 
+    MediaTypeTest mtTest;
+    QTest::qExec(&mtTest, argc, argv);
+
     // More tests here...
 
     return 0;
diff --git a/testing/EmuFrontTesting/mediatypetest.cpp b/testing/EmuFrontTesting/mediatypetest.cpp
new file mode 100644 (file)
index 0000000..ca89f30
--- /dev/null
@@ -0,0 +1,31 @@
+#include "mediatypetest.h"
+
+void MediaTypeTest::equals_data()
+{
+    qDebug() << "equals_data() starting.";
+    QTest::addColumn<MediaType>("mt1");
+    QTest::addColumn<MediaType>("mt2");
+
+    qDebug() << "Adding row 1 with id and name parameters.";
+
+    QTest::newRow("id and name")
+        << MediaType(1, "Cartridge")
+        << MediaType(1, "Cartridge");
+
+    qDebug() << "Adding row 2 with id, name and EmuFrontFile object";
+
+    QTest::newRow("id, name and EmuFrontFile object")
+        << MediaType(2, "Disk", new EmuFrontFile(1, "test", "000", 1, 1))
+        << MediaType(2, "Disk", new EmuFrontFile(1, "test", "000", 1, 1));
+
+    qDebug() << "equals_data() finishing.";
+}
+
+void MediaTypeTest::equals()
+{
+    qDebug() << "Entering equals";
+    QFETCH(MediaType, mt1);
+    QFETCH(MediaType, mt2);
+    QVERIFY(mt1 == mt2);
+    qDebug() << "Leaving equals";
+}
diff --git a/testing/EmuFrontTesting/mediatypetest.h b/testing/EmuFrontTesting/mediatypetest.h
new file mode 100644 (file)
index 0000000..eacf0db
--- /dev/null
@@ -0,0 +1,21 @@
+#ifndef MEDIATYPETEST_H
+#define MEDIATYPETEST_H
+
+#include <QObject>
+#include <QtTest/QtTest>
+#include "../../src/dataobjects/mediatype.h"
+#include "../../src/dataobjects/emufrontfile.h"
+
+Q_DECLARE_METATYPE(EmuFrontFile)
+Q_DECLARE_METATYPE(MediaType)
+
+class MediaTypeTest : public QObject
+{
+    Q_OBJECT
+
+private slots:
+    void equals();
+    void equals_data();
+};
+
+#endif // MEDIATYPETEST_H
index 88324ad..a1b339d 100644 (file)
@@ -3,29 +3,18 @@
 
 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.";
 }
 
 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.";
 }
 
 /*void PlatformTest::equals_data()
@@ -67,27 +56,30 @@ void PlatformTest::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");
+    qDebug() << "Starting equals2 test, creating EmuFrontFile objects to heap.";
+    EmuFrontFile *efA = new EmuFrontFile(1, "efA", "qa", 1, 2);
+    EmuFrontFile *efB = new EmuFrontFile(2, "efB", "qaa", 2, 3);
+    qDebug() << "Creating Platform test objects p1 and p2";
+    Platform p1(1, "px");
+    Platform p2(1, "px");
     QVERIFY(p1 == p2);
 
-    qDebug() << "efA" << efA->getName();
-    qDebug() << "efB" << efB->getName();
+    qDebug() << efB->getName();
+
+    qDebug() << "Creating Platform test objects p5 containg member " << efA->getName();
+    Platform p5(1, "p5", efA);
 
-    Platform p5(1, "test", efA);
-    // The following cannot be done, efA dies with p5:
+    // The following should not 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", efB);
+    //Platform p6(1, "p6", efA);
+
+    qDebug() << "Creating Platform test objects p6 containg member " << efB->getName();
+    Platform p6(1, "p6", efB);
 
     qDebug() << "efA" << efA->getName();
     qDebug() << "efB" << efB->getName();
 
-
     qDebug() << "Entering QVERIFY";
     QVERIFY(p5 == p6);
 
@@ -101,8 +93,6 @@ void PlatformTest::equals2()
 
     qDebug() << "Leaving QVERIFY";
     qDebug() << "Leaving equals2";
-    efA->deleteLater();
-    efB->deleteLater();
 }
 
 /* Platforms are equal if the following fields match:
@@ -110,10 +100,10 @@ void PlatformTest::equals2()
     - name (QString)
     - filename (QString)
 */
-/*void PlatformTest::notEquals()
+void PlatformTest::notEquals()
 {
     Platform p1(1, "testa");
     Platform p2(1, "test");
     // This should return true
     QVERIFY(p1 != p2);
-}*/
+}
index 1be331b..1067dfa 100644 (file)
@@ -19,16 +19,9 @@ private slots:
     void initTestCase();
     void cleanupTestCase();
     void equals2();
-  //  void equals();
-  //  void equals_data();
-
-private:
-    //EmuFrontFile *ef;
-/*
-    EmuFrontFile *efile;*/
-    //EmuFrontFile *efA;
-    //EmuFrontFile *efB;
-
+    void notEquals();
+    //void equals();
+    //void equals_data();
 };
 
 #endif // PLATFORMTEST_H