File: testfreebusyperiod.cpp

package info (click to toggle)
kcalcore 4%3A18.08.3-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 5,704 kB
  • sloc: cpp: 22,533; perl: 136; sh: 11; makefile: 5
file content (117 lines) | stat: -rw-r--r-- 3,574 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
  This file is part of the kcalcore library.

  Copyright (C) 2010 Casey Link <unnamedrambler@gmail.com>
  Copyright (C) 2009-2010 Klaralvdalens Datakonsult AB, a KDAB Group company <info@kdab.net>

  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.
*/

#include "testfreebusyperiod.h"
#include "freebusyperiod.h"

#include <QTest>
QTEST_MAIN(FreeBusyPeriodTest)

using namespace KCalCore;

void FreeBusyPeriodTest::testValidity()
{
    const QDateTime p1DateTime(QDate(2006, 8, 30), QTime(7, 0, 0), Qt::UTC);
    FreeBusyPeriod p1(p1DateTime, Duration(60));

    QString summary = QStringLiteral("I can haz summary?");
    QString location = QStringLiteral("The Moon");
    p1.setSummary(summary);
    p1.setLocation(location);

    QVERIFY(p1.hasDuration());
    QCOMPARE(p1.duration().asSeconds(), 60);
    QVERIFY(p1.start() == QDateTime(QDate(2006, 8, 30), QTime(7, 0, 0), Qt::UTC));

    QCOMPARE(p1.summary(), summary);
    QCOMPARE(p1.location(), location);
}

void FreeBusyPeriodTest::testAssign()
{
    const QDateTime p1DateTime(QDate(2006, 8, 30), QTime(7, 0, 0), Qt::UTC);
    FreeBusyPeriod p1(p1DateTime, Duration(60));
    FreeBusyPeriod p2;

    QString summary = QStringLiteral("I can haz summary?");
    QString location = QStringLiteral("The Moon");
    p1.setSummary(summary);
    p1.setLocation(location);

    p2 = p1;

    QVERIFY(p2.hasDuration());
    QVERIFY(p2.duration().asSeconds() == 60);
    QVERIFY(p2.start() == QDateTime(QDate(2006, 8, 30), QTime(7, 0, 0), Qt::UTC));
    QCOMPARE(p1.summary(), summary);
    QCOMPARE(p1.location(), location);
}

void FreeBusyPeriodTest::testDataStreamOut()
{
    const QDateTime p1DateTime(QDate(2006, 8, 30), QTime(7, 0, 0), Qt::UTC);
    FreeBusyPeriod p1(p1DateTime, Duration(60));

    p1.setSummary(QStringLiteral("I can haz summary?"));
    p1.setLocation(QStringLiteral("The Moon"));

    QByteArray byteArray;
    QDataStream out_stream(&byteArray, QIODevice::WriteOnly);

    out_stream << p1;

    QDataStream in_stream(&byteArray, QIODevice::ReadOnly);

    Period p2;
    Period periodParent = static_cast<Period>(p1);
    in_stream >> p2;
    QVERIFY(periodParent == p2);

    QString summary;
    in_stream >> summary;
    QCOMPARE(summary, p1.summary());

    QString location;
    in_stream >> location;
    QCOMPARE(location, p1.location());
}

void FreeBusyPeriodTest::testDataStreamIn()
{
    const QDateTime p1DateTime(QDate(2006, 8, 30));
    const Duration duration(24 * 60 * 60);
    FreeBusyPeriod p1(p1DateTime, duration);
    p1.setSummary(QStringLiteral("I can haz summary?"));
    p1.setLocation(QStringLiteral("The Moon"));

    QByteArray byteArray;
    QDataStream out_stream(&byteArray, QIODevice::WriteOnly);

    out_stream << p1;

    QDataStream in_stream(&byteArray, QIODevice::ReadOnly);

    FreeBusyPeriod p2;
    in_stream >> p2;

    QCOMPARE(p2, p1);
}