From 78af7d0baf4996eeece589cb262ece3d82798fd8 Mon Sep 17 00:00:00 2001 From: Jakub Jaszczynski Date: Thu, 26 Aug 2010 13:11:45 +0200 Subject: [PATCH] add to test - search with strip_accents --- trunk/src/plugins/google/src/GooglePlugin.cpp | 9 ++- trunk/src/plugins/xdxf/src/xdxfplugin.cpp | 9 +-- trunk/src/plugins/xdxf/tests/test.cpp | 99 +++++++++++++++++++++++-- trunk/src/plugins/xdxf/tests/test.h | 2 + 4 files changed, 101 insertions(+), 18 deletions(-) diff --git a/trunk/src/plugins/google/src/GooglePlugin.cpp b/trunk/src/plugins/google/src/GooglePlugin.cpp index 8faa307..41663a5 100644 --- a/trunk/src/plugins/google/src/GooglePlugin.cpp +++ b/trunk/src/plugins/google/src/GooglePlugin.cpp @@ -99,7 +99,7 @@ bool GooglePlugin::isConnectionAccept() { return _connectionAccept; } -QString GooglePlugin::search(QString key) { +QString GooglePlugin::search(QString) { /*function is not used on this plagin */ return QString(""); } @@ -152,7 +152,7 @@ Translation* GooglePlugin::getTranslationFor(QString key) { return (new TranslationGoogle(key,"",_infoNote,this)); } -QList GooglePlugin::searchWordList(QString word, int limit) { +QList GooglePlugin::searchWordList(QString word, int ) { QList translations; if(isAvailable()) { word.replace("*",""); @@ -169,11 +169,14 @@ QList GooglePlugin::searchWordList(QString word, int limit) { QByteArray data("text="); data.append(word.toUtf8()); http->setHost("www.google.pl"); + wait=true; + stopped=false; http->request(head, data); QString error(""); - while(wait && (error=="" || error=="Unknown error")) + while(wait && (error=="" || error=="Unknown error") && !stopped) error=http->errorString(); + if(error!="" && error!="Unknown error") { qDebug()<value("type"); return _type; } @@ -393,7 +387,6 @@ void XdxfPlugin::getDictionaryInfo() { QString initialPath = QDir::currentPath() + tr("/xdxf.") + format; _infoNote="path=\""+initialPath+"\"> \n" + _name + " [" + _langFrom + "-" + _langTo + "] (" + _type + ")"; - dictionaryFile.close(); } diff --git a/trunk/src/plugins/xdxf/tests/test.cpp b/trunk/src/plugins/xdxf/tests/test.cpp index 58aeb02..dffbbe9 100644 --- a/trunk/src/plugins/xdxf/tests/test.cpp +++ b/trunk/src/plugins/xdxf/tests/test.cpp @@ -80,7 +80,7 @@ void XdxfTest::searchWordListCache(){ QList te = xdxfPlugin->searchWordList(".", 10); if(te.size()>0) - QCOMPARE(te.size(), 9); + QCOMPARE(te.size(), 1); QList te2 = xdxfPlugin->searchWordList("1",10); QCOMPARE(te2.size(), 5); @@ -123,7 +123,7 @@ void XdxfTest::searchWordListFile() { QList te = xdxfPlugin->searchWordList(".", 10); if(te.size()>0) - QCOMPARE(te.size(), 9); + QCOMPARE(te.size(), 1); QList te2 = xdxfPlugin->searchWordList("1",10); QCOMPARE(te2.size(), 5); @@ -186,8 +186,7 @@ void XdxfTest::langFrom() { delete xdxfPlugin; } -void XdxfTest::timeCache() -{ +void XdxfTest::timeCache() { QTime timer; QDate date; QFile File("../tests/time.xml"); @@ -234,8 +233,7 @@ void XdxfTest::timeCache() File.close(); } -void XdxfTest::timeFile() -{ +void XdxfTest::timeFile() { QTime timer; QDate date; QFile File("../tests/time.xml"); @@ -270,11 +268,98 @@ void XdxfTest::timeFile() timer.start(); xdxfPlugin->searchWordList("level"); out<<"\n SearchWordListFile \n"; + out<< ""; + + File.close(); +} + +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 Cache with strip accent "; + + timer.start(); + xdxfPlugin->search("Bantu"); + out<<"\n SearchCache-begin with strip accent "; + + timer.start(); + xdxfPlugin->search("level"); + out<<"\n SearchCache-midle with strip accent "; + + timer.start(); + xdxfPlugin->search("zoril"); + out<<"\n SearchCache-end with strip accent "; + + timer.start(); + xdxfPlugin->searchWordList("level"); + out<<"\n SearchWorlListCache with strip accent "; File.close(); } +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 SearchFile-begin with strip accent "; + + timer.start(); + xdxfPlugin->search("level"); + out<<"\n SearchFile-midle with strip accent "; + + timer.start(); + xdxfPlugin->search("zoril"); + out<<"\n SearchFile-end with strip accent "; + + timer.start(); + xdxfPlugin->searchWordList("level"); + out<<"\n SearchWordListFile with strip accent \n"; + + File.close(); + +} QTEST_MAIN(XdxfTest) //#include "testqstring.moc" diff --git a/trunk/src/plugins/xdxf/tests/test.h b/trunk/src/plugins/xdxf/tests/test.h index 70f540c..f4fed84 100644 --- a/trunk/src/plugins/xdxf/tests/test.h +++ b/trunk/src/plugins/xdxf/tests/test.h @@ -49,6 +49,8 @@ void searchWordListCache(); void timeCache(); void timeFile(); + void timeCacheNormalize(); + void timeFileNormalize(); }; -- 1.7.9.5