1 /*******************************************************************************
3 This file is part of mDictionary.
5 mDictionary is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 mDictionary is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with mDictionary. If not, see <http://www.gnu.org/licenses/>.
18 Copyright 2010 Comarch S.A.
20 *******************************************************************************/
22 // Created by Bartosz Szatkowski
27 #include <QtCore/QString>
28 #include <QtTest/QtTest>
31 #include "../../src/base/backbone/backbone.h"
32 #include "CommonDictInterfaceMock.h"
34 class BackboneTest : public QObject
38 QList<CommonDictInterface*> dict;
49 void addDictionaryTest();
50 void removeDictionaryTest();
51 void selectedDictionaryTest();
52 void stopSearchingTest();
54 void translationTest();
55 void multiTranslationTest();
59 BackboneTest::BackboneTest()
62 for(int i = 0; i < total; i++)
63 dict.push_back(new CommonDictInterfaceMock());
68 void BackboneTest::init()
70 for(int i = 0; i < total; i++) {
71 dict[i] = new CommonDictInterfaceMock();
72 CommonDictInterfaceMock * cd = (CommonDictInterfaceMock*) dict[i];
73 cd->tov = QString("to%1").arg(i);
74 cd->fromv = QString("from%1").arg(i);
75 cd->namev = QString("name%1").arg(i);
76 cd->typev = QString("type%1").arg(i);
78 back = new Backbone("vim");
82 void BackboneTest::addDicts() {
83 for(int i = 0; i < total; i++) {
84 back->addDictionary(dict[i]);
90 void BackboneTest::cleanup()
98 void BackboneTest::addDictionaryTest()
100 QCOMPARE(back->getDictionaries().size(), total);
101 for(int i = 0; i < total; i++)
102 QCOMPARE(back->getDictionaries().keys().contains(dict[i]), QBool(true));
105 void BackboneTest::removeDictionaryTest() {
106 for(int i = 0; i < total-1; i++)
107 back->removeDictionary(dict[i]);
109 QVERIFY2(back->getDictionaries().contains(dict[total-1]) == 1,
110 "Deleted wrong dictionaries");
116 void BackboneTest::selectedDictionaryTest() {
117 QList<CommonDictInterface* > selected;
118 back->selectedDictionaries(selected);
119 foreach(bool d, back->getDictionaries().values())
122 selected << dict[0] << dict[4];
124 back->selectedDictionaries(selected);
125 foreach(CommonDictInterface* d, back->getDictionaries().keys())
126 if(selected.contains(d))
127 QCOMPARE(back->getDictionaries()[d], true);
129 QCOMPARE(back->getDictionaries()[d], false);
135 void BackboneTest::stopSearchingTest() {
136 for(int i = 0; i < total; i++) {
137 CommonDictInterfaceMock *m = (CommonDictInterfaceMock*) dict[i];
139 back->addDictionary(dict[i]);
142 for(int i = 0; i < total; i++) {
143 CommonDictInterfaceMock *m = (CommonDictInterfaceMock*)dict[i];
144 QCOMPARE(m->stopped, 0);
147 back->stopSearching();
149 for(int i = 0; i < total; i++) {
150 CommonDictInterfaceMock *m = (CommonDictInterfaceMock*)dict[i];
151 QCOMPARE(m->stopped, 1);
160 void BackboneTest::searchTest() {
161 for(int i = 0; i < total; i++) {
162 CommonDictInterfaceMock *m = (CommonDictInterfaceMock*) dict[i];
164 back->addDictionary(dict[i]);
167 for(int i = 0; i < total; i++) {
168 CommonDictInterfaceMock *m = (CommonDictInterfaceMock*)dict[i];
169 QCOMPARE(m->stopped, 1);
172 qDebug() << "main " << this->thread()->currentThreadId();
179 for(int i = 0; i < total; i++) {
180 CommonDictInterfaceMock *m = (CommonDictInterfaceMock*)dict[i];
181 QCOMPARE(m->stopped, 0);
188 void BackboneTest::translationTest() {
189 QSignalSpy translatS(back, SIGNAL(ready()));
190 QVERIFY2 (translatS.isValid() == true, "ready() signal is invalid");
198 qDebug() << "Time for backbone.search: " << time.elapsed();
201 back->translationReady();
202 qDebug() << "Time for backbone->translation: " << time.elapsed();
204 QVERIFY2(translatS.count() == 1, "Lost finall 'ready()' signal");
205 QVERIFY2(back->result().size() == total*2, "Lost some of the translations");
208 void BackboneTest::multiTranslationTest() {
209 QSignalSpy translatS(back, SIGNAL(ready()));
210 QVERIFY2 (translatS.isValid() == true, "ready() signal is invalid");
216 list << "a" << "b" << "c";
218 qDebug() << "Time for backbone.search: " << time.elapsed();
221 back->translationReady();
222 qDebug() << "Time for backbone->translation: " << time.elapsed();
224 QVERIFY2(translatS.count() == 1, "Lost finall 'ready()' signal");
225 QVERIFY2(back->result().size() == total*2*3,
226 "Lost some of the translations");
231 void BackboneTest::quitTest() {
232 QSignalSpy translatS(back, SIGNAL(closeOk()));
233 for(int i = 0; i < total; i++) {
234 CommonDictInterfaceMock *m = (CommonDictInterfaceMock*) dict[i];
236 back->addDictionary(dict[i]);
239 for(int i = 0; i < total; i++) {
240 CommonDictInterfaceMock *m = (CommonDictInterfaceMock*)dict[i];
241 QCOMPARE(m->stopped, 0);
246 for(int i = 0; i < total; i++) {
247 CommonDictInterfaceMock *m = (CommonDictInterfaceMock*)dict[i];
248 QCOMPARE(m->stopped, 1);
250 QVERIFY2(translatS.count() == 1, "Lost finall 'closeOk()' signal");
254 QTEST_APPLESS_MAIN(BackboneTest);
256 #include "tst_Backbone.moc"