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>
30 #include "../../src/base/backbone/backbone.h"
31 #include "CommonDictInterfaceMock.h"
33 class BackboneTest : public QObject
37 QList<CommonDictInterface*> dict;
48 void addDictionaryTest();
49 void removeDictionaryTest();
50 void selectedDictionaryTest();
51 void stopSearchingTest();
53 void translationTest();
57 BackboneTest::BackboneTest()
60 for(int i = 0; i < total; i++)
61 dict.push_back(new CommonDictInterfaceMock());
66 void BackboneTest::init()
68 for(int i = 0; i < total; i++) {
69 dict[i] = new CommonDictInterfaceMock();
70 CommonDictInterfaceMock * cd = (CommonDictInterfaceMock*) dict[i];
71 cd->tov = "to" + QString(i);
72 cd->fromv = "from" + QString(i);
73 cd->namev = "name" + QString(i);
74 cd->typev = "type" + QString(i);
76 back = new Backbone();
79 void BackboneTest::addDicts() {
80 for(int i = 0; i < total; i++)
81 back->addDictionary(dict[i]);
86 void BackboneTest::cleanup()
93 void BackboneTest::addDictionaryTest()
96 QCOMPARE(back->getDictionaries().size(), total);
97 for(int i = 0; i < total; i++)
98 QCOMPARE(back->getDictionaries().keys().contains(dict[i]), QBool(true));
101 void BackboneTest::removeDictionaryTest() {
103 for(int i = 0; i < total-1; i++)
104 back->removeDictionary(dict[i]);
106 QVERIFY2(back->getDictionaries().contains(dict[total-1]) == 1,
107 "Deletet wrong dictionaries");
113 void BackboneTest::selectedDictionaryTest() {
115 QList<CommonDictInterface* > selected;
116 back->selectedDictionaries(selected);
117 foreach(bool d, back->getDictionaries().values())
120 selected << dict[0] << dict[4];
122 back->selectedDictionaries(selected);
123 foreach(CommonDictInterface* d, back->getDictionaries().keys())
124 if(selected.contains(d))
125 QCOMPARE(back->getDictionaries()[d], true);
127 QCOMPARE(back->getDictionaries()[d], false);
133 void BackboneTest::stopSearchingTest() {
134 for(int i = 0; i < total; i++) {
135 CommonDictInterfaceMock *m = (CommonDictInterfaceMock*) dict[i];
137 back->addDictionary(dict[i]);
140 for(int i = 0; i < total; i++) {
141 CommonDictInterfaceMock *m = (CommonDictInterfaceMock*)dict[i];
142 QCOMPARE(m->stopped, 0);
145 back->stopSearching();
147 for(int i = 0; i < total; i++) {
148 CommonDictInterfaceMock *m = (CommonDictInterfaceMock*)dict[i];
149 QCOMPARE(m->stopped, 1);
158 void BackboneTest::searchTest() {
159 for(int i = 0; i < total; i++) {
160 CommonDictInterfaceMock *m = (CommonDictInterfaceMock*) dict[i];
162 back->addDictionary(dict[i]);
165 for(int i = 0; i < total; i++) {
166 CommonDictInterfaceMock *m = (CommonDictInterfaceMock*)dict[i];
167 QCOMPARE(m->stopped, 1);
170 qDebug() << "main " << this->thread()->currentThreadId();
171 back->search("pigwa");
174 for(int i = 0; i < total; i++) {
175 CommonDictInterfaceMock *m = (CommonDictInterfaceMock*)dict[i];
176 QCOMPARE(m->stopped, 0);
183 void BackboneTest::translationTest() {
184 QSignalSpy translatS(back, SIGNAL(ready()));
185 QVERIFY2 (translatS.isValid() == true, "ready() signal is invalid");
193 QVERIFY2(translatS.count() == 1, "Lost finall 'ready()' signal");
194 QVERIFY2(back->result().size() == total*2, "Lost some of the translations");
197 void BackboneTest::quitTest() {
198 QSignalSpy translatS(back, SIGNAL(closeOk()));
199 for(int i = 0; i < total; i++) {
200 CommonDictInterfaceMock *m = (CommonDictInterfaceMock*) dict[i];
202 back->addDictionary(dict[i]);
205 for(int i = 0; i < total; i++) {
206 CommonDictInterfaceMock *m = (CommonDictInterfaceMock*)dict[i];
207 QCOMPARE(m->stopped, 0);
212 for(int i = 0; i < total; i++) {
213 CommonDictInterfaceMock *m = (CommonDictInterfaceMock*)dict[i];
214 QCOMPARE(m->stopped, 1);
216 QVERIFY2(translatS.count() == 1, "Lost finall 'closeOk()' signal");
220 QTEST_APPLESS_MAIN(BackboneTest);
222 #include "tst_Backbone.moc"