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());
58 qRegisterMetaType(Translation);
63 void BackboneTest::initTestCase()
65 for(int i = 0; i < total; i++) {
66 dict[i] = new CommonDictInterfaceMock();
67 CommonDictInterfaceMock * cd = (CommonDictInterfaceMock*) dict[i];
68 cd->tov = "to" + QString(i);
69 cd->fromv = "from" + QString(i);
70 cd->namev = "name" + QString(i);
71 cd->typev = "type" + QString(i);
73 back = new Backbone();
78 void BackboneTest::cleanupTestCase()
80 for(int i = 0; i < total; i++)
87 void BackboneTest::addDictionaryTest()
89 for(int i = 0; i < total; i++)
90 back->addDictionary(dict[i]);
91 QCOMPARE(back->getDictionaries().size(), total);
92 for(int i = 0; i < total; i++)
93 QCOMPARE(back->getDictionaries().keys().contains(dict[i]), QBool(true));
98 void BackboneTest::selectedDictionaryTest() {
99 for(int i = 0; i < total; i++)
100 back->addDictionary(dict[i]);
101 QList<CommonDictInterface* > selected;
102 back->selectedDictionaries(selected);
103 foreach(bool d, back->getDictionaries().values())
106 selected << dict[0] << dict[4];
108 back->selectedDictionaries(selected);
109 foreach(CommonDictInterface* d, back->getDictionaries().keys())
110 if(selected.contains(d))
111 QCOMPARE(back->getDictionaries()[d], true);
113 QCOMPARE(back->getDictionaries()[d], false);
119 void BackboneTest::stopSearchingTest() {
120 for(int i = 0; i < total; i++) {
121 CommonDictInterfaceMock *m = (CommonDictInterfaceMock*) dict[i];
123 back->addDictionary(dict[i]);
126 for(int i = 0; i < total; i++) {
127 CommonDictInterfaceMock *m = (CommonDictInterfaceMock*)dict[i];
128 QCOMPARE(m->stopped, 0);
131 back->stopSearching();
133 for(int i = 0; i < total; i++) {
134 CommonDictInterfaceMock *m = (CommonDictInterfaceMock*)dict[i];
135 QCOMPARE(m->stopped, 1);
144 void BackboneTest::searchTest() {
145 for(int i = 0; i < total; i++) {
146 CommonDictInterfaceMock *m = (CommonDictInterfaceMock*) dict[i];
148 back->addDictionary(dict[i]);
151 for(int i = 0; i < total; i++) {
152 CommonDictInterfaceMock *m = (CommonDictInterfaceMock*)dict[i];
153 QCOMPARE(m->stopped, 1);
156 back->search("pigwa");
158 for(int i = 0; i < total; i++) {
159 CommonDictInterfaceMock *m = (CommonDictInterfaceMock*)dict[i];
160 QCOMPARE(m->stopped, 0);
167 void BackboneTest::translationTest() {
168 QSignalSpy** ss = new QSignalSpy*[total];
170 for(int i = 0; i < total; i++) {
171 CommonDictInterfaceMock *m = (CommonDictInterfaceMock*) dict[i];
173 back->addDictionary(dict[i]);
174 ss[i] = new QSignalSpy(m,SIGNAL(finalTranslation(QList<Translation*>)));
175 QVERIFY2(ss[i]->isValid() == 1, "Signal invalid");
180 for(int i = 0; i < total; i++) {
181 QVERIFY2(ss[i]->count() == 1, "Translation signal lost");
186 QTEST_APPLESS_MAIN(BackboneTest);
188 #include "tst_Backbone.moc"