diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index eb044a81b..9b111d13d 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -1,78 +1,78 @@ -option(WITH_latex "Enable Kopete latex plugin" ON) -option(WITH_autoreplace "Enable Kopete autoreplace plugin" ON) +option(WITH_latex "Enable Kopete latex plugin" OFF) # to be fixed or rewritten +option(WITH_autoreplace "Enable Kopete autoreplace plugin" ON) option(WITH_history "Enable Kopete history plugin" OFF) # To be re-written option(WITH_history2 "Enable Kopete history2 plugin" OFF) # To be re-written option(WITH_contactnotes "Enable Kopete contactnotes plugin" ON) option(WITH_translator "Enable Kopete translator plugin" OFF) option(WITH_nowlistening "Enable Kopete nowlistening plugin" OFF) option(WITH_texteffect "Enable Kopete texteffect plugin" ON) option(WITH_highlight "Enable Kopete highlight plugin" ON) option(WITH_alias "Enable Kopete alias plugin" OFF) # Disabled because someone thought it does nothing :P option(WITH_addbookmarks "Enable Kopete addbookmarks plugin" ON) option(WITH_privacy "Enable Kopete privacy plugin" ON) option(WITH_urlpicpreview "Enable Kopete urlpicpreview plugin" ON) option(WITH_statistics "Enable Kopete statistics plugin" ON) option(WITH_webpresence "Enable Kopete webpresence plugin" ON) option(WITH_pipes "Enable Kopete pipes plugin" OFF) option(WITH_otr "Enable Kopete Off-the-Record plugin" ON) option(WITH_cryptography "Enable Kopete Cryptography plugin" OFF) # To be re-written # Laurent this plugins use shell script which will not work on windows if (WITH_latex AND UNIX) add_subdirectory( latex ) endif() if (WITH_autoreplace) add_subdirectory( autoreplace ) endif() if (WITH_history) add_subdirectory( history ) endif() if (WITH_history2) add_subdirectory( history2 ) endif() if (WITH_contactnotes) add_subdirectory( contactnotes ) endif() if (WITH_translator) add_subdirectory( translator ) endif() if (WITH_nowlistening) add_subdirectory( nowlistening ) endif() if (WITH_texteffect) add_subdirectory( texteffect ) endif() if (WITH_highlight) add_subdirectory( highlight ) endif() if (WITH_alias) add_subdirectory( alias ) endif() if (WITH_addbookmarks) add_subdirectory( addbookmarks ) endif() if(NOT MSVC) if (WITH_privacy) add_subdirectory( privacy ) endif() else() message(STATUS "disabled privacy plugin because some KGenericFactory<> template won't compile") endif() if (WITH_urlpicpreview) add_subdirectory( urlpicpreview ) endif() if (WITH_statistics AND SQLITE_FOUND) add_subdirectory ( statistics ) endif() if(WITH_pipes) add_subdirectory ( pipes ) endif() if(WITH_webpresence AND LIBXML2_FOUND AND LIBXSLT_FOUND) add_subdirectory( webpresence ) endif() if (WITH_otr AND LIBOTR_FOUND) add_subdirectory ( otr ) endif() if (WITH_cryptography AND QGpgme_FOUND) add_subdirectory ( cryptography ) endif() diff --git a/plugins/texteffect/texteffectplugin.cpp b/plugins/texteffect/texteffectplugin.cpp index 53c256e14..a41f3ec12 100644 --- a/plugins/texteffect/texteffectplugin.cpp +++ b/plugins/texteffect/texteffectplugin.cpp @@ -1,187 +1,185 @@ /* texteffectplugin.cpp - description Copyright (c) 2002 by Olivier Goffart Kopete (c) 2002-2007 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 "texteffectplugin.h" #include -#include "plugin_texteffect_debug.h" #include #include #include "kopetechatsessionmanager.h" #include "texteffectconfig.h" K_PLUGIN_FACTORY(TextEffectPluginFactory, registerPlugin(); ) TextEffectPlugin::TextEffectPlugin(QObject *parent, const QVariantList & /*args*/) : Kopete::Plugin(parent) { if (!pluginStatic_) { pluginStatic_ = this; } m_config = new TextEffectConfig; m_config->load(); connect(this, SIGNAL(settingsChanged()), this, SLOT(slotSettingsChanged())); - connect(Kopete::ChatSessionManager::self(), - SIGNAL(aboutToSend(Kopete::Message&)), - SLOT(slotOutgoingMessage(Kopete::Message&))); + connect(Kopete::ChatSessionManager::self(), SIGNAL(aboutToSend(Kopete::Message&)), + this, SLOT(slotOutgoingMessage(Kopete::Message&))); last_color = 0; } TextEffectPlugin::~TextEffectPlugin() { delete m_config; pluginStatic_ = nullptr; } TextEffectPlugin *TextEffectPlugin::plugin() { return pluginStatic_; } TextEffectPlugin *TextEffectPlugin::pluginStatic_ = nullptr; void TextEffectPlugin::slotOutgoingMessage(Kopete::Message &msg) { if (msg.direction() != Kopete::Message::Outbound) { return; } QStringList colors = m_config->colors(); if (m_config->colorChar() || m_config->colorWords() || m_config->lamer() || m_config->waves()) { QString original = msg.plainBody(); QString resultat; int c = 0; bool wavein = false; for (int f = 0; f < original.length(); f++) { QChar x = original[f]; if (f == 0 || m_config->colorChar() || (m_config->colorWords() && x == ' ')) { if (f != 0) { resultat += QLatin1String(""); } resultat += QLatin1String("colorRandom()) { c = rand()%colors.count(); } else { c++; if (c >= colors.count()) { c = 0; } } resultat += QLatin1String("\">"); } switch (x.toLatin1()) { case '>': resultat += QLatin1String(">"); break; case '<': resultat += QLatin1String("<"); break; case '&': resultat += QLatin1String("&"); break; case '\n': resultat += QLatin1String("
"); case 'a': case 'A': if (m_config->lamer()) { resultat += '4'; break; } //else, go to the default, all other case have this check case 'e': case 'E': if (m_config->lamer()) { resultat += '3'; break; } //else, go to the default, all other case have this check case 'i': case 'I': if (m_config->lamer()) { resultat += '1'; break; } //else, go to the default, all other case have this check case 'l': case 'L': if (m_config->lamer()) { resultat += '|'; break; } //else, go to the default, all other case have this check case 't': case 'T': if (m_config->lamer()) { resultat += '7'; break; } //else, go to the default, all other case have this check case 's': case 'S': if (m_config->lamer()) { resultat += '5'; break; } //else, go to the default, all other case have this check case 'o': case 'O': if (m_config->lamer()) { resultat += '0'; break; } //else, go to the default, all other case have this check default: if (m_config->waves()) { resultat += wavein ? x.toLower() : x.toUpper(); wavein = !wavein; } else { resultat += x; } break; } } if (m_config->colorChar() || m_config->colorWords()) { resultat += QLatin1String("
"); } msg.setHtmlBody(resultat); } if (m_config->colorLines()) { if (m_config->colorRandom()) { last_color = rand()%colors.count(); } else { last_color++; if (last_color >= colors.count()) { last_color = 0; } } msg.setForegroundColor(QColor(colors[last_color])); } } void TextEffectPlugin::slotSettingsChanged() { m_config->load(); } #include "texteffectplugin.moc" diff --git a/tests/plugins/CMakeLists.txt b/tests/plugins/CMakeLists.txt index e69de29bb..542353408 100755 --- a/tests/plugins/CMakeLists.txt +++ b/tests/plugins/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(texteffect) diff --git a/tests/plugins/texteffect/CMakeLists.txt b/tests/plugins/texteffect/CMakeLists.txt new file mode 100644 index 000000000..e75c00262 --- /dev/null +++ b/tests/plugins/texteffect/CMakeLists.txt @@ -0,0 +1,19 @@ +include_directories( + ${KOPETE_INCLUDES} + ${CMAKE_SOURCE_DIR}/plugins/texteffect +) + +set( + kopete_texteffect_test_PART_SRCS + ${CMAKE_SOURCE_DIR}/plugins/texteffect/texteffectplugin.cpp + ${CMAKE_SOURCE_DIR}/plugins/texteffect/texteffectconfig.cpp + kopetetexteffectplugintest.cpp +) + +set( KOPETE_TEST_LIBRARIES + kopete + Qt5::Test + KF5::KIOCore +) + +ecm_add_test(${kopete_texteffect_test_PART_SRCS} TEST_NAME texteffecttest LINK_LIBRARIES ${KOPETE_TEST_LIBRARIES}) diff --git a/tests/plugins/texteffect/kopetetexteffectplugintest.cpp b/tests/plugins/texteffect/kopetetexteffectplugintest.cpp new file mode 100644 index 000000000..6259dd4c6 --- /dev/null +++ b/tests/plugins/texteffect/kopetetexteffectplugintest.cpp @@ -0,0 +1,127 @@ +/* + Tests for Kopete TextEffect 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 "texteffectplugin.h" +#include "texteffectconfig.h" + +#include +#include +#include +#include +Q_DECLARE_METATYPE(Kopete::Message); +Q_DECLARE_METATYPE(Kopete::Message::MessageDirection); + + +class TextEffectPluginTest : public QObject +{ + Q_OBJECT +private slots: + void testDefaultTextEffect(); + void testTextEffectConfig(); + void testDefaultTextEffect_data(); + void testTextEffectConfig_data(); +}; + +void TextEffectPluginTest::testDefaultTextEffect_data() +{ + QTest::addColumn("messageTest"); + QTest::addColumn("colorExpected"); + QTest::addColumn("direction"); + QTest::newRow("Ideal Outbound Case") << QStringLiteral("a>\n \n") << QStringLiteral("#0088dd") << Kopete::Message::Outbound; + QTest::newRow("Affected Case 1") << QString() << QString("#0088dd") << Kopete::Message::Outbound; + QTest::newRow("Affected Case 2") << QStringLiteral("<") << QStringLiteral("#0088dd") << Kopete::Message::Outbound; + QTest::newRow("Affected Case 3") << QStringLiteral("&") << QStringLiteral("#0088dd") << Kopete::Message::Outbound; + QTest::newRow("Affected Case 4") << QStringLiteral("\n") << QStringLiteral("#0088dd") << Kopete::Message::Outbound; + QTest::newRow("Ideal Inbound Case") << QStringLiteral(">") << QStringLiteral("#000000") << Kopete::Message::Inbound; + QTest::newRow("UnAffected Case 1") << QString() << QString("#000000") << Kopete::Message::Inbound; + QTest::newRow("UnAffected Case 2") << QStringLiteral("<") << QStringLiteral("#000000") << Kopete::Message::Inbound; + QTest::newRow("UnAffected Case 3") << QStringLiteral("&") << QStringLiteral("#000000") << Kopete::Message::Inbound; + QTest::newRow("UnAffected Case 4") << QStringLiteral("\n") << QStringLiteral("#000000") << Kopete::Message::Inbound; +} + +void TextEffectPluginTest::testDefaultTextEffect() +{ + QFETCH(QString, colorExpected); + QFETCH(QString, messageTest); + QFETCH(Kopete::Message::MessageDirection, direction); + + TextEffectPlugin *pulgin = new TextEffectPlugin(nullptr, QVariantList()); + Kopete::ChatSessionManager *csm = Kopete::ChatSessionManager::self(); + QSignalSpy spy(csm, &Kopete::ChatSessionManager::aboutToSend); + TextEffectConfig *config = new TextEffectConfig(); + QStringList colorList = config->defaultColorList(); + Kopete::Message msg; + msg.setPlainBody(messageTest); + msg.setDirection(direction); + emit csm->aboutToSend(msg); + QCOMPARE(msg.foregroundColor().name(QColor::HexRgb), colorExpected); + delete plugin; + delete config; +} + +void TextEffectPluginTest::testTextEffectConfig_data() +{ + QTest::addColumn("messageTest"); + QTest::addColumn("messageExpected"); + QTest::addColumn("direction"); + QTest::newRow("Ideal Outbound Case") << QStringLiteral("asdfghjkl") << QStringLiteral("AsDfGhJkL") << Kopete::Message::Outbound; + QTest::newRow("Affected Case 1") << QString() << QString() << Kopete::Message::Outbound; + QTest::newRow("Affected Case 2") << QStringLiteral("/") << QStringLiteral("/") << Kopete::Message::Outbound; + QTest::newRow("Affected Case 3") << QStringLiteral(".AsDfghjkl") << QStringLiteral(".aSdFgHjKl") << Kopete::Message::Outbound; + QTest::newRow("Affected Case 4") << QStringLiteral("aSdF") << QStringLiteral("AsDf") << Kopete::Message::Outbound; + QTest::newRow("UnAffected Case 1") << QStringLiteral("***") << QStringLiteral("***") << Kopete::Message::Inbound; + QTest::newRow("UnAffected Case 2") << QString() << QString() << Kopete::Message::Inbound; + QTest::newRow("Ideal Outbound Case") << QStringLiteral("rome") << QStringLiteral("rome") << Kopete::Message::Inbound; + QTest::newRow("UnAffected Case 3") << QStringLiteral("123456") << QStringLiteral("123456") << Kopete::Message::Inbound; + QTest::newRow("UnAffected Case 4") << QStringLiteral("/") << QStringLiteral("/") << Kopete::Message::Inbound; +} + +void TextEffectPluginTest::testTextEffectConfig() +{ + QFETCH(QString, messageExpected); + QFETCH(QString, messageTest); + QFETCH(Kopete::Message::MessageDirection, direction); + + TextEffectConfig *config = new TextEffectConfig(); + config->load(); + config->setColorWords(true); + config->save(); + config->setColorWords(false); + config->load(); // value should be overridden + QVERIFY(config->colorWords()); + config->setColorWords(false); // reset as we are going to test waves + config->save(); + TextEffectPlugin *plugin = new TextEffectPlugin(nullptr, QVariantList()); + config->setWaves(true); + config->save(); + plugin->slotSettingsChanged(); + Kopete::ChatSessionManager *csm = Kopete::ChatSessionManager::self(); + Kopete::Message msg; + msg.setPlainBody(messageTest); + msg.setDirection(direction); + emit csm->aboutToSend(msg); + QCOMPARE(msg.plainBody(), messageExpected); + KConfigGroup configr(KSharedConfig::openConfig(), "TextEffect Plugin"); + configr.deleteGroup(); + delete plugin; + delete csm; + delete config; +} + +QTEST_MAIN(TextEffectPluginTest) +#include "kopetetexteffectplugintest.moc"