File: testsession.cpp

package info (click to toggle)
kronometer 2.3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,220 kB
  • sloc: cpp: 2,619; xml: 470; makefile: 7; sh: 2
file content (113 lines) | stat: -rw-r--r-- 2,495 bytes parent folder | download | duplicates (2)
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
/*
    SPDX-FileCopyrightText: 2015 Elvis Angelaccio <elvis.angelaccio@kde.org>

    SPDX-License-Identifier: GPL-2.0-or-later
*/

#include "testsession.h"
#include "session.h"

void TestSession::testDefaultSession()
{
    Session session;

    QCOMPARE(session.time(), 0);
    QVERIFY(session.isEmpty());
    QVERIFY(!session.isOutdated());
    QVERIFY(session.laps().isEmpty());
    QVERIFY(session.name().isNull());
    QVERIFY(session.note().isEmpty());
}

void TestSession::testTime()
{
    int time = 1000;
    Session session {time};

    QCOMPARE(session.time(), time);
}

void TestSession::testName()
{
    Session session;
    auto test = QLatin1String("test");

    session.setName(test);

    QCOMPARE(session.name(), test);
}

void TestSession::testNote()
{
    Session session;
    auto test = QLatin1String("test");

    session.setNote(test);

    QCOMPARE(session.note(), test);
}

void TestSession::testDate()
{
    auto date = QDateTime::currentDateTime();
    Session session {0, date};

    QCOMPARE(session.date(), date);
}

void TestSession::testLaps()
{
    Session session;

    const auto laps = QVector<Lap> {Lap {{1, 30}}, Lap {{2, 0}}, Lap {{1, 45}}};
    for (const auto& lap : laps) {
        session.addLap(lap);
    }

    QCOMPARE(session.laps().size(), laps.size());
}

void TestSession::testEquality()
{
    auto date = QDateTime::currentDateTime();

    Session session1 {0, date};
    Session session2 {1000, date};

    QCOMPARE(session1, session2);
}

void TestSession::testInequality()
{
    Session session1 {0, QDateTime::currentDateTime()};
    QTest::qSleep(100);
    Session session2 {0, QDateTime::currentDateTime()};

    QVERIFY(session1 != session2);
}

void TestSession::testJson()
{
    auto date = QDateTime::currentDateTime();
    Session session1 {1000, QDateTime::fromString(date.toString(Qt::ISODate), Qt::ISODate)};
    session1.setName(QStringLiteral("test-name"));
    session1.setNote(QStringLiteral("test-note"));

    const auto laps = QVector<Lap> {Lap {{1, 30}}, Lap {{2, 0}}, Lap {{1, 45}}};
    for (const auto& lap : laps) {
        session1.addLap(lap);
    }

    QJsonObject json;
    session1.write(json);

    Session session2 = Session::fromJson(json);

    QCOMPARE(session1, session2);
    QCOMPARE(session1.time(), session2.time());
    QCOMPARE(session1.name(), session2.name());
    QCOMPARE(session1.note(), session2.note());
    QCOMPARE(session1.laps().size(), session2.laps().size());
}

QTEST_MAIN(TestSession)