Small refactoring and added test
authorBartosz Szatkowski <bulislaw@linux.com>
Tue, 10 Aug 2010 13:16:34 +0000 (15:16 +0200)
committerBartosz Szatkowski <bulislaw@linux.com>
Tue, 10 Aug 2010 13:16:34 +0000 (15:16 +0200)
trunk/src/base/backbone/backbone.cpp
trunk/src/base/backbone/backbone.h
trunk/tests/mDictionaryTests/mDictionaryTests.pro.user
trunk/tests/mDictionaryTests/tst_Backbone.cpp

index 6dcdda4..0988523 100644 (file)
@@ -122,7 +122,7 @@ QMultiHash<QString, Translation*> Backbone::result() {
 
 void Backbone::stopSearching() {
     _timerSearch.stop();
-    _innerResult.clear();
+    _timerHtmlSearch.stop();
     foreach(CommonDictInterface* dict, _dicts.keys())
         dict->stop();
 }
@@ -242,10 +242,6 @@ void Backbone::loadPlugins() {
 
         CommonDictInterface *plugin = qobject_cast<CommonDictInterface*>(pl);
         _plugins.append(plugin);
-       // addDictionary(plugin->getNew(0)); //TODO change 0 to real settings
-        //Settings* set = new Settings();
-        //set->setValue("path", "dict2.xdxf");
-        //addDictionary(plugin->getNew(set));
     }
 }
 
index 8a1b29d..61db1bc 100644 (file)
@@ -168,8 +168,8 @@ private:
     void loadPrefs();
     void loadDicts();
     void saveState(QSettings*, Settings*, bool, uint);
-    CommonDictInterface* plugin(QString type); //< search for given type plugin
     void addInternalDictionary(CommonDictInterface*, bool);
+    CommonDictInterface* plugin(QString type); //< search for given type plugin
     //void writeConfig(QString key, QString value);
 
 };
index ef5a8f0..bd14af5 100644 (file)
@@ -46,7 +46,7 @@
     <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Qt w PATH Debug</value>
     <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.Qt4BuildConfiguration</value>
     <value key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration" type="int">2</value>
-    <value key="Qt4ProjectManager.Qt4BuildConfiguration.BuildDirectory" type="QString">/home/bulislaw/devel/mdictionary/trunk/tests/mDictionaryTests-build-desktop</value>
+    <value key="Qt4ProjectManager.Qt4BuildConfiguration.BuildDirectory" type="QString">/home/bulislaw/devel/mDictionaryTests-build</value>
     <value key="Qt4ProjectManager.Qt4BuildConfiguration.QtVersionId" type="int">3</value>
     <value key="Qt4ProjectManager.Qt4BuildConfiguration.ToolChain" type="int">0</value>
     <value key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild" type="bool">true</value>
index 01f6a77..cf998e2 100644 (file)
@@ -52,6 +52,7 @@ private Q_SLOTS:
     void stopSearchingTest();
     void searchTest();
     void translationTest();
+    void multiTranslationTest();
     void quitTest();
 };
 
@@ -69,17 +70,19 @@ void BackboneTest::init()
     for(int i = 0; i < total; i++) {
         dict[i] = new CommonDictInterfaceMock();
         CommonDictInterfaceMock * cd = (CommonDictInterfaceMock*) dict[i];
-        cd->tov = "to" + QString(i);
-        cd->fromv = "from" + QString(i);
-        cd->namev = "name" + QString(i);
-        cd->typev = "type" + QString(i);
+        cd->tov =   QString("to%1").arg(i);
+        cd->fromv = QString("from%1").arg(i);
+        cd->namev = QString("name%1").arg(i);
+        cd->typev = QString("type%1").arg(i);
     }
     back = new Backbone("vim");
+    addDicts();
 }
 
 void BackboneTest::addDicts() {
-    for(int i = 0; i < total; i++)
+    for(int i = 0; i < total; i++) {
         back->addDictionary(dict[i]);
+    }
 }
 
 
@@ -91,16 +94,15 @@ void BackboneTest::cleanup()
 
 
 
+
 void BackboneTest::addDictionaryTest()
 {
-    addDicts();
     QCOMPARE(back->getDictionaries().size(), total);
     for(int i = 0; i < total; i++)
         QCOMPARE(back->getDictionaries().keys().contains(dict[i]), QBool(true));
 }
 
 void BackboneTest::removeDictionaryTest() {
-    addDicts();
     for(int i = 0; i < total-1; i++)
         back->removeDictionary(dict[i]);
 
@@ -112,7 +114,6 @@ void BackboneTest::removeDictionaryTest() {
 
 
 void BackboneTest::selectedDictionaryTest() {
-    addDicts();
     QList<CommonDictInterface* > selected;
     back->selectedDictionaries(selected);
     foreach(bool d, back->getDictionaries().values())
@@ -188,7 +189,6 @@ void BackboneTest::translationTest() {
     QSignalSpy translatS(back, SIGNAL(ready()));
     QVERIFY2 (translatS.isValid() == true, "ready() signal is invalid");
 
-    addDicts();
 
     QTime time;
     time.start();
@@ -196,7 +196,7 @@ void BackboneTest::translationTest() {
     list << "nic";
     back->search(list);
     qDebug() << "Time for backbone.search: " << time.elapsed();
-    usleep(2000);
+    usleep(1000);
     time.start();
     back->translationReady();
     qDebug() << "Time for backbone->translation: " << time.elapsed();
@@ -205,6 +205,29 @@ void BackboneTest::translationTest() {
     QVERIFY2(back->result().size() == total*2, "Lost some of the translations");
 }
 
+void BackboneTest::multiTranslationTest() {
+    QSignalSpy translatS(back, SIGNAL(ready()));
+    QVERIFY2 (translatS.isValid() == true, "ready() signal is invalid");
+
+
+    QTime time;
+    QStringList list;
+
+    list << "a" << "b" << "c";
+    back->search(list);
+    qDebug() << "Time for backbone.search: " << time.elapsed();
+    usleep(1000);
+    time.start();
+    back->translationReady();
+    qDebug() << "Time for backbone->translation: " << time.elapsed();
+
+    QVERIFY2(translatS.count() == 1, "Lost finall 'ready()' signal");
+    QVERIFY2(back->result().size() == total*2*3,
+             "Lost some of the translations");
+}
+
+
+
 void BackboneTest::quitTest() {
     QSignalSpy translatS(back, SIGNAL(closeOk()));
     for(int i = 0; i < total; i++) {