From 3655f6b8edf426cbaee850d9adb0b4e0c5e8c49e Mon Sep 17 00:00:00 2001 From: Laurent Montel Date: Wed, 23 Oct 2019 13:51:49 +0200 Subject: [PATCH] Improve undosend support + add kmail_private_export.h for helping to create autotestd --- CMakeLists.txt | 3 + src/CMakeLists.txt | 2 + src/kmail_private_export.h | 34 ++++++++ src/undosend/autotests/CMakeLists.txt | 10 +++ .../autotests/undosendcomboboxtest.cpp | 36 ++++++++ src/undosend/autotests/undosendcomboboxtest.h | 36 ++++++++ .../autotests/undosendcreatejobtest.cpp | 37 +++++++++ .../autotests/undosendcreatejobtest.h | 35 ++++++++ src/undosend/undosendcombobox.h | 3 +- src/undosend/undosendcreatejob.cpp | 82 +++++++++++++++++++ src/undosend/undosendcreatejob.h | 49 +++++++++++ src/undosend/undosendmanager.cpp | 3 +- src/undosend/undosendmanager.h | 2 +- 13 files changed, 329 insertions(+), 3 deletions(-) create mode 100644 src/kmail_private_export.h create mode 100644 src/undosend/autotests/CMakeLists.txt create mode 100644 src/undosend/autotests/undosendcomboboxtest.cpp create mode 100644 src/undosend/autotests/undosendcomboboxtest.h create mode 100644 src/undosend/autotests/undosendcreatejobtest.cpp create mode 100644 src/undosend/autotests/undosendcreatejobtest.h create mode 100644 src/undosend/undosendcreatejob.cpp create mode 100644 src/undosend/undosendcreatejob.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 24d0eb2f1..33beb5085 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -142,6 +142,9 @@ configure_file(config-enterprise.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-ente include_directories(${kmail_SOURCE_DIR} ${kmail_BINARY_DIR}) configure_file(kmail-version.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/kmail-version.h @ONLY) +if(BUILD_TESTING) + add_definitions(-DBUILD_TESTING) +endif() if (EXISTS "${CMAKE_SOURCE_DIR}/.git") add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0x060000) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index cabb9d76c..a1d0cc30b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -179,6 +179,7 @@ set(kmailprivate_undosend_LIB_SRCS undosend/undosendcombobox.cpp undosend/undosendinfowidget.cpp undosend/undosendmanager.cpp + undosend/undosendcreatejob.cpp ) set(kmail_common_SRCS) @@ -390,6 +391,7 @@ if(BUILD_TESTING) add_subdirectory(editor/potentialphishingemail/autotests) add_subdirectory(editor/warningwidgets/autotests) add_subdirectory(sieveimapinterface/tests/) + add_subdirectory(undosend/autotests/) endif() ########### install files ############### diff --git a/src/kmail_private_export.h b/src/kmail_private_export.h new file mode 100644 index 000000000..da9be10ac --- /dev/null +++ b/src/kmail_private_export.h @@ -0,0 +1,34 @@ +/* This file is part of the KDE project + Copyright (C) 2019 Laurent Montel + + 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 KMAILPRIVATE_EXPORT_H +#define KMAILPRIVATE_EXPORT_H + +#include "kmail_export.h" + +/* Classes which are exported only for unit tests */ +#ifdef BUILD_TESTING + #ifndef KMAILTESTS_TESTS_EXPORT + #define KMAILTESTS_TESTS_EXPORT KMAIL_EXPORT + # endif +#else /* not compiling tests */ + #define KMAILTESTS_TESTS_EXPORT +#endif + +#endif diff --git a/src/undosend/autotests/CMakeLists.txt b/src/undosend/autotests/CMakeLists.txt new file mode 100644 index 000000000..96edb769f --- /dev/null +++ b/src/undosend/autotests/CMakeLists.txt @@ -0,0 +1,10 @@ +macro(add_kmail_undosend_unittest _source) + get_filename_component(_name ${_source} NAME_WE) + ecm_add_test(${_source} + TEST_NAME ${_name} + LINK_LIBRARIES kmailprivate Qt5::Test Qt5::Widgets + ) +endmacro () + +add_kmail_undosend_unittest(undosendcomboboxtest.cpp) +add_kmail_undosend_unittest(undosendcreatejobtest.cpp) diff --git a/src/undosend/autotests/undosendcomboboxtest.cpp b/src/undosend/autotests/undosendcomboboxtest.cpp new file mode 100644 index 000000000..af9465067 --- /dev/null +++ b/src/undosend/autotests/undosendcomboboxtest.cpp @@ -0,0 +1,36 @@ +/* + Copyright (C) 2019 Montel Laurent + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + 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; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + + +#include "undosendcomboboxtest.h" +#include "undosend/undosendcombobox.h" +#include +QTEST_MAIN(UndoSendComboboxTest) + +UndoSendComboboxTest::UndoSendComboboxTest(QObject *parent) + : QObject(parent) +{ + +} + +void UndoSendComboboxTest::shouldHaveDefaultValues() +{ + UndoSendCombobox w; + QCOMPARE(w.count(), 5); +} diff --git a/src/undosend/autotests/undosendcomboboxtest.h b/src/undosend/autotests/undosendcomboboxtest.h new file mode 100644 index 000000000..d01603809 --- /dev/null +++ b/src/undosend/autotests/undosendcomboboxtest.h @@ -0,0 +1,36 @@ +/* + Copyright (C) 2019 Montel Laurent + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + 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; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + + +#ifndef UNDOSENDCOMBOBOXTEST_H +#define UNDOSENDCOMBOBOXTEST_H + +#include + +class UndoSendComboboxTest : public QObject +{ + Q_OBJECT +public: + explicit UndoSendComboboxTest(QObject *parent = nullptr); + ~UndoSendComboboxTest() = default; +private Q_SLOTS: + void shouldHaveDefaultValues(); +}; + +#endif // UNDOSENDCOMBOBOXTEST_H diff --git a/src/undosend/autotests/undosendcreatejobtest.cpp b/src/undosend/autotests/undosendcreatejobtest.cpp new file mode 100644 index 000000000..b926ed114 --- /dev/null +++ b/src/undosend/autotests/undosendcreatejobtest.cpp @@ -0,0 +1,37 @@ +/* + Copyright (C) 2019 Montel Laurent + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + 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; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "undosendcreatejobtest.h" +#include "undosend/undosendcreatejob.h" +#include +QTEST_MAIN(UndoSendCreateJobTest) + +UndoSendCreateJobTest::UndoSendCreateJobTest(QObject *parent) + : QObject(parent) +{ + +} + +void UndoSendCreateJobTest::shouldHaveDefaultValues() +{ + UndoSendCreateJob job; + QCOMPARE(job.akonadiIndex(), -1); + QCOMPARE(job.delay(), -1); + QVERIFY(job.subject().isEmpty()); +} diff --git a/src/undosend/autotests/undosendcreatejobtest.h b/src/undosend/autotests/undosendcreatejobtest.h new file mode 100644 index 000000000..a03a99124 --- /dev/null +++ b/src/undosend/autotests/undosendcreatejobtest.h @@ -0,0 +1,35 @@ +/* + Copyright (C) 2019 Montel Laurent + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + 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; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef UNDOSENDCREATEJOBTEST_H +#define UNDOSENDCREATEJOBTEST_H + +#include + +class UndoSendCreateJobTest : public QObject +{ + Q_OBJECT +public: + explicit UndoSendCreateJobTest(QObject *parent = nullptr); + ~UndoSendCreateJobTest() = default; +private Q_SLOTS: + void shouldHaveDefaultValues(); +}; + +#endif // UNDOSENDCREATEJOBTEST_H diff --git a/src/undosend/undosendcombobox.h b/src/undosend/undosendcombobox.h index e44d4e7ee..a27969568 100644 --- a/src/undosend/undosendcombobox.h +++ b/src/undosend/undosendcombobox.h @@ -21,8 +21,9 @@ #define UNDOSENDCOMBOBOX_H #include +#include "kmail_private_export.h" -class UndoSendCombobox : public QComboBox +class KMAILTESTS_TESTS_EXPORT UndoSendCombobox : public QComboBox { Q_OBJECT public: diff --git a/src/undosend/undosendcreatejob.cpp b/src/undosend/undosendcreatejob.cpp new file mode 100644 index 000000000..fbaafa08e --- /dev/null +++ b/src/undosend/undosendcreatejob.cpp @@ -0,0 +1,82 @@ +/* + Copyright (C) 2019 Montel Laurent + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + 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; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + + +#include "undosendcreatejob.h" +#include "kmail_debug.h" + +UndoSendCreateJob::UndoSendCreateJob(QObject *parent) + : QObject(parent) +{ + +} + +UndoSendCreateJob::~UndoSendCreateJob() +{ + +} + +bool UndoSendCreateJob::canStart() const +{ + if (mAkonadiIndex < 0 || mDelay <= 0) { + return false; + } + return true; +} + +bool UndoSendCreateJob::start() +{ + if (!canStart()) { + qCWarning(KMAIL_LOG) << "Impossible to start undosendcreatejob"; + deleteLater(); + return false; + } + //TODO + return true; +} + +QString UndoSendCreateJob::subject() const +{ + return mSubject; +} + +void UndoSendCreateJob::setSubject(const QString &subject) +{ + mSubject = subject; +} + +int UndoSendCreateJob::delay() const +{ + return mDelay; +} + +void UndoSendCreateJob::setDelay(int delay) +{ + mDelay = delay; +} + +qint64 UndoSendCreateJob::akonadiIndex() const +{ + return mAkonadiIndex; +} + +void UndoSendCreateJob::setAkonadiIndex(const qint64 &akonadiIndex) +{ + mAkonadiIndex = akonadiIndex; +} diff --git a/src/undosend/undosendcreatejob.h b/src/undosend/undosendcreatejob.h new file mode 100644 index 000000000..b38d414b5 --- /dev/null +++ b/src/undosend/undosendcreatejob.h @@ -0,0 +1,49 @@ +/* + Copyright (C) 2019 Montel Laurent + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + 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; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef UNDOSENDCREATEJOB_H +#define UNDOSENDCREATEJOB_H + +#include +#include "kmail_private_export.h" +class KMAILTESTS_TESTS_EXPORT UndoSendCreateJob : public QObject +{ + Q_OBJECT +public: + explicit UndoSendCreateJob(QObject *parent = nullptr); + ~UndoSendCreateJob(); + Q_REQUIRED_RESULT bool canStart() const; + Q_REQUIRED_RESULT bool start(); + + Q_REQUIRED_RESULT QString subject() const; + void setSubject(const QString &subject); + + Q_REQUIRED_RESULT int delay() const; + void setDelay(int delay); + + Q_REQUIRED_RESULT qint64 akonadiIndex() const; + void setAkonadiIndex(const qint64 &akonadiIndex); + +private: + QString mSubject; + qint64 mAkonadiIndex = -1; + int mDelay = -1; +}; + +#endif // UNDOSENDCREATEJOB_H diff --git a/src/undosend/undosendmanager.cpp b/src/undosend/undosendmanager.cpp index fc75fc56a..d0cd1bd3b 100644 --- a/src/undosend/undosendmanager.cpp +++ b/src/undosend/undosendmanager.cpp @@ -18,6 +18,7 @@ */ #include "undosendmanager.h" +#include "undosendcreatejob.h" UndoSendManager::UndoSendManager(QObject *parent) : QObject(parent) @@ -39,7 +40,7 @@ void UndoSendManager::removeItem(qint64 index) } -void UndoSendManager::addItem(qint64 index) +void UndoSendManager::addItem(qint64 index, const QString &subject, int delay) { //TODO } diff --git a/src/undosend/undosendmanager.h b/src/undosend/undosendmanager.h index df71b0d3d..3669daac3 100644 --- a/src/undosend/undosendmanager.h +++ b/src/undosend/undosendmanager.h @@ -31,7 +31,7 @@ public: static UndoSendManager *self(); void removeItem(qint64 index); - void addItem(qint64 index); + void addItem(qint64 index, const QString &subject, int delay); }; #endif // UNDOSENDMANAGER_H