service/DavPushServiceTest.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | #include <QPointer> | ||
| 3 | |||
| 4 | #include <QObject> | ||
| 5 | #include <QPointer> | ||
| 6 | #include <QTimer> | ||
| 7 | #include <functional> | ||
| 8 | |||
| 9 | class NtfyPushReceiver; | ||
| 10 | class QNetworkAccessManager; | ||
| 11 | |||
| 12 | // Sprint 96 S96.4.2 / §4.4: "Test connection" of a push service draft. It | ||
| 13 | // opens a stream on a throw-away channel, publishes one message to that | ||
| 14 | // channel through the service and succeeds when the message comes back. | ||
| 15 | // It proves reachability, TLS, sign-in and delivery through the service — | ||
| 16 | // not Nextcloud delivery (that needs a real change, J96-03). It creates no | ||
| 17 | // DAV subscription, changes no calendar and never replaces the active | ||
| 18 | // service. | ||
| 19 | class AuthenticatedRequest; | ||
| 20 | |||
| 21 | class DavPushServiceTest final : public QObject { | ||
| 22 | ✗ | Q_OBJECT | |
| 23 | public: | ||
| 24 | enum class Result { Ok, InvalidUrl, Unreachable, Tls, Authentication, Timeout, NoDelivery }; | ||
| 25 | 7 | Q_ENUM(Result) | |
| 26 | |||
| 27 | explicit DavPushServiceTest(QObject *parent = nullptr); | ||
| 28 | ~DavPushServiceTest() override; | ||
| 29 | |||
| 30 | // The settings' "Test connection" for a push service (product code: one | ||
| 31 | // outgoing stream and one outgoing POST, no inbound surface). A start() | ||
| 32 | // while a test runs is ignored — the running test's finished() is the | ||
| 33 | // answer for both callers (S106-072: the former "joins" overstated it). | ||
| 34 | void start(const QString &server, const QByteArray &token); | ||
| 35 | void cancel(); | ||
| 36 | 1 | bool running() const { return m_running; } | |
| 37 | |||
| 38 | // Test seams. | ||
| 39 | void setNetworkAccessManager(QNetworkAccessManager *nam); | ||
| 40 | void setTimeoutMs(int ms) { m_timeout.setInterval(ms); } | ||
| 41 | 2 | void setReceiverFactory(std::function<NtfyPushReceiver *(QObject *)> factory) { m_receiverFactory = std::move(factory); } | |
| 42 | |||
| 43 | signals: | ||
| 44 | void finished(DavPushServiceTest::Result result, const QString &detail); | ||
| 45 | |||
| 46 | private: | ||
| 47 | void publish(); | ||
| 48 | void finish(Result result, const QString &detail = {}); | ||
| 49 | |||
| 50 | QPointer<NtfyPushReceiver> m_receiver; | ||
| 51 | QNetworkAccessManager *m_nam = nullptr; | ||
| 52 | std::function<NtfyPushReceiver *(QObject *)> m_receiverFactory; | ||
| 53 | QTimer m_timeout; | ||
| 54 | QString m_server; | ||
| 55 | QString m_channel; | ||
| 56 | QByteArray m_token; | ||
| 57 | QByteArray m_probe; | ||
| 58 | bool m_running = false; | ||
| 59 | QPointer<AuthenticatedRequest> m_publishRequest; | ||
| 60 | bool m_published = false; | ||
| 61 | }; | ||
| 62 |