From 4242fe38b152bd4d71916bfd21ddbaa20df512c9 Mon Sep 17 00:00:00 2001 From: Jakub Jaszczynski Date: Tue, 7 Sep 2010 08:28:54 +0200 Subject: [PATCH] refaktoring --- src/include/AccentsNormalizer.h | 5 +- src/include/CommonDictInterface.h | 22 ++++--- src/include/DictDialog.h | 6 ++ src/include/GUIInterface.h | 1 - src/include/settings.h | 14 ++-- src/include/translation.h | 7 +- src/mdictionary/backbone/BookmarkTranslations.h | 2 +- src/mdictionary/backbone/Bookmarks.cpp | 1 - src/plugins/google/GooglePlugin.cpp | 17 +---- src/plugins/google/GooglePlugin.h | 24 +++++-- src/plugins/google/GoogleSettingsDialog.h | 16 +---- src/plugins/google/TranslationGoogle.h | 3 +- src/plugins/xdxf/TranslationXdxf.cpp | 7 +- src/plugins/xdxf/XdxfCachingDialog.cpp | 4 -- src/plugins/xdxf/XdxfCachingDialog.h | 5 +- src/plugins/xdxf/XdxfLoadDialog.cpp | 3 - src/plugins/xdxf/XdxfLoadDialog.h | 4 -- src/plugins/xdxf/XdxfSettingsDialog.h | 6 +- src/plugins/xdxf/xdxfplugin.cpp | 28 ++------ src/plugins/xdxf/xdxfplugin.h | 45 ++++++++----- tests/GooglePluginTests/test.cpp | 28 ++++++++ tests/GooglePluginTests/test.h | 2 + tests/XdxfPluginTests/test.cpp | 77 +++++++++++++--------- tests/XdxfPluginTests/test.h | 1 + tests/mDictionaryTests/CommonDictInterfaceMock.h | 2 - 25 files changed, 183 insertions(+), 147 deletions(-) diff --git a/src/include/AccentsNormalizer.h b/src/include/AccentsNormalizer.h index 0343e88..9381313 100644 --- a/src/include/AccentsNormalizer.h +++ b/src/include/AccentsNormalizer.h @@ -21,7 +21,6 @@ /*! /file AccentsNormalizer.h \brief Common functionality for all classes that need to remove accents from strings - \author Bartosz Szatkowski */ @@ -32,12 +31,13 @@ #include #include - +//! Common functionality for all classes that need to remove accents from strings class AccentsNormalizer { protected: QMap letters; QRegExp noLetter; + //! removes accents from letters in searched word (e.g. ą -> a, ł -> l) QString removeAccents(QString string) { string = string.toLower(); QString normalized = string.normalized(QString::NormalizationForm_KD); @@ -48,6 +48,7 @@ class AccentsNormalizer { return normalized; } + //! initializes the list of pairs (letters, accents) void initAccents() { letters['a'] = QRegExp(QString::fromUtf8("[ÀàÁáÂÂâÃãÄäÅåæÆĀāĂ㥹ǠȀǡȁǢȂǣȃȦȧǺȺǻǼǍǽǎǞǟⱥ]"), Qt::CaseInsensitive); letters['b'] = QRegExp(QString::fromUtf8("[ƀƁƂƃɃƄƅ]"), Qt::CaseInsensitive); diff --git a/src/include/CommonDictInterface.h b/src/include/CommonDictInterface.h index f09815d..a3c9790 100644 --- a/src/include/CommonDictInterface.h +++ b/src/include/CommonDictInterface.h @@ -45,7 +45,6 @@ class CommonDictInterface : public QObject, public AccentsNormalizer { Q_OBJECT public: CommonDictInterface(QObject *parent = 0):QObject(parent) {} - virtual ~CommonDictInterface() {} //! returns source language code iso 639-2 @@ -67,7 +66,6 @@ class CommonDictInterface : public QObject, public AccentsNormalizer { for adding new dictionary and changing plugin settings*/ virtual DictDialog* dictDialog() = 0; - //! returns new, clean copy of plugin with settings set as in Settings* virtual CommonDictInterface* getNew(const Settings*) const = 0; @@ -78,10 +76,14 @@ class CommonDictInterface : public QObject, public AccentsNormalizer { virtual QString search(QString key) = 0; //! \returns unique value (unique for every dictionary, not plugin) - virtual uint hash() const = 0; + uint hash() const { + return _hash; + } //! sets unique value (unique for every dictionary, not plugin) - virtual void setHash(uint) = 0; + void setHash(uint) { + this->_hash=_hash; + } //! returns current plugin settings virtual Settings* settings() = 0; @@ -112,13 +114,10 @@ class CommonDictInterface : public QObject, public AccentsNormalizer { //! stops current operation virtual void stop() = 0; - virtual void retranslate() = 0; + //! loads translations for each plugin only once + virtual void retranslate() {} Q_SIGNALS: - - //! emitted when dictionary is ready to use afer being loaded - void loaded(CommonDictInterface*); - //! emitted after change in dictionary settings void settingsChanged(); @@ -131,11 +130,16 @@ class CommonDictInterface : public QObject, public AccentsNormalizer { protected: +//! removes accents from letters in searched word (e.g. ą -> a, ł -> l) QString removeAccents(QString string) { if(settings()->value("strip_accents") == "true") return AccentsNormalizer::removeAccents(string); return string; } + +private: + uint _hash; + }; Q_DECLARE_INTERFACE(CommonDictInterface, "CommonDictInterface/0.1"); diff --git a/src/include/DictDialog.h b/src/include/DictDialog.h index fc83744..1cfd403 100644 --- a/src/include/DictDialog.h +++ b/src/include/DictDialog.h @@ -19,6 +19,12 @@ *******************************************************************************/ +/*! \file DictDialog.h + \brief Interface for plugin dialog provider + \author Mateusz Półrola +*/ + + //Created by Mateusz Półrola #ifndef DICTDIALOG_H diff --git a/src/include/GUIInterface.h b/src/include/GUIInterface.h index 2f10cc1..6f94f06 100644 --- a/src/include/GUIInterface.h +++ b/src/include/GUIInterface.h @@ -43,7 +43,6 @@ class GUIInterface : public QMainWindow { public: GUIInterface(QWidget *parent = 0) :QMainWindow(parent) {} - virtual ~GUIInterface() {} //! Returns all loaded dictionaries with information about that they are diff --git a/src/include/settings.h b/src/include/settings.h index 6843a79..9b338ae 100644 --- a/src/include/settings.h +++ b/src/include/settings.h @@ -39,14 +39,15 @@ It's important for plugin to store all information given to it in Settings.*/ class Settings { public: - Settings(){} + Settings() {} + ~Settings() {} Settings(const Settings* set) { _settings = QHash(set->_settings); } - ~Settings(){} /*! \returns value fo given key - \param key + \param key name of given setting + \return value of given setting */ QString value(const QString key) const { if(!_settings.contains(key)) { @@ -55,16 +56,21 @@ class Settings { return _settings[key]; } - //! sets key to value + /*! sets key to value + \param key name of given setting + \param value of given setting + */ void setValue(const QString key, const QString value) { _settings.insert(key, value); } + //! \returns list of keys (QList) QList keys() const { return _settings.keys(); } private: + //! keeps the settings QHash _settings; }; diff --git a/src/include/translation.h b/src/include/translation.h index a6a20a9..20e1453 100644 --- a/src/include/translation.h +++ b/src/include/translation.h @@ -42,9 +42,11 @@ class Translation { public: Translation () { _bookmark = 0;} virtual ~Translation () {} + //! \return word to be translated virtual QString key() const = 0; + //! compares two translations by key bool operator==(Translation* translation) { return this->key()==translation->key(); } @@ -69,8 +71,9 @@ class Translation { //! returns coresponding dict object virtual uint dict() const {return 0;} - protected: - bool _bookmark; + protected: + //! indicates whether this translation is in bookmark + bool _bookmark; }; diff --git a/src/mdictionary/backbone/BookmarkTranslations.h b/src/mdictionary/backbone/BookmarkTranslations.h index 6dbd1b9..6931ce9 100644 --- a/src/mdictionary/backbone/BookmarkTranslations.h +++ b/src/mdictionary/backbone/BookmarkTranslations.h @@ -73,7 +73,7 @@ public: \param word for which we want to find a translation */ void setKey(QString key) { _key = key; - }; + } //! sets information about dictionary void setDictionaryInfo(QString dictionaryInfo) { diff --git a/src/mdictionary/backbone/Bookmarks.cpp b/src/mdictionary/backbone/Bookmarks.cpp index 32a3ab3..a3a0fca 100644 --- a/src/mdictionary/backbone/Bookmarks.cpp +++ b/src/mdictionary/backbone/Bookmarks.cpp @@ -139,7 +139,6 @@ QList Bookmarks::searchWordList(QString word) { QStringList Bookmarks::search(QString word, QString dbName) { - checkAndCreateDb(); QStringList result; QSqlDatabase db = getDbCnx(dbName); if(!db.isOpen() && !db.open()) { diff --git a/src/plugins/google/GooglePlugin.cpp b/src/plugins/google/GooglePlugin.cpp index 5a9c13f..970ee39 100644 --- a/src/plugins/google/GooglePlugin.cpp +++ b/src/plugins/google/GooglePlugin.cpp @@ -116,6 +116,7 @@ void GooglePlugin::setConnectionAccept(QString connectionAcepted) { _settings->setValue("connection_accepted","false"); } + bool GooglePlugin::isConnectionAccept() const { if(_settings->value("connection_accepted")=="true") return true; @@ -124,23 +125,7 @@ bool GooglePlugin::isConnectionAccept() const { } -uint GooglePlugin::hash() const { - return _hash; -} - - -void GooglePlugin::setHash(uint _hash) { - this->_hash=_hash; -} - - Settings* GooglePlugin::settings() { -/* Settings *returnSettings=new Settings; - QStringList list = _settings->keys(); - foreach(QString key, list) - returnSettings->setValue(key,_settings->value(key)); - return returnSettings; -*/ return _settings; } diff --git a/src/plugins/google/GooglePlugin.h b/src/plugins/google/GooglePlugin.h index 6e898b0..2d9d7ff 100644 --- a/src/plugins/google/GooglePlugin.h +++ b/src/plugins/google/GooglePlugin.h @@ -65,8 +65,10 @@ public: //! returns information about dictionary in html (name, authors, etc) QString infoNote() const; + //! sets the language to which the translation is done void setLangTo(QString langTo); + //! sets the language from which the translation is done void setLangFrom(QString langFrom); /*! returns DictDialog object that creates dialogs @@ -80,19 +82,15 @@ public: //! returns whether plugin can start searching bool isAvailable() const; + //! sets if connection with Internet is possible void setConnectionAccept(QString connectionAcepted); + //! returns the value of "connection_accepted" from settings bool isConnectionAccept() const; //! returns a description of a word given by a QString QString search(QString key); - //! returns a unique hash for a dictionary - uint hash() const; - - //! sets unique value (unique for every dictionary, not plugin) - void setHash(uint); - //! returns current plugin settings Settings* settings(); @@ -102,8 +100,10 @@ public: //! returns plugin icon QIcon* icon(); + //! returns empty translation object (to be fetched later) for given key Translation* getTranslationFor(QString key); + //! initializes the list of available languages in Google translator static QMap initLanguages(); public slots: @@ -119,25 +119,37 @@ public slots: //! stop current operation void stop(); + //! function called after the request from Google is returned void done(); + //! transforms Google format to String with translation QString jsonParse(QString result); + + //! sets information about dictionary void getDictionaryInfo(); + //! loads translations for each plugin only once void retranslate(); private: + //! maps languages full names to two-letter acronyms QMap languages; + + //! name of a dictionary QString _name; //! type of a dictionary QString _type; //! information about dictionary QString _infoNote; + //! unique number of a dictionary assigned to it by backbone uint _hash; + //! icon displayed during translations and when the dictionary is chosen QIcon _icon; Settings *_settings; + //! indicates if search is stopped bool stopped; bool _connectionAccept; + //! indicates if response from Google appeared volatile bool wait; QHttp *http; GoogleDictDialog *_dictDialog; diff --git a/src/plugins/google/GoogleSettingsDialog.h b/src/plugins/google/GoogleSettingsDialog.h index 24d1857..991f65c 100644 --- a/src/plugins/google/GoogleSettingsDialog.h +++ b/src/plugins/google/GoogleSettingsDialog.h @@ -65,8 +65,11 @@ public: QString langTo(); private slots: + //! assigns the language chosen from a list(langFromComboBox) to _langFrom void activatedFrom(int); + //! assigns the language chosen from a list(langToComboBox) to _langTo void activatedTo(int); + //! handles the "swap languages" button void changeLangButtonClicked(); @@ -77,28 +80,15 @@ private: QLabel* connectInfoLabel; QPushButton* saveButton; QPushButton* changeLangButton; - - QComboBox *langFromComboBox; QComboBox *langToComboBox; - QVBoxLayout* verticalLayout; QVBoxLayout* langLayout; QHBoxLayout* langFromLayout; QHBoxLayout* langToLayout; QHBoxLayout* changelangLayout; - QString _langFrom; QString _langTo; - - -/* QPushButton* browseButton; - QLabel* browseLabel; - QCheckBox* cacheCheckBox; - - QHBoxLayout* browseLayout; - QHBoxLayout* cacheLayout; -*/ }; #endif // GOOGLESETTINGSDIALOG_H diff --git a/src/plugins/google/TranslationGoogle.h b/src/plugins/google/TranslationGoogle.h index 4068136..d1a0797 100644 --- a/src/plugins/google/TranslationGoogle.h +++ b/src/plugins/google/TranslationGoogle.h @@ -68,10 +68,9 @@ private: QString _key; QString _dictionaryInfo; QString _trans; - GooglePlugin *googlePlugin; int _dictHash; bool error; - + GooglePlugin *googlePlugin; }; #endif // TRANSLATIONGOOGLE_H diff --git a/src/plugins/xdxf/TranslationXdxf.cpp b/src/plugins/xdxf/TranslationXdxf.cpp index 7bb8d8d..7a622d4 100644 --- a/src/plugins/xdxf/TranslationXdxf.cpp +++ b/src/plugins/xdxf/TranslationXdxf.cpp @@ -54,11 +54,12 @@ QString TranslationXdxf::toHtml() const { QString result(""); if(!xdxfPlugin) return result; - result=result + "" + " \n"; else - result+= " bookmark=\"false\" "; + result+= " bookmark=\"false\" > \n"; result+= _dictionaryInfo + "" + xdxfPlugin->search(_key) + ""; return result.replace("&","&"); } diff --git a/src/plugins/xdxf/XdxfCachingDialog.cpp b/src/plugins/xdxf/XdxfCachingDialog.cpp index 7ad2f59..8083ae6 100644 --- a/src/plugins/xdxf/XdxfCachingDialog.cpp +++ b/src/plugins/xdxf/XdxfCachingDialog.cpp @@ -75,10 +75,6 @@ void XdxfCachingDialog::updateCachingProgress(int progress, int time) { } -void XdxfCachingDialog::reject() { - return; -} - void XdxfCachingDialog::cancelButtonClicked(){ return; } diff --git a/src/plugins/xdxf/XdxfCachingDialog.h b/src/plugins/xdxf/XdxfCachingDialog.h index 93eac93..8d638f7 100644 --- a/src/plugins/xdxf/XdxfCachingDialog.h +++ b/src/plugins/xdxf/XdxfCachingDialog.h @@ -39,11 +39,9 @@ public: explicit XdxfCachingDialog(XdxfPlugin *parent = 0); Q_SIGNALS: + //! signal emitted when user cancels caching of a dictionary void cancelCaching(); -public Q_SLOTS: - void reject(); - private Q_SLOTS: void cancelButtonClicked(); void updateCachingProgress(int, int); @@ -53,6 +51,7 @@ private: QProgressBar* cachingProgressBar; QPushButton* cancelButton; QVBoxLayout* verticalLayout; + //! used to check the progress of dictionary caching QTime time; }; diff --git a/src/plugins/xdxf/XdxfLoadDialog.cpp b/src/plugins/xdxf/XdxfLoadDialog.cpp index 269bb87..d43175d 100644 --- a/src/plugins/xdxf/XdxfLoadDialog.cpp +++ b/src/plugins/xdxf/XdxfLoadDialog.cpp @@ -102,9 +102,6 @@ void XdxfLoadDialog::addDictionary() { if(!_dicitonaryFilePath.isEmpty()) { accept(); } - else { - reject(); - } } QString XdxfLoadDialog::dicitonaryFilePath() { diff --git a/src/plugins/xdxf/XdxfLoadDialog.h b/src/plugins/xdxf/XdxfLoadDialog.h index 97e79e5..8ce8df0 100644 --- a/src/plugins/xdxf/XdxfLoadDialog.h +++ b/src/plugins/xdxf/XdxfLoadDialog.h @@ -47,10 +47,6 @@ public: //! Returns if user wants to cache dictionary bool generateCache(); -signals: - -public slots: - private Q_SLOTS: void selectFile(); void addDictionary(); diff --git a/src/plugins/xdxf/XdxfSettingsDialog.h b/src/plugins/xdxf/XdxfSettingsDialog.h index b7543f8..b36597b 100644 --- a/src/plugins/xdxf/XdxfSettingsDialog.h +++ b/src/plugins/xdxf/XdxfSettingsDialog.h @@ -35,13 +35,13 @@ class XdxfSettingsDialog : public QDialog Q_OBJECT public: explicit XdxfSettingsDialog(XdxfPlugin* plugin, QWidget *parent = 0); - + //! \returns settings of a given plugin static Settings* getSettings(XdxfPlugin* plugin, QWidget *parent); - //! Returns dictionary file path chosen by user + //! \returns dictionary file path chosen by user QString dicitonaryFilePath(); - //! Returns if user wants to cache dictionary + //! \returns if user wants to cache dictionary bool generateCache(); private Q_SLOTS: diff --git a/src/plugins/xdxf/xdxfplugin.cpp b/src/plugins/xdxf/xdxfplugin.cpp index 626e300..330afa8 100644 --- a/src/plugins/xdxf/xdxfplugin.cpp +++ b/src/plugins/xdxf/xdxfplugin.cpp @@ -87,7 +87,7 @@ QString XdxfPlugin::type() const { QString XdxfPlugin::infoNote() const { - return _infoNote; + return _infoNote; } @@ -146,7 +146,7 @@ QList XdxfPlugin::searchWordListCache(QString word, int limit) { if(ok) { /*add key word to list*/ translations.insert(new TranslationXdxf( cur.value(0).toString().toLower(), - _infoNote, this)); + _dictionaryInfo, this)); i++; } } @@ -197,7 +197,7 @@ QList XdxfPlugin::searchWordListFile(QString word, int limit) { } if(ok) { /*add key word to list*/ translations<<(new TranslationXdxf(readKey.toLower(), - _infoNote,this)); + _dictionaryInfo,this)); i++; } if(i>=limit && limit!=0) @@ -338,24 +338,7 @@ bool XdxfPlugin::isAvailable() const { } -void XdxfPlugin::setHash(uint _hash) { - this->_hash=_hash; -} - - -uint XdxfPlugin::hash() const { - return _hash; -} - - Settings* XdxfPlugin::settings() { -/* - Settings *returnSettings=new Settings; - QStringList list = _settings->keys(); - foreach(QString key, list) - returnSettings->setValue(key,_settings->value(key)); - return returnSettings; -*/ return _settings; } @@ -453,10 +436,9 @@ bool XdxfPlugin::getDictionaryInfo() { if(reader.name()=="description") _infoNote=reader.readElementText(); - QString initialPath = "/usr/share/mdictionary/xdxf.png"; - - _infoNote=" path=\""+initialPath+"\"> \n" + _name + " [" + _langFrom + "-" + _dictionaryInfo= _name + " [" + _langFrom + "-" + _langTo + "]"; + dictionaryFile.close(); if(okFormat) return true; diff --git a/src/plugins/xdxf/xdxfplugin.h b/src/plugins/xdxf/xdxfplugin.h index fcaf34a..76ac714 100644 --- a/src/plugins/xdxf/xdxfplugin.h +++ b/src/plugins/xdxf/xdxfplugin.h @@ -83,12 +83,6 @@ public: //! returns a description of a word given by a QString QString search(QString key); - //! returns a unique hash for a dictionary - uint hash() const; - - //! sets unique value (unique for every dictionary, not plugin) - void setHash(uint); - //! returns current plugin settings Settings* settings(); @@ -121,6 +115,7 @@ public Q_SLOTS: //! stop current operation void stop(); + //! loads translations for each plugin only once void retranslate(); @@ -133,27 +128,43 @@ Q_SIGNALS: private: -/*! returns true or false depending on whether the dictionary is cached - or not, not implemented yet - */ - bool isCached(); - -//! sets the path to dictionary file and adds it to settings - // void setPath(QString); + /*! returns true or false depending on whether the dictionary is cached + or not, not implemented yet + */ + bool isCached(); + /*! searches for a list of words similar to a word in a database file + \param word key compared with keys in a database + \param limit limits the number of translations in returned list, + 0 means unlimited + \returns list of translations + */ QList searchWordListCache(QString word, int limit=0); + /*! searches for a list of words similar to a word in a xdxf file + \param word key compared with keys in a xdxf file + \param limit limits the number of translations in returned list, + 0 means unlimited + \returns list of translations + */ QList searchWordListFile(QString word, int limit=0); + /*! searches for a translation of a word which is exactly like a key + in xdxf file */ QString searchFile(QString key); + /*! searches for a translation of a word which is exactly like a key + in database file */ QString searchCache(QString key); //! scans dictionary file to get information about it bool getDictionaryInfo(); + //! counts the keys in xdxf file int countWords(); + /*! transforms xdxf files to database files (caching operation) + \returns true on success, false on failure */ bool makeCache(QString dir); //! language from which we translate @@ -164,14 +175,18 @@ private: QString _name; //! information about dictionary QString _infoNote; - //! path to dictionary file - // QString path; + + QString _dictionaryInfo; + + //! unique number of a dictionary assigned to it by backbone uint _hash; + //! icon displayed during translations and when the dictionary is chosen QIcon _icon; QSqlDatabase db; QString db_name; //! number of words in dictionary long _wordsCount; + //! indicates if search is stopped volatile bool stopped; Settings *_settings; XdxfDictDialog* _dictDialog; diff --git a/tests/GooglePluginTests/test.cpp b/tests/GooglePluginTests/test.cpp index c803afd..cca9ba3 100644 --- a/tests/GooglePluginTests/test.cpp +++ b/tests/GooglePluginTests/test.cpp @@ -45,4 +45,32 @@ void GoogleTest::getDictionaryInfo() { QCOMPARE(plugin.infoNote(),QString(" [Polish-English] " )); } +void GoogleTest::langFrom() { + GooglePlugin plugin; + Settings *settings=new Settings; + settings->setValue("lang_to","pl"); + settings->setValue("lang_from","en"); + plugin.setSettings(settings); + delete settings; + + QCOMPARE(plugin.langFrom(),QString("English")); + QCOMPARE(plugin.langTo(),QString("Polish")); + QCOMPARE(plugin.type(),QString("google")); +} + +void GoogleTest::getNew() { + GooglePlugin plugin; + Settings *settings=new Settings; + settings->setValue("lang_to","pl"); + settings->setValue("lang_from","en"); + CommonDictInterface *test=plugin.getNew(settings); + delete settings; + + QCOMPARE(test->langFrom(),QString("English")); + QCOMPARE(test->langTo(),QString("Polish")); + QCOMPARE(test->type(),QString("google")); + + delete test; +} + QTEST_MAIN(GoogleTest) diff --git a/tests/GooglePluginTests/test.h b/tests/GooglePluginTests/test.h index b3fe336..20a518e 100644 --- a/tests/GooglePluginTests/test.h +++ b/tests/GooglePluginTests/test.h @@ -34,6 +34,8 @@ private slots: void jsonParse(); void getDictionaryInfo(); + void langFrom(); + void getNew(); }; diff --git a/tests/XdxfPluginTests/test.cpp b/tests/XdxfPluginTests/test.cpp index 8cb0a2e..b6f4b70 100644 --- a/tests/XdxfPluginTests/test.cpp +++ b/tests/XdxfPluginTests/test.cpp @@ -134,6 +134,9 @@ void XdxfTest::searchWordListCache(){ QCOMPARE(te11.at(0)->key(), QString("house")); xdxfPlugin->clean(); + QList te12 = xdxfPlugin->searchWordList("1",10); + QCOMPARE(te2.size(), 5); + delete xdxfPlugin; } @@ -211,11 +214,46 @@ void XdxfTest::langFrom() { delete settings; QCOMPARE(xdxfPlugin->langFrom(), QString("ENG")); + QCOMPARE(xdxfPlugin->langTo(), QString("POL")); + QCOMPARE(xdxfPlugin->name(), QString("English-Polish dictionary")); + QCOMPARE(xdxfPlugin->infoNote(), QString("Copyright: http://www.freelang.net/dictionary/; Version: 1.0")); + QCOMPARE(xdxfPlugin->type(), QString("xdxf")); xdxfPlugin->clean(); delete xdxfPlugin; } +void XdxfTest::isAvailable() { + XdxfPlugin xdxfPluginB(this); + Settings *settings=new Settings; + settings->setValue("path","../XdxfPluginTests/dict.xdxf"); + CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings); + delete settings; + + QCOMPARE(xdxfPlugin->isAvailable(), true); + + xdxfPlugin->clean(); + delete xdxfPlugin; +} + +void XdxfTest::removeAccents() { + qDebug()<<"\n"; + XdxfPluginSub xdxf; + xdxf.settings()->setValue(QString("strip_accents"), QString("true")); + + QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("nóżka")), QString("nozka")); + QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("motor")), QString("motor")); + QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("nÓżKa")), QString("nozka")); + QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("ławka")), QString("lawka")); + QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("éàèùâêîôûëïüÿäöüç")), QString("eaeuaeioueiuyaouc")); + QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("íőűúó")), QString("iouuo")); + QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("-ę")), QString("-e")); + QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("\"e\"")), QString("\"e\"")); + QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("'e'")), QString("'e'")); + QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("\\e")), QString("e")); + QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("\\")), QString("")); +} + void XdxfTest::timeCache() { qDebug()<<"\n"; QTime timer; @@ -225,7 +263,7 @@ void XdxfTest::timeCache() { qDebug()<<"Error: could not open file"; return; } - if(!QFile::exists("../../../../../../dict.xdxf")) { + if(!QFile::exists("../../../dict.xdxf")) { qDebug()<<"Error: could not open dict file"; return; } @@ -236,7 +274,7 @@ void XdxfTest::timeCache() { timer.start(); XdxfPlugin xdxfPluginB(this); Settings *settings=new Settings; - settings->setValue("path","../../../../../../dict.xdxf"); + settings->setValue("path","../../../dict.xdxf"); settings->setValue("generateCache", "true"); CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings); delete settings; @@ -274,13 +312,12 @@ void XdxfTest::timeCache() { void XdxfTest::timeFile() { qDebug()<<"\n"; QTime timer; - QDate date; QFile File("../XdxfPluginTests/time.xml"); if(!File.open(QFile::ReadWrite | QFile::Text)) { qDebug()<<"Error: could not open file"; return; } - if(!QFile::exists("../../../../../../dict.xdxf")) { + if(!QFile::exists("../../../dict.xdxf")) { qDebug()<<"Error: could not open dict file"; return; } @@ -290,9 +327,9 @@ void XdxfTest::timeFile() { XdxfPlugin xdxfPluginB(this); Settings *settings=new Settings; - if(!QFile::exists("../../../../../../dict.xdxf")) + if(!QFile::exists("../../../dict.xdxf")) return; - settings->setValue("path","../../../../../../dict.xdxf"); + settings->setValue("path","../../../dict.xdxf"); CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings); delete settings; @@ -324,13 +361,12 @@ void XdxfTest::timeFile() { void XdxfTest::timeCacheNormalize() { qDebug()<<"\n"; QTime timer; - QDate date; QFile File("../XdxfPluginTests/time.xml"); if(!File.open(QFile::ReadWrite | QFile::Text)) { qDebug()<<"Error: could not open file"; return; } - if(!QFile::exists("../../../../../../dict.xdxf")) { + if(!QFile::exists("../../../dict.xdxf")) { qDebug()<<"Error: could not open dict file"; return; } @@ -342,7 +378,7 @@ void XdxfTest::timeCacheNormalize() { XdxfPlugin xdxfPluginB(this); Settings *settings=new Settings; - settings->setValue("path","../../../../../../dict.xdxf"); + settings->setValue("path","../../../dict.xdxf"); settings->setValue("generateCache", "true"); settings->setValue("strip_accents", "true"); CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings); @@ -376,34 +412,15 @@ void XdxfTest::timeCacheNormalize() { delete xdxfPlugin; } -void XdxfTest::removeAccents() { - qDebug()<<"\n"; - XdxfPluginSub xdxf; - xdxf.settings()->setValue(QString("strip_accents"), QString("true")); - - QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("nóżka")), QString("nozka")); - QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("motor")), QString("motor")); - QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("nÓżKa")), QString("nozka")); - QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("ławka")), QString("lawka")); - QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("éàèùâêîôûëïüÿäöüç")), QString("eaeuaeioueiuyaouc")); - QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("íőűúó")), QString("iouuo")); - QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("-ę")), QString("-e")); - QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("\"e\"")), QString("\"e\"")); - QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("'e'")), QString("'e'")); - QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("\\e")), QString("e")); - QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("\\")), QString("")); -} - void XdxfTest::timeFileNormalize(){ qDebug()<<"\n"; QTime timer; - QDate date; QFile File("../XdxfPluginTests/time.xml"); if(!File.open(QFile::ReadWrite | QFile::Text)) { qDebug()<<"Error: could not open file"; return; } - if(!QFile::exists("../../../../../../dict.xdxf")) { + if(!QFile::exists("../../../dict.xdxf")) { qDebug()<<"Error: could not open dict file"; return; } @@ -413,7 +430,7 @@ void XdxfTest::timeFileNormalize(){ XdxfPlugin xdxfPluginB(this); Settings *settings=new Settings; - settings->setValue("path","../../../../../../dict.xdxf"); + settings->setValue("path","../../../dict.xdxf"); settings->setValue("strip_accents", "true"); CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings); delete settings; diff --git a/tests/XdxfPluginTests/test.h b/tests/XdxfPluginTests/test.h index e75db70..d1b37a3 100644 --- a/tests/XdxfPluginTests/test.h +++ b/tests/XdxfPluginTests/test.h @@ -47,6 +47,7 @@ void searchCache(); void searchWordListCache(); void removeAccents(); + void isAvailable(); void timeCache(); void timeFile(); void timeCacheNormalize(); diff --git a/tests/mDictionaryTests/CommonDictInterfaceMock.h b/tests/mDictionaryTests/CommonDictInterfaceMock.h index 7d67498..268ad3b 100644 --- a/tests/mDictionaryTests/CommonDictInterfaceMock.h +++ b/tests/mDictionaryTests/CommonDictInterfaceMock.h @@ -54,8 +54,6 @@ public: QDialog* settingsDialog() {return 0;} CommonDictInterface* getNew(const Settings *) const { return 0;} bool isAvailable() const {return available;} - uint hash() const { return _hash;} - void setHash(uint h) {_hash = h;} void stop() {stopped = 1;} QIcon* icon(){return 0;} QString search(QString key) {return "";} -- 1.7.9.5