Commit a9fb7c00 authored by Laurent Montel's avatar Laurent Montel 😁

Add unittest

parent 4c631470
...@@ -42,3 +42,4 @@ endif () ...@@ -42,3 +42,4 @@ endif ()
target_link_libraries(akonadi_mbox_resource ${KDEPIMLIBS_KMBOX_LIBS} ${KDEPIMLIBS_AKONADI_LIBS} ${KDEPIMLIBS_AKONADI_KMIME_LIBS} ${QT_QTDBUS_LIBRARY} ${KDE4_KIO_LIBS} ${KDEPIMLIBS_KMIME_LIBS}) target_link_libraries(akonadi_mbox_resource ${KDEPIMLIBS_KMBOX_LIBS} ${KDEPIMLIBS_AKONADI_LIBS} ${KDEPIMLIBS_AKONADI_KMIME_LIBS} ${QT_QTDBUS_LIBRARY} ${KDE4_KIO_LIBS} ${KDEPIMLIBS_KMIME_LIBS})
install(TARGETS akonadi_mbox_resource DESTINATION ${PLUGIN_INSTALL_DIR}) install(TARGETS akonadi_mbox_resource DESTINATION ${PLUGIN_INSTALL_DIR})
add_subdirectory(autotests)
set( mbox_deleteitemsattributetest_source deleteitemsattributetest.cpp ../deleteditemsattribute.cpp)
kde4_add_unit_test( deleteitemsattributetest ${mbox_deleteitemsattributetest_source})
target_link_libraries( deleteitemsattributetest ${QT_QTTEST_LIBRARY} ${KDE4_KDECORE_LIBS} ${QT_QTGUI_LIBRARY} ${KDEPIMLIBS_AKONADI_LIBS} ${KDEPIMLIBS_KMBOX_LIBS})
/*
Copyright (c) 2015 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program 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
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "deleteitemsattributetest.h"
#include "../deleteditemsattribute.h"
#include <qtest_kde.h>
DeleteItemsAttributeTest::DeleteItemsAttributeTest(QObject *parent)
: QObject(parent)
{
}
DeleteItemsAttributeTest::~DeleteItemsAttributeTest()
{
}
void DeleteItemsAttributeTest::shouldHaveDefaultValue()
{
DeletedItemsAttribute attr;
QVERIFY(attr.deletedItemOffsets().isEmpty());
QCOMPARE(attr.offsetCount(), 0);
}
void DeleteItemsAttributeTest::shouldAssignValue()
{
DeletedItemsAttribute attr;
QSet<quint64> lst;
lst.insert(15);
attr.addDeletedItemOffset(15);
lst.insert(154);
attr.addDeletedItemOffset(154);
lst.insert(225);
attr.addDeletedItemOffset(225);
QVERIFY(!attr.deletedItemOffsets().isEmpty());
QCOMPARE(attr.offsetCount(), 3);
QCOMPARE(lst, attr.deletedItemOffsets());
}
void DeleteItemsAttributeTest::shouldDeserializeValue()
{
DeletedItemsAttribute attr;
attr.addDeletedItemOffset(15);
attr.addDeletedItemOffset(154);
attr.addDeletedItemOffset(225);
const QByteArray ba = attr.serialized();
DeletedItemsAttribute result;
result.deserialize(ba);
QVERIFY(result == attr);
}
void DeleteItemsAttributeTest::shouldCloneAttribute()
{
DeletedItemsAttribute attr;
attr.addDeletedItemOffset(15);
attr.addDeletedItemOffset(154);
attr.addDeletedItemOffset(225);
DeletedItemsAttribute *result = attr.clone();
QVERIFY(*result == attr);
}
void DeleteItemsAttributeTest::shouldHaveTypeName()
{
DeletedItemsAttribute attr;
QCOMPARE(attr.type(), QByteArray("DeletedMboxItems"));
}
QTEST_KDEMAIN(DeleteItemsAttributeTest, NoGUI)
/*
Copyright (c) 2015 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program 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
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef DELETEITEMSATTRIBUTETEST_H
#define DELETEITEMSATTRIBUTETEST_H
#include <QObject>
class DeleteItemsAttributeTest : public QObject
{
Q_OBJECT
public:
explicit DeleteItemsAttributeTest(QObject *parent = 0);
~DeleteItemsAttributeTest();
private Q_SLOTS:
void shouldHaveDefaultValue();
void shouldDeserializeValue();
void shouldAssignValue();
void shouldCloneAttribute();
void shouldHaveTypeName();
};
#endif // DELETEITEMSATTRIBUTETEST_H
...@@ -41,7 +41,7 @@ void DeletedItemsAttribute::addDeletedItemOffset( quint64 offset ) ...@@ -41,7 +41,7 @@ void DeletedItemsAttribute::addDeletedItemOffset( quint64 offset )
mDeletedItemOffsets.insert( offset ); mDeletedItemOffsets.insert( offset );
} }
Akonadi::Attribute *DeletedItemsAttribute::clone() const DeletedItemsAttribute *DeletedItemsAttribute::clone() const
{ {
return new DeletedItemsAttribute( *this ); return new DeletedItemsAttribute( *this );
} }
...@@ -95,3 +95,8 @@ QByteArray DeletedItemsAttribute::type() const ...@@ -95,3 +95,8 @@ QByteArray DeletedItemsAttribute::type() const
static const QByteArray sType( "DeletedMboxItems" ); static const QByteArray sType( "DeletedMboxItems" );
return sType; return sType;
} }
bool DeletedItemsAttribute::operator==(const DeletedItemsAttribute &other) const
{
return mDeletedItemOffsets == other.deletedItemOffsets();
}
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
#include <QtCore/QSet> #include <QtCore/QSet>
/** /**
* This attribute stores a list of offdets in the mbox file of mails which are * This attribute stores a list of offsets in the mbox file of mails which are
* deleted but not yet actually removed from the file yet. * deleted but not yet actually removed from the file yet.
*/ */
class DeletedItemsAttribute : public Akonadi::Attribute class DeletedItemsAttribute : public Akonadi::Attribute
...@@ -40,7 +40,7 @@ class DeletedItemsAttribute : public Akonadi::Attribute ...@@ -40,7 +40,7 @@ class DeletedItemsAttribute : public Akonadi::Attribute
void addDeletedItemOffset( quint64 ); void addDeletedItemOffset( quint64 );
virtual Attribute *clone() const; virtual DeletedItemsAttribute *clone() const;
QSet<quint64> deletedItemOffsets() const; QSet<quint64> deletedItemOffsets() const;
KMBox::MBoxEntry::List deletedItemEntries() const; KMBox::MBoxEntry::List deletedItemEntries() const;
...@@ -56,7 +56,8 @@ class DeletedItemsAttribute : public Akonadi::Attribute ...@@ -56,7 +56,8 @@ class DeletedItemsAttribute : public Akonadi::Attribute
virtual QByteArray type() const; virtual QByteArray type() const;
private: bool operator ==(const DeletedItemsAttribute &other) const;
private:
QSet<quint64> mDeletedItemOffsets; QSet<quint64> mDeletedItemOffsets;
}; };
......
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