summaryrefslogtreecommitdiff
path: root/tests/presence.cpp
blob: 14d463db6e2f421b3729c9320fc62ce3668f2a29 (plain)
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#include <QtTest/QtTest>

#include <TelepathyQt/Constants>
#include <TelepathyQt/Debug>
#include <TelepathyQt/Presence>
#include <TelepathyQt/Types>

using namespace Tp;

class TestPresence : public QObject
{
    Q_OBJECT

public:
    TestPresence(QObject *parent = nullptr);

private Q_SLOTS:
    void testPresence();
    void testPresenceSpec();
};

TestPresence::TestPresence(QObject *parent)
    : QObject(parent)
{
    Tp::enableDebug(true);
    Tp::enableWarnings(true);
}

#define TEST_PRESENCE(pr, prValid, prType, prStatus, prStatusMessage) \
{ \
    QVERIFY(pr.isValid() == prValid); \
    QCOMPARE(pr.type(), prType); \
    QCOMPARE(pr.status(), prStatus); \
    QCOMPARE(pr.statusMessage(), prStatusMessage); \
}

void TestPresence::testPresence()
{
    Presence pr;
    TEST_PRESENCE(pr, false, ConnectionPresenceTypeUnknown, QString(), QString());
    pr.setStatus(ConnectionPresenceTypeAvailable, QLatin1String("available"),
            QLatin1String("I am available"));
    TEST_PRESENCE(pr, true, ConnectionPresenceTypeAvailable, QLatin1String("available"), QLatin1String("I am available"));

    pr = Presence::available();
    TEST_PRESENCE(pr, true, ConnectionPresenceTypeAvailable, QLatin1String("available"), QString());
    pr = Presence::available(QLatin1String("I am available"));
    TEST_PRESENCE(pr, true, ConnectionPresenceTypeAvailable, QLatin1String("available"), QLatin1String("I am available"));

    pr = Presence::chat();
    TEST_PRESENCE(pr, true, ConnectionPresenceTypeAvailable, QLatin1String("chat"), QString());
    pr = Presence::chat(QLatin1String("I am chat"));
    TEST_PRESENCE(pr, true, ConnectionPresenceTypeAvailable, QLatin1String("chat"), QLatin1String("I am chat"));

    pr = Presence::away();
    TEST_PRESENCE(pr, true, ConnectionPresenceTypeAway, QLatin1String("away"), QString());
    pr = Presence::away(QLatin1String("I am away"));
    TEST_PRESENCE(pr, true, ConnectionPresenceTypeAway, QLatin1String("away"), QLatin1String("I am away"));

    pr = Presence::brb();
    TEST_PRESENCE(pr, true, ConnectionPresenceTypeAway, QLatin1String("brb"), QString());
    pr = Presence::brb(QLatin1String("I am brb"));
    TEST_PRESENCE(pr, true, ConnectionPresenceTypeAway, QLatin1String("brb"), QLatin1String("I am brb"));

    pr = Presence::busy();
    TEST_PRESENCE(pr, true, ConnectionPresenceTypeBusy, QLatin1String("busy"), QString());
    pr = Presence::busy(QLatin1String("I am busy"));
    TEST_PRESENCE(pr, true, ConnectionPresenceTypeBusy, QLatin1String("busy"), QLatin1String("I am busy"));

    pr = Presence::dnd();
    TEST_PRESENCE(pr, true, ConnectionPresenceTypeBusy, QLatin1String("dnd"), QString());
    pr = Presence::dnd(QLatin1String("I am dnd"));
    TEST_PRESENCE(pr, true, ConnectionPresenceTypeBusy, QLatin1String("dnd"), QLatin1String("I am dnd"));

    pr = Presence::xa();
    TEST_PRESENCE(pr, true, ConnectionPresenceTypeExtendedAway, QLatin1String("xa"), QString());
    pr = Presence::xa(QLatin1String("I am xa"));
    TEST_PRESENCE(pr, true, ConnectionPresenceTypeExtendedAway, QLatin1String("xa"), QLatin1String("I am xa"));

    pr = Presence::hidden();
    TEST_PRESENCE(pr, true, ConnectionPresenceTypeHidden, QLatin1String("hidden"), QString());
    pr = Presence::hidden(QLatin1String("I am hidden"));
    TEST_PRESENCE(pr, true, ConnectionPresenceTypeHidden, QLatin1String("hidden"), QLatin1String("I am hidden"));

    pr = Presence::offline();
    TEST_PRESENCE(pr, true, ConnectionPresenceTypeOffline, QLatin1String("offline"), QString());
    pr = Presence::offline(QLatin1String("I am offline"));
    TEST_PRESENCE(pr, true, ConnectionPresenceTypeOffline, QLatin1String("offline"), QLatin1String("I am offline"));
}

#define TEST_PRESENCE_SPEC_FULL(specStatus, specType, specMaySetOnSelf, specCanHaveMessage) \
{ \
    SimpleStatusSpec bareSpec; \
    bareSpec.type = specType; \
    bareSpec.maySetOnSelf = specMaySetOnSelf; \
    bareSpec.canHaveMessage = specCanHaveMessage; \
\
    PresenceSpec spec(specStatus, bareSpec); \
    TEST_PRESENCE_SPEC(spec, true, specStatus, specType, specMaySetOnSelf, specCanHaveMessage); \
}

#define TEST_PRESENCE_SPEC(spec, specValid, specStatus, specType, specMaySetOnSelf, specCanHaveMessage) \
{ \
    QVERIFY(spec.isValid() == specValid); \
    if (specValid) { \
        QCOMPARE(spec.presence(), Presence(specType, specStatus, QString())); \
        TEST_PRESENCE(spec.presence(), true, specType, specStatus, QString()); \
        QCOMPARE(spec.presence(QLatin1String("test message")), Presence(specType, specStatus, QLatin1String("test message"))); \
        TEST_PRESENCE(spec.presence(QLatin1String("test message")), true, specType, specStatus, QLatin1String("test message")); \
    } else { \
        QVERIFY(!spec.presence().isValid()); \
    } \
    QCOMPARE(spec.maySetOnSelf(), specMaySetOnSelf); \
    QCOMPARE(spec.canHaveStatusMessage(), specCanHaveMessage); \
\
    if (specValid) { \
        SimpleStatusSpec bareSpec; \
        bareSpec.type = specType; \
        bareSpec.maySetOnSelf = specMaySetOnSelf; \
        bareSpec.canHaveMessage = specCanHaveMessage; \
        QCOMPARE(spec.bareSpec(), bareSpec); \
    } else { \
        QCOMPARE(spec.bareSpec(), SimpleStatusSpec()); \
    } \
}

void TestPresence::testPresenceSpec()
{
    PresenceSpec spec;
    TEST_PRESENCE_SPEC(spec, false, QString(), ConnectionPresenceTypeUnknown, false, false);

    TEST_PRESENCE_SPEC_FULL(QLatin1String("available"), ConnectionPresenceTypeAvailable, true, true);
    TEST_PRESENCE_SPEC_FULL(QLatin1String("brb"), ConnectionPresenceTypeAway, true, true);
    TEST_PRESENCE_SPEC_FULL(QLatin1String("away"), ConnectionPresenceTypeAway, true, true);
    TEST_PRESENCE_SPEC_FULL(QLatin1String("xa"), ConnectionPresenceTypeExtendedAway, false, false);
    TEST_PRESENCE_SPEC_FULL(QLatin1String("offline"), ConnectionPresenceTypeOffline, true, false);

    spec = PresenceSpec::available();
    TEST_PRESENCE_SPEC(spec, true, QLatin1String("available"), ConnectionPresenceTypeAvailable, true, true);
    spec = PresenceSpec::chat();
    TEST_PRESENCE_SPEC(spec, true, QLatin1String("chat"), ConnectionPresenceTypeAvailable, true, true);
    spec = PresenceSpec::pstn();
    TEST_PRESENCE_SPEC(spec, true, QLatin1String("pstn"), ConnectionPresenceTypeAvailable, false, true);
    spec = PresenceSpec::away();
    TEST_PRESENCE_SPEC(spec, true, QLatin1String("away"), ConnectionPresenceTypeAway, true, true);
    spec = PresenceSpec::brb();
    TEST_PRESENCE_SPEC(spec, true, QLatin1String("brb"), ConnectionPresenceTypeAway, true, true);
    spec = PresenceSpec::busy();
    TEST_PRESENCE_SPEC(spec, true, QLatin1String("busy"), ConnectionPresenceTypeBusy, true, true);
    spec = PresenceSpec::dnd();
    TEST_PRESENCE_SPEC(spec, true, QLatin1String("dnd"), ConnectionPresenceTypeBusy, true, true);
    spec = PresenceSpec::xa();
    TEST_PRESENCE_SPEC(spec, true, QLatin1String("xa"), ConnectionPresenceTypeExtendedAway, true, true);
    spec = PresenceSpec::hidden();
    TEST_PRESENCE_SPEC(spec, true, QLatin1String("hidden"), ConnectionPresenceTypeHidden, true, true);
    spec = PresenceSpec::offline();
    TEST_PRESENCE_SPEC(spec, true, QLatin1String("offline"), ConnectionPresenceTypeOffline, false, true);
    spec = PresenceSpec::unknown();
    TEST_PRESENCE_SPEC(spec, true, QLatin1String("unknown"), ConnectionPresenceTypeUnknown, false, true);
    spec = PresenceSpec::error();
    TEST_PRESENCE_SPEC(spec, true, QLatin1String("error"), ConnectionPresenceTypeError, false, true);
}

QTEST_MAIN(TestPresence)

#include "_gen/presence.cpp.moc.hpp"