diff --git a/resources/mbox/CMakeLists.txt b/resources/mbox/CMakeLists.txt index bae7df2394da698a5ce030310ed8cd588c311977..618851d0a73ea32f6570261b65627d8ff807c71a 100644 --- a/resources/mbox/CMakeLists.txt +++ b/resources/mbox/CMakeLists.txt @@ -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}) install(TARGETS akonadi_mbox_resource DESTINATION ${PLUGIN_INSTALL_DIR}) +add_subdirectory(autotests) diff --git a/resources/mbox/autotests/CMakeLists.txt b/resources/mbox/autotests/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..ed84ae459795c5da547575ab419c7465c9f83b82 --- /dev/null +++ b/resources/mbox/autotests/CMakeLists.txt @@ -0,0 +1,5 @@ + +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}) + diff --git a/resources/mbox/autotests/deleteitemsattributetest.cpp b/resources/mbox/autotests/deleteitemsattributetest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9375909bf396f3c5b5eb08efd9c4e4ae9546c8f0 --- /dev/null +++ b/resources/mbox/autotests/deleteitemsattributetest.cpp @@ -0,0 +1,84 @@ +/* + Copyright (c) 2015 Montel Laurent + + 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 + + +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 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) diff --git a/resources/mbox/autotests/deleteitemsattributetest.h b/resources/mbox/autotests/deleteitemsattributetest.h new file mode 100644 index 0000000000000000000000000000000000000000..ae78232ac587c0d15fddc2d6211ec19ffbe34123 --- /dev/null +++ b/resources/mbox/autotests/deleteitemsattributetest.h @@ -0,0 +1,38 @@ +/* + Copyright (c) 2015 Montel Laurent + + 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 + +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 diff --git a/resources/mbox/deleteditemsattribute.cpp b/resources/mbox/deleteditemsattribute.cpp index 6e858f5ed815798ebf6d79d585a4cd9adb3ca402..7e5459311f46a5657bbf27fb4d0b289ed48e6d1e 100644 --- a/resources/mbox/deleteditemsattribute.cpp +++ b/resources/mbox/deleteditemsattribute.cpp @@ -41,7 +41,7 @@ void DeletedItemsAttribute::addDeletedItemOffset( quint64 offset ) mDeletedItemOffsets.insert( offset ); } -Akonadi::Attribute *DeletedItemsAttribute::clone() const +DeletedItemsAttribute *DeletedItemsAttribute::clone() const { return new DeletedItemsAttribute( *this ); } @@ -95,3 +95,8 @@ QByteArray DeletedItemsAttribute::type() const static const QByteArray sType( "DeletedMboxItems" ); return sType; } + +bool DeletedItemsAttribute::operator==(const DeletedItemsAttribute &other) const +{ + return mDeletedItemOffsets == other.deletedItemOffsets(); +} diff --git a/resources/mbox/deleteditemsattribute.h b/resources/mbox/deleteditemsattribute.h index dcd947d4746fa02db0b2898b2225f586a0c09905..4af96301626d686cd00f30694eddae0d0a772053 100644 --- a/resources/mbox/deleteditemsattribute.h +++ b/resources/mbox/deleteditemsattribute.h @@ -26,7 +26,7 @@ #include /** - * 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. */ class DeletedItemsAttribute : public Akonadi::Attribute @@ -40,7 +40,7 @@ class DeletedItemsAttribute : public Akonadi::Attribute void addDeletedItemOffset( quint64 ); - virtual Attribute *clone() const; + virtual DeletedItemsAttribute *clone() const; QSet deletedItemOffsets() const; KMBox::MBoxEntry::List deletedItemEntries() const; @@ -56,7 +56,8 @@ class DeletedItemsAttribute : public Akonadi::Attribute virtual QByteArray type() const; - private: + bool operator ==(const DeletedItemsAttribute &other) const; +private: QSet mDeletedItemOffsets; };