#include <QtTest>

#include "function-control.h"

using namespace UkuiQuick;

class function_control_test : public QObject
{
    Q_OBJECT

private slots:
    void singletonCanBeCreatedAndDestroyed();
    void watchesCanBeAddedAndRemovedWithoutConfig();
};

void function_control_test::singletonCanBeCreatedAndDestroyed()
{
    auto *control = FunctionControl::instance();

    QVERIFY(control != nullptr);
    QCOMPARE(FunctionControl::instance(), control);

    delete control;
}

void function_control_test::watchesCanBeAddedAndRemovedWithoutConfig()
{
    auto *control = FunctionControl::instance();
    const QString featureName = QStringLiteral("codex.feature");

    control->removeAllWatches(featureName);
    QVERIFY(control->functionControlObject(featureName).isEmpty());

    control->addWatch(featureName);
    control->addWatch(featureName);
    QVERIFY(control->functionControlObject(featureName).isEmpty());

    control->removeWatch(featureName);
    QVERIFY(control->functionControlObject(featureName).isEmpty());

    control->removeWatch(featureName);
    QVERIFY(control->functionControlObject(featureName).isEmpty());

    control->removeWatch(featureName);
    control->removeAllWatches(featureName);
    QVERIFY(control->functionControlObject(featureName).isEmpty());

    delete control;
}

QTEST_GUILESS_MAIN(function_control_test)

#include "test-function-control.moc"
