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;
45 void cleanupTestCase();
46 void addDictionaryTest();
47 void selectedDictionaryTest();
48 void stopSearchingTest();
50 void translationTest();
53 BackboneTest::BackboneTest()
56 for(int i = 0; i < total; i++)
57 dict.push_back(new CommonDictInterfaceMock());
62 void BackboneTest::initTestCase()
64 for(int i = 0; i < total; i++) {
65 dict[i] = new CommonDictInterfaceMock();
66 CommonDictInterfaceMock * cd = (CommonDictInterfaceMock*) dict[i];
67 cd->tov = "to" + QString(i);
68 cd->fromv = "from" + QString(i);
69 cd->namev = "name" + QString(i);
70 cd->typev = "type" + QString(i);
72 back = new Backbone();
77 void BackboneTest::cleanupTestCase()
79 for(int i = 0; i < total; i++)
86 void BackboneTest::addDictionaryTest()
88 for(int i = 0; i < total; i++)
89 back->addDictionary(dict[i]);
90 QCOMPARE(back->getDictionaries().size(), total);
91 for(int i = 0; i < total; i++)
92 QCOMPARE(back->getDictionaries().keys().contains(dict[i]), QBool(true));
97 void BackboneTest::selectedDictionaryTest() {
98 for(int i = 0; i < total; i++)
99 back->addDictionary(dict[i]);
100 QList<CommonDictInterface* > selected;
101 back->selectedDictionaries(selected);
102 foreach(bool d, back->getDictionaries().values())
105 selected << dict[0] << dict[4];
107 back->selectedDictionaries(selected);
108 foreach(CommonDictInterface* d, back->getDictionaries().keys())
109 if(selected.contains(d))
110 QCOMPARE(back->getDictionaries()[d], true);
112 QCOMPARE(back->getDictionaries()[d], false);
118 void BackboneTest::stopSearchingTest() {
119 for(int i = 0; i < total; i++) {
120 CommonDictInterfaceMock *m = (CommonDictInterfaceMock*) dict[i];
122 back->addDictionary(dict[i]);
125 for(int i = 0; i < total; i++) {
126 CommonDictInterfaceMock *m = (CommonDictInterfaceMock*)dict[i];
127 QCOMPARE(m->stopped, 0);
130 back->stopSearching();
132 for(int i = 0; i < total; i++) {
133 CommonDictInterfaceMock *m = (CommonDictInterfaceMock*)dict[i];
134 QCOMPARE(m->stopped, 1);
143 void BackboneTest::searchTest() {
144 for(int i = 0; i < total; i++) {
145 CommonDictInterfaceMock *m = (CommonDictInterfaceMock*) dict[i];
147 back->addDictionary(dict[i]);
150 for(int i = 0; i < total; i++) {
151 CommonDictInterfaceMock *m = (CommonDictInterfaceMock*)dict[i];
152 QCOMPARE(m->stopped, 1);
155 back->search("pigwa");
157 for(int i = 0; i < total; i++) {
158 CommonDictInterfaceMock *m = (CommonDictInterfaceMock*)dict[i];
159 QCOMPARE(m->stopped, 0);
166 void BackboneTest::translationTest() {
167 QSignalSpy** ss = new QSignalSpy*[total];
168 QSignalSpy translatS(back, SIGNAL(ready()));
169 QVERIFY2 (translatS.isValid() == true, "ready() signal is invalid");
171 for(int i = 0; i < total; i++) {
172 CommonDictInterfaceMock *m = (CommonDictInterfaceMock*) dict[i];
174 back->addDictionary(dict[i]);
175 ss[i] = new QSignalSpy(m,SIGNAL(finalTranslation(QList<Translation*>)));
176 QVERIFY2(ss[i]->isValid() == 1, "Signal invalid");
181 for(int i = 0; i < total; i++) {
182 QVERIFY2(ss[i]->count() == 1, "Translation signal lost");
185 qDebug() << "count " << translatS.count();
186 QVERIFY2(translatS.count() == 1, "Lost finall 'ready()' signal");
187 qDebug() << "result.size " << back->result().size();
188 QVERIFY2(back->result().size() == total*2, "Lost some of translations");
192 QTEST_APPLESS_MAIN(BackboneTest);
194 #include "tst_Backbone.moc"