69c8f5b9d209972c8f6e13574be35e6b59f51d5a
[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("<t>kropka</t>"));
44     QCOMPARE(xdxfPlugin->search("1"), QString("<t>one</t>"));
45     QCOMPARE(xdxfPlugin->search("test"), QString("<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 }
57
58 void XdxfTest::searchCache() {
59     XdxfPlugin xdxfPluginB(this);
60     Settings *settings=new Settings;
61     settings->setValue("path","../tests/dict.xdxf");
62     settings->setValue("generateCache", "true");
63     CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
64
65     QCOMPARE(xdxfPlugin->settings()->value("cached"),tr("true"));
66     QCOMPARE(xdxfPlugin->search("."), QString("<t>kropka</t>"));
67     QCOMPARE(xdxfPlugin->search("1"), QString("<t>one</t>"));
68     QCOMPARE(xdxfPlugin->search("test"), QString("<t><c c=\"FF00FF\">kro</c>test01<pos>krowa</pos></t>"));
69 }
70
71 void XdxfTest::searchWordListCache(){
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);
77
78     QList<Translation*> te = xdxfPlugin->searchWordList(".", 10);
79     if(te.size()>0)
80         QCOMPARE(te.size(), 9);
81     QList<Translation*> te2 = xdxfPlugin->searchWordList("1",10);
82     QCOMPARE(te2.size(), 5);
83
84     QList<Translation*> te3 = xdxfPlugin->searchWordList("1", 2);
85         QCOMPARE(te3.size(), 2);
86
87     QList<Translation*> te4 = xdxfPlugin->searchWordList("ho*SE", 10);
88         QCOMPARE(te4.at(0)->key(), QString("house"));
89
90     QList<Translation*> te5 = xdxfPlugin->searchWordList("*");
91         QCOMPARE(te5.size(), 9);
92
93     QList<Translation*> te6 = xdxfPlugin->searchWordList("*", 8);
94         QCOMPARE(te6.size(), 8);
95
96     QList<Translation*> te7 = xdxfPlugin->searchWordList("*ou*");
97         QCOMPARE(te7.at(0)->key(), QString("house"));
98
99     QList<Translation*> te8 = xdxfPlugin->searchWordList("1?");
100         QCOMPARE(te8.at(0)->key(), QString("10"));
101
102     QList<Translation*> te9 = xdxfPlugin->searchWordList("1???");
103         QCOMPARE(te9.at(0)->key(), QString("1000"));
104
105     QList<Translation*> te10 = xdxfPlugin->searchWordList("1????*");
106         QCOMPARE(te10.at(0)->key(), QString("1 000 000"));
107
108     QList<Translation*> te11 = xdxfPlugin->searchWordList("h**?*?**e");
109         QCOMPARE(te11.at(0)->key(), QString("house"));
110 }
111
112 void XdxfTest::searchWordListFile() {
113
114     XdxfPlugin xdxfPluginB(this);
115     Settings *settings=new Settings;
116     settings->setValue("path","../tests/dict.xdxf");
117     CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
118
119     QList<Translation*> te = xdxfPlugin->searchWordList(".", 10);
120     if(te.size()>0)
121         QCOMPARE(te.size(), 9);
122     QList<Translation*> te2 = xdxfPlugin->searchWordList("1",10);
123     QCOMPARE(te2.size(), 5);
124
125     QList<Translation*> te3 = xdxfPlugin->searchWordList("1", 2);
126         QCOMPARE(te3.size(), 2);
127
128     QList<Translation*> te4 = xdxfPlugin->searchWordList("ho*SE", 10);
129         QCOMPARE(te4.at(0)->key(), QString("house"));
130
131     QList<Translation*> te5 = xdxfPlugin->searchWordList("*");
132         QCOMPARE(te5.size(), 9);
133
134     QList<Translation*> te6 = xdxfPlugin->searchWordList("*", 8);
135         QCOMPARE(te6.size(), 8);
136
137     QList<Translation*> te7 = xdxfPlugin->searchWordList("*ou*");
138         QCOMPARE(te7.at(0)->key(), QString("house"));
139
140     QList<Translation*> te8 = xdxfPlugin->searchWordList("1?");
141         QCOMPARE(te8.at(0)->key(), QString("10"));
142
143     QList<Translation*> te9 = xdxfPlugin->searchWordList("1???");
144         QCOMPARE(te9.at(0)->key(), QString("1000"));
145
146     QList<Translation*> te10 = xdxfPlugin->searchWordList("1????*");
147         QCOMPARE(te10.at(0)->key(), QString("1 000 000"));
148
149     QList<Translation*> te11 = xdxfPlugin->searchWordList("h**?*?**e");
150         QCOMPARE(te11.at(0)->key(), QString("house"));
151
152 }
153
154 void XdxfTest::stop() {
155
156     XdxfPlugin xdxfPluginB(this);
157 //  xdxfPlugin.setPatch("dict.xdxf");
158
159     Settings *settings=new Settings;
160     settings->setValue("path","../tests/dict.xdxf");
161     CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
162
163     QString string("*");
164     QFuture<QList<Translation*> > future = QtConcurrent::run(xdxfPlugin, &CommonDictInterface::searchWordList, string, 10);
165     QList<Translation*> te5 = future.result();
166     QCOMPARE(te5.size(), 9);
167 }
168
169
170 void XdxfTest::langFrom() {
171
172     XdxfPlugin xdxfPluginB(this);
173     Settings *settings=new Settings;
174     settings->setValue("path","../tests/dict.xdxf");
175     CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
176
177     QCOMPARE(xdxfPlugin->langFrom(), QString("ENG"));
178 }
179
180 QTEST_MAIN(XdxfTest)
181 //#include "testqstring.moc"