File: mockdistributor.cpp

package info (click to toggle)
kunifiedpush 25.08.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,036 kB
  • sloc: cpp: 4,524; xml: 154; java: 141; makefile: 5; sh: 1
file content (60 lines) | stat: -rw-r--r-- 1,735 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
/*
    SPDX-FileCopyrightText: 2025 Volker Krause <vkrause@kde.org>
    SPDX-License-Identifier: LGPL-2.0-or-later
*/

#include "../src/distributor/distributor.h"
#include "../src/distributor/message.h"
#include "../src/distributor/mockpushprovider.h"

#include <QCoreApplication>
#include <QDBusConnection>
#include <QDebug>
#include <QStandardPaths>

using namespace Qt::Literals;

class MockController : public QObject
{
    Q_OBJECT
public:
    Q_SCRIPTABLE void quit()
    {
        QCoreApplication::quit();
    }

    Q_SCRIPTABLE void receiveMessage(const QString &remoteId, const QByteArray &content, const QString &messageIdentifier)
    {
        KUnifiedPush::Message msg;
        msg.clientRemoteId = remoteId;
        msg.content = content;
        msg.messageId = messageIdentifier;
        Q_EMIT KUnifiedPush::MockPushProvider::s_instance->messageReceived(msg);
    }
};

int main(int argc, char **argv)
{
    QStandardPaths::setTestModeEnabled(true);

    QCoreApplication::setOrganizationDomain(u"kde.org"_s);
    QCoreApplication::setOrganizationName(u"KDE"_s);

    QCoreApplication app(argc, argv);

    qDebug() << "Starting mock distributor";
    MockController controller;
    QDBusConnection::sessionBus().registerObject("/MockController"_L1, "org.kde.unifiedpush.MockController"_L1, &controller, QDBusConnection::ExportAllContents);

    KUnifiedPush::Distributor dist;
    if (!QDBusConnection::sessionBus().registerService(u"org.unifiedpush.Distributor.mock"_s)) {
        qCritical() << "Distributor service name already in use - aborting!";
        return 1;
    }

    const auto r = QCoreApplication::exec();
    qDebug() << "Stopping mock Distributor";
    return r;
}

#include "mockdistributor.moc"