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

Added tests for libkopete covering classes - kopetestatusmessage and kopetetasks

parent e1ea145f
......@@ -104,6 +104,7 @@ void LatexPlugin::slotMessageAboutToShow(Kopete::Message &msg)
QString messageText = msg.plainBody();
if (!messageText.contains(QLatin1String("$$"))) {
// return when no latex strings found
return;
}
......
......@@ -7,3 +7,5 @@ set( KOPETE_TEST_LIBRARIES
KF5::KIOCore
kopete
)
ecm_add_test(kopetetasktest.cpp LINK_LIBRARIES ${KOPETE_TEST_LIBRARIES})
ecm_add_test(kopetestatusmessagetest.cpp LINK_LIBRARIES ${KOPETE_TEST_LIBRARIES})
/*
Tests for Kopete::StatusMessage
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 "kopetestatusmessage.h"
#include <QObject>
#include <QtTest>
class StatusMessageTest : public QObject
{
Q_OBJECT
private slots:
void testStatus();
void testConstructors();
void testStatusMetaData();
void testStatusHash();
void testEmptyStatus();
};
void StatusMessageTest::testStatus()
{
const QString str = QStringLiteral("given we are here this should work");
Kopete::StatusMessage status(str);
status.setMessage(str);
QCOMPARE(status.message(), str);
}
void StatusMessageTest::testConstructors()
{
const QString str = QStringLiteral("Hello");
Kopete::StatusMessage statusD(str);
Kopete::StatusMessage statusP;
statusP.setMessage(str);
QCOMPARE(statusD.message(), statusP.message());
}
void StatusMessageTest::testStatusMetaData()
{
const QString sname = QStringLiteral("Coldplay - Paradise");
const QString smplayer = QStringLiteral("VLC");
const QString sartist = QStringLiteral("ColdPlay");
const QString stitle = QStringLiteral("Paradise");
Kopete::StatusMessage status(sname);
status.addMetaData(QStringLiteral("MusicPlayer"), smplayer);
status.addMetaData(QStringLiteral("artist"), sartist);
status.addMetaData(QStringLiteral("title"), stitle);
QVERIFY(status.hasMetaData("sadhgsadf") == false);
QCOMPARE(status.hasMetaData("artist") , true);
QCOMPARE(status.metaData("MusicPlayer").toString(), smplayer);
QCOMPARE(status.metaData("artist").toString(), sartist);
QCOMPARE(status.metaData("title").toString(), stitle);
QCOMPARE(status.message(), sname);
}
void StatusMessageTest::testStatusHash()
{
const QString sname = QStringLiteral("Coldplay - Paradise");
const QString smplayer = QStringLiteral("VLC");
const QString sartist = QStringLiteral("ColdPlay");
const QString stitle = QStringLiteral("Paradise");
const QString salbum = QStringLiteral("Unknown");
Kopete::StatusMessage status(sname);
status.addMetaData(QStringLiteral("MusicPlayer"), smplayer);
status.addMetaData(QStringLiteral("artist"), sartist);
status.addMetaData(QStringLiteral("title"), stitle);
status.addMetaData(QStringLiteral("album"), salbum);
QCOMPARE(status.metaData("artist").toString(), sartist);
QCOMPARE(status.metaData("title").toString(), stitle);
QHash<QString, QVariant> metaDataHash;
metaDataHash.insert(QStringLiteral("artist"), QStringLiteral("Chris Martin"));
metaDataHash.insert(QStringLiteral("title"), QStringLiteral("Undefined"));
status.addMetaData(metaDataHash);
QCOMPARE(status.metaData("artist").toString(), QStringLiteral("Chris Martin"));
QCOMPARE(status.metaData("title").toString(), QStringLiteral("Undefined"));
QCOMPARE(status.metaData("album").toString(), salbum);
}
void StatusMessageTest::testEmptyStatus()
{
Kopete::StatusMessage status;
QCOMPARE(status.isEmpty(), true);
}
QTEST_MAIN(StatusMessageTest)
#include "kopetestatusmessagetest.moc"
/*
Tests for Kopete::Task
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 <QObject>
#include <QtTest>
#include <QSignalSpy>
#include <QTimer>
#include <kopetetask.h>
#include <kopeteemoticons.h>
class ParseEmoticonTask : public Kopete::Task
{
Q_OBJECT
public:
ParseEmoticonTask(const QString &sourceString);
QString parseResult() const
{
return m_parsed;
}
private slots:
void start();
private:
void parseEmoticon(const QString &value);
QString m_source;
QString m_parsed;
};
class KopeteTaskTest : public QObject
{
Q_OBJECT
private slots:
void testEmoticonTask();
};
const QString sampleString = QString("Sample string :) :D ;)");
ParseEmoticonTask::ParseEmoticonTask(const QString &sourceString)
: Kopete::Task(), m_source(sourceString)
{
QTimer::singleShot(0, this, &ParseEmoticonTask::start);
}
void ParseEmoticonTask::start()
{
parseEmoticon(m_source);
}
void ParseEmoticonTask::parseEmoticon(const QString &value)
{
m_parsed = Kopete::Emoticons::parseEmoticons(value, KEmoticonsTheme::RelaxedParse | KEmoticonsTheme::SkipHTML);
if (m_parsed.isEmpty()) {
setError(100);
}
emitResult();
}
void KopeteTaskTest::testEmoticonTask()
{
ParseEmoticonTask *task = new ParseEmoticonTask(sampleString);
QSignalSpy spy(task, SIGNAL(result(KJob*)));
// For the task to execute, we must manually call the event loop.
qApp->processEvents();
QCOMPARE(spy.count(), 1);
QCOMPARE(task->error(), 0);
}
QTEST_MAIN(KopeteTaskTest)
#include "kopetetasktest.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