#include <QGuiApplication>
#include <QScreen>
#include <QtTest>

#include "screen-area-utils.h"

using namespace UkuiQuick;

class screen_area_utils_test : public QObject
{
    Q_OBJECT

private slots:
    void instanceIsShared();
    void availableGeometryStaysWithinScreenGeometry();
};

void screen_area_utils_test::instanceIsShared()
{
    QCOMPARE(ScreenAreaUtils::instance(), ScreenAreaUtils::instance());
}

void screen_area_utils_test::availableGeometryStaysWithinScreenGeometry()
{
    QScreen *screen = QGuiApplication::primaryScreen();
    QVERIFY(screen != nullptr);

    const QRect geometry = screen->geometry();
    const QRect availableGeometry = ScreenAreaUtils::instance()->getAvailableGeometry(screen);

    QVERIFY(geometry.isValid());
    QVERIFY(availableGeometry.isValid());
    QVERIFY(geometry.contains(availableGeometry));
    QVERIFY(availableGeometry.width() <= geometry.width());
    QVERIFY(availableGeometry.height() <= geometry.height());
}

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

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

#include "test-screen-area-utils.moc"
