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"));
164 QList<Translation*> te5 = xdxfPlugin->searchWordList("*");
165 QCOMPARE(te5.size(), 9);
167 QList<Translation*> te6 = xdxfPlugin->searchWordList("*", 8);
168 QCOMPARE(te6.size(), 8);
170 QList<Translation*> te7 = xdxfPlugin->searchWordList("*ou*");
171 QCOMPARE(te7.at(0)->key(), QString("house"));
173 QList<Translation*> te8 = xdxfPlugin->searchWordList("1?");
174 QCOMPARE(te8.at(0)->key(), QString("10"));
176 QList<Translation*> te9 = xdxfPlugin->searchWordList("1???");
177 QCOMPARE(te9.at(0)->key(), QString("1000"));
179 QList<Translation*> te10 = xdxfPlugin->searchWordList("1????*");
180 QCOMPARE(te10.at(0)->key(), QString("1 000 000"));
182 QList<Translation*> te11 = xdxfPlugin->searchWordList("h**?*?**e");
183 QCOMPARE(te11.at(0)->key(), QString("house"));
189 void XdxfTest::stop() {
191 XdxfPlugin xdxfPluginB(this);
192 Settings *settings=new Settings;
193 settings->setValue("path","../XdxfPluginTests/dict.xdxf");
194 CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
198 QFuture<QList<Translation*> > future = QtConcurrent::run(xdxfPlugin,
199 &CommonDictInterface::searchWordList, string, 10);
200 QList<Translation*> te5 = future.result();
201 QCOMPARE(te5.size(), 9);
208 void XdxfTest::langFrom() {
210 XdxfPlugin xdxfPluginB(this);
211 Settings *settings=new Settings;
212 settings->setValue("path","../XdxfPluginTests/dict.xdxf");
213 CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
216 QCOMPARE(xdxfPlugin->langFrom(), QString("ENG"));
217 QCOMPARE(xdxfPlugin->langTo(), QString("POL"));
218 QCOMPARE(xdxfPlugin->name(), QString("English-Polish dictionary"));
219 QCOMPARE(xdxfPlugin->infoNote(), QString("Copyright: http://www.freelang.net/dictionary/; Version: 1.0"));
220 QCOMPARE(xdxfPlugin->type(), QString("xdxf"));
226 void XdxfTest::isAvailable() {
227 XdxfPlugin xdxfPluginB(this);
228 Settings *settings=new Settings;
229 settings->setValue("path","../XdxfPluginTests/dict.xdxf");
230 CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
233 QCOMPARE(xdxfPlugin->isAvailable(), true);
239 void XdxfTest::removeAccents() {
242 xdxf.settings()->setValue(QString("strip_accents"), QString("true"));
244 QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("nóżka")), QString("nozka"));
245 QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("motor")), QString("motor"));
246 QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("nÓżKa")), QString("nozka"));
247 QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("ławka")), QString("lawka"));
248 QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("éàèùâêîôûëïüÿäöüç")), QString("eaeuaeioueiuyaouc"));
249 QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("íőűúó")), QString("iouuo"));
250 QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("-ę")), QString("-e"));
251 QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("\"e\"")), QString("\"e\""));
252 QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("'e'")), QString("'e'"));
253 QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("\\e")), QString("e"));
254 QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("\\")), QString(""));
257 void XdxfTest::timeCache() {
261 QFile File("../XdxfPluginTests/time.xml");
262 if(!File.open(QFile::ReadWrite | QFile::Text)) {
263 qDebug()<<"Error: could not open file";
266 if(!QFile::exists("../../../dict.xdxf")) {
267 qDebug()<<"Error: could not open dict file";
270 QTextStream out(&File);
272 out.seek(out.pos()+1);
275 XdxfPlugin xdxfPluginB(this);
276 Settings *settings=new Settings;
277 settings->setValue("path","../../../dict.xdxf");
278 settings->setValue("generateCache", "true");
279 CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
282 out<<"\n<date>" + date.currentDate().toString("dd.MM.yyyy") +" ";
283 out<<timer.currentTime().toString(Qt::TextDate) + "</date>";
284 out<<"\n<type> Cache </type> <time>" << timer.elapsed();
288 xdxfPlugin->search("Bantu");
289 out<<"\n<type> SearchCache-begin </type> <time>" << timer.elapsed();
293 xdxfPlugin->search("level");
294 out<<"\n<type> SearchCache-midle </type> <time>" << timer.elapsed();
298 xdxfPlugin->search("zoril");
299 out<<"\n<type> SearchCache-end </type> <time>" << timer.elapsed();
303 xdxfPlugin->searchWordList("level");
304 out<<"\n<type> SearchWorlListCache </type> <time>" << timer.elapsed();
312 void XdxfTest::timeFile() {
315 QFile File("../XdxfPluginTests/time.xml");
316 if(!File.open(QFile::ReadWrite | QFile::Text)) {
317 qDebug()<<"Error: could not open file";
320 if(!QFile::exists("../../../dict.xdxf")) {
321 qDebug()<<"Error: could not open dict file";
324 QTextStream out(&File);
326 out.seek(out.pos()+1);
328 XdxfPlugin xdxfPluginB(this);
329 Settings *settings=new Settings;
330 if(!QFile::exists("../../../dict.xdxf"))
332 settings->setValue("path","../../../dict.xdxf");
333 CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
337 xdxfPlugin->search("Bantu");
338 out<<"\n<type> SearchFile-begin </type> <time>" << timer.elapsed();
342 xdxfPlugin->search("level");
343 out<<"\n<type> SearchFile-midle </type> <time>" << timer.elapsed();
347 xdxfPlugin->search("zoril");
348 out<<"\n<type> SearchFile-end </type> <time>" << timer.elapsed();
352 xdxfPlugin->searchWordList("level");
353 out<<"\n<type> SearchWordListFile </type> <time>" << timer.elapsed();
361 void XdxfTest::timeCacheNormalize() {
364 QFile File("../XdxfPluginTests/time.xml");
365 if(!File.open(QFile::ReadWrite | QFile::Text)) {
366 qDebug()<<"Error: could not open file";
369 if(!QFile::exists("../../../dict.xdxf")) {
370 qDebug()<<"Error: could not open dict file";
373 QTextStream out(&File);
375 out.seek(out.pos()+1);
378 XdxfPlugin xdxfPluginB(this);
379 Settings *settings=new Settings;
381 settings->setValue("path","../../../dict.xdxf");
382 settings->setValue("generateCache", "true");
383 settings->setValue("strip_accents", "true");
384 CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
387 out<<"\n<type> Cache with strip accent </type> <time>" << timer.elapsed();
391 xdxfPlugin->search("Bantu");
392 out<<"\n<type> SearchCache-begin with strip accent </type> <time>" << timer.elapsed();
396 xdxfPlugin->search("level");
397 out<<"\n<type> SearchCache-midle with strip accent </type> <time>" << timer.elapsed();
401 xdxfPlugin->search("zoril");
402 out<<"\n<type> SearchCache-end with strip accent </type> <time>" << timer.elapsed();
406 xdxfPlugin->searchWordList("level");
407 out<<"\n<type> SearchWorlListCache with strip accent </type> <time>" << timer.elapsed();
415 void XdxfTest::timeFileNormalize(){
418 QFile File("../XdxfPluginTests/time.xml");
419 if(!File.open(QFile::ReadWrite | QFile::Text)) {
420 qDebug()<<"Error: could not open file";
423 if(!QFile::exists("../../../dict.xdxf")) {
424 qDebug()<<"Error: could not open dict file";
427 QTextStream out(&File);
429 out.seek(out.pos()+1);
431 XdxfPlugin xdxfPluginB(this);
432 Settings *settings=new Settings;
433 settings->setValue("path","../../../dict.xdxf");
434 settings->setValue("strip_accents", "true");
435 CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
439 xdxfPlugin->search("Bantu");
440 out<<"\n<type> SearchFile-begin with strip accent </type> <time>" << timer.elapsed();
444 xdxfPlugin->search("level");
445 out<<"\n<type> SearchFile-midle with strip accent </type> <time>" << timer.elapsed();
449 xdxfPlugin->search("zoril");
450 out<<"\n<type> SearchFile-end with strip accent </type> <time>" << timer.elapsed();
454 xdxfPlugin->searchWordList("level");
455 out<<"\n<type> SearchWordListFile with strip accent </type> <time>" << timer.elapsed();
464 //#include "testqstring.moc"