Added unit test for xdxf plugin
authorPiotrek <ppilar11@gmail.com>
Thu, 5 Aug 2010 06:40:12 +0000 (08:40 +0200)
committerPiotrek <ppilar11@gmail.com>
Thu, 5 Aug 2010 06:40:12 +0000 (08:40 +0200)
trunk/src/plugins/xdxf/src/XdxfPlugin/xdxfplugin.cpp
trunk/src/plugins/xdxf/src/XdxfPlugin/xdxfplugin.h
trunk/src/plugins/xdxf/tests/test.cpp [new file with mode: 0644]
trunk/src/plugins/xdxf/tests/test.h [new file with mode: 0644]
trunk/src/plugins/xdxf/tests/unit_tests.pro [new file with mode: 0644]

index 4fe57f1..293ad72 100644 (file)
@@ -62,6 +62,7 @@ QList<Translation*> XdxfPlugin::searchWordList(QString word, int limit) {
             a = dictionaryReader.readElementText();
             if(regWord.exactMatch(a) && i<limit) {
                 translations.append(new TranslationXdxf(a,_infoNote,this));
+                qDebug()<<a;
                 i++;
                 if(i>=limit)
                     break;
@@ -95,8 +96,8 @@ QString XdxfPlugin::search(QString key) {
         else if(dictionaryReader.tokenType() == QXmlStreamReader::Characters)
             if(match) {
                 dictionaryFile.close();
+                qDebug()<<dictionaryReader.text().toString().replace("\n","");
                 return dictionaryReader.text().toString().replace("\n","");
-
             }
     }
     return "";
index 07e462a..8a93749 100644 (file)
@@ -20,7 +20,7 @@ public:
     //! returns destination language code iso 639-2
     QString langTo() const;
 
-    //! returns dictionary name (like "old english" or so
+    //! returns dictionary name (like "old english" or so)
     QString name() const;
 
     //! returns dictionary type (xdxf, google translate, etc)
@@ -29,14 +29,14 @@ public:
     //! returns information about dictionary in html (name, authors, etc)
     QString infoNote() const;
 
-    //! return dialog that creates new dictionary and fills necesary options
-    //! QDialog should returns Setting* object after being showed
+    //! returns dialog that creates new dictionary and fills necessary options
+    //! QDialog should return Setting* object after being shown
     QDialog* loadDialog();
 
-    //! return dialog with dictionary settings
+    //! returns dialog with dictionary settings
     QDialog* settingsDialog();
 
-    //! return new, clean copy of plugin with setting set as in Settings*
+    //! returns new, clean copy of plugin with setting set as in Settings*
     CommonDictInterface* getNew(const Settings*) const;
 
     //! returns whether plugin can start searching
@@ -53,7 +53,7 @@ public Q_SLOTS:
       \param  word word to search in dictionary
       \param limit limit on number of results
 
-      After finishing search it have to emit
+      After finishing search it has to emit
       \see CommonDictInterface:finalTranslation  finalTranslation
     */
     QList<Translation*> searchWordList(QString word, int limit);
diff --git a/trunk/src/plugins/xdxf/tests/test.cpp b/trunk/src/plugins/xdxf/tests/test.cpp
new file mode 100644 (file)
index 0000000..3ba6b25
--- /dev/null
@@ -0,0 +1,36 @@
+#include "test.h"
+#include <QSignalSpy>
+
+void Testowanie::search()
+{
+    XdxfPlugin xdxfPlugin(this);
+    xdxfPlugin.loadDialog();
+    xdxfPlugin.searchWordList("Cain",10);
+    xdxfPlugin.search("Cain");
+    QCOMPARE(xdxfPlugin.search("cain"), QString("lina"));
+    QCOMPARE(xdxfPlugin.search("sin"), QString("grzech"));
+    //QCOMPARE(xdxfPlugin.search("boss"), QString(""));
+}
+
+void Testowanie::langFrom()
+{
+    XdxfPlugin xdxfPlugin(this);
+    xdxfPlugin.loadDialog();
+  //  xdxfPlugin.searchWordList("rope",10);
+    //QCOMPARE(xdxfPlugin.langFrom(), QString("ENG"));
+}
+
+void Testowanie::sig()
+{
+    XdxfPlugin xdxfPlugin(this);
+    xdxfPlugin.loadDialog();
+
+    QSignalSpy spy(&xdxfPlugin, SIGNAL(finalTranslation(QList<Translation*>)));
+
+    xdxfPlugin.searchWordList("rope",10);
+
+    QCOMPARE(spy.count(), 1); // make sure the signal was emitted exactly one time
+}
+
+QTEST_MAIN(Testowanie)
+//#include "testqstring.moc"
diff --git a/trunk/src/plugins/xdxf/tests/test.h b/trunk/src/plugins/xdxf/tests/test.h
new file mode 100644 (file)
index 0000000..9096c6d
--- /dev/null
@@ -0,0 +1,23 @@
+#ifndef TEST_H
+#define TEST_H
+
+#include <QtTest/QtTest>
+#include "../src/XdxfPlugin/xdxfplugin.h"
+#include "../src/XdxfPlugin/TranslationXdxf.h"
+#include "../../../includes/translation.h"
+
+#include <QList>
+
+ class Testowanie: public QObject
+ {
+     Q_OBJECT
+
+
+ private slots:
+     void search();
+     void langFrom();
+     void sig();
+ };
+
+
+#endif // TEST_H
diff --git a/trunk/src/plugins/xdxf/tests/unit_tests.pro b/trunk/src/plugins/xdxf/tests/unit_tests.pro
new file mode 100644 (file)
index 0000000..f771321
--- /dev/null
@@ -0,0 +1,19 @@
+######################################################################
+# Automatically generated by qmake (1.07a) Wed Aug 4 11:35:12 2010
+######################################################################
+
+CONFIG += qtestlib
+TEMPLATE = app
+INCLUDEPATH += .
+
+# Input
+HEADERS += test.h \
+    ../src/XdxfPlugin/xdxfplugin.h \
+    ../src/XdxfPlugin/TranslationXdxf.h \
+    ../../../includes/translation.h \
+    ../../../includes/settings.h \
+    ../../../includes/CommonDictInterface.h
+
+SOURCES += test.cpp \
+    ../src/XdxfPlugin/xdxfplugin.cpp \
+    ../src/XdxfPlugin/TranslationXdxf.cpp