File indexing completed on 2025-02-16 05:09:08

0001 /****************************************************************************
0002 **
0003 ** Copyright (C) 2018 The Qt Company Ltd.
0004 ** Contact: https://www.qt.io/licensing/
0005 **
0006 ** This file is part of the test suite of the Qt Toolkit.
0007 **
0008 ** $QT_BEGIN_LICENSE:GPL-EXCEPT$
0009 ** Commercial License Usage
0010 ** Licensees holding valid commercial Qt licenses may use this file in
0011 ** accordance with the commercial license agreement provided with the
0012 ** Software or, alternatively, in accordance with the terms contained in
0013 ** a written agreement between you and The Qt Company. For licensing terms
0014 ** and conditions see https://www.qt.io/terms-conditions. For further
0015 ** information use the contact form at https://www.qt.io/contact-us.
0016 **
0017 ** GNU General Public License Usage
0018 ** Alternatively, this file may be used under the terms of the GNU
0019 ** General Public License version 3 as published by the Free Software
0020 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
0021 ** included in the packaging of this file. Please review the following
0022 ** information to ensure the GNU General Public License requirements will
0023 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
0024 **
0025 ** $QT_END_LICENSE$
0026 **
0027 ****************************************************************************/
0028 
0029 #pragma once
0030 
0031 #include "corecompositor.h"
0032 #include "coreprotocol.h"
0033 #include "datadevice.h"
0034 #include "layershell.h"
0035 #include "outputorder.h"
0036 #include "xdgoutputv1.h"
0037 #include "xdgshell.h"
0038 
0039 #include <QtGui/QGuiApplication>
0040 
0041 namespace MockCompositor
0042 {
0043 class DefaultCompositor : public CoreCompositor
0044 {
0045 public:
0046     explicit DefaultCompositor();
0047     // Convenience functions
0048     Output *output(int i = 0)
0049     {
0050         return getAll<Output>().value(i, nullptr);
0051     }
0052     Pointer *pointer()
0053     {
0054         auto *seat = get<Seat>();
0055         Q_ASSERT(seat);
0056         return seat->m_pointer;
0057     }
0058     Touch *touch()
0059     {
0060         auto *seat = get<Seat>();
0061         Q_ASSERT(seat);
0062         return seat->m_touch;
0063     }
0064     Surface *cursorSurface()
0065     {
0066         auto *p = pointer();
0067         return p ? p->cursorSurface() : nullptr;
0068     }
0069     Keyboard *keyboard()
0070     {
0071         auto *seat = get<Seat>();
0072         Q_ASSERT(seat);
0073         return seat->m_keyboard;
0074     }
0075     Surface *surface(int i = 0)
0076     {
0077         return get<WlCompositor>()->m_surfaces.value(i, nullptr);
0078     }
0079     XdgSurface *xdgSurface(int i = 0)
0080     {
0081         return get<XdgWmBase>()->m_xdgSurfaces.value(i, nullptr);
0082     }
0083     XdgToplevel *xdgToplevel(int i = 0)
0084     {
0085         return get<XdgWmBase>()->toplevel(i);
0086     }
0087     XdgPopup *xdgPopup(int i = 0)
0088     {
0089         return get<XdgWmBase>()->popup(i);
0090     }
0091     XdgOutputV1 *xdgOutput(Output *out)
0092     {
0093         return get<XdgOutputManagerV1>()->getXdgOutput(out);
0094     }
0095     uint sendXdgShellPing();
0096     void xdgPingAndWaitForPong();
0097 
0098     OutputOrder *outputOrder()
0099     {
0100         auto *order = get<OutputOrder>();
0101         Q_ASSERT(order);
0102         return order;
0103     }
0104 
0105     LayerShell *layerShell()
0106     {
0107         auto *shell = get<LayerShell>();
0108         Q_ASSERT(shell);
0109         return shell;
0110     }
0111 
0112     // Things that can be changed run-time without confusing the client (i.e. don't require separate tests)
0113     struct Config {
0114         bool autoEnter = true;
0115         bool autoRelease = true;
0116         bool autoConfigure = false;
0117     } m_config;
0118     void resetConfig()
0119     {
0120         exec([&] {
0121             m_config = Config{};
0122         });
0123     }
0124 };
0125 
0126 // addOutput(OutputData)
0127 
0128 } // namespace MockCompositor
0129 
0130 #define QCOMPOSITOR_VERIFY(expr)                                                                                                                               \
0131     QVERIFY(exec([&] {                                                                                                                                         \
0132         return expr;                                                                                                                                           \
0133     }))
0134 #define QCOMPOSITOR_TRY_VERIFY(expr)                                                                                                                           \
0135     QTRY_VERIFY(exec([&] {                                                                                                                                     \
0136         return expr;                                                                                                                                           \
0137     }))
0138 #define QCOMPOSITOR_COMPARE(expr, expr2)                                                                                                                       \
0139     QCOMPARE(exec([&] {                                                                                                                                        \
0140                  return expr;                                                                                                                                  \
0141              }),                                                                                                                                               \
0142              expr2)
0143 #define QCOMPOSITOR_TRY_COMPARE(expr, expr2)                                                                                                                   \
0144     QTRY_COMPARE(exec([&] {                                                                                                                                    \
0145                      return expr;                                                                                                                              \
0146                  }),                                                                                                                                           \
0147                  expr2)
0148 
0149 #define QCOMPOSITOR_TEST_MAIN(test)                                                                                                                            \
0150     int main(int argc, char **argv)                                                                                                                            \
0151     {                                                                                                                                                          \
0152         QTemporaryDir tmpRuntimeDir;                                                                                                                           \
0153         setenv("XDG_RUNTIME_DIR", tmpRuntimeDir.path().toLocal8Bit(), 1);                                                                                      \
0154         setenv("XDG_CURRENT_DESKTOP", "qtwaylandtests", 1);                                                                                                    \
0155         setenv("QT_QPA_PLATFORM", "wayland", 1);                                                                                                               \
0156         test tc;                                                                                                                                               \
0157         QApplication app(argc, argv);                                                                                                                          \
0158         return QTest::qExec(&tc, argc, argv);                                                                                                                  \
0159     }