{
public:
QString fromv, tov, namev, typev, infoNotev;
- bool available;
+ bool available,stopped;
+ CommonDictInterfaceMock() {}
QString langFrom () const { return fromv; }
QString langTo() const {return tov;}
CommonDictInterface* getNew(const Settings *) const { return 0;}
bool isAvailable() const {return available;}
uint hash() const { return namev.length() + 10*typev.length();}
- void search(QString word, int limit) {}
- void stop() {}
+ void search(QString word, int limit) {stopped = 0;}
+ void stop() {stopped = 1;}
};
void initTestCase();
void cleanupTestCase();
void addDictionaryTest();
+ void selectedDictionaryTest();
+ void stopSearchingTest();
+ void searchTest();
};
BackboneTest::BackboneTest()
dict.push_back(new CommonDictInterfaceMock());
}
+
+
void BackboneTest::initTestCase()
{
for(int i = 0; i < total; i++)
back = new Backbone();
}
+
+
void BackboneTest::cleanupTestCase()
{
for(int i = 0; i < total; i++)
delete back;
}
+
+
void BackboneTest::addDictionaryTest()
{
for(int i = 0; i < total; i++)
QCOMPARE(back->getDictionaries().size(), total);
for(int i = 0; i < total; i++)
QCOMPARE(back->getDictionaries().keys().contains(dict[i]), QBool(true));
+}
+
+
+void BackboneTest::selectedDictionaryTest() {
+ for(int i = 0; i < total; i++)
+ back->addDictionary(dict[i]);
+ QList<CommonDictInterface* > selected;
+ back->selectedDictionaries(selected);
+ foreach(bool d, back->getDictionaries().values())
+ QCOMPARE(d, false);
+
+ selected << dict[0] << dict[4];
+
+ back->selectedDictionaries(selected);
+ foreach(CommonDictInterface* d, back->getDictionaries().keys())
+ if(selected.contains(d))
+ QCOMPARE(back->getDictionaries()[d], true);
+ else
+ QCOMPARE(back->getDictionaries()[d], false);
}
+
+
+
+void BackboneTest::stopSearchingTest() {
+ for(int i = 0; i < total; i++) {
+ CommonDictInterfaceMock *m = (CommonDictInterfaceMock*) dict[i];
+ m->stopped = 0;
+ back->addDictionary(dict[i]);
+ }
+
+ for(int i = 0; i < total; i++) {
+ CommonDictInterfaceMock *m = (CommonDictInterfaceMock*)dict[i];
+ QCOMPARE(m->stopped, 0);
+ }
+
+ back->stopSearching();
+
+ for(int i = 0; i < total; i++) {
+ CommonDictInterfaceMock *m = (CommonDictInterfaceMock*)dict[i];
+ QCOMPARE(m->stopped, 1);
+ }
+
+
+}
+
+
+
+
+void BackboneTest::searchTest() {
+ for(int i = 0; i < total; i++) {
+ CommonDictInterfaceMock *m = (CommonDictInterfaceMock*) dict[i];
+ m->stopped = 1;
+ back->addDictionary(dict[i]);
+ }
+
+ for(int i = 0; i < total; i++) {
+ CommonDictInterfaceMock *m = (CommonDictInterfaceMock*)dict[i];
+ QCOMPARE(m->stopped, 1);
+ }
+
+ back->search("pigwa");
+
+ for(int i = 0; i < total; i++) {
+ CommonDictInterfaceMock *m = (CommonDictInterfaceMock*)dict[i];
+ QCOMPARE(m->stopped, 0);
+ }
+
+
+}
+
+
+
+
+
+
+
QTEST_APPLESS_MAIN(BackboneTest);
#include "tst_Backbone.moc"