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