/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 *
 * Copyright (C) 2024 KylinSoft  Co., Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 */
#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());
}
