Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Unmaintained
KDE Pim
Commits
c6914410
Commit
c6914410
authored
Dec 18, 2014
by
Laurent Montel
😁
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add unittest. Replace boolean by flags
parent
97e9cb90
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
181 additions
and
13 deletions
+181
-13
mailcommon/CMakeLists.txt
mailcommon/CMakeLists.txt
+1
-0
mailcommon/filter/autotests/CMakeLists.txt
mailcommon/filter/autotests/CMakeLists.txt
+7
-0
mailcommon/filter/autotests/itemcontexttest.cpp
mailcommon/filter/autotests/itemcontexttest.cpp
+118
-0
mailcommon/filter/autotests/itemcontexttest.h
mailcommon/filter/autotests/itemcontexttest.h
+36
-0
mailcommon/filter/itemcontext.cpp
mailcommon/filter/itemcontext.cpp
+8
-9
mailcommon/filter/itemcontext.h
mailcommon/filter/itemcontext.h
+11
-4
No files found.
mailcommon/CMakeLists.txt
View file @
c6914410
...
...
@@ -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
)
...
...
mailcommon/filter/autotests/CMakeLists.txt
0 → 100644
View file @
c6914410
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
}
)
mailcommon/filter/autotests/itemcontexttest.cpp
0 → 100644
View file @
c6914410
/*
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
)
mailcommon/filter/autotests/itemcontexttest.h
0 → 100644
View file @
c6914410
/*
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
mailcommon/filter/itemcontext.cpp
View file @
c6914410
...
...
@@ -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
()
{
m
NeedsP
ayloadStore
=
true
;
m
ItemContextAction
|=
Pl
ayloadStore
;
}
bool
ItemContext
::
needsPayloadStore
()
const
{
return
mNeedsP
ayloadStore
;
return
(
mItemContextAction
&
Pl
ayloadStore
)
;
}
void
ItemContext
::
setNeedsFlagStore
()
{
m
Needs
FlagStore
=
true
;
m
ItemContextAction
|=
FlagStore
;
}
bool
ItemContext
::
needsFlagStore
()
const
{
return
mNeeds
FlagStore
;
return
(
mItemContextAction
&
FlagStore
)
;
}
void
ItemContext
::
setDeleteItem
()
{
mDeleteItem
=
true
;
m
ItemContextAction
|=
DeleteItem
;
}
bool
ItemContext
::
deleteItem
()
const
{
return
m
DeleteItem
;
return
(
mItemContextAction
&
DeleteItem
)
;
}
bool
ItemContext
::
needsFullPayload
()
const
{
return
mNeeds
FullPayload
;
return
(
mItemContextAction
&
FullPayload
)
;
}
mailcommon/filter/itemcontext.h
View file @
c6914410
...
...
@@ -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
;
};
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment