Added EmuFrontObject test and (very) initial PlatformNameDialogTest.
authorMikko Keinänen <mikko.keinanen@gmail.com>
Fri, 26 Nov 2010 23:11:58 +0000 (01:11 +0200)
committerMikko Keinänen <mikko.keinanen@gmail.com>
Fri, 26 Nov 2010 23:11:58 +0000 (01:11 +0200)
12 files changed:
src/dataobjects/emufrontobject.cpp
src/dataobjects/emufrontobject.h
src/dialogs/namedialog.cpp
src/dialogs/namedialog.h
src/dialogs/platformnamedialog.cpp
src/dialogs/platformnamedialog.h
testing/EmuFrontTesting/EmuFrontTesting.pro
testing/EmuFrontTesting/emufrontobjecttest.cpp [new file with mode: 0644]
testing/EmuFrontTesting/emufrontobjecttest.h [new file with mode: 0644]
testing/EmuFrontTesting/main.cpp
testing/EmuFrontTesting/platformnamedialogtest.cpp [new file with mode: 0644]
testing/EmuFrontTesting/platformnamedialogtest.h [new file with mode: 0644]

index 977bcc4..8be68c2 100644 (file)
@@ -20,7 +20,9 @@
 #include "emufrontobject.h"
 #include <QDebug>
 
-EmuFrontObject::EmuFrontObject() : id(-1), name("")
+const int EmuFrontObject::ID_NOT_SET = -1;
+
+EmuFrontObject::EmuFrontObject() : id(EmuFrontObject::ID_NOT_SET), name("")
 {
 }
 
@@ -51,7 +53,7 @@ EmuFrontObject& EmuFrontObject::operator =(const EmuFrontObject &ob)
 
 bool EmuFrontObject::operator ==(const EmuFrontObject &sup)
 {
-    return (id >= 0 && id == sup.id && sup.name == name);
+    return (id == sup.id && sup.name == name);
 }
 
 bool EmuFrontObject::operator !=(const EmuFrontObject &sup)
index ebbd6cd..b6f363c 100644 (file)
@@ -25,6 +25,7 @@
 class EmuFrontObject : public QObject
 {
 public:
+    static const int ID_NOT_SET;
     EmuFrontObject();
     EmuFrontObject(int id, QString name);
 
index 0bbffbf..0a86b18 100644 (file)
@@ -24,14 +24,17 @@ NameDialog::NameDialog(QWidget *parent, EmuFrontObject *efObj)
         : DataObjectEditDialog(parent, efObj)
 {
        nameLabel = new QLabel(tr("&Name: "));  
-       nameEdit = new QLineEdit;
-       nameLabel->setBuddy(nameEdit);
+    nameEdit = new QLineEdit;
+    nameLabel->setBuddy(nameEdit);
     connectSignals();
        layout();
     emit test();
-       setWindowTitle(tr("Set names"));
+    setWindowTitle(tr("Set names"));
+    setFocusProxy(nameEdit);
 }
 
+
+
 NameDialog::~NameDialog()
 {
     // should be deleted in implementing classes
@@ -57,11 +60,12 @@ void NameDialog::layout()
 
        QHBoxLayout *bottomLayout = new QHBoxLayout;
     bottomLayout->addWidget(buttonBox);
+    buttonBox->setFocusPolicy(Qt::NoFocus);
 
        QVBoxLayout *mainLayout = new QVBoxLayout;
        mainLayout->addLayout(topLayout);
        mainLayout->addLayout(bottomLayout);
-       setLayout(mainLayout);
+    setLayout(mainLayout);
 }
 
 void NameDialog::acceptChanges()
index 377ac9a..c24cd4f 100644 (file)
@@ -45,7 +45,6 @@ protected:
     virtual void clear();
     QLabel *nameLabel;
        QLineEdit *nameEdit;
-
 private:
        void connectSignals();
        void layout();
index 6ce4ef7..a861450 100644 (file)
@@ -41,12 +41,17 @@ void PlatformNameDialog::setDataObject(QString name)
 
 void PlatformNameDialog::setDataObject(EmuFrontObject *ob)
 {
+    nameEdit->hide();
     if (!ob) return;
-    efObject = dynamic_cast<Platform*>(ob);    
-    QString name = efObject->getName();
-    nameEdit->setText(name);
-
-    qDebug() << "Setting name to " << efObject->getName();
+    efObject = dynamic_cast<Platform*>(ob);
     nameEdit->setText(efObject->getName());
+    nameEdit->setFocus(Qt::TabFocusReason);
+    nameEdit->show();
 }
 
+/*void PlatformNameDialog::keyPressEvent(QKeyEvent *event)
+{
+    nameEdit->setText( nameEdit->text().append(event->text()) );
+    QDialog::keyPressEvent(event);
+}*/
+
index df563e4..5ce7171 100644 (file)
@@ -34,6 +34,7 @@ public:
 
 protected:
     virtual void setDataObject(QString name);
+    //void keyPressEvent(QKeyEvent *event);
 };
 
 #endif
index 068cf85..3660fc6 100644 (file)
@@ -6,12 +6,9 @@
 
 QT       += core
 QT       += testlib
-QT       -= gui
+QT       += gui
+QT       += sql
 
-#INCLUDEPATH += "../../src/dataobjects"
-#include("../../src/emufront.pro")
-
-#INCLUDEPATH += . "../../src/"
 TARGET = EmuFrontTesting
 CONFIG   += console
 CONFIG   -= app_bundle
@@ -21,18 +18,30 @@ TEMPLATE = app
 
 SOURCES += main.cpp \
     platformtest.cpp \
+    ../../src/dataobjects/emufrontobject.cpp \
     ../../src/dataobjects/platform.cpp \
     ../../src/dataobjects/mediatype.cpp \
-    ../../src/dataobjects/emufrontobject.cpp \
     ../../src/dataobjects/emufrontfileobject.cpp \
     ../../src/dataobjects/emufrontfile.cpp \
-    mediatypetest.cpp
+    ../../src/dialogs/dataobjecteditdialog.cpp \
+    ../../src/dialogs/emufrontdialog.cpp \
+    ../../src/dialogs/namedialog.cpp \
+    ../../src/dialogs/platformnamedialog.cpp \
+    mediatypetest.cpp \
+    platformnamedialogtest.cpp \
+    emufrontobjecttest.cpp
 
 HEADERS += \
     platformtest.h \
+    ../../src/dataobjects/emufrontobject.h \
     ../../src/dataobjects/platform.h \
     ../../src/dataobjects/mediatype.h \
-    ../../src/dataobjects/emufrontobject.h \
     ../../src/dataobjects/emufrontfileobject.h \
     ../../src/dataobjects/emufrontfile.h \
-    mediatypetest.h
+    ../../src/dialogs/dataobjecteditdialog.h \
+    ../../src/dialogs/emufrontdialog.h \
+   ../../src/dialogs/namedialog.h \
+   ../../src/dialogs/platformnamedialog.h \
+   mediatypetest.h \
+   platformnamedialogtest.h \
+    emufrontobjecttest.h
diff --git a/testing/EmuFrontTesting/emufrontobjecttest.cpp b/testing/EmuFrontTesting/emufrontobjecttest.cpp
new file mode 100644 (file)
index 0000000..a83d3cc
--- /dev/null
@@ -0,0 +1,110 @@
+#include "emufrontobjecttest.h"
+
+void EmuFrontObjectTest::constructTest_data()
+{
+    QTest::addColumn<EmuFrontObject>("mt1");
+    QTest::addColumn<QString>("name");
+    QTest::addColumn<int>("id");
+    QTest::newRow("no parameters")
+        << EmuFrontObject()
+        << "" << EmuFrontObject::ID_NOT_SET;
+    QTest::newRow("id and empty string as name")
+        << EmuFrontObject(1, "")
+        << "" << 1;
+    QTest::newRow("id, name")
+        << EmuFrontObject(2, "Disk")
+        << "Disk" << 2;
+}
+
+void EmuFrontObjectTest::constructTest()
+{
+    QFETCH(EmuFrontObject, mt1);
+    QFETCH(QString, name);
+    QFETCH(int, id);
+    QVERIFY(mt1.getName() == name && mt1.getId() == id);
+}
+
+void EmuFrontObjectTest::equals_data()
+{
+    QTest::addColumn<EmuFrontObject>("mt1");
+    QTest::addColumn<EmuFrontObject>("mt2");
+    QTest::newRow("no parameters")
+        << EmuFrontObject()
+        << EmuFrontObject();
+    QTest::newRow("id and empty string as name")
+        << EmuFrontObject(1, "")
+        << EmuFrontObject(1, "");
+    QTest::newRow("id, name")
+        << EmuFrontObject(2, "Disk")
+        << EmuFrontObject(2, "Disk");
+}
+
+void EmuFrontObjectTest::equals()
+{
+    QFETCH(EmuFrontObject, mt1);
+    QFETCH(EmuFrontObject, mt2);
+    QVERIFY(mt1 == mt2);
+}
+
+void EmuFrontObjectTest::notEquals_data()
+{
+    QTest::addColumn<EmuFrontObject>("mt1");
+    QTest::addColumn<EmuFrontObject>("mt2");
+    QTest::newRow("1. with no params, 2. with id and name")
+        << EmuFrontObject()
+        << EmuFrontObject(1, "x");
+    QTest::newRow("name differs")
+        << EmuFrontObject(1, "")
+        << EmuFrontObject(1, "a");
+    QTest::newRow("id differs")
+        << EmuFrontObject(1, "")
+        << EmuFrontObject(-1, "");
+    QTest::newRow("id and name differs")
+        << EmuFrontObject(3, "Disk")
+        << EmuFrontObject(2, "Disak");
+}
+
+void EmuFrontObjectTest::notEquals()
+{
+    QFETCH(EmuFrontObject, mt1);
+    QFETCH(EmuFrontObject, mt2);
+    QVERIFY(mt1 != mt2);
+}
+
+void EmuFrontObjectTest::nameTest()
+{
+    EmuFrontObject o;
+    QString n = "hello";
+    o.setName(n);
+    QCOMPARE(n, o.getName());
+}
+
+void EmuFrontObjectTest::idTest()
+{
+    EmuFrontObject o;
+    int id = 998;
+    o.setId(id);
+    QCOMPARE(id, o.getId());
+}
+
+void EmuFrontObjectTest::copyTest()
+{
+    EmuFrontObject o(123, "qwerty");
+    EmuFrontObject b(321, "ytrewq");
+    b = o;
+    QVERIFY(o.getName() == b.getName()
+        && o.getId() == b.getId()
+        && (&o != &b));
+}
+
+void EmuFrontObjectTest::copyContructTest()
+{
+    EmuFrontObject o(123, "qwerty");
+    EmuFrontObject b(o);
+    QVERIFY(o.getName() == b.getName()
+        && o.getId() == b.getId()
+        && (&o != &b));
+}
+
+
+
diff --git a/testing/EmuFrontTesting/emufrontobjecttest.h b/testing/EmuFrontTesting/emufrontobjecttest.h
new file mode 100644 (file)
index 0000000..19e877c
--- /dev/null
@@ -0,0 +1,27 @@
+#ifndef EMUFRONTOBJECTTEST_H
+#define EMUFRONTOBJECTTEST_H
+
+#include <QObject>
+#include <QtTest/QtTest>
+#include "../../src/dataobjects/emufrontobject.h"
+
+Q_DECLARE_METATYPE(EmuFrontObject)
+
+class EmuFrontObjectTest : public QObject
+{
+    Q_OBJECT
+
+private slots:
+    void notEquals();
+    void notEquals_data();
+    void equals();
+    void equals_data();
+    void idTest();
+    void nameTest();
+    void copyTest();
+    void copyContructTest();
+    void constructTest();
+    void constructTest_data();
+};
+
+#endif // EMUFRONTOBJECTTEST_H
index dc0aaa0..eaff302 100644 (file)
@@ -1,15 +1,26 @@
+#include "emufrontobjecttest.h"
 #include "platformtest.h"
 #include "mediatypetest.h"
+//#include "platformnamedialogtest.h"
 
 int main(int argc, char *argv[])
 {
+    // Needed QApplication for widget tests
+    //QApplication app(argc, argv);
+
+    EmuFrontObjectTest efoTst;
+    QTest::qExec(&efoTst, argc, argv);
+
     PlatformTest plfTest;
     QTest::qExec(&plfTest, argc, argv);
 
     MediaTypeTest mtTest;
     QTest::qExec(&mtTest, argc, argv);
 
+    //PlatformNameDialogTest plfDlgTest;
+    //QTest::qExec(&plfDlgTest, argc, argv);
+
     // More tests here...
 
-    return 0;
+    //return app.exec();
 }
diff --git a/testing/EmuFrontTesting/platformnamedialogtest.cpp b/testing/EmuFrontTesting/platformnamedialogtest.cpp
new file mode 100644 (file)
index 0000000..82c37af
--- /dev/null
@@ -0,0 +1,17 @@
+#include "platformnamedialogtest.h"
+
+void PlatformNameDialogTest::testLineEdit()
+{
+    Platform *plf = new Platform(1, "");
+    PlatformNameDialog dlg;
+    dlg.setDataObject(plf);
+    dlg.show();
+    QTest::qWait(2000);
+
+    /*QTest::mouseClick(&dlg, Qt::LeftButton);*/
+    QTest::keyClick(&dlg, Qt::Key_N, Qt::AltModifier);
+    QTest::keyClicks(&dlg, "hello world");
+    QTest::qWait(1000);
+    QTest::keyClick(&dlg, Qt::Key_Enter);
+    QCOMPARE(plf->getName(), QString("hello world"));
+}
diff --git a/testing/EmuFrontTesting/platformnamedialogtest.h b/testing/EmuFrontTesting/platformnamedialogtest.h
new file mode 100644 (file)
index 0000000..d1d2c2d
--- /dev/null
@@ -0,0 +1,19 @@
+#ifndef PLATFORMNAMEDIALOGTEST_H
+#define PLATFORMNAMEDIALOGTEST_H
+
+#include <QObject>
+#include <QtTest/QtTest>
+#include <QtGui>
+#include "../../src/dataobjects/platform.h"
+#include "../../src/dialogs/platformnamedialog.h"
+
+class PlatformNameDialogTest : public QObject
+{
+    Q_OBJECT
+
+private slots:
+    void testLineEdit();
+
+};
+
+#endif // PLATFORMNAMEDIALOGTEST_H