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