diff options
author | Teus Benschop <teusjannette@gmail.com> | 2017-10-06 12:24:31 +0200 |
---|---|---|
committer | Teus Benschop <teusjannette@gmail.com> | 2017-10-06 12:24:31 +0200 |
commit | 90d2181239761f8950b95768d3b037843e9e8b50 (patch) | |
tree | 6cc667ab420cc04029de2de7e361d2305e214595 /tests/backend | |
parent | 1ea03c0fce8066c1e22188447b4a6ca4dcef1201 (diff) |
New upstream version 2.11.0
Diffstat (limited to 'tests/backend')
10 files changed, 1027 insertions, 0 deletions
diff --git a/tests/backend/btinstallthread/test_btinstallthread.cpp b/tests/backend/btinstallthread/test_btinstallthread.cpp new file mode 100644 index 0000000..e3289df --- /dev/null +++ b/tests/backend/btinstallthread/test_btinstallthread.cpp @@ -0,0 +1,129 @@ + +#include "test_btinstallthread.h" + +// This class serves 2 purposes. It is a test of the BtInstallThread class. +// It also installs several modules that will be used by other tests. +// It should be the second test ran (after test_btsourcesthread). + +#include <QEventLoop> + +#include <swbuf.h> +#include <stdio.h> + +#include "backend/btinstallbackend.h" +#include "backend/btinstallthread.h" +#include "backend/config/btconfig.h" +#include "backend/managers/cswordbackend.h" +#include "util/btconnect.h" +#include "util/directory.h" + +static QString s_sourceName = "CrossWire"; +static QStringList s_moduleList {"KJV", "KJVA","Scofield", "Josephus", "StrongsGreek" }; + + +class BibleTimeApp +{ +public: + BibleTimeApp() { + } + static void init() { + QVERIFY(BtConfig::initBtConfig() == + BtConfig::INIT_OK); + } +private: +}; + + +static bool installPathIsUsable(QString const & path) { + if (path.isEmpty()) + return false; + QDir const dir(path); + if (!dir.exists() || !dir.isReadable()) + return false; + return QFileInfo(dir.canonicalPath()).isWritable(); +} + + +void test_BtInstallThread::initTestCase() { + initBackend(); + getInstallPath(); + removeModulesIfInstalled(); + findModulesToInstall(); +} + +void test_BtInstallThread::initBackend() { + QVERIFY(util::directory::initDirectoryCache()); + CSwordBackend* backend = CSwordBackend::createInstance(); + QVERIFY(backend != 0); + BibleTimeApp::init(); + backend->initModules(CSwordBackend::OtherChange); +} + +void test_BtInstallThread::getInstallPath() { + QStringList const targets(BtInstallBackend::targetList()); + for (auto const & target : targets) { + if (installPathIsUsable(target)) { + m_destination = target; + break; + } + } +} + +void test_BtInstallThread::findModulesToInstall() { + sword::InstallSource const source = BtInstallBackend::source(s_sourceName); + CSwordBackend * const installBackend = BtInstallBackend::backend(source); + + for (auto moduleName : s_moduleList) { + CSwordModuleInfo * module = installBackend->findModuleByName(moduleName); + QVERIFY(module != 0); + module->setProperty("installSourceName", s_sourceName); + m_modules.append(module); + } +} + +void test_BtInstallThread::removeModulesIfInstalled() { + QList<CSwordModuleInfo *> modules; + for (auto moduleName : s_moduleList) { + CSwordModuleInfo * module = CSwordBackend::instance()->findModuleByName(moduleName); + if (module) { + modules.append(module); + } + } + BtConstModuleSet moduleSet = modules.toSet(); + CSwordBackend::instance()->uninstallModules(moduleSet); +} + + +void test_BtInstallThread::installModules() { + m_thread = new BtInstallThread(m_modules, m_destination, this); + + BT_CONNECT(m_thread, &BtInstallThread::installCompleted, + this, &test_BtInstallThread::slotOneItemCompleted); + BT_CONNECT(m_thread, &BtInstallThread::finished, + this, &test_BtInstallThread::slotThreadFinished); + + m_thread->start(); + m_eventLoop = new QEventLoop(this); + m_eventLoop->exec(); +} + +void test_BtInstallThread::slotOneItemCompleted( + int moduleIndex, + bool successful) { + CSwordModuleInfo * module = m_modules.at(moduleIndex); + QString moduleName = module->name(); + fprintf(stderr, " Installing %s\n", + moduleName.toLocal8Bit().constData()); + QVERIFY(successful); +} + +void test_BtInstallThread::slotThreadFinished() { + m_eventLoop->exit(); +} + +void test_BtInstallThread::cleanupTestCase() { + CSwordBackend::destroyInstance(); + QVERIFY(CSwordBackend::instance() == 0); +} + +QTEST_MAIN(test_BtInstallThread) diff --git a/tests/backend/btinstallthread/test_btinstallthread.h b/tests/backend/btinstallthread/test_btinstallthread.h new file mode 100644 index 0000000..0471c6e --- /dev/null +++ b/tests/backend/btinstallthread/test_btinstallthread.h @@ -0,0 +1,32 @@ +#include <QtTest/QtTest> +#include <QString> + +class BtInstallThread; +class CSwordModuleInfo; +class QEventLoop; + +class test_BtInstallThread : public QObject +{ + Q_OBJECT + +public slots: + void slotOneItemCompleted(int moduleIndex, bool successful); + void slotThreadFinished(); + +private slots: + void initTestCase(); + void installModules(); + void cleanupTestCase(); + +private: + void initBackend(); + void getInstallPath(); + void removeModulesIfInstalled(); + void findModulesToInstall(); + + BtInstallThread * m_thread; + QEventLoop * m_eventLoop; + QList<CSwordModuleInfo *> m_modules; + QString m_destination; +}; + diff --git a/tests/backend/btsourcesthread/test_btsourcesthread.cpp b/tests/backend/btsourcesthread/test_btsourcesthread.cpp new file mode 100644 index 0000000..9c9ed63 --- /dev/null +++ b/tests/backend/btsourcesthread/test_btsourcesthread.cpp @@ -0,0 +1,84 @@ + +#include "test_btsourcesthread.h" + +// This class serves 2 purposes. It is a test of the BtSourcesThread class. +// This installs the lists of available modules. +// It should be the first test ran. + +#include <QEventLoop> + +#include <stdio.h> +#include <swbuf.h> + +#include "backend/managers/cswordbackend.h" +#include "backend/config/btconfig.h" +#include "backend/btsourcesthread.h" +#include "util/btconnect.h" +#include "util/directory.h" + +class BibleTimeApp +{ +public: + BibleTimeApp() { + } + static void init() { + QVERIFY(BtConfig::initBtConfig() == + BtConfig::INIT_OK); + } +}; + +void test_BtSourcesThread::initTestCase() { + QVERIFY(util::directory::initDirectoryCache()); + CSwordBackend* backend = CSwordBackend::createInstance(); + QVERIFY(backend != 0); + BibleTimeApp::init(); + backend->initModules(CSwordBackend::OtherChange); +} + +void test_BtSourcesThread::installRemoteSources() { + m_thread = new BtSourcesThread(this); + BT_CONNECT(m_thread, &BtSourcesThread::showMessage, + this, &test_BtSourcesThread::slotShowMessage); + BT_CONNECT(m_thread, &BtSourcesThread::finished, + this, &test_BtSourcesThread::slotThreadFinished); + m_thread->start(); + m_eventLoop = new QEventLoop(this); + m_eventLoop->exec(); +} + +void test_BtSourcesThread::slotThreadFinished() { + m_eventLoop->exit(); +} + +void test_BtSourcesThread::slotShowMessage(const QString & msg) { + fprintf(stderr, " %s\n", msg.toLocal8Bit().constData()); +} + +void test_BtSourcesThread::cleanupTestCase() { + CSwordBackend::destroyInstance(); + QVERIFY(CSwordBackend::instance() == 0); +} + +QTEST_MAIN(test_BtSourcesThread) + + +//void test_BtSourcesThread::loadModule_data() { + +// QTest::addColumn<QString>("moduleName"); + +// QTest::newRow("ref1") << "KJV"; +// QTest::newRow("ref1") << "KJVA"; +//} + +//void test_BtSourcesThread::loadModule() { +// QFETCH(QString, moduleName); + +// CSwordBackend* backend = CSwordBackend::instance(); +// CSwordModuleInfo* module = backend->findModuleByName(moduleName); +// if (module) { +// qDebug() << moduleName << " is already loaded."; +// } else { +// qDebug() << moduleName << " is not loaded."; +// } +//} + diff --git a/tests/backend/btsourcesthread/test_btsourcesthread.h b/tests/backend/btsourcesthread/test_btsourcesthread.h new file mode 100644 index 0000000..48f2316 --- /dev/null +++ b/tests/backend/btsourcesthread/test_btsourcesthread.h @@ -0,0 +1,28 @@ + +#include <QtTest/QtTest> + +class BtSourcesThread; +class QEventLoop; + +class test_BtSourcesThread : public QObject +{ + Q_OBJECT +public: + + // Public slots can be used as part of a test. + // They are not automatically ran. +public slots: + void slotThreadFinished(); + void slotShowMessage(const QString & msg); + + // Private slots are automatically ran as tests. +private slots: + void initTestCase(); + void installRemoteSources(); + void cleanupTestCase(); + +private: + BtSourcesThread * m_thread; + QEventLoop * m_eventLoop; +}; + diff --git a/tests/backend/keys/cswordversekey/test_cswordversekey.cpp b/tests/backend/keys/cswordversekey/test_cswordversekey.cpp new file mode 100644 index 0000000..2f17f0e --- /dev/null +++ b/tests/backend/keys/cswordversekey/test_cswordversekey.cpp @@ -0,0 +1,218 @@ +#include <memory> +#include <QtTest/QtTest> +#include <QSignalSpy> +#include <qdebug.h> +#include <swbuf.h> +#include "test_cswordversekey.h" +#include "backend/managers/cswordbackend.h" +#include "backend/keys/cswordkey.h" +#include "backend/keys/cswordversekey.h" +#include "backend/config/btconfig.h" +#include "util/directory.h" + +class BibleTimeApp +{ +public: + BibleTimeApp() { + } + static void init() { + QVERIFY(BtConfig::initBtConfig() == + BtConfig::INIT_OK); + } + +private: +}; + +void test_CSwordVerseKey::initTestCase() { + QVERIFY(util::directory::initDirectoryCache()); + CSwordBackend* backend = CSwordBackend::createInstance(); + QVERIFY(backend != 0); + BibleTimeApp::init(); + backend->initModules(CSwordBackend::OtherChange); + + m_moduleKJV = backend->findModuleByName("KJV"); + QVERIFY(m_moduleKJV != 0); + m_moduleKJVA = backend->findModuleByName("KJVA"); + QVERIFY(m_moduleKJVA != 0); + m_moduleJosephus = backend->findModuleByName("Josephus"); + QVERIFY(m_moduleKJVA != 0); +} + +void test_CSwordVerseKey::CSwordVerseKey_module_constructor() { + try { + std::unique_ptr<CSwordVerseKey>(new CSwordVerseKey(m_moduleKJVA)); + } + catch (...) { + QFAIL("constructor failed"); + } + + // QUESTION: Should a null module cause a throw? + try { + std::unique_ptr<CSwordVerseKey>(new CSwordVerseKey(nullptr)); + } + catch (...) { + QFAIL("constructor failed"); + } +} + +void test_CSwordVerseKey::CSwordVerseKey_copy_constructor() { + + CSwordVerseKey* key = nullptr; + try { + key = new CSwordVerseKey(m_moduleKJVA); + key->setKey("II Maccabees 15:39"); + } + catch (...) { + QFAIL("constructor failed"); + } + + const CSwordVerseKey* copyKey = new CSwordVerseKey(*key); + QCOMPARE(QString(copyKey->getBookName()), QString(key->getBookName())); + QCOMPARE(QString(copyKey->getChapter()), QString(key->getChapter())); + QCOMPARE(QString(copyKey->getVerse()), QString(key->getVerse())); +} + +void test_CSwordVerseKey::CSwordVerseKey_versekey_module_constructor() { + + CSwordVerseKey* key = nullptr; + try { + key = new CSwordVerseKey(m_moduleKJVA); + key->setKey("Matthew 15:39"); + } + catch (...) { + QFAIL("constructor failed"); + } + + CSwordVerseKey* key2 = nullptr; + try { + key2 = new CSwordVerseKey(key,m_moduleKJV); + key2->setKey("Matthew 15:39"); + } + catch (...) { + QFAIL("constructor failed"); + } + QCOMPARE(QString(key2->getBookName()), QString(key->getBookName())); + QCOMPARE(QString(key2->getChapter()), QString(key->getChapter())); + QCOMPARE(QString(key2->getVerse()), QString(key->getVerse())); + + +} + +void test_CSwordVerseKey::setKey_data() { + QTest::addColumn<QString>("moduleName"); + QTest::addColumn<QString>("reference"); + + QTest::newRow("ref1") << "KJV" << "Genesis 1:1"; + QTest::newRow("ref2") << "KJV" << "Zechariah 13:9"; + QTest::newRow("ref3") << "KJV" << "Matthew 1:1"; + QTest::newRow("ref4") << "KJV" << "Revelation of John 22:21"; + + QTest::newRow("ref1A") << "KJVA" << "Genesis 1:1"; + QTest::newRow("ref2A") << "KJVA" << "Zechariah 13:9"; + QTest::newRow("ref3A") << "KJVA" << "Matthew 1:1"; + QTest::newRow("ref4A") << "KJVA" << "Revelation of John 22:21"; + + QTest::newRow("ref5A") << "KJVA" << "II Esdras 16:78"; +} + + +// Also tests key() +void test_CSwordVerseKey::setKey() { + QFETCH(QString, moduleName); + QFETCH(QString, reference); + + CSwordBackend* backend = CSwordBackend::instance(); + CSwordModuleInfo* module = backend->findModuleByName(moduleName); + QVERIFY(module != 0); + CSwordVerseKey* vKey = dynamic_cast<CSwordVerseKey*>(CSwordKey::createInstance(module)); + + vKey->setKey(reference); + QString newKey = vKey->key(); + QCOMPARE(newKey, reference); +} + + +void test_CSwordVerseKey::next_data() { + QTest::addColumn<QString>("moduleName"); + QTest::addColumn<QString>("reference"); + QTest::addColumn<QString>("reference2"); + + QTest::newRow("r1") << "KJV" << "Genesis 1:1" << "Genesis 1:2"; + QTest::newRow("r2") << "KJV" << "Malachi 4:5" << "Malachi 4:6"; + QTest::newRow("r3") << "KJV" << "Matthew 1:1" << "Matthew 1:2"; + QTest::newRow("r4") << "KJV" << "Revelation of John 22:20" << "Revelation of John 22:21"; +} + +// Does not work correctly over various chapter/book boundaries +// Implementation is in sword. +void test_CSwordVerseKey::next() { + QFETCH(QString, moduleName); + QFETCH(QString, reference); + QFETCH(QString, reference2); + + CSwordBackend* backend = CSwordBackend::instance(); + CSwordModuleInfo* module = backend->findModuleByName(moduleName); + QVERIFY(module != 0); + CSwordVerseKey* vKey = dynamic_cast<CSwordVerseKey*>(CSwordKey::createInstance(module)); + + vKey->setKey(reference); + vKey->next(CSwordVerseKey::UseVerse); + QString newKey = vKey->key(); + QCOMPARE(newKey, reference2); +} + + +void test_CSwordVerseKey::previous_data() { + QTest::addColumn<QString>("moduleName"); + QTest::addColumn<QString>("reference2"); + QTest::addColumn<QString>("reference"); + + QTest::newRow("r1") << "KJVA" << "Genesis 1:1" << "Genesis 1:2"; + QTest::newRow("r2") << "KJVA" << "Malachi 4:5" << "Malachi 4:6"; + QTest::newRow("r3") << "KJVA" << "Matthew 1:1" << "Matthew 1:2"; + QTest::newRow("r4") << "KJVA" << "Revelation of John 22:20" << "Revelation of John 22:21"; +} + +void test_CSwordVerseKey::previous() { + QFETCH(QString, moduleName); + QFETCH(QString, reference); + QFETCH(QString, reference2); + + CSwordBackend* backend = CSwordBackend::instance(); + CSwordModuleInfo* module = backend->findModuleByName(moduleName); + QVERIFY(module != 0); + CSwordVerseKey* vKey = dynamic_cast<CSwordVerseKey*>(CSwordKey::createInstance(module)); + + vKey->setKey(reference); + vKey->previous(CSwordVerseKey::UseVerse); + QString newKey = vKey->key(); + QCOMPARE(newKey, reference2); +} + + +void test_CSwordVerseKey::setModule() { + CSwordVerseKey* vKey = dynamic_cast<CSwordVerseKey*>(CSwordKey::createInstance(m_moduleKJV)); + QVERIFY(vKey != 0); + + QSignalSpy beforeSpy(vKey->beforeChangedSignaller(), SIGNAL(signal())); + QSignalSpy afterSpy(vKey->afterChangedSignaller(), SIGNAL(signal())); + + vKey->setModule(m_moduleKJVA); + + QCOMPARE(beforeSpy.count(), 1); + QCOMPARE(afterSpy.count(), 1); + + const CSwordModuleInfo* module = vKey->module(); + QVERIFY(module != 0); + QCOMPARE(module->name(), QString("KJVA")); +} + + + +void test_CSwordVerseKey::cleanupTestCase() { + CSwordBackend::destroyInstance(); + QVERIFY(CSwordBackend::instance() == 0); +} + +QTEST_MAIN(test_CSwordVerseKey) + diff --git a/tests/backend/keys/cswordversekey/test_cswordversekey.h b/tests/backend/keys/cswordversekey/test_cswordversekey.h new file mode 100644 index 0000000..58af52c --- /dev/null +++ b/tests/backend/keys/cswordversekey/test_cswordversekey.h @@ -0,0 +1,33 @@ +#include <QtTest/QtTest> +#include "backend/keys/cswordversekey.h" + +class test_CSwordVerseKey : public QObject +{ + Q_OBJECT +public: + + +private slots: + void initTestCase(); + + void CSwordVerseKey_module_constructor(); + void CSwordVerseKey_copy_constructor(); + void CSwordVerseKey_versekey_module_constructor(); + + void setKey_data(); + void setKey(); + void next_data(); + void next(); + void previous_data(); + void previous(); + void setModule(); + + void cleanupTestCase(); + +private: + CSwordKey* m_key; + CSwordModuleInfo* m_moduleKJV; + CSwordModuleInfo* m_moduleKJVA; + CSwordModuleInfo* m_moduleJosephus; +}; + diff --git a/tests/backend/managers/cswordbackend/test_cswordbackend.cpp b/tests/backend/managers/cswordbackend/test_cswordbackend.cpp new file mode 100644 index 0000000..566bc02 --- /dev/null +++ b/tests/backend/managers/cswordbackend/test_cswordbackend.cpp @@ -0,0 +1,404 @@ + +#include "test_cswordbackend.h" +#include <QtTest/QtTest> +#include <swbuf.h> +#include "backend/managers/cswordbackend.h" +#include "backend/keys/cswordversekey.h" +#include "backend/config/btconfig.h" +#include "util/directory.h" + +Q_DECLARE_METATYPE(CSwordModuleInfo::FilterTypes) + +class BibleTimeApp { +public: + BibleTimeApp() { + } + static void init() { + QVERIFY(BtConfig::initBtConfig() == + BtConfig::INIT_OK); + } + +private: +}; + +void test_CSwordBackend::initTestCase() { + QVERIFY(util::directory::initDirectoryCache()); + CSwordBackend* backend = CSwordBackend::createInstance(); + QVERIFY(backend != 0); + BibleTimeApp::init(); + backend->initModules(CSwordBackend::OtherChange); +} + +void test_CSwordBackend::instance() { + QVERIFY(CSwordBackend::instance() != 0); +} + +void test_CSwordBackend::moduleList() { + QVERIFY(CSwordBackend::instance()->moduleList().count() > 0); + QVERIFY(CSwordBackend::instance()->moduleList(CSwordModuleInfo::Bible).count() > 0); + QVERIFY(CSwordBackend::instance()->moduleList(CSwordModuleInfo::Commentary).count() > 0); + QVERIFY(CSwordBackend::instance()->moduleList(CSwordModuleInfo::Lexicon).count() > 0); + QVERIFY(CSwordBackend::instance()->moduleList(CSwordModuleInfo::GenericBook).count() > 0); + QVERIFY(CSwordBackend::instance()->moduleList(CSwordModuleInfo::Unknown).count() == 0); +} + +// Should CSwordBackend::shutdownModules be private? + +// This also tests setOption +void test_CSwordBackend::setFilterOptions() { + CSwordBackend* backend = CSwordBackend::instance(); + backend->setFilterOptions(FilterOptions()); + FilterOptions fOpt; + + { + QByteArray optName = backend->optionName(CSwordModuleInfo::footnotes).toUtf8(); + QVERIFY(QString(backend->getGlobalOption(optName.constData())) == "Off"); + + fOpt.footnotes = 1; + backend->setFilterOptions(fOpt); + QVERIFY(QString(backend->getGlobalOption(optName.constData())) == "On"); + + fOpt.footnotes = 0; + backend->setFilterOptions(fOpt); + QVERIFY(QString(backend->getGlobalOption(optName.constData())) == "Off"); + } + + { + QByteArray optName = backend->optionName(CSwordModuleInfo::strongNumbers).toUtf8(); + QVERIFY(QString(backend->getGlobalOption(optName.constData())) == "Off"); + + fOpt.strongNumbers = 1; + backend->setFilterOptions(fOpt); + QVERIFY(QString(backend->getGlobalOption(optName.constData())) == "On"); + + fOpt.strongNumbers = 0; + backend->setFilterOptions(fOpt); + QVERIFY(QString(backend->getGlobalOption(optName.constData())) == "Off"); + } + + { + QByteArray optName = backend->optionName(CSwordModuleInfo::headings).toUtf8(); + QVERIFY(QString(backend->getGlobalOption(optName.constData())) == "Off"); + + fOpt.headings = 1; + backend->setFilterOptions(fOpt); + QVERIFY(QString(backend->getGlobalOption(optName.constData())) == "On"); + + fOpt.headings = 0; + backend->setFilterOptions(fOpt); + QVERIFY(QString(backend->getGlobalOption(optName.constData())) == "Off"); + } + + { + QByteArray optName = backend->optionName(CSwordModuleInfo::morphTags).toUtf8(); + QVERIFY(QString(backend->getGlobalOption(optName.constData())) == "Off"); + + fOpt.morphTags = 1; + backend->setFilterOptions(fOpt); + QVERIFY(QString(backend->getGlobalOption(optName.constData())) == "On"); + + fOpt.morphTags = 0; + backend->setFilterOptions(fOpt); + QVERIFY(QString(backend->getGlobalOption(optName.constData())) == "Off"); + } + + { + QByteArray optName = backend->optionName(CSwordModuleInfo::lemmas).toUtf8(); + QVERIFY(QString(backend->getGlobalOption(optName.constData())) == "Off"); + + fOpt.lemmas = 1; + backend->setFilterOptions(fOpt); + QVERIFY(QString(backend->getGlobalOption(optName.constData())) == "On"); + + fOpt.lemmas = 0; + backend->setFilterOptions(fOpt); + QVERIFY(QString(backend->getGlobalOption(optName.constData())) == "Off"); + } + + { + QByteArray optName = backend->optionName(CSwordModuleInfo::hebrewPoints).toUtf8(); + QVERIFY(QString(backend->getGlobalOption(optName.constData())) == "Off"); + + fOpt.hebrewPoints = 1; + backend->setFilterOptions(fOpt); + QVERIFY(QString(backend->getGlobalOption(optName.constData())) == "On"); + + fOpt.hebrewPoints = 0; + backend->setFilterOptions(fOpt); + QVERIFY(QString(backend->getGlobalOption(optName.constData())) == "Off"); + } + + { + QByteArray optName = backend->optionName(CSwordModuleInfo::hebrewCantillation).toUtf8(); + QVERIFY(QString(backend->getGlobalOption(optName.constData())) == "Off"); + + fOpt.hebrewCantillation = 1; + backend->setFilterOptions(fOpt); + QVERIFY(QString(backend->getGlobalOption(optName.constData())) == "On"); + + fOpt.hebrewCantillation = 0; + backend->setFilterOptions(fOpt); + QVERIFY(QString(backend->getGlobalOption(optName.constData())) == "Off"); + } + + { + QByteArray optName = backend->optionName(CSwordModuleInfo::greekAccents).toUtf8(); + QVERIFY(QString(backend->getGlobalOption(optName.constData())) == "Off"); + + fOpt.greekAccents = 1; + backend->setFilterOptions(fOpt); + QVERIFY(QString(backend->getGlobalOption(optName.constData())) == "On"); + + fOpt.greekAccents = 0; + backend->setFilterOptions(fOpt); + QVERIFY(QString(backend->getGlobalOption(optName.constData())) == "Off"); + } + + { + QByteArray optName = backend->optionName(CSwordModuleInfo::scriptureReferences).toUtf8(); + QVERIFY(QString(backend->getGlobalOption(optName.constData())) == "Off"); + + fOpt.scriptureReferences = 1; + backend->setFilterOptions(fOpt); + QVERIFY(QString(backend->getGlobalOption(optName.constData())) == "On"); + + fOpt.scriptureReferences = 0; + backend->setFilterOptions(fOpt); + QVERIFY(QString(backend->getGlobalOption(optName.constData())) == "Off"); + } + + { + QByteArray optName = backend->optionName(CSwordModuleInfo::redLetterWords).toUtf8(); + QVERIFY(QString(backend->getGlobalOption(optName.constData())) == "Off"); + + fOpt.redLetterWords = 1; + backend->setFilterOptions(fOpt); + QVERIFY(QString(backend->getGlobalOption(optName.constData())) == "On"); + + fOpt.redLetterWords = 0; + backend->setFilterOptions(fOpt); + QVERIFY(QString(backend->getGlobalOption(optName.constData())) == "Off"); + } + + { + QByteArray optName = backend->optionName(CSwordModuleInfo::textualVariants).toUtf8(); + QVERIFY(QString(backend->getGlobalOption(optName.constData())) == "Primary Reading"); + + fOpt.textualVariants = 1; + backend->setFilterOptions(fOpt); + QVERIFY(QString(backend->getGlobalOption(optName.constData())) == "Secondary Reading"); + + fOpt.textualVariants = 0; + backend->setFilterOptions(fOpt); + QVERIFY(QString(backend->getGlobalOption(optName.constData())) == "Primary Reading"); + } + + { + QByteArray optName = backend->optionName(CSwordModuleInfo::morphSegmentation).toUtf8(); + + // Test only if morph option is available + if (backend->getGlobalOption(optName.constData()) != 0) { + + fOpt.morphSegmentation = 1; + backend->setFilterOptions(fOpt); + QCOMPARE(backend->getGlobalOption(optName.constData()), "On"); + + fOpt.morphSegmentation = 0; + backend->setFilterOptions(fOpt); + QCOMPARE(backend->getGlobalOption(optName.constData()), "Off"); + } + } +} + +void test_CSwordBackend::booknameLanguage_data() { + QTest::addColumn<QString>("language"); + QTest::addColumn<QString>("reference"); + QTest::addColumn<QString>("bookName"); + + QTest::newRow("L1") << "en_US" << "John 4:5" << "John"; + QTest::newRow("L2") << "de" << "John 4:5" << "Johannes"; + QTest::newRow("L3") << "en_US" << "Genesis 1:1" << "Genesis"; + QTest::newRow("L4") << "de" << "Genesis 1:1" << "1. Mose"; +} + +void test_CSwordBackend::booknameLanguage() { + QFETCH(QString, language); + QFETCH(QString, reference); + QFETCH(QString, bookName); + + CSwordBackend* backend = CSwordBackend::instance(); + CSwordModuleInfo* module = backend->findModuleByName("KJV"); + QVERIFY(module != 0); + CSwordVerseKey* vKey = dynamic_cast<CSwordVerseKey*>(CSwordKey::createInstance(module)); + + backend->booknameLanguage(language); + vKey->setKey(reference); + QCOMPARE(QString(vKey->getBookName()), bookName); +} + +void test_CSwordBackend::findModuleByDescription() { + CSwordBackend* backend = CSwordBackend::instance(); + QVERIFY(backend->findModuleByDescription("Josephus: The Complete Works") != 0); +} + +void test_CSwordBackend::findModuleByName() { + CSwordBackend* backend = CSwordBackend::instance(); + QVERIFY(backend->findModuleByName("KJV") != 0); + QVERIFY(backend->findModuleByName("KJVA") != 0); + QVERIFY(backend->findModuleByName("Scofield") != 0); + QVERIFY(backend->findModuleByName("Josephus") != 0); + QVERIFY(backend->findModuleByName("StrongsGreek") != 0); + QVERIFY(backend->findModuleByName("ABC") == 0); +} + +void test_CSwordBackend::findModuleByPointer() { + CSwordBackend* backend = CSwordBackend::instance(); + CSwordModuleInfo* module1 = backend->findModuleByName("KJV"); + sword::SWModule& swModule = module1->module(); + + CSwordModuleInfo* module2 = backend->findSwordModuleByPointer(&swModule); + QCOMPARE(module1,module2); +} + +void test_CSwordBackend::getConfig() { + CSwordBackend* backend = CSwordBackend::instance(); + sword::SWConfig* config = backend->getConfig(); + QVERIFY(config != 0); +} + +void test_CSwordBackend::optionName_data() { + QTest::addColumn<CSwordModuleInfo::FilterTypes>("type"); + QTest::addColumn<QString>("name"); + + QTest::newRow("Opt1") << CSwordModuleInfo::footnotes << "Footnotes"; + QTest::newRow("Opt2") << CSwordModuleInfo::filterTypesMIN << "Footnotes"; + QTest::newRow("Opt3") << CSwordModuleInfo::morphSegmentation << "Morph Segmentation"; + QTest::newRow("Opt4") << CSwordModuleInfo::filterTypesMAX << "Morph Segmentation"; +} + +void test_CSwordBackend::optionName() { + QFETCH(QString, name); + QFETCH(CSwordModuleInfo::FilterTypes, type); + + CSwordBackend* backend = CSwordBackend::instance(); + QCOMPARE(backend->optionName(type), name); +} + +void test_CSwordBackend::configOptionName_data() { + QTest::addColumn<CSwordModuleInfo::FilterTypes>("type"); + QTest::addColumn<QString>("name"); + + QTest::newRow("configOpt1") << CSwordModuleInfo::footnotes << "Footnotes"; + QTest::newRow("configOpt2") << CSwordModuleInfo::filterTypesMIN << "Footnotes"; + QTest::newRow("configOpt3") << CSwordModuleInfo::morphSegmentation << "MorphSegmentation"; + QTest::newRow("configOpt4") << CSwordModuleInfo::filterTypesMAX << "MorphSegmentation"; +} + +void test_CSwordBackend::configOptionName() { + QFETCH(QString, name); + QFETCH(CSwordModuleInfo::FilterTypes, type); + + CSwordBackend* backend = CSwordBackend::instance(); + QCOMPARE(backend->configOptionName(type), name); +} + +void test_CSwordBackend::translatedOptionName_data() { + QTest::addColumn<CSwordModuleInfo::FilterTypes>("type"); + QTest::addColumn<QString>("name"); + QTest::addColumn<QString>("transFile"); + + QTest::newRow("transOpt1") << CSwordModuleInfo::footnotes << "Footnotes" << "bibletime_ui_en_US"; + QTest::newRow("transOpt2") << CSwordModuleInfo::filterTypesMIN << "Footnotes" << "bibletime_ui_en_US"; + QTest::newRow("transOpt3") << CSwordModuleInfo::morphSegmentation << "Morph segmentation" << "bibletime_ui_en_US"; + QTest::newRow("transOpt4") << CSwordModuleInfo::filterTypesMAX << "Morph segmentation" << "bibletime_ui_en_US"; + + QTest::newRow("transOpt5") << CSwordModuleInfo::footnotes << "Fu\u00DFnoten" << "bibletime_ui_de"; + QTest::newRow("transOpt6") << CSwordModuleInfo::morphSegmentation << "Morphologische Segmentierung" << "bibletime_ui_de"; +} + +void test_CSwordBackend::translatedOptionName() { + QFETCH(QString, name); + QFETCH(CSwordModuleInfo::FilterTypes, type); + QFETCH(QString, transFile); + + CSwordBackend* backend = CSwordBackend::instance(); + QCoreApplication* app = QCoreApplication::instance(); + QTranslator qtTranslator; + qtTranslator.load(transFile); + app->installTranslator(&qtTranslator); + + QCOMPARE(backend->translatedOptionName(type), name); +} + +#if 0 +// test reloadModules - see takeModulesFromList + +void test_CSwordBackend::takeModulesFromList() { + QStringList modules; + modules << "KJV"; + modules << "abc"; + modules << "KJVA"; + modules << "def"; + + CSwordBackend* backend = CSwordBackend::instance(); + CSwordModuleInfo* kjv = backend->findModuleByName("KJV"); + CSwordModuleInfo* kjva = backend->findModuleByName("KJVA"); + + QList<CSwordModuleInfo*> moduleList = backend->takeModulesFromList(modules); + QVERIFY(moduleList.count() == 2); + QVERIFY(moduleList.contains(kjv)); + QVERIFY(moduleList.contains(kjva)); + + QVERIFY(backend->findModuleByName("KJV") == nullptr); + QVERIFY(backend->findModuleByName("KJVA") == nullptr); + + // Tests reloadModules + backend->reloadModules(CSwordBackend::OtherChange); + QVERIFY(backend->findModuleByName("KJV") != nullptr); + QVERIFY(backend->findModuleByName("KJVA") != nullptr); +} +#endif + +void test_CSwordBackend::getPointerList() { + + CSwordBackend* backend = CSwordBackend::instance(); + CSwordModuleInfo* kjv = backend->findModuleByName("KJV"); + CSwordModuleInfo* kjva = backend->findModuleByName("KJVA"); + + QStringList modules; + modules << "KJV"; + modules << "KJVA"; + + QList<CSwordModuleInfo*> moduleList = backend->getPointerList(modules); + QVERIFY(moduleList.count() == 2); + QVERIFY(moduleList.contains(kjv)); + QVERIFY(moduleList.contains(kjva)); +} + +void test_CSwordBackend::getConstPointerList() { + + CSwordBackend* backend = CSwordBackend::instance(); + CSwordModuleInfo* kjv = backend->findModuleByName("KJV"); + CSwordModuleInfo* kjva = backend->findModuleByName("KJVA"); + + QStringList modules; + modules << "KJV"; + modules << "KJVA"; + + BtConstModuleList moduleList = backend->getConstPointerList(modules); + QVERIFY(moduleList.count() == 2); + QVERIFY(moduleList.contains(kjv)); + QVERIFY(moduleList.contains(kjva)); +} + +// TODO test swordDirList + +// TODO test deleteOrphanedIndices + +void test_CSwordBackend::cleanupTestCase() { + CSwordBackend::destroyInstance(); + QVERIFY(CSwordBackend::instance() == 0); +} + +QTEST_MAIN(test_CSwordBackend) + diff --git a/tests/backend/managers/cswordbackend/test_cswordbackend.h b/tests/backend/managers/cswordbackend/test_cswordbackend.h new file mode 100644 index 0000000..f1685e2 --- /dev/null +++ b/tests/backend/managers/cswordbackend/test_cswordbackend.h @@ -0,0 +1,40 @@ + +#include <QObject> + +class test_CSwordBackend : public QObject { + Q_OBJECT + +private slots: + void initTestCase(); + + void instance(); + void moduleList(); + void setFilterOptions(); + + void booknameLanguage_data(); + void booknameLanguage(); + + void findModuleByDescription(); + void findModuleByName(); + void findModuleByPointer(); + void getConfig(); + + void optionName_data(); + void optionName(); + + void configOptionName_data(); + void configOptionName(); + + void translatedOptionName_data(); + void translatedOptionName(); + +#if 0 + void takeModulesFromList(); +#endif + + void getPointerList(); + void getConstPointerList(); + + void cleanupTestCase(); +}; + diff --git a/tests/backend/models/btlistmodel/test_btlistmodel.cpp b/tests/backend/models/btlistmodel/test_btlistmodel.cpp new file mode 100644 index 0000000..3af5c21 --- /dev/null +++ b/tests/backend/models/btlistmodel/test_btlistmodel.cpp @@ -0,0 +1,45 @@ + +#include "test_btlistmodel.h" +#include "backend/models/btlistmodel.h" +#include <QtTest/QtTest> + +void test_BtListModel::initTestCase() { +} + +void test_BtListModel::appendItem_data() { + QTest::addColumn<bool>("checkable"); + QTest::addColumn<QString>("title1"); + QTest::addColumn<QString>("title2"); + QTest::addColumn<QString>("tip1"); + QTest::addColumn<QString>("tip2"); + QTest::addColumn<int>("columns"); + QTest::newRow("T1") << false << "a" << "b" << "c" << "d" << 1; + QTest::newRow("T2") << false << "a" << "b" << "c" << "d" << 2; + QTest::newRow("T3") << true << "a" << "b" << "c" << "d" << 1; + QTest::newRow("T4") << true << "a" << "b" << "c" << "d" << 2; +} + +void test_BtListModel::appendItem() { + QFETCH(bool, checkable); + QFETCH(QString, title1); + QFETCH(QString, title2); + QFETCH(QString, tip1); + QFETCH(QString, tip2); + QFETCH(int, columns); + + BtListModel model(checkable, this, columns); + QCOMPARE(model.columnCount(), columns); + model.appendItem(title1, tip1); + model.appendItem(title2, tip2); + + QStandardItem* item0 = model.item(0,0); + QCOMPARE(item0->text(), title1); + QCOMPARE(item0->toolTip(),tip1); + QStandardItem* item1 = model.item(1,0); + QCOMPARE(item1->text(), title2); + QCOMPARE(item1->toolTip(),tip2); + QCOMPARE(item0->isCheckable(),checkable); +} + +QTEST_MAIN(test_BtListModel) + diff --git a/tests/backend/models/btlistmodel/test_btlistmodel.h b/tests/backend/models/btlistmodel/test_btlistmodel.h new file mode 100644 index 0000000..cbb14ab --- /dev/null +++ b/tests/backend/models/btlistmodel/test_btlistmodel.h @@ -0,0 +1,14 @@ + +#include <QObject> + +class test_BtListModel : public QObject { + Q_OBJECT + +private slots: + void initTestCase(); + + void appendItem_data(); + void appendItem(); + +}; + |