From 2020d83089f2f6c7da6d48967dfc937ba6f91b18 Mon Sep 17 00:00:00 2001 From: Bartosz Szatkowski Date: Fri, 8 Oct 2010 13:42:35 +0200 Subject: [PATCH] Added tests for StarDictPlugin --- src/plugins/stardict/StarDictPlugin.cpp | 10 +- src/plugins/stardict/StarDictPlugin.h | 7 +- tests/StarDictPluginTests/StarDictPluginTests.pro | 35 ++++++ tests/StarDictPluginTests/test.cpp | 134 +++++++++++++++++++++ tests/tests.pro | 2 +- 5 files changed, 179 insertions(+), 9 deletions(-) create mode 100644 tests/StarDictPluginTests/StarDictPluginTests.pro create mode 100644 tests/StarDictPluginTests/test.cpp diff --git a/src/plugins/stardict/StarDictPlugin.cpp b/src/plugins/stardict/StarDictPlugin.cpp index 14691e7..af5a0d6 100644 --- a/src/plugins/stardict/StarDictPlugin.cpp +++ b/src/plugins/stardict/StarDictPlugin.cpp @@ -174,7 +174,8 @@ QString StarDictPlugin::interpret(QByteArray::iterator it, int pos=result.indexOf(""); if(pos!=-1) result.remove(pos,4); - result+=""; + if(result.contains("")) + result+=""; } else if(mode == 'y') result += QString::fromUtf8(read(it++, end)); @@ -187,6 +188,7 @@ QString StarDictPlugin::interpret(QByteArray::iterator it, else if(mode == 'r') result += QString::fromUtf8(read(it++, end)); + /* else if(mode == 'W') { if(!last) { QByteArray tmp ; @@ -194,7 +196,7 @@ QString StarDictPlugin::interpret(QByteArray::iterator it, tmp.append(*(it++)); tmp.append(*(it++)); tmp.append(*(it)); - result += read(it++, end, (qint32)qFromBigEndian(tmp.data())); + result += read(it++, end, (qint32)qFromBigEndian(*(qint32*)tmp.data())); } else result += read(it++, end); } else if(mode == 'P') { @@ -204,10 +206,10 @@ QString StarDictPlugin::interpret(QByteArray::iterator it, tmp.append(*(it++)); tmp.append(*(it++)); tmp.append(*(it)); - result += read(it++, end, (qint32)qFromBigEndian(tmp.data())); + result += read(it++, end, (qint32)qFromBigEndian(*(qint32*)tmp.data())); } else result += read(it++, end); - } + } */ return result; } diff --git a/src/plugins/stardict/StarDictPlugin.h b/src/plugins/stardict/StarDictPlugin.h index c8efbae..480370c 100644 --- a/src/plugins/stardict/StarDictPlugin.h +++ b/src/plugins/stardict/StarDictPlugin.h @@ -30,11 +30,8 @@ #include #include #include -#include -#include -#include #include -#include +//#include #include #include #include @@ -209,6 +206,8 @@ private: \return QSting containing interpreted data chunk */ QString interpret(QByteArray::iterator it, QByteArray::iterator end, QChar mode,QString key, bool last = false); + + friend class StarDictTests; }; #endif // XDXFPLUGIN_H diff --git a/tests/StarDictPluginTests/StarDictPluginTests.pro b/tests/StarDictPluginTests/StarDictPluginTests.pro new file mode 100644 index 0000000..dd59d57 --- /dev/null +++ b/tests/StarDictPluginTests/StarDictPluginTests.pro @@ -0,0 +1,35 @@ +###################################################################### +# Automatically generated by qmake (2.01a) pt. pa? 8 12:09:49 2010 +###################################################################### + +CONFIG += qtestlib core gui xml sql +TEMPLATE = app +TARGET = +DEPENDPATH += . +INCLUDEPATH += . + +LIBS += -lz + +# Input +HEADERS += ../../src/plugins/stardict/StarDictPlugin.h \ + ../../src/include/CommonDictInterface.h \ + ../../src/include/translation.h \ + ../../src/include/Notify.h \ + ../../src/include/settings.h \ + ../../src/include/AccentsNormalizer.h \ + ../../src/plugins/stardict/StarDictDialog.h \ + ../../src/include/DictDialog.h \ + ../../src/plugins/stardict/TranslationStarDict.h \ + ../../src/plugins/stardict/StarDictReaderFactory.h \ + ../../src/plugins/stardict/StarDialog.h \ + ../../src/plugins/stardict/CompressedReader.h \ + ../../src/plugins/stardict/UncompressedReader.h \ + ../../src/plugins/stardict/StarDictReader.h +SOURCES += test.cpp \ + ../../src/plugins/stardict/StarDictPlugin.cpp \ + ../../src/plugins/stardict/CompressedReader.cpp \ + ../../src/plugins/stardict/UncompressedReader.cpp \ + ../../src/plugins/stardict/StarDictDialog.cpp \ + ../../src/plugins/stardict/StarDialog.cpp \ + ../../src/plugins/stardict/TranslationStarDict.cpp \ + ../../src/plugins/stardict/StarDictReaderFactory.cpp diff --git a/tests/StarDictPluginTests/test.cpp b/tests/StarDictPluginTests/test.cpp new file mode 100644 index 0000000..f84b41c --- /dev/null +++ b/tests/StarDictPluginTests/test.cpp @@ -0,0 +1,134 @@ +/******************************************************************************* + + This file is part of mDictionary. + + mDictionary is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + mDictionary is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with mDictionary. If not, see . + + Copyright 2010 Comarch S.A. + +*******************************************************************************/ + +#include +#include +#include +#include "../../src/plugins/stardict/StarDictPlugin.h" +#include +#include +#include + + class StarDictTests: public QObject + { + Q_OBJECT + + private slots: + void readTest_till0(); + void readTest_bytes(); + void interpretTest(); + }; + + + +void StarDictTests::readTest_till0() { + StarDictPlugin plug; + QList data; + data << "asdf\0" << "\0" << "a\0a\0" << "" << "asdf" << "╖\0" << "aᑇo\0"; + QList expected; + expected << "asdf" << "" << "a" << "" << "asdf" << "╖" << "aᑇo"; + QListIterator itData(data), itExpected(expected); + + while(itData.hasNext()) { + QByteArray tmp = itData.next(); + QCOMPARE(itExpected.next(), plug.read(tmp.begin(), tmp.end(), 0)); + } + + +} + +void StarDictTests::readTest_bytes() { + StarDictPlugin plug; + QList data; + data << "asdf\0" << "\0" << "a\0a\0" << "" << "asdf" << "╖\0" << "aᑇo\0"; + QList expected; + expected << "asdf" << "" << "a" << "" << "asdf" << "╖" << "aᑇo"; + QListIterator itData(data), itExpected(expected); + + while(itData.hasNext()) { + QByteArray tmp = itData.next(); + QByteArray exp = itExpected.next(); + QCOMPARE(exp, plug.read(tmp.begin(), tmp.end(), exp.length())); + } + +} + + +void StarDictTests::interpretTest() { + StarDictPlugin plug; + QList data; + data << "asdf\0" << "\0" << "aᑇo\0" << "asdf⍕ᑘቖፔ\0asd" + << "asdf⍕ᑘቖፔ"; + QList modes; + + //Test transparent modes + modes.clear(); + modes << 'm' << 'l' << 't' << 'y' << 'k' << 'w' << 'h' << 'r'; + QList expected; + expected << "asdf" << "" << "aᑇo" << "asdf⍕ᑘቖፔ" + << "asdf⍕ᑘቖፔ"; + foreach(QChar mode, modes) { + QListIterator itData(data), itExpected(expected); + while(itData.hasNext()) { + QByteArray tmp = itData.next(); + QByteArray exp = itExpected.next(); + QCOMPARE(QString::fromUtf8(exp), plug.interpret(tmp.begin(), tmp.end(), + mode, "key", false)); + } + } + + + //Test pango + expected.clear(); + expected << "asdf" << "" << "aᑇo" << "asdf⍕ᑘቖፔ" + << "asdf⍕ᑘቖፔ"; + QListIterator itData = QListIterator(data); + QListIterator itExpected = QListIterator(expected); + while(itData.hasNext()) { + QByteArray tmp = itData.next(); + QByteArray exp = itExpected.next(); + QCOMPARE("key" + QString::fromUtf8(exp), + plug.interpret(tmp.begin(), tmp.end(), + 'g', "key", false)); + } + + + //Test xdxf + expected.clear(); + expected << "asdf" << "" << "aᑇo" + << "asdf⍕ᑘቖፔ" + << "asdf⍕ᑘቖፔ"; + itData = QListIterator(data); + itExpected = QListIterator(expected); + while(itData.hasNext()) { + QByteArray tmp = itData.next(); + QByteArray exp = itExpected.next(); + QCOMPARE(QString::fromUtf8(exp), + plug.interpret(tmp.begin(), tmp.end(), + 'x', "key", false)); + } + + +} + + +QTEST_MAIN(StarDictTests) +#include "test.moc" diff --git a/tests/tests.pro b/tests/tests.pro index 0acde8b..8c5a289 100644 --- a/tests/tests.pro +++ b/tests/tests.pro @@ -1,5 +1,5 @@ TEMPLATE = subdirs -SUBDIRS = mDictionaryTests GooglePluginTests XdxfPluginTests +SUBDIRS = mDictionaryTests GooglePluginTests XdxfPluginTests StarDictPluginTests check.CONFIG = recursive check.recurse = mDictionaryTests GooglePluginTests XdxfPluginTests -- 1.7.9.5