#include <QGuiApplication>
#include <QtTest>
#include <QWindow>

#include "wm-interface.h"

using namespace UkuiQuick;

class TestWMInterface : public WMInterface
{
public:
    explicit TestWMInterface(QWindow *window)
        : WMInterface(window)
    {
    }

    void setWindowType(WindowType::Type type) override { Q_UNUSED(type); }
    void setSkipTaskBar(bool skip = true) override { Q_UNUSED(skip); }
    void setSkipSwitcher(bool skip = true) override { Q_UNUSED(skip); }
    void setRemoveTitleBar(bool remove = true) override { Q_UNUSED(remove); }
    void setPanelTakesFocus(bool takesFocus = true) override { Q_UNUSED(takesFocus); }
    void setPanelAutoHide(bool autoHide = false) override { Q_UNUSED(autoHide); }
    QScreen *currentScreen() override { return QGuiApplication::primaryScreen(); }
};

class wm_interface_test : public QObject
{
    Q_OBJECT

private slots:
    void isWaylandReflectsQtPlatformName();
    void windowAndPositionAreForwarded();
    void decorationComponentsDefaultImplementationIsNoop();
};

void wm_interface_test::isWaylandReflectsQtPlatformName()
{
    QCOMPARE(WMInterface::isWayland(), QGuiApplication::platformName().startsWith(QStringLiteral("wayland")));
}

void wm_interface_test::windowAndPositionAreForwarded()
{
    QWindow window;
    TestWMInterface wm(&window);

    QCOMPARE(wm.window(), &window);

    const QPoint expectedPosition(12, 34);
    wm.setPosition(expectedPosition);
    QCOMPARE(wm.position(), expectedPosition);
}

void wm_interface_test::decorationComponentsDefaultImplementationIsNoop()
{
    QWindow window;
    TestWMInterface wm(&window);

    wm.setDecorationComponents(Decoration::RoundCorner | Decoration::Border | Decoration::Shadow);
    QCOMPARE(wm.window(), &window);
}

int main(int argc, char *argv[])
{
    qputenv("QT_QPA_PLATFORM", "offscreen");
    qputenv("QT_QPA_PLATFORMTHEME", "generic");
    qputenv("GSETTINGS_BACKEND", "memory");

    QGuiApplication app(argc, argv);
    wm_interface_test testCase;
    return QTest::qExec(&testCase, argc, argv);
}

#include "test-wm-interface.moc"
