diff --git a/tests/plugins/CMakeLists.txt b/tests/plugins/CMakeLists.txt index 542353408..077a96df2 100755 --- a/tests/plugins/CMakeLists.txt +++ b/tests/plugins/CMakeLists.txt @@ -1 +1,3 @@ add_subdirectory(texteffect) +add_subdirectory(autoreplace) + diff --git a/tests/plugins/autoreplace/CMakeLists.txt b/tests/plugins/autoreplace/CMakeLists.txt new file mode 100644 index 000000000..2b540f79f --- /dev/null +++ b/tests/plugins/autoreplace/CMakeLists.txt @@ -0,0 +1,20 @@ +include_directories( + ${KOPETE_INCLUDES} + ${CMAKE_SOURCE_DIR}/plugins/autoreplace +) + +set( + kopete_autoreplace_test_PART_SRCS + ${CMAKE_SOURCE_DIR}/plugins/autoreplace/autoreplaceplugin.cpp + ${CMAKE_SOURCE_DIR}/plugins/autoreplace/autoreplaceconfig.cpp + kopeteautoreplaceplugintest.cpp +) + +set( KOPETE_TEST_LIBRARIES + kopete + Qt5::Test + KF5::KIOCore +) + +ecm_add_test(${kopete_autoreplace_test_PART_SRCS} TEST_NAME autoreplacetest LINK_LIBRARIES ${KOPETE_TEST_LIBRARIES}) + diff --git a/tests/plugins/autoreplace/kopeteautoreplaceplugintest.cpp b/tests/plugins/autoreplace/kopeteautoreplaceplugintest.cpp new file mode 100644 index 000000000..8c157a919 --- /dev/null +++ b/tests/plugins/autoreplace/kopeteautoreplaceplugintest.cpp @@ -0,0 +1,84 @@ +/* + Tests for Kopete AutoReplace Plugin + + Copyright (c) 2017 by Vijay Krishnavanshi + + Kopete (c) 2002-2017 by the Kopete developers + + ************************************************************************* + * * + * This program 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 2 of the License, or * + * (at your option) any later version. * + * * + ************************************************************************* +*/ +#include "kopetechatsessionmanager.h" +#include "kopetemessage.h" +#include "autoreplaceplugin.h" +#include "autoreplaceconfig.h" + +#include +#include +Q_DECLARE_METATYPE(Kopete::Message); + + +class AutoReplacePluginTest : public QObject +{ + Q_OBJECT +private slots: + void testDefaultAutoReplace(); + void testAutoReplaceConfig(); +}; + +void AutoReplacePluginTest::testDefaultAutoReplace() +{ + Kopete::Message msg; + msg.setPlainBody("arent"); + msg.setDirection(Kopete::Message::Outbound); + AutoReplacePlugin *A = new AutoReplacePlugin(nullptr, QVariantList()); + Kopete::ChatSessionManager *csm = Kopete::ChatSessionManager::self(); + QSignalSpy spy(csm, &Kopete::ChatSessionManager::aboutToSend); + QVERIFY(spy.isValid()); + emit csm->aboutToSend(msg); + QCOMPARE(msg.plainBody(), QStringLiteral("are not")); + msg.setPlainBody("u"); + emit csm->aboutToSend(msg); + QCOMPARE(spy.count(), 2); + QCOMPARE(msg.plainBody(), QStringLiteral("you")); + msg.setPlainBody("r"); + emit csm->aboutToSend(msg); + QCOMPARE(spy.count(), 3); + QCOMPARE(msg.plainBody(), QStringLiteral("are")); + msg.setPlainBody("ur"); + emit csm->aboutToSend(msg); + QCOMPARE(spy.count(), 4); + QCOMPARE(msg.plainBody(), QStringLiteral("your")); + Q_UNUSED(A); +} + +void AutoReplacePluginTest::testAutoReplaceConfig() +{ + AutoReplaceConfig *config = new AutoReplaceConfig(); + QVERIFY(!config->autoReplaceIncoming()); + QVERIFY(config->autoReplaceOutgoing()); + QVERIFY(!config->dotEndSentence()); + QVERIFY(!config->capitalizeBeginningSentence()); + config->setAutoReplaceIncoming(true); + QVERIFY(config->autoReplaceIncoming()); + config->setDotEndSentence(true); + QVERIFY(config->dotEndSentence()); + config->setCapitalizeBeginningSentence(true); + QVERIFY(config->capitalizeBeginningSentence()); + AutoReplaceConfig::WordsToReplace map = config->map(); + const QString value = QStringLiteral("Hello Auto Replace Plugin"); + const QString key = QStringLiteral("Are not."); + map[key] = value; + config->setMap(map); + AutoReplaceConfig::WordsToReplace newMap = config->map(); + QCOMPARE(newMap[key], map[key]); +} + +QTEST_MAIN(AutoReplacePluginTest) +#include "kopeteautoreplaceplugintest.moc"