Few unit tests added
authorBartosz Szatkowski <bulislaw@linux.com>
Tue, 3 Aug 2010 13:55:14 +0000 (15:55 +0200)
committerBartosz Szatkowski <bulislaw@linux.com>
Tue, 3 Aug 2010 13:55:14 +0000 (15:55 +0200)
trunk/src/base/backbone/backbone.cpp
trunk/tests/mDictionaryTests/CommonDictInterfaceMock.h
trunk/tests/mDictionaryTests/tst_Backbone.cpp

index 298442a..7500884 100644 (file)
@@ -86,8 +86,7 @@ void Backbone::search(QString word) {
  }
 
  void Backbone::quit() {
-    foreach(CommonDictInterface* dict, dicts.keys())
-        dict->stop();
+    stopSearching();
     Q_EMIT closeOk();
 }
 
index 232acc9..9d4a073 100644 (file)
@@ -33,7 +33,8 @@ class CommonDictInterfaceMock : public CommonDictInterface
 {
 public:
     QString fromv, tov, namev, typev, infoNotev;
-    bool available;
+    bool available,stopped;
+    CommonDictInterfaceMock() {}
 
     QString langFrom () const { return fromv; }
     QString langTo() const {return tov;}
@@ -45,8 +46,8 @@ public:
     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;}
 
 };
 
index 41f90fb..7e5bef5 100644 (file)
@@ -44,6 +44,9 @@ private Q_SLOTS:
     void initTestCase();
     void cleanupTestCase();
     void addDictionaryTest();
+    void selectedDictionaryTest();
+    void stopSearchingTest();
+    void searchTest();
 };
 
 BackboneTest::BackboneTest()
@@ -53,6 +56,8 @@ BackboneTest::BackboneTest()
         dict.push_back(new CommonDictInterfaceMock());
 }
 
+
+
 void BackboneTest::initTestCase()
 {
     for(int i = 0; i < total; i++)
@@ -60,6 +65,8 @@ void BackboneTest::initTestCase()
     back = new Backbone();
 }
 
+
+
 void BackboneTest::cleanupTestCase()
 {
     for(int i = 0; i < total; i++)
@@ -67,6 +74,8 @@ void BackboneTest::cleanupTestCase()
     delete back;
 }
 
+
+
 void BackboneTest::addDictionaryTest()
 {
     for(int i = 0; i < total; i++)
@@ -74,9 +83,84 @@ void BackboneTest::addDictionaryTest()
     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"