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","../tests/dict.xdxf");
30 CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
33 QList<Translation*> te6=xdxfPlugin->searchWordList("*",8);
34 QCOMPARE(te6.size(),8);
40 void XdxfTest::searchFile() {
42 XdxfPlugin xdxfPluginB(this);
43 Settings *settings=new Settings;
44 settings->setValue("path","../tests/dict.xdxf");
45 CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
48 QCOMPARE(xdxfPlugin->search("."), QString("<key>.</key><t>kropka</t>"));
49 QCOMPARE(xdxfPlugin->search("1"), QString("<key>1</key><t>one</t>"));
50 QCOMPARE(xdxfPlugin->search("test"), QString("<key>test</key><t><c c=\"FF00FF\">kro</c>test01<pos>krowa</pos></t>"));
56 void XdxfTest::makeCache()
58 XdxfPlugin xdxfPluginB(this);
59 Settings *settings=new Settings;
60 settings->setValue("path","../tests/dict.xdxf");
61 settings->setValue("generateCache", "true");
62 CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
65 QCOMPARE(xdxfPlugin->settings()->value("cached"),tr("true"));
71 void XdxfTest::searchCache() {
72 XdxfPlugin xdxfPluginB(this);
73 Settings *settings=new Settings;
74 settings->setValue("path","../tests/dict.xdxf");
75 settings->setValue("generateCache", "true");
76 CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
79 QCOMPARE(xdxfPlugin->settings()->value("cached"),tr("true"));
80 QCOMPARE(xdxfPlugin->search("."), QString("<key>.</key><t>kropka</t>"));
81 QCOMPARE(xdxfPlugin->search("1"), QString("<key>1</key><t>one</t>"));
82 QCOMPARE(xdxfPlugin->search("test"), QString("<key>test</key><t><c c=\"FF00FF\">kro</c>test01<pos>krowa</pos></t>"));
88 void XdxfTest::searchWordListCache(){
89 XdxfPlugin xdxfPluginB(this);
90 Settings *settings=new Settings;
91 settings->setValue("path","../tests/dict.xdxf");
92 settings->setValue("generateCache", "true");
93 CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
96 QList<Translation*> te = xdxfPlugin->searchWordList(".", 10);
98 QCOMPARE(te.size(), 1);
99 QList<Translation*> te2 = xdxfPlugin->searchWordList("1",10);
100 QCOMPARE(te2.size(), 5);
102 QList<Translation*> te3 = xdxfPlugin->searchWordList("1", 2);
103 QCOMPARE(te3.size(), 2);
105 QList<Translation*> te4 = xdxfPlugin->searchWordList("ho*SE", 10);
106 QCOMPARE(te4.at(0)->key(), QString("house"));
108 QList<Translation*> te5 = xdxfPlugin->searchWordList("*");
109 QCOMPARE(te5.size(), 9);
111 QList<Translation*> te6 = xdxfPlugin->searchWordList("*", 8);
112 QCOMPARE(te6.size(), 8);
114 QList<Translation*> te7 = xdxfPlugin->searchWordList("*ou*");
115 QCOMPARE(te7.at(0)->key(), QString("house"));
117 QList<Translation*> te8 = xdxfPlugin->searchWordList("1?");
118 QCOMPARE(te8.at(0)->key(), QString("10"));
120 QList<Translation*> te9 = xdxfPlugin->searchWordList("1???");
121 QCOMPARE(te9.at(0)->key(), QString("1000"));
123 QList<Translation*> te10 = xdxfPlugin->searchWordList("1????*");
124 QCOMPARE(te10.at(0)->key(), QString("1 000 000"));
126 QList<Translation*> te11 = xdxfPlugin->searchWordList("h**?*?**e");
127 QCOMPARE(te11.at(0)->key(), QString("house"));
133 void XdxfTest::searchWordListFile() {
135 XdxfPlugin xdxfPluginB(this);
136 Settings *settings=new Settings;
137 settings->setValue("path","../tests/dict.xdxf");
138 CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
141 QList<Translation*> te = xdxfPlugin->searchWordList(".", 10);
143 QCOMPARE(te.size(), 1);
144 QList<Translation*> te2 = xdxfPlugin->searchWordList("1",10);
145 QCOMPARE(te2.size(), 5);
147 QList<Translation*> te3 = xdxfPlugin->searchWordList("1", 2);
148 QCOMPARE(te3.size(), 2);
150 QList<Translation*> te4 = xdxfPlugin->searchWordList("ho*SE", 10);
151 QCOMPARE(te4.at(0)->key(), QString("house"));
153 QList<Translation*> te5 = xdxfPlugin->searchWordList("*");
154 QCOMPARE(te5.size(), 9);
156 QList<Translation*> te6 = xdxfPlugin->searchWordList("*", 8);
157 QCOMPARE(te6.size(), 8);
159 QList<Translation*> te7 = xdxfPlugin->searchWordList("*ou*");
160 QCOMPARE(te7.at(0)->key(), QString("house"));
162 QList<Translation*> te8 = xdxfPlugin->searchWordList("1?");
163 QCOMPARE(te8.at(0)->key(), QString("10"));
165 QList<Translation*> te9 = xdxfPlugin->searchWordList("1???");
166 QCOMPARE(te9.at(0)->key(), QString("1000"));
168 QList<Translation*> te10 = xdxfPlugin->searchWordList("1????*");
169 QCOMPARE(te10.at(0)->key(), QString("1 000 000"));
171 QList<Translation*> te11 = xdxfPlugin->searchWordList("h**?*?**e");
172 QCOMPARE(te11.at(0)->key(), QString("house"));
178 void XdxfTest::stop() {
180 XdxfPlugin xdxfPluginB(this);
181 Settings *settings=new Settings;
182 settings->setValue("path","../tests/dict.xdxf");
183 CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
187 QFuture<QList<Translation*> > future = QtConcurrent::run(xdxfPlugin,
188 &CommonDictInterface::searchWordList, string, 10);
189 QList<Translation*> te5 = future.result();
190 QCOMPARE(te5.size(), 9);
197 void XdxfTest::langFrom() {
198 XdxfPlugin xdxfPluginB(this);
199 Settings *settings=new Settings;
200 settings->setValue("path","../tests/dict.xdxf");
201 CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
204 QCOMPARE(xdxfPlugin->langFrom(), QString("ENG"));
210 void XdxfTest::timeCache() {
213 QFile File("../tests/time.xml");
214 if(!File.open(QFile::ReadWrite | QFile::Text)) {
215 qDebug()<<"Error: could not open file";
218 QTextStream out(&File);
220 out.seek(out.pos()+1);
223 XdxfPlugin xdxfPluginB(this);
224 Settings *settings=new Settings;
225 settings->setValue("path","../../../../../../dict.xdxf");
226 settings->setValue("generateCache", "true");
227 CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
230 out<<"\n<date>" + date.currentDate().toString("dd.MM.yyyy") +" ";
231 out<<timer.currentTime().toString(Qt::TextDate) + "</date>";
232 out<<"\n<type> Cache </type> <time>" << timer.elapsed();
236 xdxfPlugin->search("Bantu");
237 out<<"\n<type> SearchCache-begin </type> <time>" << timer.elapsed();
241 xdxfPlugin->search("level");
242 out<<"\n<type> SearchCache-midle </type> <time>" << timer.elapsed();
246 xdxfPlugin->search("zoril");
247 out<<"\n<type> SearchCache-end </type> <time>" << timer.elapsed();
251 xdxfPlugin->searchWordList("level");
252 out<<"\n<type> SearchWorlListCache </type> <time>" << timer.elapsed();
260 void XdxfTest::timeFile() {
263 QFile File("../tests/time.xml");
264 if(!File.open(QFile::ReadWrite | QFile::Text)) {
265 qDebug()<<"Error: could not open file";
268 QTextStream out(&File);
270 out.seek(out.pos()+1);
272 XdxfPlugin xdxfPluginB(this);
273 Settings *settings=new Settings;
274 settings->setValue("path","../../../../../../dict.xdxf");
275 CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
279 xdxfPlugin->search("Bantu");
280 out<<"\n<type> SearchFile-begin </type> <time>" << timer.elapsed();
284 xdxfPlugin->search("level");
285 out<<"\n<type> SearchFile-midle </type> <time>" << timer.elapsed();
289 xdxfPlugin->search("zoril");
290 out<<"\n<type> SearchFile-end </type> <time>" << timer.elapsed();
294 xdxfPlugin->searchWordList("level");
295 out<<"\n<type> SearchWordListFile </type> <time>" << timer.elapsed();
303 void XdxfTest::timeCacheNormalize() {
306 QFile File("../tests/time.xml");
307 if(!File.open(QFile::ReadWrite | QFile::Text)) {
308 qDebug()<<"Error: could not open file";
311 QTextStream out(&File);
313 out.seek(out.pos()+1);
316 XdxfPlugin xdxfPluginB(this);
317 Settings *settings=new Settings;
318 settings->setValue("path","../../../../../../dict.xdxf");
319 settings->setValue("generateCache", "true");
320 settings->setValue("strip_accents", "true");
321 CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
324 out<<"\n<type> Cache with strip accent </type> <time>" << timer.elapsed();
328 xdxfPlugin->search("Bantu");
329 out<<"\n<type> SearchCache-begin with strip accent </type> <time>" << timer.elapsed();
333 xdxfPlugin->search("level");
334 out<<"\n<type> SearchCache-midle with strip accent </type> <time>" << timer.elapsed();
338 xdxfPlugin->search("zoril");
339 out<<"\n<type> SearchCache-end with strip accent </type> <time>" << timer.elapsed();
343 xdxfPlugin->searchWordList("level");
344 out<<"\n<type> SearchWorlListCache with strip accent </type> <time>" << timer.elapsed();
352 void XdxfTest::removeAccents() {
355 xdxf.settings()->setValue(QString("strip_accents"), QString("true"));
357 QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("nóżka")), QString("nozka"));
358 QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("motor")), QString("motor"));
359 QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("nÓżKa")), QString("nozka"));
360 QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("ławka")), QString("lawka"));
361 QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("éàèùâêîôûëïüÿäöüç")), QString("eaeuaeioueiuyaouc"));
362 QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("íőűúó")), QString("iouuo"));
363 QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("-ę")), QString("-e"));
364 QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("\"e\"")), QString("\"e\""));
365 QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("'e'")), QString("'e'"));
366 QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("\\e")), QString("e"));
367 QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("\\")), QString(""));
370 void XdxfTest::timeFileNormalize(){
373 QFile File("../tests/time.xml");
374 if(!File.open(QFile::ReadWrite | QFile::Text)) {
375 qDebug()<<"Error: could not open file";
378 QTextStream out(&File);
380 out.seek(out.pos()+1);
382 XdxfPlugin xdxfPluginB(this);
383 Settings *settings=new Settings;
384 settings->setValue("path","../../../../../../dict.xdxf");
385 settings->setValue("strip_accents", "true");
386 CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
390 xdxfPlugin->search("Bantu");
391 out<<"\n<type> SearchFile-begin with strip accent </type> <time>" << timer.elapsed();
395 xdxfPlugin->search("level");
396 out<<"\n<type> SearchFile-midle with strip accent </type> <time>" << timer.elapsed();
400 xdxfPlugin->search("zoril");
401 out<<"\n<type> SearchFile-end with strip accent </type> <time>" << timer.elapsed();
405 xdxfPlugin->searchWordList("level");
406 out<<"\n<type> SearchWordListFile with strip accent </type> <time>" << timer.elapsed();
415 //#include "testqstring.moc"