refactoring code
authorJakub Jaszczynski <j.j.jaszczynski@gmail.com>
Wed, 1 Sep 2010 12:34:08 +0000 (14:34 +0200)
committerJakub Jaszczynski <j.j.jaszczynski@gmail.com>
Wed, 1 Sep 2010 12:34:08 +0000 (14:34 +0200)
trunk/src/includes/AccentsNormalizer.h
trunk/src/plugins/xdxf/src/xdxfplugin.cpp
trunk/src/plugins/xdxf/tests/test.cpp
trunk/src/plugins/xdxf/tests/test.h

index dc378c6..c786b45 100644 (file)
@@ -41,13 +41,13 @@ class AccentsNormalizer {
     QString removeAccents(QString string) {
        string = string.toLower();
        QString normalized = string.normalized(QString::NormalizationForm_KD);
-       foreach(QChar let, letters.keys())
+       foreach(QChar let, letters.keys()) {
            normalized.replace(letters[let], QString(let));
-
+       }
        normalized.replace(noLetter, "");
-       //qDebug() << "NORMALIZED: " << normalized;
        return normalized;
     }
+
     void initAccents() {
         letters['a'] = QRegExp(QString::fromUtf8("[ÀàÁáÂÂâÃãÄäÅåæÆĀāĂ㥹ǠȀǡȁǢȂǣȃȦȧǺȺǻǼǍǽǎǞǟⱥ]"), Qt::CaseInsensitive);
         letters['b'] = QRegExp(QString::fromUtf8("[ƀƁƂƃɃƄƅ]"), Qt::CaseInsensitive);
index fc38b2e..345caf0 100644 (file)
@@ -41,7 +41,8 @@ XdxfPlugin::XdxfPlugin(QObject *parent) : CommonDictInterface(parent),
     connect(cachingDialog, SIGNAL(cancelCaching()),
             this, SLOT(stop()));
     connect(this, SIGNAL(updateCachingProgress(int,int)),
-            cachingDialog, SLOT(updateCachingProgress(int,int)));    
+            cachingDialog, SLOT(updateCachingProgress(int,int)));
+    initAccents();
 }
 
 
@@ -372,6 +373,7 @@ void XdxfPlugin::setSettings(const Settings *settings) {
         if((_settings->value("cached") == "false" ||
             _settings->value("cached").isEmpty()) &&
             settings->value("generateCache") == "true") {
+            clean();
             makeCache("");
         }
 
@@ -419,7 +421,6 @@ void XdxfPlugin::getDictionaryInfo() {
 }
 
 
-
 QIcon* XdxfPlugin::icon() {
     return &_icon;
 }
@@ -582,8 +583,9 @@ bool XdxfPlugin::makeCache(QString) {
 
 
 void XdxfPlugin::clean() {
-    if(_settings->value("cached") == "true")
+    if(QFile::exists(_settings->value("cache_path")))
         QFile(_settings->value("cache_path")).remove();
 }
 
+
 Q_EXPORT_PLUGIN2(xdxf, XdxfPlugin)
index 05aeee9..429b135 100644 (file)
 
 void XdxfTest::getNew() {
 
-    XdxfPlugin xdxfPlugin(this);
+    XdxfPlugin xdxfPluginB(this);
     Settings *settings=new Settings;
     settings->setValue("path","../tests/dict.xdxf");
-    CommonDictInterface *xdxfPlugin2 = xdxfPlugin.getNew(settings);
+    CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
 
-    QList<Translation*> te6=xdxfPlugin2->searchWordList("*",8);
+    QList<Translation*> te6=xdxfPlugin->searchWordList("*",8);
     QCOMPARE(te6.size(),8);
+
+    xdxfPlugin->clean();
+    delete xdxfPlugin;
 }
 
 void XdxfTest::searchFile() {
@@ -43,6 +46,9 @@ void XdxfTest::searchFile() {
     QCOMPARE(xdxfPlugin->search("."), QString("<key>.</key><t>kropka</t>"));
     QCOMPARE(xdxfPlugin->search("1"), QString("<key>1</key><t>one</t>"));
     QCOMPARE(xdxfPlugin->search("test"), QString("<key>test</key><t><c c=\"FF00FF\">kro</c>test01<pos>krowa</pos></t>"));
+
+    xdxfPlugin->clean();
+    delete xdxfPlugin;
 }
 
 void XdxfTest::makeCache()
@@ -53,6 +59,8 @@ void XdxfTest::makeCache()
     settings->setValue("generateCache", "true");
     CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
     QCOMPARE(xdxfPlugin->settings()->value("cached"),tr("true"));
+
+    xdxfPlugin->clean();
     delete xdxfPlugin;
 }
 
@@ -68,6 +76,7 @@ void XdxfTest::searchCache() {
     QCOMPARE(xdxfPlugin->search("1"), QString("<key>1</key><t>one</t>"));
     QCOMPARE(xdxfPlugin->search("test"), QString("<key>test</key><t><c c=\"FF00FF\">kro</c>test01<pos>krowa</pos></t>"));
 
+    xdxfPlugin->clean();
     delete xdxfPlugin;
 }
 
@@ -111,6 +120,7 @@ void XdxfTest::searchWordListCache(){
     QList<Translation*> te11 = xdxfPlugin->searchWordList("h**?*?**e");
         QCOMPARE(te11.at(0)->key(), QString("house"));
 
+    xdxfPlugin->clean();
     delete xdxfPlugin;
 }
 
@@ -154,6 +164,7 @@ void XdxfTest::searchWordListFile() {
     QList<Translation*> te11 = xdxfPlugin->searchWordList("h**?*?**e");
         QCOMPARE(te11.at(0)->key(), QString("house"));
 
+    xdxfPlugin->clean();
     delete xdxfPlugin;
 }
 
@@ -170,6 +181,7 @@ void XdxfTest::stop() {
     QList<Translation*> te5 = future.result();
     QCOMPARE(te5.size(), 9);
 
+    xdxfPlugin->clean();
     delete xdxfPlugin;
 }
 
@@ -183,6 +195,7 @@ void XdxfTest::langFrom() {
 
     QCOMPARE(xdxfPlugin->langFrom(), QString("ENG"));
 
+    xdxfPlugin->clean();
     delete xdxfPlugin;
 }
 
@@ -231,6 +244,8 @@ void XdxfTest::timeCache() {
     out<< "</time>";
 
     File.close();
+    xdxfPlugin->clean();
+    delete xdxfPlugin;
 }
 
 void XdxfTest::timeFile() {
@@ -271,6 +286,8 @@ void XdxfTest::timeFile() {
     out<< "</time>";
 
     File.close();
+    xdxfPlugin->clean();
+    delete xdxfPlugin;
 }
 
 void  XdxfTest::timeCacheNormalize() {
@@ -317,10 +334,12 @@ void  XdxfTest::timeCacheNormalize() {
     out<< "</time>";
 
     File.close();
+    xdxfPlugin->clean();
+    delete xdxfPlugin;
 }
 
-void  XdxfTest::removeAccents()
-{
+void  XdxfTest::removeAccents() {
+
     XdxfPluginSub xdxf;
     xdxf.settings()->setValue(QString("strip_accents"), QString("true"));
     QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("nóżka")), QString("nozka"));
@@ -375,6 +394,8 @@ void XdxfTest::timeFileNormalize(){
     out<< "</time>\n";
 
     File.close();
+    xdxfPlugin->clean();
+    delete xdxfPlugin;
 
 }
 
index a916908..1012b93 100644 (file)
@@ -29,9 +29,9 @@
 #include <QtConcurrentRun>
 #include <QFuture>
 #include "../src/xdxfplugin.h"
-#include <QTime>
 #include <QDate>
 #include <QTextStream>
+#include <QString>
 
  class XdxfTest: public QObject
  {
@@ -47,9 +47,9 @@
      void makeCache();
      void searchCache();
      void searchWordListCache();
+     void removeAccents();
      void timeCache();
      void timeFile();
-     void removeAccents();
      void timeCacheNormalize();
      void timeFileNormalize();
  };