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);
32 QList<Translation*> te6=xdxfPlugin->searchWordList("*",8);
33 QCOMPARE(te6.size(),8);
39 void XdxfTest::searchFile() {
41 XdxfPlugin xdxfPluginB(this);
42 Settings *settings=new Settings;
43 settings->setValue("path","../tests/dict.xdxf");
44 CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
46 QCOMPARE(xdxfPlugin->search("."), QString("<key>.</key><t>kropka</t>"));
47 QCOMPARE(xdxfPlugin->search("1"), QString("<key>1</key><t>one</t>"));
48 QCOMPARE(xdxfPlugin->search("test"), QString("<key>test</key><t><c c=\"FF00FF\">kro</c>test01<pos>krowa</pos></t>"));
54 void XdxfTest::makeCache()
56 XdxfPlugin xdxfPluginB(this);
57 Settings *settings=new Settings;
58 settings->setValue("path","../tests/dict.xdxf");
59 settings->setValue("generateCache", "true");
60 CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
61 QCOMPARE(xdxfPlugin->settings()->value("cached"),tr("true"));
67 void XdxfTest::searchCache() {
68 XdxfPlugin xdxfPluginB(this);
69 Settings *settings=new Settings;
70 settings->setValue("path","../tests/dict.xdxf");
71 settings->setValue("generateCache", "true");
72 CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
74 QCOMPARE(xdxfPlugin->settings()->value("cached"),tr("true"));
75 QCOMPARE(xdxfPlugin->search("."), QString("<key>.</key><t>kropka</t>"));
76 QCOMPARE(xdxfPlugin->search("1"), QString("<key>1</key><t>one</t>"));
77 QCOMPARE(xdxfPlugin->search("test"), QString("<key>test</key><t><c c=\"FF00FF\">kro</c>test01<pos>krowa</pos></t>"));
83 void XdxfTest::searchWordListCache(){
84 XdxfPlugin xdxfPluginB(this);
85 Settings *settings=new Settings;
86 settings->setValue("path","../tests/dict.xdxf");
87 settings->setValue("generateCache", "true");
88 CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
90 QList<Translation*> te = xdxfPlugin->searchWordList(".", 10);
92 QCOMPARE(te.size(), 1);
93 QList<Translation*> te2 = xdxfPlugin->searchWordList("1",10);
94 QCOMPARE(te2.size(), 5);
96 QList<Translation*> te3 = xdxfPlugin->searchWordList("1", 2);
97 QCOMPARE(te3.size(), 2);
99 QList<Translation*> te4 = xdxfPlugin->searchWordList("ho*SE", 10);
100 QCOMPARE(te4.at(0)->key(), QString("house"));
102 QList<Translation*> te5 = xdxfPlugin->searchWordList("*");
103 QCOMPARE(te5.size(), 9);
105 QList<Translation*> te6 = xdxfPlugin->searchWordList("*", 8);
106 QCOMPARE(te6.size(), 8);
108 QList<Translation*> te7 = xdxfPlugin->searchWordList("*ou*");
109 QCOMPARE(te7.at(0)->key(), QString("house"));
111 QList<Translation*> te8 = xdxfPlugin->searchWordList("1?");
112 QCOMPARE(te8.at(0)->key(), QString("10"));
114 QList<Translation*> te9 = xdxfPlugin->searchWordList("1???");
115 QCOMPARE(te9.at(0)->key(), QString("1000"));
117 QList<Translation*> te10 = xdxfPlugin->searchWordList("1????*");
118 QCOMPARE(te10.at(0)->key(), QString("1 000 000"));
120 QList<Translation*> te11 = xdxfPlugin->searchWordList("h**?*?**e");
121 QCOMPARE(te11.at(0)->key(), QString("house"));
127 void XdxfTest::searchWordListFile() {
129 XdxfPlugin xdxfPluginB(this);
130 Settings *settings=new Settings;
131 settings->setValue("path","../tests/dict.xdxf");
132 CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
134 QList<Translation*> te = xdxfPlugin->searchWordList(".", 10);
136 QCOMPARE(te.size(), 1);
137 QList<Translation*> te2 = xdxfPlugin->searchWordList("1",10);
138 QCOMPARE(te2.size(), 5);
140 QList<Translation*> te3 = xdxfPlugin->searchWordList("1", 2);
141 QCOMPARE(te3.size(), 2);
143 QList<Translation*> te4 = xdxfPlugin->searchWordList("ho*SE", 10);
144 QCOMPARE(te4.at(0)->key(), QString("house"));
146 QList<Translation*> te5 = xdxfPlugin->searchWordList("*");
147 QCOMPARE(te5.size(), 9);
149 QList<Translation*> te6 = xdxfPlugin->searchWordList("*", 8);
150 QCOMPARE(te6.size(), 8);
152 QList<Translation*> te7 = xdxfPlugin->searchWordList("*ou*");
153 QCOMPARE(te7.at(0)->key(), QString("house"));
155 QList<Translation*> te8 = xdxfPlugin->searchWordList("1?");
156 QCOMPARE(te8.at(0)->key(), QString("10"));
158 QList<Translation*> te9 = xdxfPlugin->searchWordList("1???");
159 QCOMPARE(te9.at(0)->key(), QString("1000"));
161 QList<Translation*> te10 = xdxfPlugin->searchWordList("1????*");
162 QCOMPARE(te10.at(0)->key(), QString("1 000 000"));
164 QList<Translation*> te11 = xdxfPlugin->searchWordList("h**?*?**e");
165 QCOMPARE(te11.at(0)->key(), QString("house"));
171 void XdxfTest::stop() {
173 XdxfPlugin xdxfPluginB(this);
174 Settings *settings=new Settings;
175 settings->setValue("path","../tests/dict.xdxf");
176 CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
179 QFuture<QList<Translation*> > future = QtConcurrent::run(xdxfPlugin,
180 &CommonDictInterface::searchWordList, string, 10);
181 QList<Translation*> te5 = future.result();
182 QCOMPARE(te5.size(), 9);
189 void XdxfTest::langFrom() {
191 XdxfPlugin xdxfPluginB(this);
192 Settings *settings=new Settings;
193 settings->setValue("path","../tests/dict.xdxf");
194 CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
196 QCOMPARE(xdxfPlugin->langFrom(), QString("ENG"));
202 void XdxfTest::timeCache() {
205 QFile File("../tests/time.xml");
206 if(!File.open(QFile::ReadWrite | QFile::Text)) {
207 qDebug()<<"Error: could not open file";
210 QTextStream out(&File);
212 out.seek(out.pos()+1);
215 XdxfPlugin xdxfPluginB(this);
216 Settings *settings=new Settings;
217 settings->setValue("path","../../../../../../dict.xdxf");
218 settings->setValue("generateCache", "true");
219 CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
221 out<<"\n<date>" + date.currentDate().toString("dd.MM.yyyy") +" ";
222 out<<timer.currentTime().toString(Qt::TextDate) + "</date>";
223 out<<"\n<type> Cache </type> <time>" << timer.elapsed();
227 xdxfPlugin->search("Bantu");
228 out<<"\n<type> SearchCache-begin </type> <time>" << timer.elapsed();
232 xdxfPlugin->search("level");
233 out<<"\n<type> SearchCache-midle </type> <time>" << timer.elapsed();
237 xdxfPlugin->search("zoril");
238 out<<"\n<type> SearchCache-end </type> <time>" << timer.elapsed();
242 xdxfPlugin->searchWordList("level");
243 out<<"\n<type> SearchWorlListCache </type> <time>" << timer.elapsed();
251 void XdxfTest::timeFile() {
254 QFile File("../tests/time.xml");
255 if(!File.open(QFile::ReadWrite | QFile::Text)) {
256 qDebug()<<"Error: could not open file";
259 QTextStream out(&File);
261 out.seek(out.pos()+1);
263 XdxfPlugin xdxfPluginB(this);
264 Settings *settings=new Settings;
265 settings->setValue("path","../../../../../../dict.xdxf");
266 CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
269 xdxfPlugin->search("Bantu");
270 out<<"\n<type> SearchFile-begin </type> <time>" << timer.elapsed();
274 xdxfPlugin->search("level");
275 out<<"\n<type> SearchFile-midle </type> <time>" << timer.elapsed();
279 xdxfPlugin->search("zoril");
280 out<<"\n<type> SearchFile-end </type> <time>" << timer.elapsed();
284 xdxfPlugin->searchWordList("level");
285 out<<"\n<type> SearchWordListFile </type> <time>" << timer.elapsed();
293 void XdxfTest::timeCacheNormalize() {
296 QFile File("../tests/time.xml");
297 if(!File.open(QFile::ReadWrite | QFile::Text)) {
298 qDebug()<<"Error: could not open file";
301 QTextStream out(&File);
303 out.seek(out.pos()+1);
306 XdxfPlugin xdxfPluginB(this);
307 Settings *settings=new Settings;
308 settings->setValue("path","../../../../../../dict.xdxf");
309 settings->setValue("generateCache", "true");
310 settings->setValue("strip_accents", "true");
311 CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
313 out<<"\n<type> Cache with strip accent </type> <time>" << timer.elapsed();
317 xdxfPlugin->search("Bantu");
318 out<<"\n<type> SearchCache-begin with strip accent </type> <time>" << timer.elapsed();
322 xdxfPlugin->search("level");
323 out<<"\n<type> SearchCache-midle with strip accent </type> <time>" << timer.elapsed();
327 xdxfPlugin->search("zoril");
328 out<<"\n<type> SearchCache-end with strip accent </type> <time>" << timer.elapsed();
332 xdxfPlugin->searchWordList("level");
333 out<<"\n<type> SearchWorlListCache with strip accent </type> <time>" << timer.elapsed();
341 void XdxfTest::removeAccents() {
344 xdxf.settings()->setValue(QString("strip_accents"), QString("true"));
345 QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("nóżka")), QString("nozka"));
346 QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("motor")), QString("motor"));
347 QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("nÓżKa")), QString("nozka"));
348 QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("ławka")), QString("lawka"));
349 QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("éàèùâêîôûëïüÿäöüç")), QString("eaeuaeioueiuyaouc"));
350 QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("íőűúó")), QString("iouuo"));
351 QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("-ę")), QString("-e"));
352 QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("\"e\"")), QString("\"e\""));
353 QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("'e'")), QString("'e'"));
354 QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("\\e")), QString("e"));
355 QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("\\")), QString(""));
358 void XdxfTest::timeFileNormalize(){
361 QFile File("../tests/time.xml");
362 if(!File.open(QFile::ReadWrite | QFile::Text)) {
363 qDebug()<<"Error: could not open file";
366 QTextStream out(&File);
368 out.seek(out.pos()+1);
370 XdxfPlugin xdxfPluginB(this);
371 Settings *settings=new Settings;
372 settings->setValue("path","../../../../../../dict.xdxf");
373 settings->setValue("strip_accents", "true");
374 CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
377 xdxfPlugin->search("Bantu");
378 out<<"\n<type> SearchFile-begin with strip accent </type> <time>" << timer.elapsed();
382 xdxfPlugin->search("level");
383 out<<"\n<type> SearchFile-midle with strip accent </type> <time>" << timer.elapsed();
387 xdxfPlugin->search("zoril");
388 out<<"\n<type> SearchFile-end with strip accent </type> <time>" << timer.elapsed();
392 xdxfPlugin->searchWordList("level");
393 out<<"\n<type> SearchWordListFile with strip accent </type> <time>" << timer.elapsed();
403 //#include "testqstring.moc"