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

Add unittest. Replace boolean by flags

parent 97e9cb90
......@@ -217,6 +217,7 @@ install(TARGETS mailcommon ${INSTALL_TARGETS_DEFAULT_ARGS})
add_subdirectory(filter/filterimporter/tests)
add_subdirectory(collectionpage/autotests)
add_subdirectory(filter/autotests)
#install(FILES viewer/viewer.h viewer/attachmentstrategy.h header/headerstrategy.h messageviewer_export.h DESTINATION ${INCLUDE_INSTALL_DIR}/messageviewer COMPONENT devel)
if (QT_QTDESIGNER_FOUND)
......
include_directories(
${CMAKE_SOURCE_DIR}/mailcommon
)
set( mailcommon_itemcontexttest_source itemcontexttest.cpp ../itemcontext.cpp )
kde4_add_unit_test( itemcontexttest ${mailcommon_itemcontexttest_source})
target_link_libraries( itemcontexttest ${QT_QTTEST_LIBRARY} ${KDE4_KDECORE_LIBS} ${QT_QTGUI_LIBRARY} ${KDEPIMLIBS_AKONADI_LIBS})
/*
Copyright (c) 2014 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 "itemcontexttest.h"
#include "../itemcontext.h"
#include <qtest_kde.h>
#include <Akonadi/Item>
ItemContextTest::ItemContextTest(QObject *parent)
: QObject(parent)
{
}
ItemContextTest::~ItemContextTest()
{
}
void ItemContextTest::shouldHaveDefaultValue()
{
Akonadi::Item item(42);
MailCommon::ItemContext itemContext(item, true);
QCOMPARE(itemContext.item(), item);
QVERIFY(!itemContext.moveTargetCollection().isValid());
QVERIFY(!itemContext.needsPayloadStore());
QVERIFY(!itemContext.needsFlagStore());
QVERIFY(itemContext.needsFullPayload());
QVERIFY(!itemContext.deleteItem());
MailCommon::ItemContext itemContext2(item, false);
QCOMPARE(itemContext2.item(), item);
QVERIFY(!itemContext2.moveTargetCollection().isValid());
QVERIFY(!itemContext2.needsPayloadStore());
QVERIFY(!itemContext2.needsFlagStore());
QVERIFY(!itemContext2.needsFullPayload());
QVERIFY(!itemContext2.deleteItem());
}
void ItemContextTest::shouldAssignContext_data()
{
QTest::addColumn<bool>( "needspayloadstore" );
QTest::addColumn<bool>( "needsflagstore" );
QTest::addColumn<bool>( "needsfullpayload" );
QTest::addColumn<bool>( "deleteitem" );
QTest::newRow( "no boolean" ) << false << false << false << false;
QTest::newRow( "needspayloadstore" ) << true << false << false << false;
QTest::newRow( "needsflagstore" ) << false << true << false << false;
QTest::newRow( "needsfullpayload" ) << false << false << true << false;
QTest::newRow( "deleteitem" ) << false << false << false << true;
QTest::newRow( "all" ) << true << true << true << true;
QTest::newRow( "T T F F" ) << true << true << false << false;
QTest::newRow( "T T T F" ) << true << true << true << false;
QTest::newRow( "F T F F" ) << false << true << false << false;
QTest::newRow( "F F T F" ) << false << false << true << false;
QTest::newRow( "F T T F" ) << false << true << true << false;
QTest::newRow( "F T T T" ) << false << true << true << true;
QTest::newRow( "F F F T" ) << false << false << false << true;
QTest::newRow( "F T F T" ) << false << true << false << true;
QTest::newRow( "F F F T" ) << false << false << false << true;
}
void ItemContextTest::shouldAssignContext()
{
QFETCH( bool, needspayloadstore );
QFETCH( bool, needsflagstore );
QFETCH( bool, needsfullpayload );
QFETCH( bool, deleteitem );
Akonadi::Item item(42);
MailCommon::ItemContext itemContext(item, needsfullpayload);
if (needspayloadstore) {
itemContext.setNeedsPayloadStore();
}
if (needsflagstore) {
itemContext.setNeedsFlagStore();
}
if (deleteitem) {
itemContext.setDeleteItem();
}
QCOMPARE(itemContext.item(), item);
QCOMPARE(itemContext.needsFlagStore(), needsflagstore);
QCOMPARE(itemContext.needsFullPayload(), needsfullpayload);
QCOMPARE(itemContext.needsPayloadStore(), needspayloadstore);
QCOMPARE(itemContext.deleteItem(), deleteitem);
}
void ItemContextTest::shouldAssignCollection()
{
Akonadi::Item item(42);
Akonadi::Collection col(12);
MailCommon::ItemContext itemContext(item, true);
itemContext.setMoveTargetCollection(col);
QCOMPARE(itemContext.item(), item);
QCOMPARE(itemContext.moveTargetCollection(), col);
}
QTEST_KDEMAIN(ItemContextTest, NoGUI)
/*
Copyright (c) 2014 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 ITEMCONTEXTTEST_H
#define ITEMCONTEXTTEST_H
#include <QObject>
class ItemContextTest : public QObject
{
Q_OBJECT
public:
explicit ItemContextTest(QObject *parent = 0);
~ItemContextTest();
private Q_SLOTS:
void shouldHaveDefaultValue();
void shouldAssignContext_data();
void shouldAssignContext();
void shouldAssignCollection();
};
#endif // ITEMCONTEXTTEST_H
......@@ -22,8 +22,7 @@
using namespace MailCommon;
ItemContext::ItemContext( const Akonadi::Item& item, bool needsFullPayload )
: mItem( item ), mNeedsPayloadStore( false ), mNeedsFlagStore( false ), mDeleteItem( false ),
mNeedsFullPayload( needsFullPayload )
: mItem( item ), mItemContextAction(needsFullPayload ? FullPayload : None)
{
}
......@@ -44,36 +43,36 @@ Akonadi::Collection ItemContext::moveTargetCollection() const
void ItemContext::setNeedsPayloadStore()
{
mNeedsPayloadStore = true;
mItemContextAction |= PlayloadStore;
}
bool ItemContext::needsPayloadStore() const
{
return mNeedsPayloadStore;
return (mItemContextAction & PlayloadStore);
}
void ItemContext::setNeedsFlagStore()
{
mNeedsFlagStore = true;
mItemContextAction |= FlagStore;
}
bool ItemContext::needsFlagStore() const
{
return mNeedsFlagStore;
return (mItemContextAction & FlagStore);
}
void ItemContext::setDeleteItem()
{
mDeleteItem = true;
mItemContextAction |= DeleteItem;
}
bool ItemContext::deleteItem() const
{
return mDeleteItem;
return (mItemContextAction & DeleteItem);
}
bool ItemContext::needsFullPayload() const
{
return mNeedsFullPayload;
return (mItemContextAction & FullPayload);
}
......@@ -89,12 +89,19 @@ public:
bool deleteItem() const;
private:
enum ItemContextAction {
None = 0,
PlayloadStore = 1,
FlagStore = 2,
DeleteItem = 4,
FullPayload = 8
};
Q_DECLARE_FLAGS(ItemContextActions, ItemContextAction)
Akonadi::Item mItem;
Akonadi::Collection mMoveTargetCollection;
bool mNeedsPayloadStore;
bool mNeedsFlagStore;
bool mDeleteItem;
bool mNeedsFullPayload;
ItemContextActions mItemContextAction;
};
}
......
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