1 /*******************************************************************************
3 This file is part of mDictionary.
5 mDictionary is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 mDictionary is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with mDictionary. If not, see <http://www.gnu.org/licenses/>.
18 Copyright 2010 Comarch S.A.
20 *******************************************************************************/
25 void XdxfTest::getNew() {
27 XdxfPlugin xdxfPluginB(this);
28 Settings *settings=new Settings;
29 settings->setValue("path","../XdxfPluginTests/dict.xdxf");
30 CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
33 QList<Translation*> te6=xdxfPlugin->searchWordList("*",8);
34 QCOMPARE(te6.size(),8);
41 void XdxfTest::searchFile() {
43 XdxfPlugin xdxfPluginB(this);
44 Settings *settings=new Settings;
45 settings->setValue("path","../XdxfPluginTests/dict.xdxf");
46 CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
49 QCOMPARE(xdxfPlugin->search("."), QString("<key>.</key><t>kropka</t>"));
50 QCOMPARE(xdxfPlugin->search("1"), QString("<key>1</key><t>one</t>"));
51 QCOMPARE(xdxfPlugin->search("test"), QString("<key>test</key><t><c c=\"FF00FF\">kro</c>test01<pos>krowa</pos></t>"));
58 void XdxfTest::makeCache()
61 XdxfPlugin xdxfPluginB(this);
62 Settings *settings=new Settings;
63 settings->setValue("path","../XdxfPluginTests/dict.xdxf");
64 settings->setValue("generateCache", "true");
65 CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
67 QCOMPARE(xdxfPlugin->settings()->value("cached"),tr("true"));
75 void XdxfTest::searchCache() {
77 XdxfPlugin xdxfPluginB(this);
78 Settings *settings=new Settings;
79 settings->setValue("path","../XdxfPluginTests/dict.xdxf");
80 settings->setValue("generateCache", "true");
81 CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
84 QCOMPARE(xdxfPlugin->settings()->value("cached"),tr("true"));
85 QCOMPARE(xdxfPlugin->search("."), QString("<key>.</key><t>kropka</t>"));
86 QCOMPARE(xdxfPlugin->search("1"), QString("<key>1</key><t>one</t>"));
87 QCOMPARE(xdxfPlugin->search("test"), QString("<key>test</key><t><c c=\"FF00FF\">kro</c>test01<pos>krowa</pos></t>"));
94 void XdxfTest::searchWordListCache(){
96 XdxfPlugin xdxfPluginB(this);
97 Settings *settings=new Settings;
98 settings->setValue("path","../XdxfPluginTests/dict.xdxf");
99 settings->setValue("generateCache", "true");
100 CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
103 QList<Translation*> te = xdxfPlugin->searchWordList(".", 10);
105 QCOMPARE(te.size(), 1);
106 QList<Translation*> te2 = xdxfPlugin->searchWordList("1",10);
107 QCOMPARE(te2.size(), 5);
109 QList<Translation*> te3 = xdxfPlugin->searchWordList("1", 2);
110 QCOMPARE(te3.size(), 2);
112 QList<Translation*> te4 = xdxfPlugin->searchWordList("ho*SE", 10);
113 QCOMPARE(te4.at(0)->key(), QString("house"));
115 QList<Translation*> te5 = xdxfPlugin->searchWordList("*");
116 QCOMPARE(te5.size(), 9);
118 QList<Translation*> te6 = xdxfPlugin->searchWordList("*", 8);
119 QCOMPARE(te6.size(), 8);
121 QList<Translation*> te7 = xdxfPlugin->searchWordList("*ou*");
122 QCOMPARE(te7.at(0)->key(), QString("house"));
124 QList<Translation*> te8 = xdxfPlugin->searchWordList("1?");
125 QCOMPARE(te8.at(0)->key(), QString("10"));
127 QList<Translation*> te9 = xdxfPlugin->searchWordList("1???");
128 QCOMPARE(te9.at(0)->key(), QString("1000"));
130 QList<Translation*> te10 = xdxfPlugin->searchWordList("1????*");
131 QCOMPARE(te10.at(0)->key(), QString("1 000 000"));
133 QList<Translation*> te11 = xdxfPlugin->searchWordList("h**?*?**e");
134 QCOMPARE(te11.at(0)->key(), QString("house"));
137 QList<Translation*> te12 = xdxfPlugin->searchWordList("1",10);
138 QCOMPARE(te2.size(), 5);
144 void XdxfTest::searchWordListFile() {
146 XdxfPlugin xdxfPluginB(this);
147 Settings *settings=new Settings;
148 settings->setValue("path","../XdxfPluginTests/dict.xdxf");
149 CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
152 QList<Translation*> te = xdxfPlugin->searchWordList(".", 10);
154 QCOMPARE(te.size(), 1);
155 QList<Translation*> te2 = xdxfPlugin->searchWordList("1",10);
156 QCOMPARE(te2.size(), 5);
158 QList<Translation*> te3 = xdxfPlugin->searchWordList("1", 2);
159 QCOMPARE(te3.size(), 2);
161 QList<Translation*> te4 = xdxfPlugin->searchWordList("ho*SE", 10);
162 QCOMPARE(te4.at(0)->key(), QString("house"));
165 QList<Translation*> te5 = xdxfPlugin->searchWordList("*");
167 QCOMPARE(te5.size(), 9);
170 QList<Translation*> te6 = xdxfPlugin->searchWordList("*", 8);
171 QCOMPARE(te6.size(), 8);
173 QList<Translation*> te7 = xdxfPlugin->searchWordList("*ou*");
174 QCOMPARE(te7.at(0)->key(), QString("house"));
176 QList<Translation*> te8 = xdxfPlugin->searchWordList("1?");
177 QCOMPARE(te8.at(0)->key(), QString("10"));
179 QList<Translation*> te9 = xdxfPlugin->searchWordList("1???");
180 QCOMPARE(te9.at(0)->key(), QString("1000"));
182 QList<Translation*> te10 = xdxfPlugin->searchWordList("1????*");
183 QCOMPARE(te10.at(0)->key(), QString("1 000 000"));
185 QList<Translation*> te11 = xdxfPlugin->searchWordList("h**?*?**e");
186 QCOMPARE(te11.at(0)->key(), QString("house"));
192 void XdxfTest::stop() {
194 XdxfPlugin xdxfPluginB(this);
195 Settings *settings=new Settings;
196 settings->setValue("path","../XdxfPluginTests/dict.xdxf");
197 CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
201 QFuture<QList<Translation*> > future = QtConcurrent::run(xdxfPlugin,
202 &CommonDictInterface::searchWordList, string, 10);
203 QList<Translation*> te5 = future.result();
204 QCOMPARE(te5.size(), 9);
211 void XdxfTest::langFrom() {
213 XdxfPlugin xdxfPluginB(this);
214 Settings *settings=new Settings;
215 settings->setValue("path","../XdxfPluginTests/dict.xdxf");
216 CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
219 QCOMPARE(xdxfPlugin->langFrom(), QString("ENG"));
220 QCOMPARE(xdxfPlugin->langTo(), QString("POL"));
221 QCOMPARE(xdxfPlugin->name(), QString("English-Polish dictionary"));
222 QCOMPARE(xdxfPlugin->infoNote(), QString("Copyright: http://www.freelang.net/dictionary/; Version: 1.0"));
223 QCOMPARE(xdxfPlugin->type(), QString("xdxf"));
229 void XdxfTest::isAvailable() {
230 XdxfPlugin xdxfPluginB(this);
231 Settings *settings=new Settings;
232 settings->setValue("path","../XdxfPluginTests/dict.xdxf");
233 CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
236 QCOMPARE(xdxfPlugin->isAvailable(), true);
242 void XdxfTest::removeAccents() {
245 xdxf.settings()->setValue(QString("strip_accents"), QString("true"));
247 QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("nóżka")), QString("nozka"));
248 QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("motor")), QString("motor"));
249 QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("nÓżKa")), QString("nozka"));
250 QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("ławka")), QString("lawka"));
251 QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("éàèùâêîôûëïüÿäöüç")), QString("eaeuaeioueiuyaouc"));
252 QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("íőűúó")), QString("iouuo"));
253 QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("-ę")), QString("-e"));
254 QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("\"e\"")), QString("\"e\""));
255 QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("'e'")), QString("'e'"));
256 QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("\\e")), QString("e"));
257 QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("\\")), QString(""));
260 void XdxfTest::timeCache() {
264 QFile File("../XdxfPluginTests/time.xml");
265 if(!File.open(QFile::ReadWrite | QFile::Text)) {
266 qDebug()<<"Error: could not open file";
269 if(!QFile::exists("../../../dict.xdxf")) {
270 qDebug()<<"Error: could not open dict file";
273 QTextStream out(&File);
275 out.seek(out.pos()+1);
278 XdxfPlugin xdxfPluginB(this);
279 Settings *settings=new Settings;
280 settings->setValue("path","../../../dict.xdxf");
281 settings->setValue("generateCache", "true");
282 CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
285 out<<"\n<date>" + date.currentDate().toString("dd.MM.yyyy") +" ";
286 out<<timer.currentTime().toString(Qt::TextDate) + "</date>";
287 out<<"\n<type> Cache </type> <time>" << timer.elapsed();
291 xdxfPlugin->search("Bantu");
292 out<<"\n<type> SearchCache-begin </type> <time>" << timer.elapsed();
296 xdxfPlugin->search("level");
297 out<<"\n<type> SearchCache-midle </type> <time>" << timer.elapsed();
301 xdxfPlugin->search("zoril");
302 out<<"\n<type> SearchCache-end </type> <time>" << timer.elapsed();
306 xdxfPlugin->searchWordList("level");
307 out<<"\n<type> SearchWorlListCache </type> <time>" << timer.elapsed();
315 void XdxfTest::timeFile() {
318 QFile File("../XdxfPluginTests/time.xml");
319 if(!File.open(QFile::ReadWrite | QFile::Text)) {
320 qDebug()<<"Error: could not open file";
323 if(!QFile::exists("../../../dict.xdxf")) {
324 qDebug()<<"Error: could not open dict file";
327 QTextStream out(&File);
329 out.seek(out.pos()+1);
331 XdxfPlugin xdxfPluginB(this);
332 Settings *settings=new Settings;
333 if(!QFile::exists("../../../dict.xdxf"))
335 settings->setValue("path","../../../dict.xdxf");
336 CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
340 xdxfPlugin->search("Bantu");
341 out<<"\n<type> SearchFile-begin </type> <time>" << timer.elapsed();
345 xdxfPlugin->search("level");
346 out<<"\n<type> SearchFile-midle </type> <time>" << timer.elapsed();
350 xdxfPlugin->search("zoril");
351 out<<"\n<type> SearchFile-end </type> <time>" << timer.elapsed();
355 xdxfPlugin->searchWordList("level");
356 out<<"\n<type> SearchWordListFile </type> <time>" << timer.elapsed();
364 void XdxfTest::timeCacheNormalize() {
367 QFile File("../XdxfPluginTests/time.xml");
368 if(!File.open(QFile::ReadWrite | QFile::Text)) {
369 qDebug()<<"Error: could not open file";
372 if(!QFile::exists("../../../dict.xdxf")) {
373 qDebug()<<"Error: could not open dict file";
376 QTextStream out(&File);
378 out.seek(out.pos()+1);
381 XdxfPlugin xdxfPluginB(this);
382 Settings *settings=new Settings;
384 settings->setValue("path","../../../dict.xdxf");
385 settings->setValue("generateCache", "true");
386 settings->setValue("strip_accents", "true");
387 CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
390 out<<"\n<type> Cache with strip accent </type> <time>" << timer.elapsed();
394 xdxfPlugin->search("Bantu");
395 out<<"\n<type> SearchCache-begin with strip accent </type> <time>" << timer.elapsed();
399 xdxfPlugin->search("level");
400 out<<"\n<type> SearchCache-midle with strip accent </type> <time>" << timer.elapsed();
404 xdxfPlugin->search("zoril");
405 out<<"\n<type> SearchCache-end with strip accent </type> <time>" << timer.elapsed();
409 xdxfPlugin->searchWordList("level");
410 out<<"\n<type> SearchWorlListCache with strip accent </type> <time>" << timer.elapsed();
418 void XdxfTest::timeFileNormalize(){
421 QFile File("../XdxfPluginTests/time.xml");
422 if(!File.open(QFile::ReadWrite | QFile::Text)) {
423 qDebug()<<"Error: could not open file";
426 if(!QFile::exists("../../../dict.xdxf")) {
427 qDebug()<<"Error: could not open dict file";
430 QTextStream out(&File);
432 out.seek(out.pos()+1);
434 XdxfPlugin xdxfPluginB(this);
435 Settings *settings=new Settings;
436 settings->setValue("path","../../../dict.xdxf");
437 settings->setValue("strip_accents", "true");
438 CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
442 xdxfPlugin->search("Bantu");
443 out<<"\n<type> SearchFile-begin with strip accent </type> <time>" << timer.elapsed();
447 xdxfPlugin->search("level");
448 out<<"\n<type> SearchFile-midle with strip accent </type> <time>" << timer.elapsed();
452 xdxfPlugin->search("zoril");
453 out<<"\n<type> SearchFile-end with strip accent </type> <time>" << timer.elapsed();
457 xdxfPlugin->searchWordList("level");
458 out<<"\n<type> SearchWordListFile with strip accent </type> <time>" << timer.elapsed();
467 //#include "testqstring.moc"