refaktoring
[mdictionary] / tests / GooglePluginTests / 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 GoogleTest::jsonParse() {
26
27     GooglePlugin plugin;
28     QString test1("[[[\"kot\",\"cat\",\"\"]],[[\"rzeczownik\",[\"kot\",\"kotka\",\"kociątko\",\"złośliwa kobieta\"]],[\"czasownik\",[\"podnieść\"]]],\"en\"]");
29     QString test2("[[[\"Go! \",\"go!\",\"\"],[\"wyjechać\",\"go away\",\"\"]],[[\"czasownik\",[\"wyjechać\",\"odchodzić\",\"zgrzeszyć\"]],[\"wykrzyknik\",[\"Odejdź\"]]],\"en\"]");
30     QString test3("");
31     QString test4("");
32     QString test5("");
33
34     QCOMPARE(plugin.jsonParse(test1),QString("kot<br/><pos>rzeczownik</pos>: kot, kotka, kociątko, złośliwa kobieta<br/><pos>czasownik</pos>: podnieść"));
35     QCOMPARE(plugin.jsonParse(test2),QString("Go! wyjechać<br/><pos>czasownik</pos>: wyjechać, odchodzić, zgrzeszyć<br/><pos>wykrzyknik</pos>: Odejdź"));
36 }
37
38
39 void GoogleTest::getDictionaryInfo() {
40     GooglePlugin plugin;
41     plugin.setLangFrom("pl");
42     plugin.setLangTo("en");
43     plugin.getDictionaryInfo();
44
45     QCOMPARE(plugin.infoNote(),QString(" [Polish-English] " ));
46 }
47
48 void GoogleTest::langFrom() {
49     GooglePlugin plugin;
50     Settings *settings=new Settings;
51     settings->setValue("lang_to","pl");
52     settings->setValue("lang_from","en");
53     plugin.setSettings(settings);
54     delete settings;
55
56     QCOMPARE(plugin.langFrom(),QString("English"));
57     QCOMPARE(plugin.langTo(),QString("Polish"));
58     QCOMPARE(plugin.type(),QString("google"));
59 }
60
61 void GoogleTest::getNew() {
62     GooglePlugin plugin;
63     Settings *settings=new Settings;
64     settings->setValue("lang_to","pl");
65     settings->setValue("lang_from","en");
66     CommonDictInterface *test=plugin.getNew(settings);
67     delete settings;
68
69     QCOMPARE(test->langFrom(),QString("English"));
70     QCOMPARE(test->langTo(),QString("Polish"));
71     QCOMPARE(test->type(),QString("google"));
72
73     delete test;
74 }
75
76 QTEST_MAIN(GoogleTest)