--- /dev/null
+/*******************************************************************************
+
+ This file is part of mDictionary.
+
+ mDictionary is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ mDictionary is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with mDictionary. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
+#include "test.h"
+#include <QSignalSpy>
+
+void XdxfTest::getNew() {
+
+ XdxfPlugin xdxfPluginB(this);
+ Settings *settings=new Settings;
+ settings->setValue("path","../tests/dict.xdxf");
+ CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
+
+ QList<Translation*> te6=xdxfPlugin->searchWordList("*",8);
+ QCOMPARE(te6.size(),8);
+
+ xdxfPlugin->clean();
+ delete xdxfPlugin;
+}
+
+void XdxfTest::searchFile() {
+
+ XdxfPlugin xdxfPluginB(this);
+ Settings *settings=new Settings;
+ settings->setValue("path","../tests/dict.xdxf");
+ CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
+
+ 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()
+{
+ XdxfPlugin xdxfPluginB(this);
+ Settings *settings=new Settings;
+ settings->setValue("path","../tests/dict.xdxf");
+ settings->setValue("generateCache", "true");
+ CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
+ QCOMPARE(xdxfPlugin->settings()->value("cached"),tr("true"));
+
+ xdxfPlugin->clean();
+ delete xdxfPlugin;
+}
+
+void XdxfTest::searchCache() {
+ XdxfPlugin xdxfPluginB(this);
+ Settings *settings=new Settings;
+ settings->setValue("path","../tests/dict.xdxf");
+ settings->setValue("generateCache", "true");
+ CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
+
+ QCOMPARE(xdxfPlugin->settings()->value("cached"),tr("true"));
+ 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::searchWordListCache(){
+ XdxfPlugin xdxfPluginB(this);
+ Settings *settings=new Settings;
+ settings->setValue("path","../tests/dict.xdxf");
+ settings->setValue("generateCache", "true");
+ CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
+
+ QList<Translation*> te = xdxfPlugin->searchWordList(".", 10);
+ if(te.size()>0)
+ QCOMPARE(te.size(), 1);
+ QList<Translation*> te2 = xdxfPlugin->searchWordList("1",10);
+ QCOMPARE(te2.size(), 5);
+
+ QList<Translation*> te3 = xdxfPlugin->searchWordList("1", 2);
+ QCOMPARE(te3.size(), 2);
+
+ QList<Translation*> te4 = xdxfPlugin->searchWordList("ho*SE", 10);
+ QCOMPARE(te4.at(0)->key(), QString("house"));
+
+ QList<Translation*> te5 = xdxfPlugin->searchWordList("*");
+ QCOMPARE(te5.size(), 9);
+
+ QList<Translation*> te6 = xdxfPlugin->searchWordList("*", 8);
+ QCOMPARE(te6.size(), 8);
+
+ QList<Translation*> te7 = xdxfPlugin->searchWordList("*ou*");
+ QCOMPARE(te7.at(0)->key(), QString("house"));
+
+ QList<Translation*> te8 = xdxfPlugin->searchWordList("1?");
+ QCOMPARE(te8.at(0)->key(), QString("10"));
+
+ QList<Translation*> te9 = xdxfPlugin->searchWordList("1???");
+ QCOMPARE(te9.at(0)->key(), QString("1000"));
+
+ QList<Translation*> te10 = xdxfPlugin->searchWordList("1????*");
+ QCOMPARE(te10.at(0)->key(), QString("1 000 000"));
+
+ QList<Translation*> te11 = xdxfPlugin->searchWordList("h**?*?**e");
+ QCOMPARE(te11.at(0)->key(), QString("house"));
+
+ xdxfPlugin->clean();
+ delete xdxfPlugin;
+}
+
+void XdxfTest::searchWordListFile() {
+
+ XdxfPlugin xdxfPluginB(this);
+ Settings *settings=new Settings;
+ settings->setValue("path","../tests/dict.xdxf");
+ CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
+
+ QList<Translation*> te = xdxfPlugin->searchWordList(".", 10);
+ if(te.size()>0)
+ QCOMPARE(te.size(), 1);
+ QList<Translation*> te2 = xdxfPlugin->searchWordList("1",10);
+ QCOMPARE(te2.size(), 5);
+
+ QList<Translation*> te3 = xdxfPlugin->searchWordList("1", 2);
+ QCOMPARE(te3.size(), 2);
+
+ QList<Translation*> te4 = xdxfPlugin->searchWordList("ho*SE", 10);
+ QCOMPARE(te4.at(0)->key(), QString("house"));
+
+ QList<Translation*> te5 = xdxfPlugin->searchWordList("*");
+ QCOMPARE(te5.size(), 9);
+
+ QList<Translation*> te6 = xdxfPlugin->searchWordList("*", 8);
+ QCOMPARE(te6.size(), 8);
+
+ QList<Translation*> te7 = xdxfPlugin->searchWordList("*ou*");
+ QCOMPARE(te7.at(0)->key(), QString("house"));
+
+ QList<Translation*> te8 = xdxfPlugin->searchWordList("1?");
+ QCOMPARE(te8.at(0)->key(), QString("10"));
+
+ QList<Translation*> te9 = xdxfPlugin->searchWordList("1???");
+ QCOMPARE(te9.at(0)->key(), QString("1000"));
+
+ QList<Translation*> te10 = xdxfPlugin->searchWordList("1????*");
+ QCOMPARE(te10.at(0)->key(), QString("1 000 000"));
+
+ QList<Translation*> te11 = xdxfPlugin->searchWordList("h**?*?**e");
+ QCOMPARE(te11.at(0)->key(), QString("house"));
+
+ xdxfPlugin->clean();
+ delete xdxfPlugin;
+}
+
+void XdxfTest::stop() {
+
+ XdxfPlugin xdxfPluginB(this);
+ Settings *settings=new Settings;
+ settings->setValue("path","../tests/dict.xdxf");
+ CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
+
+ QString string("*");
+ QFuture<QList<Translation*> > future = QtConcurrent::run(xdxfPlugin,
+ &CommonDictInterface::searchWordList, string, 10);
+ QList<Translation*> te5 = future.result();
+ QCOMPARE(te5.size(), 9);
+
+ xdxfPlugin->clean();
+ delete xdxfPlugin;
+}
+
+
+void XdxfTest::langFrom() {
+
+ XdxfPlugin xdxfPluginB(this);
+ Settings *settings=new Settings;
+ settings->setValue("path","../tests/dict.xdxf");
+ CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
+
+ QCOMPARE(xdxfPlugin->langFrom(), QString("ENG"));
+
+ xdxfPlugin->clean();
+ delete xdxfPlugin;
+}
+
+void XdxfTest::timeCache() {
+ QTime timer;
+ QDate date;
+ QFile File("../tests/time.xml");
+ if(!File.open(QFile::ReadWrite | QFile::Text)) {
+ qDebug()<<"Error: could not open file";
+ return;
+ }
+ QTextStream out(&File);
+ while(!out.atEnd())
+ out.seek(out.pos()+1);
+
+ timer.start();
+ XdxfPlugin xdxfPluginB(this);
+ Settings *settings=new Settings;
+ settings->setValue("path","../../../../../../dict.xdxf");
+ settings->setValue("generateCache", "true");
+ CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
+
+ out<<"\n<date>" + date.currentDate().toString("dd.MM.yyyy") +" ";
+ out<<timer.currentTime().toString(Qt::TextDate) + "</date>";
+ out<<"\n<type> Cache </type> <time>" << timer.elapsed();
+ out<<"</time>";
+
+ timer.start();
+ xdxfPlugin->search("Bantu");
+ out<<"\n<type> SearchCache-begin </type> <time>" << timer.elapsed();
+ out<< "</time>";
+
+ timer.start();
+ xdxfPlugin->search("level");
+ out<<"\n<type> SearchCache-midle </type> <time>" << timer.elapsed();
+ out<< "</time>";
+
+ timer.start();
+ xdxfPlugin->search("zoril");
+ out<<"\n<type> SearchCache-end </type> <time>" << timer.elapsed();
+ out<< "</time>";
+
+ timer.start();
+ xdxfPlugin->searchWordList("level");
+ out<<"\n<type> SearchWorlListCache </type> <time>" << timer.elapsed();
+ out<< "</time>";
+
+ File.close();
+ xdxfPlugin->clean();
+ delete xdxfPlugin;
+}
+
+void XdxfTest::timeFile() {
+ QTime timer;
+ QDate date;
+ QFile File("../tests/time.xml");
+ if(!File.open(QFile::ReadWrite | QFile::Text)) {
+ qDebug()<<"Error: could not open file";
+ return;
+ }
+ QTextStream out(&File);
+ while(!out.atEnd())
+ out.seek(out.pos()+1);
+
+ XdxfPlugin xdxfPluginB(this);
+ Settings *settings=new Settings;
+ settings->setValue("path","../../../../../../dict.xdxf");
+ CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
+
+ timer.start();
+ xdxfPlugin->search("Bantu");
+ out<<"\n<type> SearchFile-begin </type> <time>" << timer.elapsed();
+ out << "</time>";
+
+ timer.start();
+ xdxfPlugin->search("level");
+ out<<"\n<type> SearchFile-midle </type> <time>" << timer.elapsed();
+ out << "</time>";
+
+ timer.start();
+ xdxfPlugin->search("zoril");
+ out<<"\n<type> SearchFile-end </type> <time>" << timer.elapsed();
+ out << "</time>";
+
+ timer.start();
+ xdxfPlugin->searchWordList("level");
+ out<<"\n<type> SearchWordListFile </type> <time>" << timer.elapsed();
+ out<< "</time>";
+
+ File.close();
+ xdxfPlugin->clean();
+ delete xdxfPlugin;
+}
+
+void XdxfTest::timeCacheNormalize() {
+ QTime timer;
+ QDate date;
+ QFile File("../tests/time.xml");
+ if(!File.open(QFile::ReadWrite | QFile::Text)) {
+ qDebug()<<"Error: could not open file";
+ return;
+ }
+ QTextStream out(&File);
+ while(!out.atEnd())
+ out.seek(out.pos()+1);
+
+ timer.start();
+ XdxfPlugin xdxfPluginB(this);
+ Settings *settings=new Settings;
+ settings->setValue("path","../../../../../../dict.xdxf");
+ settings->setValue("generateCache", "true");
+ settings->setValue("strip_accents", "true");
+ CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
+
+ out<<"\n<type> Cache with strip accent </type> <time>" << timer.elapsed();
+ out<<"</time>";
+
+ timer.start();
+ xdxfPlugin->search("Bantu");
+ out<<"\n<type> SearchCache-begin with strip accent </type> <time>" << timer.elapsed();
+ out<< "</time>";
+
+ timer.start();
+ xdxfPlugin->search("level");
+ out<<"\n<type> SearchCache-midle with strip accent </type> <time>" << timer.elapsed();
+ out<< "</time>";
+
+ timer.start();
+ xdxfPlugin->search("zoril");
+ out<<"\n<type> SearchCache-end with strip accent </type> <time>" << timer.elapsed();
+ out<< "</time>";
+
+ timer.start();
+ xdxfPlugin->searchWordList("level");
+ out<<"\n<type> SearchWorlListCache with strip accent </type> <time>" << timer.elapsed();
+ out<< "</time>";
+
+ File.close();
+ xdxfPlugin->clean();
+ delete xdxfPlugin;
+}
+
+void XdxfTest::removeAccents() {
+
+ 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(){
+ QTime timer;
+ QDate date;
+ QFile File("../tests/time.xml");
+ if(!File.open(QFile::ReadWrite | QFile::Text)) {
+ qDebug()<<"Error: could not open file";
+ return;
+ }
+ QTextStream out(&File);
+ while(!out.atEnd())
+ out.seek(out.pos()+1);
+
+ XdxfPlugin xdxfPluginB(this);
+ Settings *settings=new Settings;
+ settings->setValue("path","../../../../../../dict.xdxf");
+ settings->setValue("strip_accents", "true");
+ CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
+
+ timer.start();
+ xdxfPlugin->search("Bantu");
+ out<<"\n<type> SearchFile-begin with strip accent </type> <time>" << timer.elapsed();
+ out << "</time>";
+
+ timer.start();
+ xdxfPlugin->search("level");
+ out<<"\n<type> SearchFile-midle with strip accent </type> <time>" << timer.elapsed();
+ out << "</time>";
+
+ timer.start();
+ xdxfPlugin->search("zoril");
+ out<<"\n<type> SearchFile-end with strip accent </type> <time>" << timer.elapsed();
+ out << "</time>";
+
+ timer.start();
+ xdxfPlugin->searchWordList("level");
+ out<<"\n<type> SearchWordListFile with strip accent </type> <time>" << timer.elapsed();
+ out<< "</time>\n";
+
+ File.close();
+ xdxfPlugin->clean();
+ delete xdxfPlugin;
+
+}
+
+QTEST_MAIN(XdxfTest)
+//#include "testqstring.moc"