File indexing completed on 2024-04-28 07:41:06
0001 /* 0002 This file is part of the kcalcore library. 0003 0004 SPDX-FileCopyrightText: 2010 Casey Link <unnamedrambler@gmail.com> 0005 SPDX-FileCopyrightText: 2009-2010 Klaralvdalens Datakonsult AB, a KDAB Group company <info@kdab.net> 0006 0007 SPDX-License-Identifier: LGPL-2.0-or-later 0008 */ 0009 0010 #include "testfreebusyperiod.h" 0011 #include "freebusyperiod.h" 0012 0013 #include <QTest> 0014 #include <QTimeZone> 0015 QTEST_MAIN(FreeBusyPeriodTest) 0016 0017 using namespace KCalendarCore; 0018 0019 void FreeBusyPeriodTest::testValidity() 0020 { 0021 const QDateTime p1DateTime(QDate(2006, 8, 30), QTime(7, 0, 0), QTimeZone::UTC); 0022 FreeBusyPeriod p1(p1DateTime, Duration(60)); 0023 0024 QString summary = QStringLiteral("I can haz summary?"); 0025 QString location = QStringLiteral("The Moon"); 0026 p1.setSummary(summary); 0027 p1.setLocation(location); 0028 0029 QVERIFY(p1.hasDuration()); 0030 QCOMPARE(p1.duration().asSeconds(), 60); 0031 QVERIFY(p1.start() == QDateTime(QDate(2006, 8, 30), QTime(7, 0, 0), QTimeZone::UTC)); 0032 0033 QCOMPARE(p1.summary(), summary); 0034 QCOMPARE(p1.location(), location); 0035 } 0036 0037 void FreeBusyPeriodTest::testAssign() 0038 { 0039 const QDateTime p1DateTime(QDate(2006, 8, 30), QTime(7, 0, 0), QTimeZone::UTC); 0040 FreeBusyPeriod p1(p1DateTime, Duration(60)); 0041 FreeBusyPeriod p2; 0042 0043 QString summary = QStringLiteral("I can haz summary?"); 0044 QString location = QStringLiteral("The Moon"); 0045 p1.setSummary(summary); 0046 p1.setLocation(location); 0047 0048 p2 = p1; 0049 0050 QVERIFY(p2.hasDuration()); 0051 QVERIFY(p2.duration().asSeconds() == 60); 0052 QVERIFY(p2.start() == p1DateTime); 0053 QCOMPARE(p1.summary(), summary); 0054 QCOMPARE(p1.location(), location); 0055 } 0056 0057 void FreeBusyPeriodTest::testCopyConstructor() 0058 { 0059 const QDateTime p1DateTime(QDate(2006, 8, 30), QTime(7, 0, 0), QTimeZone::UTC); 0060 FreeBusyPeriod p1(p1DateTime, Duration(60)); 0061 QString summary = QStringLiteral("I can haz summary?"); 0062 QString location = QStringLiteral("The Moon"); 0063 p1.setSummary(summary); 0064 p1.setLocation(location); 0065 0066 FreeBusyPeriod p2 {p1}; 0067 0068 QVERIFY(p2.hasDuration()); 0069 QVERIFY(p2.duration().asSeconds() == 60); 0070 QVERIFY(p2.start() == p1DateTime); 0071 QCOMPARE(p1.summary(), summary); 0072 QCOMPARE(p1.location(), location); 0073 } 0074 0075 0076 void FreeBusyPeriodTest::testDataStreamOut() 0077 { 0078 const QDateTime p1DateTime(QDate(2006, 8, 30), QTime(7, 0, 0), QTimeZone::UTC); 0079 FreeBusyPeriod p1(p1DateTime, Duration(60)); 0080 0081 p1.setSummary(QStringLiteral("I can haz summary?")); 0082 p1.setLocation(QStringLiteral("The Moon")); 0083 0084 QByteArray byteArray; 0085 QDataStream out_stream(&byteArray, QIODevice::WriteOnly); 0086 0087 out_stream << p1; 0088 0089 QDataStream in_stream(&byteArray, QIODevice::ReadOnly); 0090 0091 Period p2; 0092 Period periodParent = static_cast<Period>(p1); 0093 in_stream >> p2; 0094 QVERIFY(periodParent == p2); 0095 0096 QString summary; 0097 in_stream >> summary; 0098 QCOMPARE(summary, p1.summary()); 0099 0100 QString location; 0101 in_stream >> location; 0102 QCOMPARE(location, p1.location()); 0103 } 0104 0105 void FreeBusyPeriodTest::testDataStreamIn() 0106 { 0107 const QDateTime p1DateTime = QDate(2006, 8, 30).startOfDay(); 0108 const Duration duration(24 * 60 * 60); 0109 FreeBusyPeriod p1(p1DateTime, duration); 0110 p1.setSummary(QStringLiteral("I can haz summary?")); 0111 p1.setLocation(QStringLiteral("The Moon")); 0112 0113 QByteArray byteArray; 0114 QDataStream out_stream(&byteArray, QIODevice::WriteOnly); 0115 0116 out_stream << p1; 0117 0118 QDataStream in_stream(&byteArray, QIODevice::ReadOnly); 0119 0120 FreeBusyPeriod p2; 0121 in_stream >> p2; 0122 0123 QCOMPARE(p2, p1); 0124 } 0125 0126 #include "moc_testfreebusyperiod.cpp"