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();
58 BackboneTest::BackboneTest()
61 for(int i = 0; i < total; i++)
62 dict.push_back(new CommonDictInterfaceMock());
67 void BackboneTest::init()
69 for(int i = 0; i < total; i++) {
70 dict[i] = new CommonDictInterfaceMock();
71 CommonDictInterfaceMock * cd = (CommonDictInterfaceMock*) dict[i];
72 cd->tov = "to" + QString(i);
73 cd->fromv = "from" + QString(i);
74 cd->namev = "name" + QString(i);
75 cd->typev = "type" + QString(i);
77 back = new Backbone("vim");
80 void BackboneTest::addDicts() {
81 for(int i = 0; i < total; i++)
82 back->addDictionary(dict[i]);
87 void BackboneTest::cleanup()
94 void BackboneTest::addDictionaryTest()
97 QCOMPARE(back->getDictionaries().size(), total);
98 for(int i = 0; i < total; i++)
99 QCOMPARE(back->getDictionaries().keys().contains(dict[i]), QBool(true));
102 void BackboneTest::removeDictionaryTest() {
104 for(int i = 0; i < total-1; i++)
105 back->removeDictionary(dict[i]);
107 QVERIFY2(back->getDictionaries().contains(dict[total-1]) == 1,
108 "Deleted wrong dictionaries");
114 void BackboneTest::selectedDictionaryTest() {
116 QList<CommonDictInterface* > selected;
117 back->selectedDictionaries(selected);
118 foreach(bool d, back->getDictionaries().values())
121 selected << dict[0] << dict[4];
123 back->selectedDictionaries(selected);
124 foreach(CommonDictInterface* d, back->getDictionaries().keys())
125 if(selected.contains(d))
126 QCOMPARE(back->getDictionaries()[d], true);
128 QCOMPARE(back->getDictionaries()[d], false);
134 void BackboneTest::stopSearchingTest() {
135 for(int i = 0; i < total; i++) {
136 CommonDictInterfaceMock *m = (CommonDictInterfaceMock*) dict[i];
138 back->addDictionary(dict[i]);
141 for(int i = 0; i < total; i++) {
142 CommonDictInterfaceMock *m = (CommonDictInterfaceMock*)dict[i];
143 QCOMPARE(m->stopped, 0);
146 back->stopSearching();
148 for(int i = 0; i < total; i++) {
149 CommonDictInterfaceMock *m = (CommonDictInterfaceMock*)dict[i];
150 QCOMPARE(m->stopped, 1);
159 void BackboneTest::searchTest() {
160 for(int i = 0; i < total; i++) {
161 CommonDictInterfaceMock *m = (CommonDictInterfaceMock*) dict[i];
163 back->addDictionary(dict[i]);
166 for(int i = 0; i < total; i++) {
167 CommonDictInterfaceMock *m = (CommonDictInterfaceMock*)dict[i];
168 QCOMPARE(m->stopped, 1);
171 qDebug() << "main " << this->thread()->currentThreadId();
172 back->search("pigwa");
175 for(int i = 0; i < total; i++) {
176 CommonDictInterfaceMock *m = (CommonDictInterfaceMock*)dict[i];
177 QCOMPARE(m->stopped, 0);
184 void BackboneTest::translationTest() {
185 QSignalSpy translatS(back, SIGNAL(ready()));
186 QVERIFY2 (translatS.isValid() == true, "ready() signal is invalid");
193 qDebug() << "Time for backbone.search: " << time.elapsed();
197 qDebug() << "Time for backbone->translation: " << time.elapsed();
199 QVERIFY2(translatS.count() == 1, "Lost finall 'ready()' signal");
200 QVERIFY2(back->result().size() == total*2, "Lost some of the translations");
203 void BackboneTest::quitTest() {
204 QSignalSpy translatS(back, SIGNAL(closeOk()));
205 for(int i = 0; i < total; i++) {
206 CommonDictInterfaceMock *m = (CommonDictInterfaceMock*) dict[i];
208 back->addDictionary(dict[i]);
211 for(int i = 0; i < total; i++) {
212 CommonDictInterfaceMock *m = (CommonDictInterfaceMock*)dict[i];
213 QCOMPARE(m->stopped, 0);
218 for(int i = 0; i < total; i++) {
219 CommonDictInterfaceMock *m = (CommonDictInterfaceMock*)dict[i];
220 QCOMPARE(m->stopped, 1);
222 QVERIFY2(translatS.count() == 1, "Lost finall 'closeOk()' signal");
226 QTEST_APPLESS_MAIN(BackboneTest);
228 #include "tst_Backbone.moc"