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 xdxfPlugin(this);
28 Settings *settings=new Settings;
29 settings->setValue("path","../tests/dict.xdxf");
30 CommonDictInterface *xdxfPlugin2 = xdxfPlugin.getNew(settings);
32 QList<Translation*> te6=xdxfPlugin2->searchWordList("*",8);
33 QCOMPARE(te6.size(),8);
36 void XdxfTest::searchFile() {
38 XdxfPlugin xdxfPluginB(this);
39 Settings *settings=new Settings;
40 settings->setValue("path","../tests/dict.xdxf");
41 CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
43 QCOMPARE(xdxfPlugin->search("."), QString("<key>.</key><t>kropka</t>"));
44 QCOMPARE(xdxfPlugin->search("1"), QString("<key>1</key><t>one</t>"));
45 QCOMPARE(xdxfPlugin->search("test"), QString("<key>test</key><t><c c=\"FF00FF\">kro</c>test01<pos>krowa</pos></t>"));
48 void XdxfTest::makeCache()
50 XdxfPlugin xdxfPluginB(this);
51 Settings *settings=new Settings;
52 settings->setValue("path","../tests/dict.xdxf");
53 settings->setValue("generateCache", "true");
54 CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
55 QCOMPARE(xdxfPlugin->settings()->value("cached"),tr("true"));
59 void XdxfTest::searchCache() {
60 XdxfPlugin xdxfPluginB(this);
61 Settings *settings=new Settings;
62 settings->setValue("path","../tests/dict.xdxf");
63 settings->setValue("generateCache", "true");
64 CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
66 QCOMPARE(xdxfPlugin->settings()->value("cached"),tr("true"));
67 QCOMPARE(xdxfPlugin->search("."), QString("<key>.</key><t>kropka</t>"));
68 QCOMPARE(xdxfPlugin->search("1"), QString("<key>1</key><t>one</t>"));
69 QCOMPARE(xdxfPlugin->search("test"), QString("<key>test</key><t><c c=\"FF00FF\">kro</c>test01<pos>krowa</pos></t>"));
74 void XdxfTest::searchWordListCache(){
75 XdxfPlugin xdxfPluginB(this);
76 Settings *settings=new Settings;
77 settings->setValue("path","../tests/dict.xdxf");
78 settings->setValue("generateCache", "true");
79 CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
81 QList<Translation*> te = xdxfPlugin->searchWordList(".", 10);
83 QCOMPARE(te.size(), 1);
84 QList<Translation*> te2 = xdxfPlugin->searchWordList("1",10);
85 QCOMPARE(te2.size(), 5);
87 QList<Translation*> te3 = xdxfPlugin->searchWordList("1", 2);
88 QCOMPARE(te3.size(), 2);
90 QList<Translation*> te4 = xdxfPlugin->searchWordList("ho*SE", 10);
91 QCOMPARE(te4.at(0)->key(), QString("house"));
93 QList<Translation*> te5 = xdxfPlugin->searchWordList("*");
94 QCOMPARE(te5.size(), 9);
96 QList<Translation*> te6 = xdxfPlugin->searchWordList("*", 8);
97 QCOMPARE(te6.size(), 8);
99 QList<Translation*> te7 = xdxfPlugin->searchWordList("*ou*");
100 QCOMPARE(te7.at(0)->key(), QString("house"));
102 QList<Translation*> te8 = xdxfPlugin->searchWordList("1?");
103 QCOMPARE(te8.at(0)->key(), QString("10"));
105 QList<Translation*> te9 = xdxfPlugin->searchWordList("1???");
106 QCOMPARE(te9.at(0)->key(), QString("1000"));
108 QList<Translation*> te10 = xdxfPlugin->searchWordList("1????*");
109 QCOMPARE(te10.at(0)->key(), QString("1 000 000"));
111 QList<Translation*> te11 = xdxfPlugin->searchWordList("h**?*?**e");
112 QCOMPARE(te11.at(0)->key(), QString("house"));
117 void XdxfTest::searchWordListFile() {
119 XdxfPlugin xdxfPluginB(this);
120 Settings *settings=new Settings;
121 settings->setValue("path","../tests/dict.xdxf");
122 CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
124 QList<Translation*> te = xdxfPlugin->searchWordList(".", 10);
126 QCOMPARE(te.size(), 1);
127 QList<Translation*> te2 = xdxfPlugin->searchWordList("1",10);
128 QCOMPARE(te2.size(), 5);
130 QList<Translation*> te3 = xdxfPlugin->searchWordList("1", 2);
131 QCOMPARE(te3.size(), 2);
133 QList<Translation*> te4 = xdxfPlugin->searchWordList("ho*SE", 10);
134 QCOMPARE(te4.at(0)->key(), QString("house"));
136 QList<Translation*> te5 = xdxfPlugin->searchWordList("*");
137 QCOMPARE(te5.size(), 9);
139 QList<Translation*> te6 = xdxfPlugin->searchWordList("*", 8);
140 QCOMPARE(te6.size(), 8);
142 QList<Translation*> te7 = xdxfPlugin->searchWordList("*ou*");
143 QCOMPARE(te7.at(0)->key(), QString("house"));
145 QList<Translation*> te8 = xdxfPlugin->searchWordList("1?");
146 QCOMPARE(te8.at(0)->key(), QString("10"));
148 QList<Translation*> te9 = xdxfPlugin->searchWordList("1???");
149 QCOMPARE(te9.at(0)->key(), QString("1000"));
151 QList<Translation*> te10 = xdxfPlugin->searchWordList("1????*");
152 QCOMPARE(te10.at(0)->key(), QString("1 000 000"));
154 QList<Translation*> te11 = xdxfPlugin->searchWordList("h**?*?**e");
155 QCOMPARE(te11.at(0)->key(), QString("house"));
160 void XdxfTest::stop() {
162 XdxfPlugin xdxfPluginB(this);
163 Settings *settings=new Settings;
164 settings->setValue("path","../tests/dict.xdxf");
165 CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
168 QFuture<QList<Translation*> > future = QtConcurrent::run(xdxfPlugin,
169 &CommonDictInterface::searchWordList, string, 10);
170 QList<Translation*> te5 = future.result();
171 QCOMPARE(te5.size(), 9);
177 void XdxfTest::langFrom() {
179 XdxfPlugin xdxfPluginB(this);
180 Settings *settings=new Settings;
181 settings->setValue("path","../tests/dict.xdxf");
182 CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
184 QCOMPARE(xdxfPlugin->langFrom(), QString("ENG"));
189 void XdxfTest::timeCache()
193 QFile File("../tests/time.xml");
194 if(!File.open(QFile::ReadWrite | QFile::Text)) {
195 qDebug()<<"Error: could not open file";
198 QTextStream out(&File);
200 out.seek(out.pos()+1);
203 XdxfPlugin xdxfPluginB(this);
204 Settings *settings=new Settings;
205 settings->setValue("path","../../../../../../dict.xdxf");
206 settings->setValue("generateCache", "true");
207 CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
209 out<<"\n<date>" + date.currentDate().toString("dd.MM.yyyy") +" ";
210 out<<timer.currentTime().toString(Qt::TextDate) + "</date>";
211 out<<"\n<type> Cache </type> <time>" << timer.elapsed();
215 xdxfPlugin->search("Bantu");
216 out<<"\n<type> SearchCache-begin </type> <time>" << timer.elapsed();
220 xdxfPlugin->search("level");
221 out<<"\n<type> SearchCache-midle </type> <time>" << timer.elapsed();
225 xdxfPlugin->search("zoril");
226 out<<"\n<type> SearchCache-end </type> <time>" << timer.elapsed();
230 xdxfPlugin->searchWordList("level");
231 out<<"\n<type> SearchWorlListCache </type> <time>" << timer.elapsed();
237 void XdxfTest::timeFile()
241 QFile File("../tests/time.xml");
242 if(!File.open(QFile::ReadWrite | QFile::Text)) {
243 qDebug()<<"Error: could not open file";
246 QTextStream out(&File);
248 out.seek(out.pos()+1);
250 XdxfPlugin xdxfPluginB(this);
251 Settings *settings=new Settings;
252 settings->setValue("path","../../../../../../dict.xdxf");
253 CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
256 xdxfPlugin->search("Bantu");
257 out<<"\n<type> SearchFile-begin </type> <time>" << timer.elapsed();
261 xdxfPlugin->search("level");
262 out<<"\n<type> SearchFile-midle </type> <time>" << timer.elapsed();
266 xdxfPlugin->search("zoril");
267 out<<"\n<type> SearchFile-end </type> <time>" << timer.elapsed();
271 xdxfPlugin->searchWordList("level");
272 out<<"\n<type> SearchWordListFile </type> <time>" << timer.elapsed();
278 void XdxfTest::removeAccents()
281 cheat.settings()->setValue(QString("strip_accents"), QString("true"));
282 QCOMPARE(cheat.getRemoveAccents(QString::fromUtf8("nóżka")), QString("nozka"));
283 QCOMPARE(cheat.getRemoveAccents(QString::fromUtf8("motor")), QString("motor"));
284 QCOMPARE(cheat.getRemoveAccents(QString::fromUtf8("nÓżKa")), QString("nozka"));
285 QCOMPARE(cheat.getRemoveAccents(QString::fromUtf8("ławka")), QString("lawka"));
286 QCOMPARE(cheat.getRemoveAccents(QString::fromUtf8("éàèùâêîôûëïüÿäöüç")), QString("eaeuaeioueiuyaouc"));
287 QCOMPARE(cheat.getRemoveAccents(QString::fromUtf8("íőűúó")), QString("iouuo"));
288 QCOMPARE(cheat.getRemoveAccents(QString::fromUtf8("-ę")), QString("-e"));
293 //#include "testqstring.moc"