void Backbone::addDictionary(CommonDictInterface* dict) {
dicts[dict] = 1;
+ connect(dict, SIGNAL(finalTranslation(QList<Translation*>)),
+ this, SLOT(translation(QList<Translation*>)));
}
void Backbone::quit() {
+void Backbone::translation(QList<Translation *> trans) {
+
+}
+
+
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)
//! \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();
//! 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*);
//! emitted when there are search result ready to fetch
void ready();
+
+
private:
QHash<CommonDictInterface*, bool> dicts;
QList<CommonDictInterface*> plugins;
<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>
+++ /dev/null
-/*******************************************************************************
-
- 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"
-
#define COMMONDICTINTERFACEMOCK_H
#include "../../src/includes/CommonDictInterface.h"
+#include "TranslationMock.h"
class CommonDictInterfaceMock : public CommonDictInterface
{
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);
+ }
};
--- /dev/null
+/*******************************************************************************
+
+ 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
SOURCES += tst_Backbone.cpp \
- CommonDictInterfaceMock.cpp \
../../src/base/backbone/backbone.cpp
DEFINES += SRCDIR=\\\"$$PWD/\\\"
../../src/base/backbone/backbone.h \
../../src/includes/translation.h \
../../src/includes/settings.h \
- ../../src/includes/CommonDictInterface.h
+ ../../src/includes/CommonDictInterface.h \
+ TranslationMock.h
void selectedDictionaryTest();
void stopSearchingTest();
void searchTest();
+ void translationTest();
};
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();
}
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);