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();
56 BackboneTest::BackboneTest()
59 for(int i = 0; i < total; i++)
60 dict.push_back(new CommonDictInterfaceMock());
65 void BackboneTest::init()
67 for(int i = 0; i < total; i++) {
68 dict[i] = new CommonDictInterfaceMock();
69 CommonDictInterfaceMock * cd = (CommonDictInterfaceMock*) dict[i];
70 cd->tov = "to" + QString(i);
71 cd->fromv = "from" + QString(i);
72 cd->namev = "name" + QString(i);
73 cd->typev = "type" + QString(i);
75 back = new Backbone();
78 void BackboneTest::addDicts() {
79 for(int i = 0; i < total; i++)
80 back->addDictionary(dict[i]);
85 void BackboneTest::cleanup()
92 void BackboneTest::addDictionaryTest()
95 QCOMPARE(back->getDictionaries().size(), total);
96 for(int i = 0; i < total; i++)
97 QCOMPARE(back->getDictionaries().keys().contains(dict[i]), QBool(true));
100 void BackboneTest::removeDictionaryTest() {
102 for(int i = 0; i < total-1; i++)
103 back->removeDictionary(dict[i]);
105 QVERIFY2(back->getDictionaries().contains(dict[total-1]) == 1,
106 "Deletet wrong dictionaries");
112 void BackboneTest::selectedDictionaryTest() {
114 QList<CommonDictInterface* > selected;
115 back->selectedDictionaries(selected);
116 foreach(bool d, back->getDictionaries().values())
119 selected << dict[0] << dict[4];
121 back->selectedDictionaries(selected);
122 foreach(CommonDictInterface* d, back->getDictionaries().keys())
123 if(selected.contains(d))
124 QCOMPARE(back->getDictionaries()[d], true);
126 QCOMPARE(back->getDictionaries()[d], false);
132 void BackboneTest::stopSearchingTest() {
133 for(int i = 0; i < total; i++) {
134 CommonDictInterfaceMock *m = (CommonDictInterfaceMock*) dict[i];
136 back->addDictionary(dict[i]);
139 for(int i = 0; i < total; i++) {
140 CommonDictInterfaceMock *m = (CommonDictInterfaceMock*)dict[i];
141 QCOMPARE(m->stopped, 0);
144 back->stopSearching();
146 for(int i = 0; i < total; i++) {
147 CommonDictInterfaceMock *m = (CommonDictInterfaceMock*)dict[i];
148 QCOMPARE(m->stopped, 1);
157 void BackboneTest::searchTest() {
158 for(int i = 0; i < total; i++) {
159 CommonDictInterfaceMock *m = (CommonDictInterfaceMock*) dict[i];
161 back->addDictionary(dict[i]);
164 for(int i = 0; i < total; i++) {
165 CommonDictInterfaceMock *m = (CommonDictInterfaceMock*)dict[i];
166 QCOMPARE(m->stopped, 1);
169 qDebug() << "main " << this->thread()->currentThreadId();
170 back->search("pigwa");
173 for(int i = 0; i < total; i++) {
174 CommonDictInterfaceMock *m = (CommonDictInterfaceMock*)dict[i];
175 QCOMPARE(m->stopped, 0);
182 void BackboneTest::translationTest() {
183 QSignalSpy translatS(back, SIGNAL(ready()));
184 QVERIFY2 (translatS.isValid() == true, "ready() signal is invalid");
192 QVERIFY2(translatS.count() == 1, "Lost finall 'ready()' signal");
193 QVERIFY2(back->result().size() == total*2, "Lost some of translations");
197 QTEST_APPLESS_MAIN(BackboneTest);
199 #include "tst_Backbone.moc"