diff --git a/src/domain/CMakeLists.txt b/src/domain/CMakeLists.txt index 451d73ce..15b6e442 100644 --- a/src/domain/CMakeLists.txt +++ b/src/domain/CMakeLists.txt @@ -1,21 +1,20 @@ set(domain_SRCS - artifact.cpp context.cpp contextqueries.cpp contextrepository.cpp datasource.cpp datasourcequeries.cpp datasourcerepository.cpp project.cpp projectqueries.cpp projectrepository.cpp queryresult.cpp queryresultinterface.cpp queryresultprovider.cpp task.cpp taskqueries.cpp taskrepository.cpp ) add_library(domain STATIC ${domain_SRCS}) target_link_libraries(domain Qt5::Core) diff --git a/src/domain/artifact.cpp b/src/domain/artifact.cpp deleted file mode 100644 index 4a7402cb..00000000 --- a/src/domain/artifact.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/* This file is part of Zanshin - - Copyright 2014 Kevin Ottens - - 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) version 3 or any later version - accepted by the membership of KDE e.V. (or its successor approved - by the membership of KDE e.V.), which shall act as a proxy - defined in Section 14 of version 3 of the license. - - 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 "artifact.h" - -using namespace Domain; - -Artifact::Artifact(QObject *parent) - : QObject(parent) -{ -} - -Artifact::~Artifact() -{ -} - -QString Artifact::text() const -{ - return m_text; -} - -void Artifact::setText(const QString &text) -{ - if (m_text == text) - return; - - m_text = text; - emit textChanged(text); -} - -QString Artifact::title() const -{ - return m_title; -} - -void Artifact::setTitle(const QString &title) -{ - if (m_title == title) - return; - - m_title = title; - emit titleChanged(title); -} - diff --git a/src/domain/artifact.h b/src/domain/artifact.h deleted file mode 100644 index 957b8b75..00000000 --- a/src/domain/artifact.h +++ /dev/null @@ -1,68 +0,0 @@ -/* This file is part of Zanshin - - Copyright 2014 Kevin Ottens - - 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) version 3 or any later version - accepted by the membership of KDE e.V. (or its successor approved - by the membership of KDE e.V.), which shall act as a proxy - defined in Section 14 of version 3 of the license. - - 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 DOMAIN_ARTIFACT_H -#define DOMAIN_ARTIFACT_H - -#include -#include -#include - -namespace Domain { - -class Artifact : public QObject -{ - Q_OBJECT - Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged) - Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged) - -public: - typedef QSharedPointer Ptr; - typedef QList List; - - explicit Artifact(QObject *parent = Q_NULLPTR); - virtual ~Artifact(); - - QString text() const; - QString title() const; - -public slots: - void setText(const QString &text); - void setTitle(const QString &title); - -signals: - void textChanged(const QString &text); - void titleChanged(const QString &title); - -private: - QString m_text; - QString m_title; -}; - -} - -Q_DECLARE_METATYPE(Domain::Artifact::Ptr) -Q_DECLARE_METATYPE(Domain::Artifact::List) - -#endif // DOMAIN_ARTIFACT_H diff --git a/src/domain/task.cpp b/src/domain/task.cpp index 8bf8e58f..aae820e0 100644 --- a/src/domain/task.cpp +++ b/src/domain/task.cpp @@ -1,253 +1,281 @@ /* This file is part of Zanshin Copyright 2014 Kevin Ottens 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) version 3 or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of version 3 of the license. 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 "task.h" #include "utils/datetime.h" using namespace Domain; Task::Task(QObject *parent) - : Artifact(parent), + : QObject(parent), m_running(false), m_done(false), m_recurrence(NoRecurrence) { } Task::~Task() { } +QString Task::text() const +{ + return m_text; +} + +QString Task::title() const +{ + return m_title; +} + bool Task::isRunning() const { return m_running; } bool Task::isDone() const { return m_done; } void Task::setDone(bool done) { if (m_done == done) return; const QDate doneDate = done ? Utils::DateTime::currentDate() : QDate(); m_done = done; m_doneDate = doneDate; emit doneChanged(done); emit doneDateChanged(doneDate); } void Task::setDoneDate(const QDate &doneDate) { if (m_doneDate == doneDate) return; m_doneDate = doneDate; emit doneDateChanged(doneDate); } QDate Task::startDate() const { return m_startDate; } void Task::setStartDate(const QDate &startDate) { if (m_startDate == startDate) return; m_startDate = startDate; emit startDateChanged(startDate); } QDate Task::dueDate() const { return m_dueDate; } QDate Task::doneDate() const { return m_doneDate; } Task::Recurrence Task::recurrence() const { return m_recurrence; } Task::Attachments Task::attachments() const { return m_attachments; } +void Task::setText(const QString &text) +{ + if (m_text == text) + return; + + m_text = text; + emit textChanged(text); +} + +void Task::setTitle(const QString &title) +{ + if (m_title == title) + return; + + m_title = title; + emit titleChanged(title); +} + void Task::setRunning(bool running) { if (m_running == running) return; m_running = running; emit runningChanged(running); } void Task::setDueDate(const QDate &dueDate) { if (m_dueDate == dueDate) return; m_dueDate = dueDate; emit dueDateChanged(dueDate); } void Task::setRecurrence(Task::Recurrence recurrence) { if (m_recurrence == recurrence) return; m_recurrence = recurrence; emit recurrenceChanged(recurrence); } void Task::setAttachments(const Task::Attachments &attachments) { if (m_attachments == attachments) return; m_attachments = attachments; emit attachmentsChanged(attachments); } Task::Attachment::Attachment() { } Task::Attachment::Attachment(const QByteArray &data) { setData(data); } Task::Attachment::Attachment(const QUrl &uri) { setUri(uri); } Task::Attachment::Attachment(const Task::Attachment &other) : m_uri(other.m_uri), m_data(other.m_data), m_label(other.m_label), m_mimeType(other.m_mimeType), m_iconName(other.m_iconName) { } Task::Attachment::~Attachment() { } Task::Attachment &Task::Attachment::operator=(const Task::Attachment &other) { Attachment copy(other); std::swap(m_uri, copy.m_uri); std::swap(m_data, copy.m_data); std::swap(m_label, copy.m_label); std::swap(m_mimeType, copy.m_mimeType); std::swap(m_iconName, copy.m_iconName); return *this; } bool Task::Attachment::operator==(const Task::Attachment &other) const { return m_uri == other.m_uri && m_data == other.m_data && m_label == other.m_label && m_mimeType == other.m_mimeType && m_iconName == other.m_iconName; } bool Task::Attachment::isValid() const { return m_uri.isValid() || !m_data.isEmpty(); } bool Task::Attachment::isUri() const { return m_uri.isValid(); } QUrl Task::Attachment::uri() const { return m_uri; } void Task::Attachment::setUri(const QUrl &uri) { m_uri = uri; m_data.clear(); } QByteArray Task::Attachment::data() const { return m_data; } void Task::Attachment::setData(const QByteArray &data) { m_data = data; m_uri.clear(); } QString Task::Attachment::label() const { return m_label; } void Task::Attachment::setLabel(const QString &label) { m_label = label; } QString Task::Attachment::mimeType() const { return m_mimeType; } void Task::Attachment::setMimeType(const QString &mimeType) { m_mimeType = mimeType; } QString Task::Attachment::iconName() const { return m_iconName; } void Task::Attachment::setIconName(const QString &iconName) { m_iconName = iconName; } diff --git a/src/domain/task.h b/src/domain/task.h index 2b711005..3ba2aeff 100644 --- a/src/domain/task.h +++ b/src/domain/task.h @@ -1,141 +1,153 @@ /* This file is part of Zanshin Copyright 2014 Kevin Ottens 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) version 3 or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of version 3 of the license. 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 DOMAIN_TASK_H #define DOMAIN_TASK_H -#include "artifact.h" #include +#include +#include +#include #include namespace Domain { -class Task : public Artifact +class Task : public QObject { Q_OBJECT + Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged) + Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged) Q_PROPERTY(bool running READ isRunning WRITE setRunning NOTIFY runningChanged) Q_PROPERTY(bool done READ isDone WRITE setDone NOTIFY doneChanged) Q_PROPERTY(QDate startDate READ startDate WRITE setStartDate NOTIFY startDateChanged) Q_PROPERTY(QDate dueDate READ dueDate WRITE setDueDate NOTIFY dueDateChanged) Q_PROPERTY(Domain::Task::Recurrence recurrence READ recurrence WRITE setRecurrence NOTIFY recurrenceChanged) Q_PROPERTY(Domain::Task::Attachments attachements READ attachments WRITE setAttachments NOTIFY attachmentsChanged) public: typedef QSharedPointer Ptr; typedef QList List; enum Recurrence { NoRecurrence = 0, RecursDaily, RecursWeekly, RecursMonthly // for now only monthly on the same day (say 11th day of the month) }; Q_ENUM(Recurrence) class Attachment { public: Attachment(); explicit Attachment(const QByteArray &data); explicit Attachment(const QUrl &uri); Attachment(const Attachment &other); ~Attachment(); Attachment &operator=(const Attachment &other); bool operator==(const Attachment &other) const; bool isValid() const; bool isUri() const; QUrl uri() const; void setUri(const QUrl &uri); QByteArray data() const; void setData(const QByteArray &data); QString label() const; void setLabel(const QString &label); QString mimeType() const; void setMimeType(const QString &mimeType); QString iconName() const; void setIconName(const QString &iconName); private: QUrl m_uri; QByteArray m_data; QString m_label; QString m_mimeType; QString m_iconName; }; typedef QList Attachments; explicit Task(QObject *parent = Q_NULLPTR); virtual ~Task(); + QString text() const; + QString title() const; bool isRunning() const; bool isDone() const; QDate startDate() const; QDate dueDate() const; QDate doneDate() const; Recurrence recurrence() const; Attachments attachments() const; public slots: + void setText(const QString &text); + void setTitle(const QString &title); void setRunning(bool running); void setDone(bool done); void setDoneDate(const QDate &doneDate); void setStartDate(const QDate &startDate); void setDueDate(const QDate &dueDate); void setRecurrence(Domain::Task::Recurrence recurrence); void setAttachments(const Domain::Task::Attachments &attachments); signals: + void textChanged(const QString &text); + void titleChanged(const QString &title); void runningChanged(bool isRunning); void doneChanged(bool isDone); void doneDateChanged(const QDate &doneDate); void startDateChanged(const QDate &startDate); void dueDateChanged(const QDate &dueDate); void recurrenceChanged(Domain::Task::Recurrence recurrence); void attachmentsChanged(const Domain::Task::Attachments &attachments); private: + QString m_text; + QString m_title; bool m_running; bool m_done; QDate m_startDate; QDate m_dueDate; QDate m_doneDate; Recurrence m_recurrence; Attachments m_attachments; }; } Q_DECLARE_METATYPE(Domain::Task::Ptr) Q_DECLARE_METATYPE(Domain::Task::List) Q_DECLARE_METATYPE(Domain::Task::Attachment) Q_DECLARE_METATYPE(Domain::Task::Attachments) #endif // DOMAIN_TASK_H diff --git a/tests/units/domain/CMakeLists.txt b/tests/units/domain/CMakeLists.txt index fa1c67ef..c370d4ca 100644 --- a/tests/units/domain/CMakeLists.txt +++ b/tests/units/domain/CMakeLists.txt @@ -1,11 +1,10 @@ zanshin_auto_tests( - artifacttest contexttest datasourcetest livequerytest liverelationshipquerytest mockitotest projecttest queryresulttest tasktest ) diff --git a/tests/units/domain/artifacttest.cpp b/tests/units/domain/artifacttest.cpp deleted file mode 100644 index 4fa3a0b1..00000000 --- a/tests/units/domain/artifacttest.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/* This file is part of Zanshin - - Copyright 2014 Kevin Ottens - - 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) version 3 or any later version - accepted by the membership of KDE e.V. (or its successor approved - by the membership of KDE e.V.), which shall act as a proxy - defined in Section 14 of version 3 of the license. - - 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 - -#include "domain/artifact.h" - -using namespace Domain; - -class ArtifactTest : public QObject -{ - Q_OBJECT -private slots: - void shouldHaveEmptyPropertiesByDefault() - { - Artifact a; - QCOMPARE(a.text(), QString()); - QCOMPARE(a.title(), QString()); - } - - void shouldNotifyTextChanges() - { - Artifact a; - QSignalSpy spy(&a, &Artifact::textChanged); - a.setText(QStringLiteral("foo")); - QCOMPARE(spy.count(), 1); - QCOMPARE(spy.first().first().toString(), QStringLiteral("foo")); - } - - void shouldNotNotifyIdenticalTextChanges() - { - Artifact a; - a.setText(QStringLiteral("foo")); - QSignalSpy spy(&a, &Artifact::textChanged); - a.setText(QStringLiteral("foo")); - QCOMPARE(spy.count(), 0); - } - - void shouldNotifyTitleChanges() - { - Artifact a; - QSignalSpy spy(&a, &Artifact::titleChanged); - a.setTitle(QStringLiteral("foo")); - QCOMPARE(spy.count(), 1); - QCOMPARE(spy.first().first().toString(), QStringLiteral("foo")); - } - - void shouldNotNotifyIdenticalTitleChanges() - { - Artifact a; - a.setTitle(QStringLiteral("foo")); - QSignalSpy spy(&a, &Artifact::titleChanged); - a.setTitle(QStringLiteral("foo")); - QCOMPARE(spy.count(), 0); - } -}; - -ZANSHIN_TEST_MAIN(ArtifactTest) - -#include "artifacttest.moc" diff --git a/tests/units/domain/tasktest.cpp b/tests/units/domain/tasktest.cpp index d1ee49a3..23f6cc10 100644 --- a/tests/units/domain/tasktest.cpp +++ b/tests/units/domain/tasktest.cpp @@ -1,271 +1,307 @@ /* This file is part of Zanshin Copyright 2014 Kevin Ottens 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) version 3 or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of version 3 of the license. 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 #include "domain/task.h" #include "utils/datetime.h" using namespace Domain; class TaskTest : public QObject { Q_OBJECT public: explicit TaskTest(QObject *parent = Q_NULLPTR) : QObject(parent) { qRegisterMetaType(); qRegisterMetaType(); } private slots: void shouldHaveEmptyPropertiesByDefault() { Task t; QCOMPARE(t.text(), QString()); QCOMPARE(t.title(), QString()); QCOMPARE(t.isDone(), false); QCOMPARE(t.startDate(), QDate()); QCOMPARE(t.dueDate(), QDate()); QCOMPARE(t.doneDate(), QDate()); QCOMPARE(t.recurrence(), Domain::Task::NoRecurrence); QVERIFY(t.attachments().isEmpty()); } + void shouldNotifyTextChanges() + { + Task t; + QSignalSpy spy(&t, &Task::textChanged); + t.setText(QStringLiteral("foo")); + QCOMPARE(spy.count(), 1); + QCOMPARE(spy.first().first().toString(), QStringLiteral("foo")); + } + + void shouldNotNotifyIdenticalTextChanges() + { + Task t; + t.setText(QStringLiteral("foo")); + QSignalSpy spy(&t, &Task::textChanged); + t.setText(QStringLiteral("foo")); + QCOMPARE(spy.count(), 0); + } + + void shouldNotifyTitleChanges() + { + Task t; + QSignalSpy spy(&t, &Task::titleChanged); + t.setTitle(QStringLiteral("foo")); + QCOMPARE(spy.count(), 1); + QCOMPARE(spy.first().first().toString(), QStringLiteral("foo")); + } + + void shouldNotNotifyIdenticalTitleChanges() + { + Task t; + t.setTitle(QStringLiteral("foo")); + QSignalSpy spy(&t, &Task::titleChanged); + t.setTitle(QStringLiteral("foo")); + QCOMPARE(spy.count(), 0); + } + void shouldHaveValueBasedAttachment() { Task::Attachment a; QVERIFY(!a.isValid()); QVERIFY(!a.isUri()); QCOMPARE(a.uri(), QUrl()); QCOMPARE(a.data(), QByteArray()); QCOMPARE(a.label(), QString()); QCOMPARE(a.mimeType(), QString()); QCOMPARE(a.iconName(), QString()); a.setUri(QUrl("https://www.kde.org")); QVERIFY(a.isValid()); QVERIFY(a.isUri()); QCOMPARE(a.uri(), QUrl("https://www.kde.org")); QCOMPARE(a.data(), QByteArray()); QCOMPARE(a.label(), QString()); QCOMPARE(a.mimeType(), QString()); QCOMPARE(a.iconName(), QString()); a.setData(QByteArrayLiteral("foobar")); QVERIFY(a.isValid()); QVERIFY(!a.isUri()); QCOMPARE(a.uri(), QUrl()); QCOMPARE(a.data(), QByteArrayLiteral("foobar")); QCOMPARE(a.label(), QString()); QCOMPARE(a.mimeType(), QString()); QCOMPARE(a.iconName(), QString()); a.setLabel(QStringLiteral("baz")); QVERIFY(a.isValid()); QVERIFY(!a.isUri()); QCOMPARE(a.uri(), QUrl()); QCOMPARE(a.data(), QByteArrayLiteral("foobar")); QCOMPARE(a.label(), QStringLiteral("baz")); QCOMPARE(a.mimeType(), QString()); QCOMPARE(a.iconName(), QString()); a.setMimeType(QStringLiteral("text/plain")); QVERIFY(a.isValid()); QVERIFY(!a.isUri()); QCOMPARE(a.uri(), QUrl()); QCOMPARE(a.data(), QByteArrayLiteral("foobar")); QCOMPARE(a.label(), QStringLiteral("baz")); QCOMPARE(a.mimeType(), QStringLiteral("text/plain")); QCOMPARE(a.iconName(), QString()); a.setIconName(QStringLiteral("text")); QVERIFY(a.isValid()); QVERIFY(!a.isUri()); QCOMPARE(a.uri(), QUrl()); QCOMPARE(a.data(), QByteArrayLiteral("foobar")); QCOMPARE(a.label(), QStringLiteral("baz")); QCOMPARE(a.mimeType(), QStringLiteral("text/plain")); QCOMPARE(a.iconName(), QStringLiteral("text")); a.setUri(QUrl("https://www.kde.org")); QVERIFY(a.isValid()); QVERIFY(a.isUri()); QCOMPARE(a.uri(), QUrl("https://www.kde.org")); QCOMPARE(a.data(), QByteArray()); QCOMPARE(a.label(), QStringLiteral("baz")); QCOMPARE(a.mimeType(), QStringLiteral("text/plain")); QCOMPARE(a.iconName(), QStringLiteral("text")); a.setUri(QUrl()); QVERIFY(!a.isValid()); QVERIFY(!a.isUri()); QCOMPARE(a.uri(), QUrl()); QCOMPARE(a.data(), QByteArray()); QCOMPARE(a.label(), QStringLiteral("baz")); QCOMPARE(a.mimeType(), QStringLiteral("text/plain")); QCOMPARE(a.iconName(), QStringLiteral("text")); } void shouldNotifyStatusChanges() { Task t; QSignalSpy spy(&t, &Task::doneChanged); t.setDone(true); QCOMPARE(spy.count(), 1); QCOMPARE(spy.first().first().toBool(), true); } void shouldNotNotifyIdenticalStatusChanges() { Task t; t.setDone(true); QSignalSpy spy(&t, &Task::doneChanged); t.setDone(true); QCOMPARE(spy.count(), 0); } void shouldNotifyStartDateChanges() { Task t; QSignalSpy spy(&t, &Task::startDateChanged); t.setStartDate(QDate(2014, 1, 13)); QCOMPARE(spy.count(), 1); QCOMPARE(spy.first().first().toDate(), QDate(2014, 1, 13)); } void shouldNotNotifyIdenticalStartDateChanges() { Task t; t.setStartDate(QDate(2014, 1, 13)); QSignalSpy spy(&t, &Task::startDateChanged); t.setStartDate(QDate(2014, 1, 13)); QCOMPARE(spy.count(), 0); } void shouldNotifyDueDateChanges() { Task t; QSignalSpy spy(&t, &Task::dueDateChanged); t.setDueDate(QDate(2014, 1, 13)); QCOMPARE(spy.count(), 1); QCOMPARE(spy.first().first().toDate(), QDate(2014, 1, 13)); } void shouldNotNotifyIdenticalDueDateChanges() { Task t; t.setDueDate(QDate(2014, 1, 13)); QSignalSpy spy(&t, &Task::dueDateChanged); t.setDueDate(QDate(2014, 1, 13)); QCOMPARE(spy.count(), 0); } void shouldNotifyRecurrenceChanges() { Task t; QSignalSpy spy(&t, &Task::recurrenceChanged); t.setRecurrence(Task::RecursWeekly); QCOMPARE(spy.count(), 1); QCOMPARE(spy.first().first().value(), Task::RecursWeekly); } void shouldNotNotifyIdenticalRecurrenceChanges() { Task t; t.setRecurrence(Task::RecursWeekly); QSignalSpy spy(&t, &Task::recurrenceChanged); t.setRecurrence(Task::RecursWeekly); QCOMPARE(spy.count(), 0); } void shouldNotifyAttachmentsChanges() { Task::Attachments attachments; attachments.append(Task::Attachment(QByteArrayLiteral("foobar"))); attachments.append(Task::Attachment(QUrl("https://www.kde.org"))); Task t; QSignalSpy spy(&t, &Task::attachmentsChanged); t.setAttachments(attachments); QCOMPARE(spy.count(), 1); QCOMPARE(spy.first().first().value(), attachments); } void shouldNotNotifyIdenticalAttachmentsChanges() { Task::Attachments attachments; attachments.append(Task::Attachment(QByteArrayLiteral("foobar"))); attachments.append(Task::Attachment(QUrl("https://www.kde.org"))); Task t; t.setAttachments(attachments); QSignalSpy spy(&t, &Task::attachmentsChanged); t.setAttachments(attachments); QCOMPARE(spy.count(), 0); } void shouldNotifyDoneDateChanges() { Task t; QSignalSpy spy(&t, &Task::doneDateChanged); t.setDoneDate(QDate(2014, 1, 13)); QCOMPARE(spy.count(), 1); QCOMPARE(spy.first().first().toDate(), QDate(2014, 1, 13)); } void shouldNotNotifyIdenticalDoneDateChanges() { Task t; t.setDoneDate(QDate(2014, 1, 13)); QSignalSpy spy(&t, &Task::doneDateChanged); t.setDoneDate(QDate(2014, 1, 13)); QCOMPARE(spy.count(), 0); } void shouldNotifyDoneDateSet() { Task t; QSignalSpy spy(&t, &Task::doneDateChanged); t.setDone(true); QCOMPARE(spy.count(), 1); QCOMPARE(spy.takeFirst().at(0).toDate(), Utils::DateTime::currentDate()); } void shouldNotifyDoneDateUnset() { Task t; t.setDone(true); QSignalSpy spy(&t, &Task::doneDateChanged); t.setDone(false); QCOMPARE(spy.count(), 1); QCOMPARE(spy.takeFirst().at(0).toDate(), QDate()); } }; ZANSHIN_TEST_MAIN(TaskTest) #include "tasktest.moc"