#include <gtest/gtest.h>
#include <gtest/gtest-death-test.h>
#include "../../registeredSession/plugins/screenlock/screenlockinterface.h"


class ScreenlockInterfaceTest : public testing::Test
{
protected:
    static void SetUpTestSuite()
    {
        m_pScreenlockInterface = new ScreenlockInterface();
    }

    static void TearDownTestSuite()
    {
        if (m_pScreenlockInterface) {
	    delete m_pScreenlockInterface;
	    m_pScreenlockInterface = nullptr;
	}
    }

    static ScreenlockInterface *m_pScreenlockInterface;
};

ScreenlockInterface *ScreenlockInterfaceTest::m_pScreenlockInterface = nullptr;

TEST_F(ScreenlockInterfaceTest, setShowOnLogin)
{
    bool oldValue = m_pScreenlockInterface->property("showOnLogin").toBool();
    m_pScreenlockInterface->setShowOnLogin(false);
    bool newValue = m_pScreenlockInterface->property("showOnLogin").toBool();
    ASSERT_EQ(newValue, false);
    m_pScreenlockInterface->setShowOnLogin(oldValue);
}

TEST_F(ScreenlockInterfaceTest, setWallpaper)
{
    QGSettings gset("org.ukui.screensaver");
    std::string oldValue = gset.get("background").toString().toStdString(); 
    m_pScreenlockInterface->setWallpaper("/usr/share/backgrounds/city.jpg");
    std::string newValue = gset.get("background").toString().toStdString(); 
    ASSERT_STREQ(newValue.c_str(), "/usr/share/backgrounds/city.jpg");
    m_pScreenlockInterface->setWallpaper(oldValue.c_str());
}

TEST_F(ScreenlockInterfaceTest, resetDefault)
{
    QGSettings gset("org.ukui.screensaver");
    std::string oldValue = gset.get("background").toString().toStdString(); 
    m_pScreenlockInterface->resetDefault();
    std::string newValue = gset.get("background").toString().toStdString(); 
    ASSERT_STREQ(newValue.c_str(), "/usr/share/backgrounds/1-openkylin.jpg");
    m_pScreenlockInterface->setWallpaper(oldValue.c_str());
}


TEST_F(ScreenlockInterfaceTest, getPreviewWallpapers)
{
    int size = m_pScreenlockInterface->getPreviewWallpapers().size();
    ASSERT_GE(size, 0);
}

TEST_F(ScreenlockInterfaceTest, getSourceWallpapers)
{
    int size = m_pScreenlockInterface->getSourceWallpapers().size();
    ASSERT_GE(size, 0);
}

TEST_F(ScreenlockInterfaceTest, getWallpaper)
{
    int size = m_pScreenlockInterface->getWallpaper().size();
    ASSERT_GE(size, 0);
}
