aboutsummaryrefslogtreecommitdiff
path: root/tests/IntegrationTesting.h
blob: 15d45c62232e3136ed150fb61114aadb6bb61f28 (plain) (blame)
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
// SPDX-FileCopyrightText: 2021 Linus Jahn <lnj@kaidan.im>
//
// SPDX-License-Identifier: LGPL-2.1-or-later

#ifndef INTEGRATIONTESTING_H
#define INTEGRATIONTESTING_H

#include "QXmppConfiguration.h"

#include <QDebug>
#include <QtGlobal>

#define ENV_ENABLED "QXMPP_TESTS_INTEGRATION_ENABLED"
#define ENV_JID "QXMPP_TESTS_JID"
#define ENV_PASSWORD "QXMPP_TESTS_PASSWORD"

#define SKIP_IF_INTEGRATION_TESTS_DISABLED()                            \
    if (!IntegrationTests::enabled()) {                                 \
        QSKIP("Export 'QXMPP_TESTS_INTEGRATION_ENABLED=1' to enable."); \
    } else if (!IntegrationTests::credentialsAvailable()) {             \
        QFAIL("No credentials for integration tests provided! "         \
              "Export 'QXMPP_TESTS_JID' and 'QXMPP_TESTS_PASSWORD'.");  \
    }

class IntegrationTests
{
public:
    static QString environmentVariable(const char *varName, const QString &defaultValue = {})
    {
        return qEnvironmentVariable(varName, defaultValue);
    }

    static bool enabled()
    {
        return environmentVariable(ENV_ENABLED, "0") == "1";
    }

    static bool credentialsAvailable()
    {
        return !qEnvironmentVariableIsEmpty(ENV_JID) && !qEnvironmentVariableIsEmpty(ENV_PASSWORD);
    }

    static QXmppConfiguration clientConfiguration()
    {
        QXmppConfiguration config;
        config.setJid(environmentVariable(ENV_JID));
        config.setPassword(environmentVariable(ENV_PASSWORD));
        return config;
    }
};

#undef ENV_ENABLED
#undef ENV_JID
#undef ENV_PASSWORD

#endif  // INTEGRATIONTESTING_H