File indexing completed on 2025-01-19 04:46:59
0001 /* 0002 * SPDX-FileCopyrightText: 2016 Daniel Vrátil <dvratil@kde.org> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 * 0006 */ 0007 0008 #pragma once 0009 0010 #include <CalendarEvents/CalendarEventsPlugin> 0011 #include <QDebug> 0012 #include <QTest> 0013 0014 QDebug operator<<(QDebug dbg, const CalendarEvents::EventData &data) 0015 { 0016 dbg.nospace() << data.title() << " (UID " << data.uid() << "), " << data.startDateTime().toString(QStringLiteral("yyyy-MM-dd HH:mm:ss t")) << " - " 0017 << data.endDateTime().toString(QStringLiteral("yyyy-MM-dd HH:mm:ss t")); 0018 return dbg; 0019 } 0020 0021 namespace CalendarEvents 0022 { 0023 bool operator==(const EventData &lhs, const EventData &rhs) 0024 { 0025 return lhs.uid() == rhs.uid() && lhs.type() == rhs.type() && lhs.isAllDay() == rhs.isAllDay() && lhs.isMinor() == rhs.isMinor() 0026 && lhs.title() == rhs.title() && lhs.startDateTime() == rhs.startDateTime() && lhs.endDateTime() == rhs.endDateTime() 0027 && lhs.description() == rhs.description() && lhs.eventColor() == rhs.eventColor(); 0028 } 0029 0030 bool operator<(const EventData &lhs, const EventData &rhs) 0031 { 0032 if (lhs.startDateTime() != rhs.startDateTime()) { 0033 return lhs.startDateTime() < rhs.startDateTime(); 0034 } else if (lhs.endDateTime() != rhs.endDateTime()) { 0035 return lhs.endDateTime() < rhs.endDateTime(); 0036 } else { 0037 return lhs.uid() < rhs.uid(); 0038 } 0039 } 0040 } 0041 0042 #define COMPARE(_actual, _expected) \ 0043 { \ 0044 bool ok = false; \ 0045 [&]() { \ 0046 QCOMPARE(_actual, _expected); \ 0047 ok = true; \ 0048 }(); \ 0049 if (!ok) { \ 0050 return false; \ 0051 } \ 0052 } 0053 0054 #define VERIFY(_cond) \ 0055 { \ 0056 bool ok = false; \ 0057 [&]() { \ 0058 QVERIFY(_cond); \ 0059 ok = true; \ 0060 }(); \ 0061 if (!ok) { \ 0062 return false; \ 0063 } \ 0064 } 0065 0066 namespace TestUtils 0067 { 0068 bool compareEventData(const CalendarEvents::EventData &actual, const CalendarEvents::EventData &expected) 0069 { 0070 COMPARE(actual.title(), expected.title()); 0071 COMPARE(actual.description(), expected.description()); 0072 COMPARE(actual.isAllDay(), expected.isAllDay()); 0073 COMPARE(actual.isMinor(), expected.isMinor()); 0074 COMPARE(actual.type(), expected.type()); 0075 COMPARE(actual.eventColor(), expected.eventColor()); 0076 COMPARE(actual.uid(), expected.uid()); 0077 COMPARE(actual.startDateTime(), expected.startDateTime()); 0078 COMPARE(actual.endDateTime(), expected.endDateTime()); 0079 0080 return true; 0081 } 0082 }