#include <gtest/gtest.h>
#include <gtest/gtest-death-test.h>
#include "../../registeredSession/plugins/shortcut/shortcutinterface.h"

class ShortcutInterfaceTest : public testing::Test
{
protected:
    static void SetUpTestSuite()
    {
        m_pShortcutInterface = new ShortcutInterface();
        m_pShortcutInterface->getThreadStart();
    }

    static void TearDownTestSuite()
    {
    }

    static ShortcutInterface *m_pShortcutInterface;
};

ShortcutInterface *ShortcutInterfaceTest::m_pShortcutInterface = nullptr;

TEST_F(ShortcutInterfaceTest, getSystemShortcut)
{
    QStringPairList pairList = m_pShortcutInterface->getSystemShortcut();
    ASSERT_GE(pairList.size(), 15);
}

TEST_F(ShortcutInterfaceTest, getCustomShortcut)
{
    QStringPairList pairList = m_pShortcutInterface->getCustomShortcut();
    ASSERT_GE(pairList.size(), 0);
}

TEST_F(ShortcutInterfaceTest, getSystemShortcutEntry)
{
    QList<KeyEntry> pairList = m_pShortcutInterface->getSystemShortcutEntry();
    ASSERT_GE(pairList.size(), 15);
}

TEST_F(ShortcutInterfaceTest, getCustomShortcutEntry)
{
    QList<KeyEntry> pairList = m_pShortcutInterface->getCustomShortcutEntry();
    ASSERT_GE(pairList.size(), 0);
}

TEST_F(ShortcutInterfaceTest, getShowShortcutString)
{
    QString shortKey = "Meta+A";
    m_pShortcutInterface->updateShortcut();
    QString newShortKey = m_pShortcutInterface->getShowShortcutString(shortKey);
    ASSERT_GE(newShortKey.toStdString().c_str(), "Win+A");
}

TEST_F(ShortcutInterfaceTest, updateShortcut)
{
    bool ret = m_pShortcutInterface->updateShortcut();
    ASSERT_EQ(ret, true);
}

TEST_F(ShortcutInterfaceTest, setSystemShortcut)
{
    QGSettings generalShort("org.ukui.SettingsDaemon.plugins.media-keys");
    std::string oldValue = generalShort.get("kylin-display-switch").toString().toStdString();

    m_pShortcutInterface->setSystemShortcut("kylin-display-switch", "<Win>V");
    std::string newValue = generalShort.get("kylin-display-switch").toString().toStdString();

    ASSERT_STREQ(newValue.c_str(), "<Win>V");

    generalShort.set("kylin-display-switch", oldValue.c_str());
}
