Further xdxf tests fixing
[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","dict.xdxf");
29     CommonDictInterface *xdxfPlugin2 = xdxfPlugin.getNew(settings);
30     QList<Translation*> te6=xdxfPlugin2->searchWordList("*",8);
31         QCOMPARE(te6.size(),8);
32 }
33
34 void XdxfTest::search() {
35     /*test for English-Polish dictionary */
36     XdxfPlugin xdxfPluginB(this);
37 //    xdxfPlugin.setPatch("dict.xdxf");
38
39     Settings *settings=new Settings;
40     settings->setValue("path","dict.xdxf");
41     CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
42     xdxfPlugin->search("wino");
43     QCOMPARE(xdxfPlugin->search("."), QString("kropka\n"));
44     QCOMPARE(xdxfPlugin->search("1"), QString("one\n"));
45 }
46
47 void XdxfTest::searchWordList() {
48      /*test for English-Polish dictionary */
49     XdxfPlugin xdxfPluginB(this);
50 //    xdxfPlugin.setPatch("dict.xdxf");
51
52     Settings *settings=new Settings;
53     settings->setValue("path","dict.xdxf");
54     CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
55     QList<Translation*> te=xdxfPlugin->searchWordList(".",10);
56     if(te.size()>0)
57         QCOMPARE(te.at(0)->key(), QString("."));
58     QList<Translation*> te2=xdxfPlugin->searchWordList("1",10);
59     QCOMPARE(te2.size(),5);
60
61     QList<Translation*> te3=xdxfPlugin->searchWordList("1",2);
62     QCOMPARE(te3.size(),2);
63
64     QList<Translation*> te4=xdxfPlugin->searchWordList("ho*SE",10);
65         QCOMPARE(te4.at(0)->key(), QString("house"));
66
67     QList<Translation*> te5=xdxfPlugin->searchWordList("*");
68         QCOMPARE(te5.size(),8);
69
70     QList<Translation*> te6=xdxfPlugin->searchWordList("*",8);
71         QCOMPARE(te6.size(),8);
72
73 }
74
75 void XdxfTest::stop() {
76     /*test for English-Polish dictionary */
77     XdxfPlugin xdxfPluginB(this);
78 //    xdxfPlugin.setPatch("dict.xdxf");
79
80     Settings *settings=new Settings;
81     settings->setValue("path","dict.xdxf");
82     CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
83
84     QString string("*");
85     QFuture<QList<Translation*> > future = QtConcurrent::run(xdxfPlugin, &CommonDictInterface::searchWordList, string, 10);
86     QList<Translation*> te5 = future.result();
87
88     QCOMPARE(te5.size(),8);
89 }
90
91
92 void XdxfTest::langFrom() {
93      /*test for English-Polish dictionary */
94     XdxfPlugin xdxfPluginB(this);
95 //    xdxfPlugin.setPatch("dict.xdxf");
96
97     Settings *settings=new Settings;
98     settings->setValue("path","dict.xdxf");
99     CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
100     xdxfPlugin->searchWordList("rope",10);
101     QCOMPARE(xdxfPlugin->langFrom(), QString("ENG"));
102 }
103
104 QTEST_MAIN(XdxfTest)
105 //#include "testqstring.moc"