Commit 4b007c5c authored by Laurent Montel's avatar Laurent Montel 😁

Add more unittest

parent adee5935
......@@ -80,3 +80,8 @@ void ScamAttribute::setIsAScam(bool b)
{
d->isAScam = b;
}
bool ScamAttribute::operator==(const ScamAttribute &other) const
{
return (d->isAScam == other.isAScam());
}
......@@ -38,6 +38,8 @@ public:
bool isAScam() const;
void setIsAScam(bool b);
bool operator==(const ScamAttribute &other) const;
private:
friend class ScamAttributePrivate;
ScamAttributePrivate * const d;
......
......@@ -28,3 +28,8 @@ target_link_libraries(scamdetection_gui
)
set( scamattributetest_source scamattributetest.cpp ../scamattribute.cpp)
kde4_add_unit_test( scamattributetest ${scamattributetest_source})
target_link_libraries( scamattributetest ${QT_QTTEST_LIBRARY} ${KDE4_KDECORE_LIBS} ${QT_QTGUI_LIBRARY} ${KDEPIMLIBS_AKONADI_LIBS})
/*
Copyright (c) 2014 Montel Laurent <montel@kde.org>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#include "scamattributetest.h"
#include "../scamattribute.h"
#include <qtest_kde.h>
ScamAttributeTest::ScamAttributeTest(QObject *parent)
: QObject(parent)
{
}
ScamAttributeTest::~ScamAttributeTest()
{
}
void ScamAttributeTest::shouldHaveDefaultValue()
{
MessageViewer::ScamAttribute attr;
QVERIFY(!attr.isAScam());
}
void ScamAttributeTest::shouldAffectValue()
{
MessageViewer::ScamAttribute attr;
bool isScam = false;
attr.setIsAScam(isScam);
QCOMPARE(attr.isAScam(), isScam);
isScam = true;
attr.setIsAScam(isScam);
QCOMPARE(attr.isAScam(), isScam);
}
void ScamAttributeTest::shouldDeserializeValue()
{
MessageViewer::ScamAttribute attr;
const bool isScam = true;
attr.setIsAScam(isScam);
const QByteArray ba = attr.serialized();
MessageViewer::ScamAttribute result;
result.deserialize(ba);
QVERIFY(result == attr);
}
void ScamAttributeTest::shouldCloneAttribute()
{
MessageViewer::ScamAttribute attr;
const bool isScam = true;
attr.setIsAScam(isScam);
MessageViewer::ScamAttribute *cloneAttr = attr.clone();
QCOMPARE(attr.isAScam(), cloneAttr->isAScam());
delete cloneAttr;
}
QTEST_KDEMAIN(ScamAttributeTest, NoGUI)
/*
Copyright (c) 2014 Montel Laurent <montel@kde.org>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#ifndef SCAMATTRIBUTETEST_H
#define SCAMATTRIBUTETEST_H
#include <QObject>
class ScamAttributeTest : public QObject
{
Q_OBJECT
public:
explicit ScamAttributeTest(QObject *parent = 0);
~ScamAttributeTest();
private Q_SLOTS:
void shouldHaveDefaultValue();
void shouldAffectValue();
void shouldDeserializeValue();
void shouldCloneAttribute();
};
#endif // SCAMATTRIBUTETEST_H
......@@ -64,4 +64,16 @@ void MessageDisplayFormatAttributeTest::shouldChangeMessageFormat()
}
void MessageDisplayFormatAttributeTest::shouldDeserializeValue()
{
MessageViewer::Viewer::DisplayFormatMessage format = MessageViewer::Viewer::Html;
MessageViewer::MessageDisplayFormatAttribute attr;
attr.setMessageFormat(format);
attr.setRemoteContent(true);
const QByteArray ba = attr.serialized();
MessageViewer::MessageDisplayFormatAttribute result;
result.deserialize(ba);
QVERIFY(attr == result);
}
QTEST_KDEMAIN(MessageDisplayFormatAttributeTest, NoGUI)
......@@ -33,7 +33,7 @@ private Q_SLOTS:
void shouldHaveDefaultValue();
void shouldChangeRemoteValue();
void shouldChangeMessageFormat();
void shouldDeserializeValue();
};
#endif // MESSAGEDISPLAYFORMATATTRIBUTETEST_H
......@@ -86,6 +86,11 @@ bool MessageDisplayFormatAttribute::remoteContent() const
return d->remoteContent;
}
bool MessageDisplayFormatAttribute::operator==(const MessageDisplayFormatAttribute &other) const
{
return (d->messageFormat == other.messageFormat()) && (d->remoteContent == other.remoteContent());
}
Viewer::DisplayFormatMessage MessageDisplayFormatAttribute::messageFormat() const
{
return d->messageFormat;
......
......@@ -44,7 +44,7 @@ public:
void setRemoteContent(bool remote);
bool remoteContent() const;
bool operator==(const MessageDisplayFormatAttribute &other) const;
private:
friend class MessageDisplayFormatAttributePrivate;
......
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