improve a search function in xdxfPlugin
[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     XdxfPlugin xdxfPlugin(this);
27     Settings *settings=new Settings;
28     settings->setValue("path","../tests/dict.xdxf");
29
30     CommonDictInterface *xdxfPlugin2 = xdxfPlugin.getNew(settings);
31     QList<Translation*> te6=xdxfPlugin2->searchWordList("*",8);
32         QCOMPARE(te6.size(),8);
33 }
34
35 void XdxfTest::search() {
36     /*test for English-Polish dictionary */
37     XdxfPlugin xdxfPluginB(this);
38
39
40
41     Settings *settings=new Settings;
42     settings->setValue("path","../tests/dict.xdxf");
43     CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
44
45     xdxfPlugin->search("wino");
46     QCOMPARE(xdxfPlugin->search("."), QString("<t>kropka</t>"));
47     QCOMPARE(xdxfPlugin->search("1"), QString("<t>one</t>"));
48
49     QCOMPARE(xdxfPlugin->search("test"), QString("<t><pos>krowa</pos>test01</t>"));
50 }
51
52 void XdxfTest::searchWordList() {
53      /*test for English-Polish dictionary */
54     XdxfPlugin xdxfPluginB(this);
55
56     Settings *settings=new Settings;
57     settings->setValue("path","../tests/dict.xdxf");
58     CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
59     QList<Translation*> te = xdxfPlugin->searchWordList(".", 10);
60     if(te.size()>0)
61         QCOMPARE(te.size(), 9);
62     QList<Translation*> te2 = xdxfPlugin->searchWordList("1",10);
63     QCOMPARE(te2.size(), 5);
64
65     QList<Translation*> te3 = xdxfPlugin->searchWordList("1", 2);
66         QCOMPARE(te3.size(), 2);
67
68     QList<Translation*> te4 = xdxfPlugin->searchWordList("ho*SE", 10);
69         QCOMPARE(te4.at(0)->key(), QString("house"));
70
71     QList<Translation*> te5 = xdxfPlugin->searchWordList("*");
72         QCOMPARE(te5.size(), 9);
73
74     QList<Translation*> te6 = xdxfPlugin->searchWordList("*", 8);
75         QCOMPARE(te6.size(), 8);
76
77     QList<Translation*> te7 = xdxfPlugin->searchWordList("*ou*");
78         QCOMPARE(te7.at(0)->key(), QString("house"));
79
80     QList<Translation*> te8 = xdxfPlugin->searchWordList("1?");
81         QCOMPARE(te8.at(0)->key(), QString("10"));
82
83     QList<Translation*> te9 = xdxfPlugin->searchWordList("1???");
84         QCOMPARE(te9.at(0)->key(), QString("1000"));
85
86     QList<Translation*> te10 = xdxfPlugin->searchWordList("1????*");
87         QCOMPARE(te10.at(0)->key(), QString("1 000 000"));
88
89     QList<Translation*> te11 = xdxfPlugin->searchWordList("h**?*?**e");
90         QCOMPARE(te11.at(0)->key(), QString("house"));
91
92
93 }
94
95 void XdxfTest::stop() {
96     /*test for English-Polish dictionary */
97     XdxfPlugin xdxfPluginB(this);
98 //    xdxfPlugin.setPatch("dict.xdxf");
99
100     Settings *settings=new Settings;
101     settings->setValue("path","../tests/dict.xdxf");
102     CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
103
104     QString string("*");
105     QFuture<QList<Translation*> > future = QtConcurrent::run(xdxfPlugin, &CommonDictInterface::searchWordList, string, 10);
106     QList<Translation*> te5 = future.result();
107
108     QCOMPARE(te5.size(), 9);
109 }
110
111
112 void XdxfTest::langFrom() {
113      /*test for English-Polish dictionary */
114     XdxfPlugin xdxfPluginB(this);
115 //    xdxfPlugin.setPatch("dict.xdxf");
116
117     Settings *settings=new Settings;
118     settings->setValue("path","../tests/dict.xdxf");
119     CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
120     xdxfPlugin->searchWordList("rope", 10);
121     QCOMPARE(xdxfPlugin->langFrom(), QString("ENG"));
122 }
123
124 QTEST_MAIN(XdxfTest)
125 //#include "testqstring.moc"