Changed button labels in google plugin
[mdictionary] / trunk / src / plugins / xdxf / tests / test.cpp
1 /*******************************************************************************
2
3     This file is part of mDictionary.
4
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.
9
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.
14
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/>.
17
18     Copyright 2010 Comarch S.A.
19
20 *******************************************************************************/
21
22 #include "test.h"
23 #include <QSignalSpy>
24
25 void XdxfTest::getNew() {
26
27     XdxfPlugin xdxfPlugin(this);
28     Settings *settings=new Settings;
29     settings->setValue("path","../tests/dict.xdxf");
30     CommonDictInterface *xdxfPlugin2 = xdxfPlugin.getNew(settings);
31
32     QList<Translation*> te6=xdxfPlugin2->searchWordList("*",8);
33     QCOMPARE(te6.size(),8);
34 }
35
36 void XdxfTest::searchFile() {
37
38     XdxfPlugin xdxfPluginB(this);
39     Settings *settings=new Settings;
40     settings->setValue("path","../tests/dict.xdxf");
41     CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
42
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>"));
46 }
47
48 void XdxfTest::makeCache()
49 {
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"));
56     delete xdxfPlugin;
57 }
58
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);
65
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>"));
70
71     delete xdxfPlugin;
72 }
73
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);
80
81     QList<Translation*> te = xdxfPlugin->searchWordList(".", 10);
82     if(te.size()>0)
83         QCOMPARE(te.size(), 1);
84     QList<Translation*> te2 = xdxfPlugin->searchWordList("1",10);
85     QCOMPARE(te2.size(), 5);
86
87     QList<Translation*> te3 = xdxfPlugin->searchWordList("1", 2);
88         QCOMPARE(te3.size(), 2);
89
90     QList<Translation*> te4 = xdxfPlugin->searchWordList("ho*SE", 10);
91         QCOMPARE(te4.at(0)->key(), QString("house"));
92
93     QList<Translation*> te5 = xdxfPlugin->searchWordList("*");
94         QCOMPARE(te5.size(), 9);
95
96     QList<Translation*> te6 = xdxfPlugin->searchWordList("*", 8);
97         QCOMPARE(te6.size(), 8);
98
99     QList<Translation*> te7 = xdxfPlugin->searchWordList("*ou*");
100         QCOMPARE(te7.at(0)->key(), QString("house"));
101
102     QList<Translation*> te8 = xdxfPlugin->searchWordList("1?");
103         QCOMPARE(te8.at(0)->key(), QString("10"));
104
105     QList<Translation*> te9 = xdxfPlugin->searchWordList("1???");
106         QCOMPARE(te9.at(0)->key(), QString("1000"));
107
108     QList<Translation*> te10 = xdxfPlugin->searchWordList("1????*");
109         QCOMPARE(te10.at(0)->key(), QString("1 000 000"));
110
111     QList<Translation*> te11 = xdxfPlugin->searchWordList("h**?*?**e");
112         QCOMPARE(te11.at(0)->key(), QString("house"));
113
114     delete xdxfPlugin;
115 }
116
117 void XdxfTest::searchWordListFile() {
118
119     XdxfPlugin xdxfPluginB(this);
120     Settings *settings=new Settings;
121     settings->setValue("path","../tests/dict.xdxf");
122     CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
123
124     QList<Translation*> te = xdxfPlugin->searchWordList(".", 10);
125     if(te.size()>0)
126         QCOMPARE(te.size(), 1);
127     QList<Translation*> te2 = xdxfPlugin->searchWordList("1",10);
128     QCOMPARE(te2.size(), 5);
129
130     QList<Translation*> te3 = xdxfPlugin->searchWordList("1", 2);
131         QCOMPARE(te3.size(), 2);
132
133     QList<Translation*> te4 = xdxfPlugin->searchWordList("ho*SE", 10);
134         QCOMPARE(te4.at(0)->key(), QString("house"));
135
136     QList<Translation*> te5 = xdxfPlugin->searchWordList("*");
137         QCOMPARE(te5.size(), 9);
138
139     QList<Translation*> te6 = xdxfPlugin->searchWordList("*", 8);
140         QCOMPARE(te6.size(), 8);
141
142     QList<Translation*> te7 = xdxfPlugin->searchWordList("*ou*");
143         QCOMPARE(te7.at(0)->key(), QString("house"));
144
145     QList<Translation*> te8 = xdxfPlugin->searchWordList("1?");
146         QCOMPARE(te8.at(0)->key(), QString("10"));
147
148     QList<Translation*> te9 = xdxfPlugin->searchWordList("1???");
149         QCOMPARE(te9.at(0)->key(), QString("1000"));
150
151     QList<Translation*> te10 = xdxfPlugin->searchWordList("1????*");
152         QCOMPARE(te10.at(0)->key(), QString("1 000 000"));
153
154     QList<Translation*> te11 = xdxfPlugin->searchWordList("h**?*?**e");
155         QCOMPARE(te11.at(0)->key(), QString("house"));
156
157     delete xdxfPlugin;
158 }
159
160 void XdxfTest::stop() {
161
162     XdxfPlugin xdxfPluginB(this);
163     Settings *settings=new Settings;
164     settings->setValue("path","../tests/dict.xdxf");
165     CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
166
167     QString string("*");
168     QFuture<QList<Translation*> > future = QtConcurrent::run(xdxfPlugin,
169                         &CommonDictInterface::searchWordList, string, 10);
170     QList<Translation*> te5 = future.result();
171     QCOMPARE(te5.size(), 9);
172
173     delete xdxfPlugin;
174 }
175
176
177 void XdxfTest::langFrom() {
178
179     XdxfPlugin xdxfPluginB(this);
180     Settings *settings=new Settings;
181     settings->setValue("path","../tests/dict.xdxf");
182     CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
183
184     QCOMPARE(xdxfPlugin->langFrom(), QString("ENG"));
185
186     delete xdxfPlugin;
187 }
188
189 void XdxfTest::timeCache() {
190     QTime timer;
191     QDate date;
192     QFile File("../tests/time.xml");
193     if(!File.open(QFile::ReadWrite | QFile::Text)) {
194         qDebug()<<"Error: could not open file";
195         return;
196     }
197     QTextStream out(&File);
198     while(!out.atEnd())
199         out.seek(out.pos()+1);
200
201     timer.start();
202     XdxfPlugin xdxfPluginB(this);
203     Settings *settings=new Settings;
204     settings->setValue("path","../../../../../../dict.xdxf");
205     settings->setValue("generateCache", "true");
206     CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
207
208     out<<"\n<date>" + date.currentDate().toString("dd.MM.yyyy") +" ";
209     out<<timer.currentTime().toString(Qt::TextDate) + "</date>";
210     out<<"\n<type> Cache </type> <time>" << timer.elapsed();
211     out<<"</time>";
212
213     timer.start();
214     xdxfPlugin->search("Bantu");
215     out<<"\n<type> SearchCache-begin </type> <time>" << timer.elapsed();
216     out<< "</time>";
217
218     timer.start();
219     xdxfPlugin->search("level");
220     out<<"\n<type> SearchCache-midle </type> <time>" << timer.elapsed();
221     out<< "</time>";
222
223     timer.start();
224     xdxfPlugin->search("zoril");
225     out<<"\n<type> SearchCache-end </type> <time>" << timer.elapsed();
226     out<< "</time>";
227
228     timer.start();
229     xdxfPlugin->searchWordList("level");
230     out<<"\n<type> SearchWorlListCache </type> <time>" << timer.elapsed();
231     out<< "</time>";
232
233     File.close();
234 }
235
236 void XdxfTest::timeFile() {
237     QTime timer;
238     QDate date;
239     QFile File("../tests/time.xml");
240     if(!File.open(QFile::ReadWrite | QFile::Text)) {
241         qDebug()<<"Error: could not open file";
242         return;
243     }
244     QTextStream out(&File);
245     while(!out.atEnd())
246         out.seek(out.pos()+1);
247
248     XdxfPlugin xdxfPluginB(this);
249     Settings *settings=new Settings;
250     settings->setValue("path","../../../../../../dict.xdxf");
251     CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
252
253     timer.start();
254     xdxfPlugin->search("Bantu");
255     out<<"\n<type> SearchFile-begin </type> <time>" << timer.elapsed();
256     out << "</time>";
257
258     timer.start();
259     xdxfPlugin->search("level");
260     out<<"\n<type> SearchFile-midle </type> <time>" << timer.elapsed();
261     out << "</time>";
262
263     timer.start();
264     xdxfPlugin->search("zoril");
265     out<<"\n<type> SearchFile-end </type> <time>" << timer.elapsed();
266     out << "</time>";
267
268     timer.start();
269     xdxfPlugin->searchWordList("level");
270     out<<"\n<type> SearchWordListFile </type> <time>" << timer.elapsed();
271     out<< "</time>";
272
273     File.close();
274 }
275
276 void XdxfTest::timeCacheNormalize() {
277     QTime timer;
278     QDate date;
279     QFile File("../tests/time.xml");
280     if(!File.open(QFile::ReadWrite | QFile::Text)) {
281         qDebug()<<"Error: could not open file";
282         return;
283     }
284     QTextStream out(&File);
285     while(!out.atEnd())
286         out.seek(out.pos()+1);
287
288     timer.start();
289     XdxfPlugin xdxfPluginB(this);
290     Settings *settings=new Settings;
291     settings->setValue("path","../../../../../../dict.xdxf");
292     settings->setValue("generateCache", "true");
293     settings->setValue("strip_accents", "true");
294     CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
295
296     out<<"\n<type> Cache with strip accent </type> <time>" << timer.elapsed();
297     out<<"</time>";
298
299     timer.start();
300     xdxfPlugin->search("Bantu");
301     out<<"\n<type> SearchCache-begin with strip accent </type> <time>" << timer.elapsed();
302     out<< "</time>";
303
304     timer.start();
305     xdxfPlugin->search("level");
306     out<<"\n<type> SearchCache-midle with strip accent </type> <time>" << timer.elapsed();
307     out<< "</time>";
308
309     timer.start();
310     xdxfPlugin->search("zoril");
311     out<<"\n<type> SearchCache-end with strip accent </type> <time>" << timer.elapsed();
312     out<< "</time>";
313
314     timer.start();
315     xdxfPlugin->searchWordList("level");
316     out<<"\n<type> SearchWorlListCache with strip accent </type> <time>" << timer.elapsed();
317     out<< "</time>";
318
319     File.close();
320 }
321
322 void XdxfTest::timeFileNormalize(){
323     QTime timer;
324     QDate date;
325     QFile File("../tests/time.xml");
326     if(!File.open(QFile::ReadWrite | QFile::Text)) {
327         qDebug()<<"Error: could not open file";
328         return;
329     }
330     QTextStream out(&File);
331     while(!out.atEnd())
332         out.seek(out.pos()+1);
333
334     XdxfPlugin xdxfPluginB(this);
335     Settings *settings=new Settings;
336     settings->setValue("path","../../../../../../dict.xdxf");
337     settings->setValue("strip_accents", "true");
338     CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
339
340     timer.start();
341     xdxfPlugin->search("Bantu");
342     out<<"\n<type> SearchFile-begin with strip accent </type> <time>" << timer.elapsed();
343     out << "</time>";
344
345     timer.start();
346     xdxfPlugin->search("level");
347     out<<"\n<type> SearchFile-midle with strip accent </type> <time>" << timer.elapsed();
348     out << "</time>";
349
350     timer.start();
351     xdxfPlugin->search("zoril");
352     out<<"\n<type> SearchFile-end with strip accent </type> <time>" << timer.elapsed();
353     out << "</time>";
354
355     timer.start();
356     xdxfPlugin->searchWordList("level");
357     out<<"\n<type> SearchWordListFile with strip accent </type> <time>" << timer.elapsed();
358     out<< "</time>\n";
359
360     File.close();
361
362 }
363
364 QTEST_MAIN(XdxfTest)
365 //#include "testqstring.moc"