Test suit expanded (added few tests and mocks)
authorBartosz Szatkowski <bulislaw@linux.com>
Wed, 4 Aug 2010 06:53:25 +0000 (08:53 +0200)
committerBartosz Szatkowski <bulislaw@linux.com>
Wed, 4 Aug 2010 06:53:25 +0000 (08:53 +0200)
trunk/src/base/backbone/backbone.cpp
trunk/src/base/backbone/backbone.h
trunk/src/base/mDictionary.pro.user
trunk/tests/mDictionaryTests/CommonDictInterfaceMock.cpp [deleted file]
trunk/tests/mDictionaryTests/CommonDictInterfaceMock.h
trunk/tests/mDictionaryTests/TranslationMock.h [new file with mode: 0644]
trunk/tests/mDictionaryTests/mDictionaryTests.pro
trunk/tests/mDictionaryTests/tst_Backbone.cpp

index 7500884..1b0c70e 100644 (file)
@@ -83,6 +83,8 @@ void Backbone::search(QString word) {
 
  void Backbone::addDictionary(CommonDictInterface* dict) {
      dicts[dict] = 1;
+     connect(dict, SIGNAL(finalTranslation(QList<Translation*>)),
+             this, SLOT(translation(QList<Translation*>)));
  }
 
  void Backbone::quit() {
@@ -92,4 +94,9 @@ void Backbone::search(QString word) {
 
 
 
+void Backbone::translation(QList<Translation *> trans) {
+
+}
+
+
 
index ff47056..ddd0dbb 100644 (file)
@@ -43,10 +43,10 @@ public:
     Backbone(const Backbone& b);
 
     //! \return all loadded dictionaries with activity state flag
-    QHash<CommonDictInterface*, bool > getDictionaries();
+    QHash<CommonDictInterface*, bool> getDictionaries();
 
     //! \return all loadded plugins
-    QList<CommonDictInterface* > getPlugins();
+    QList<CommonDictInterface*> getPlugins();
 
     //! \return history of performed searches
     QList<QString> getHistory(); //TODO implementation needed (in future)
@@ -54,6 +54,9 @@ public:
     //! \return return search fesult
     QHash<QString, Translation*> result();
 
+    //! \return maximum number of word that plugin could find
+    int searchLimit() const;
+
 public Q_SLOTS:
     //! stops all current searches
     void stopSearching();
@@ -71,8 +74,9 @@ public Q_SLOTS:
     //! stops all current activity and kill plugins - be ready to exit
     void quit();
 
-    //! \return maximum number of word that plugin could find
-    int searchLimit() const;
+
+    //! Fired when dictionary call finalTranslation(..) with translation ready
+    void translation(QList<Translation*>);
 
     // TODO void removeDictionary(CommonDictInterface* dict);
     // TODO addToBookmark(Translation*);
@@ -86,6 +90,8 @@ Q_SIGNALS:
     //! emitted when there are search result ready to fetch
     void ready();
 
+
+
 private:
     QHash<CommonDictInterface*, bool> dicts;
     QList<CommonDictInterface*> plugins;
index e1335af..4f7d2ca 100644 (file)
     <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Qt 4.6.3 OpenSource Debug</value>
     <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.Qt4BuildConfiguration</value>
     <value key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration" type="int">2</value>
-    <value key="Qt4ProjectManager.Qt4BuildConfiguration.BuildDirectory" type="QString">/home/bulislaw/devel/mDictionary-build</value>
+    <value key="Qt4ProjectManager.Qt4BuildConfiguration.BuildDirectory" type="QString">/home/bulislaw/devel/mDictionaryTests-build</value>
     <value key="Qt4ProjectManager.Qt4BuildConfiguration.QtVersionId" type="int">2</value>
     <value key="Qt4ProjectManager.Qt4BuildConfiguration.ToolChain" type="int">0</value>
     <value key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild" type="bool">true</value>
diff --git a/trunk/tests/mDictionaryTests/CommonDictInterfaceMock.cpp b/trunk/tests/mDictionaryTests/CommonDictInterfaceMock.cpp
deleted file mode 100644 (file)
index 9f414b9..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-/*******************************************************************************
-
-    This file is part of mDictionary.
-
-    mDictionary is free software: you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation, either version 3 of the License, or
-    (at your option) any later version.
-
-    mDictionary is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with mDictionary.  If not, see <http://www.gnu.org/licenses/>.
-
-    Copyright 2010 Comarch S.A.
-
-*******************************************************************************/
-
-// Created by Bartosz Szatkowski
-
-
-
-
-#include "CommonDictInterfaceMock.h"
-
index 9d4a073..74aa5c0 100644 (file)
@@ -28,6 +28,7 @@
 #define COMMONDICTINTERFACEMOCK_H
 
 #include "../../src/includes/CommonDictInterface.h"
+#include "TranslationMock.h"
 
 class CommonDictInterfaceMock : public CommonDictInterface
 {
@@ -46,8 +47,21 @@ public:
     CommonDictInterface* getNew(const Settings *) const { return 0;}
     bool isAvailable() const {return available;}
     uint hash() const { return namev.length() + 10*typev.length();}
-    void search(QString word, int limit) {stopped = 0;}
     void stop() {stopped = 1;}
+    void search(QString word, int limit) {
+        stopped = 0;
+        QList<Translation*> list;
+
+        TranslationMock *tm = new TranslationMock();
+        tm->_key = fromv;
+        tm->_translation = tov;
+        TranslationMock *tm1 = new TranslationMock();
+        tm1->_key = namev;
+        tm1->_translation = typev;
+        list << tm << tm1;
+
+        Q_EMIT finalTranslation(list);
+    }
 
 };
 
diff --git a/trunk/tests/mDictionaryTests/TranslationMock.h b/trunk/tests/mDictionaryTests/TranslationMock.h
new file mode 100644 (file)
index 0000000..56fdf28
--- /dev/null
@@ -0,0 +1,41 @@
+/*******************************************************************************
+
+    This file is part of mDictionary.
+
+    mDictionary is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    mDictionary is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with mDictionary.  If not, see <http://www.gnu.org/licenses/>.
+
+    Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
+// Created by Bartosz Szatkowski
+
+
+
+
+#ifndef TRANSLATIONMOCK_H
+#define TRANSLATIONMOCK_H
+
+#include "../../src/includes/translation.h"
+
+class TranslationMock : public Translation
+{
+public:
+    QString _key, _translation;
+    QString key() const {return _key;}
+    QString dictionaryInfo() const {return "";}
+    QString toHtml() const {return _translation;}
+};
+
+#endif // TRANSLATIONMOCK_H
index cfe9528..860fc75 100644 (file)
@@ -15,7 +15,6 @@ TEMPLATE = app
 
 
 SOURCES += tst_Backbone.cpp \
-    CommonDictInterfaceMock.cpp \
     ../../src/base/backbone/backbone.cpp
 DEFINES += SRCDIR=\\\"$$PWD/\\\"
 
@@ -24,4 +23,5 @@ HEADERS += \
     ../../src/base/backbone/backbone.h \
     ../../src/includes/translation.h \
     ../../src/includes/settings.h \
-    ../../src/includes/CommonDictInterface.h
+    ../../src/includes/CommonDictInterface.h \
+    TranslationMock.h
index 7e5bef5..4a58344 100644 (file)
@@ -47,6 +47,7 @@ private Q_SLOTS:
     void selectedDictionaryTest();
     void stopSearchingTest();
     void searchTest();
+    void translationTest();
 };
 
 BackboneTest::BackboneTest()
@@ -54,14 +55,21 @@ BackboneTest::BackboneTest()
     total = 5;
     for(int i = 0; i < total; i++)
         dict.push_back(new CommonDictInterfaceMock());
+    qRegisterMetaType(Translation);
 }
 
 
 
 void BackboneTest::initTestCase()
 {
-    for(int i = 0; i < total; i++)
+    for(int i = 0; i < total; i++) {
         dict[i] = new CommonDictInterfaceMock();
+        CommonDictInterfaceMock * cd = (CommonDictInterfaceMock*) dict[i];
+        cd->tov = "to" + QString(i);
+        cd->fromv = "from" + QString(i);
+        cd->namev = "name" + QString(i);
+        cd->typev = "type" + QString(i);
+    }
     back = new Backbone();
 }
 
@@ -151,14 +159,28 @@ void BackboneTest::searchTest() {
         CommonDictInterfaceMock *m = (CommonDictInterfaceMock*)dict[i];
         QCOMPARE(m->stopped, 0);
     }
+}
 
 
-}
 
 
+void BackboneTest::translationTest() {
+    QSignalSpy** ss = new QSignalSpy*[total];
 
+    for(int i = 0; i < total; i++) {
+        CommonDictInterfaceMock *m = (CommonDictInterfaceMock*) dict[i];
+        m->stopped = 1;
+        back->addDictionary(dict[i]);
+        ss[i] = new QSignalSpy(m,SIGNAL(finalTranslation(QList<Translation*>)));
+        QVERIFY2(ss[i]->isValid() == 1, "Signal invalid");
+    }
 
+    back->search("nic");
 
+    for(int i = 0; i < total; i++) {
+        QVERIFY2(ss[i]->count() == 1, "Translation signal lost");
+    }
+}
 
 
 QTEST_APPLESS_MAIN(BackboneTest);