File: testthread.cpp

package info (click to toggle)
libquotient 0.9.5-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,588 kB
  • sloc: xml: 39,103; cpp: 25,226; sh: 97; makefile: 10
file content (88 lines) | stat: -rw-r--r-- 3,391 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
// SPDX-FileCopyrightText: 2024 James Graham <james.h.graham@protonmail.com>
//
// SPDX-License-Identifier: LGPL-2.1-or-later

#include <QTest>

#include <Quotient/events/roommessageevent.h>
#include <Quotient/thread.h>

#include "testutils.h"

using namespace Quotient;

class TestThread : public QObject
{
    Q_OBJECT

private Q_SLOTS:
    void newThread();
    void historicalThread();
};

void TestThread::newThread()
{
    auto testThread = Thread();
    const auto rootEvent = loadEventFromFile<RoomMessageEvent>("test-threadroot-event.json"_L1);

    testThread.threadRootId = rootEvent->id();
    QCOMPARE(testThread.threadRootId, "$threadroot:example.org"_L1);
    QCOMPARE(testThread.latestEventId, QString());
    QCOMPARE(testThread.size, 0);
    QCOMPARE(testThread.localUserParticipated, false);

    testThread.addEvent(rootEvent.get(), true, false);
    QCOMPARE(testThread.threadRootId, "$threadroot:example.org"_L1);
    QCOMPARE(testThread.latestEventId, "$threadroot:example.org"_L1);
    QCOMPARE(testThread.size, 1);
    QCOMPARE(testThread.localUserParticipated, false);

    const auto replyEvent1 = loadEventFromFile<RoomMessageEvent>("test-thread1-event.json"_L1);
    testThread.addEvent(replyEvent1.get(), true, true);
    QCOMPARE(testThread.threadRootId, "$threadroot:example.org"_L1);
    QCOMPARE(testThread.latestEventId, "$thread1:example.org"_L1);
    QCOMPARE(testThread.size, 2);
    QCOMPARE(testThread.localUserParticipated, true);

    const auto replyEvent2 = loadEventFromFile<RoomMessageEvent>("test-thread2-event.json"_L1);
    testThread.addEvent(replyEvent2.get(), true, false);
    QCOMPARE(testThread.threadRootId, "$threadroot:example.org"_L1);
    QCOMPARE(testThread.latestEventId, "$thread2:example.org"_L1);
    QCOMPARE(testThread.size, 3);
    QCOMPARE(testThread.localUserParticipated, true);
}

void TestThread::historicalThread()
{
    auto testThread = Thread();
    const auto replyEvent2 = loadEventFromFile<RoomMessageEvent>("test-thread2-event.json"_L1);

    testThread.threadRootId = replyEvent2->threadRootEventId();
    QCOMPARE(testThread.threadRootId, "$threadroot:example.org"_L1);
    QCOMPARE(testThread.latestEventId, QString());
    QCOMPARE(testThread.size, 0);
    QCOMPARE(testThread.localUserParticipated, false);

    testThread.addEvent(replyEvent2.get(), true, false);
    QCOMPARE(testThread.threadRootId, "$threadroot:example.org"_L1);
    QCOMPARE(testThread.latestEventId, "$thread2:example.org"_L1);
    QCOMPARE(testThread.size, 1);
    QCOMPARE(testThread.localUserParticipated, false);

    const auto replyEvent1 = loadEventFromFile<RoomMessageEvent>("test-thread1-event.json"_L1);
    testThread.addEvent(replyEvent1.get(), false, true);
    QCOMPARE(testThread.threadRootId, "$threadroot:example.org"_L1);
    QCOMPARE(testThread.latestEventId, "$thread2:example.org"_L1);
    QCOMPARE(testThread.size, 2);
    QCOMPARE(testThread.localUserParticipated, true);

    const auto rootEvent = loadEventFromFile<RoomMessageEvent>("test-threadroot-event.json"_L1);
    testThread.addEvent(rootEvent.get(), false, true);
    QCOMPARE(testThread.threadRootId, "$threadroot:example.org"_L1);
    QCOMPARE(testThread.latestEventId, "$thread2:example.org"_L1);
    QCOMPARE(testThread.size, 3);
    QCOMPARE(testThread.localUserParticipated, true);
}

QTEST_GUILESS_MAIN(TestThread)
#include "testthread.moc"