Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qfakexdgportalfixture_p.h
Go to the documentation of this file.
1// Copyright (C) 2026 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef QFAKEXDGPORTALFIXTURE_P_H
5#define QFAKEXDGPORTALFIXTURE_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtCore/qsize.h>
19#include <QtCore/qstring.h>
20#include <QtCore/private/qexpected_p.h>
21
22#include <private/qsyntheticvideoscene_p.h>
23
24#include <memory>
25
26QT_BEGIN_NAMESPACE
27
28/*!
29 \internal
30
31 Runs an unattended stand-in for xdg-desktop-portal, so that tests can exercise
32 the portal-backed PipeWire code paths end to end without a human approving a
33 consent dialog. Today it implements the ScreenCast interface; the intent is that
34 every portal interface qtmultimedia talks to is faked here.
35
36 It brings up, and tears down:
37 \list
38 \li a private pipewire daemon, with no session manager and no access to any
39 real hardware;
40 \li a helper process (this test binary, re-executed with
41 QtFakeXdgPortal::HelperArgument) which owns
42 \c org.freedesktop.portal.Desktop on a private D-Bus session bus and
43 publishes a synthetic video source rendering a SyntheticVideoScene.
44 \endlist
45
46 Usage from a test's main():
47 \code
48 #define main testlib_main
49 QTEST_MAIN(tst_Foo)
50 #undef main
51
52 int main(int argc, char *argv[])
53 {
54 if (QFakeXdgPortalFixture::isHelperProcess(argc, argv))
55 return QFakeXdgPortalFixture::runHelperProcess(argc, argv);
56 QFakeXdgPortalFixture::reexecUnderPrivateBusIfRequested(argc, argv);
57 return testlib_main(argc, argv);
58 }
59 \endcode
60
61 The re-exec must happen before QApplication is constructed: QApplication opens
62 the session bus, and QDBusConnection caches it for the lifetime of the process.
63*/
64class QFakeXdgPortalFixture
65{
66public:
67 QFakeXdgPortalFixture();
68 ~QFakeXdgPortalFixture();
69
70 Q_DISABLE_COPY_MOVE(QFakeXdgPortalFixture)
71
72 //! True when this process was started as the fake portal helper.
73 static bool isHelperProcess(int argc, char **argv);
74 static int runHelperProcess(int argc, char **argv);
75
76 /*!
77 Whether the fixture should be used at all. Controlled by
78 QT_MULTIMEDIA_TEST_XDG_PORTAL_FIXTURE: "fake" forces it on, "none" forces it
79 off, and the default "auto" enables it on Linux for non-X11 sessions, where
80 the real portal would otherwise block on a consent dialog.
81 */
82 static bool isRequested();
83
84 //! Whether the external pieces (pipewire, dbus-run-session) are present.
85 static bool prerequisitesAvailable(QString *unavailableReason = nullptr);
86
87 /*!
88 Re-executes the test binary under dbus-run-session when isRequested() and the
89 prerequisites hold, so the whole test runs against a private session bus.
90 Returns normally when no re-exec is needed or possible.
91 */
92 static void reexecUnderPrivateBusIfRequested(int argc, char **argv);
93
94 //! True if the current process is already running on the fixture's private bus.
95 static bool isRunningOnPrivateBus();
96
97 q23::expected<void, QString> start(const SyntheticVideoScene &initialScene);
98 void stop();
99 [[nodiscard]] bool isActive() const;
100
101 //! The node id the fake portal reports from Start(). Mostly useful for diagnostics.
102 [[nodiscard]] quint32 nodeId() const;
103
104 //! Replaces the content published by the synthetic source.
105 q23::expected<void, QString> setScene(const SyntheticVideoScene &scene);
106
107 //! Revokes the portal session mid-stream, as a compositor would.
108 q23::expected<void, QString> closeSessions();
109
110private:
111 q23::expected<void, QString> startHelper(QSize frameSize);
112 void stopHelper();
113
114 class Private;
115 std::unique_ptr<Private> d;
116};
117
118QT_END_NAMESPACE
119
120#endif // QFAKEXDGPORTALFIXTURE_P_H