Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 46977c08 authored by Vijay Krishnavanshi's avatar Vijay Krishnavanshi Committed by Pali Rohár

Autotests for text effect plugin

parent 7a48c8e0
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)
......
......@@ -19,7 +19,6 @@
#include <stdlib.h>
#include "plugin_texteffect_debug.h"
#include <kpluginfactory.h>
#include <QColor>
......@@ -42,9 +41,8 @@ TextEffectPlugin::TextEffectPlugin(QObject *parent, const QVariantList & /*args*
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;
}
......
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})
/*
Tests for Kopete TextEffect Plugin
Copyright (c) 2017 by Vijay Krishnavanshi <vijaykrishnavashi>
Kopete (c) 2002-2017 by the Kopete developers <kopete-devel@kde.org>
*************************************************************************
* *
* 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 <KSharedConfig>
#include <KConfigGroup>
#include <QObject>
#include <QtTest>
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<QString>("messageTest");
QTest::addColumn<QString>("colorExpected");
QTest::addColumn<Kopete::Message::MessageDirection>("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<QString>("messageTest");
QTest::addColumn<QString>("messageExpected");
QTest::addColumn<Kopete::Message::MessageDirection>("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"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment