1 /*******************************************************************************
3 This file is part of mDictionary.
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.
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.
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/>.
18 Copyright 2010 Comarch S.A.
20 *******************************************************************************/
22 #include <QtTest/QtTest>
25 #include "../../src/plugins/stardict/StarDictPlugin.h"
30 class StarDictTests: public QObject
35 void readTest_till0();
36 void readTest_bytes();
42 void StarDictTests::readTest_till0() {
44 QList<QByteArray> data;
45 data << "asdf\0" << "\0" << "a\0a\0" << "" << "asdf" << "╖\0" << "aᑇo\0";
46 QList<QByteArray> expected;
47 expected << "asdf" << "" << "a" << "" << "asdf" << "╖" << "aᑇo";
48 QListIterator<QByteArray> itData(data), itExpected(expected);
50 while(itData.hasNext()) {
51 QByteArray tmp = itData.next();
52 QCOMPARE(itExpected.next(), plug.read(tmp.begin(), tmp.end(), 0));
58 void StarDictTests::readTest_bytes() {
60 QList<QByteArray> data;
61 data << "asdf\0" << "\0" << "a\0a\0" << "" << "asdf" << "╖\0" << "aᑇo\0";
62 QList<QByteArray> expected;
63 expected << "asdf" << "" << "a" << "" << "asdf" << "╖" << "aᑇo";
64 QListIterator<QByteArray> itData(data), itExpected(expected);
66 while(itData.hasNext()) {
67 QByteArray tmp = itData.next();
68 QByteArray exp = itExpected.next();
69 QCOMPARE(exp, plug.read(tmp.begin(), tmp.end(), exp.length()));
75 void StarDictTests::interpretTest() {
77 QList<QByteArray> data;
78 data << "<k>a</k>sdf\0" << "\0" << "aᑇo\0" << "<k>asdf⍕ᑘቖፔ</k>\0asd"
82 //Test transparent modes
84 modes << 'm' << 'l' << 't' << 'y' << 'k' << 'w' << 'h' << 'r';
85 QList<QByteArray> expected;
86 expected << "<k>a</k>sdf" << "" << "aᑇo" << "<k>asdf⍕ᑘቖፔ</k>"
88 foreach(QChar mode, modes) {
89 QListIterator<QByteArray> itData(data), itExpected(expected);
90 while(itData.hasNext()) {
91 QByteArray tmp = itData.next();
92 QByteArray exp = itExpected.next();
93 QCOMPARE(QString::fromUtf8(exp), plug.interpret(tmp.begin(), tmp.end(),
101 expected << "<k>a</k>sdf" << "" << "aᑇo" << "<k>asdf⍕ᑘቖፔ</k>"
102 << "<k>asdf⍕ᑘቖፔ</k>";
103 QListIterator<QByteArray> itData = QListIterator<QByteArray>(data);
104 QListIterator<QByteArray> itExpected = QListIterator<QByteArray>(expected);
105 while(itData.hasNext()) {
106 QByteArray tmp = itData.next();
107 QByteArray exp = itExpected.next();
108 QCOMPARE("<key>key</key>" + QString::fromUtf8(exp),
109 plug.interpret(tmp.begin(), tmp.end(),
116 expected << "<key>a</key><t>sdf</t>" << "" << "aᑇo"
117 << "<key>asdf⍕ᑘቖፔ</key><t></t>"
118 << "<key>asdf⍕ᑘቖፔ</key><t></t>";
119 itData = QListIterator<QByteArray>(data);
120 itExpected = QListIterator<QByteArray>(expected);
121 while(itData.hasNext()) {
122 QByteArray tmp = itData.next();
123 QByteArray exp = itExpected.next();
124 QCOMPARE(QString::fromUtf8(exp),
125 plug.interpret(tmp.begin(), tmp.end(),
133 QTEST_MAIN(StarDictTests)