/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 *
 * Copyright (C) 2019 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 <QDBusReply>
#include <QStringList>
#include "../../registeredSession/plugins/autoboot/autostartinterface.h"

class AutobootInterfaceTest : public testing::Test
{
protected:
    static void SetUpTestSuite()
    {
        m_pAutoStartInterface = new AutoStartInterface();
    }

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

    static AutoStartInterface* m_pAutoStartInterface;
};

AutoStartInterface *AutobootInterfaceTest::m_pAutoStartInterface = nullptr;

TEST_F(AutobootInterfaceTest, addAutobootApp)
{
    bool ret = m_pAutoStartInterface->addAutobootApp("/usr/share/applications/kylin-video.desktop");
    ASSERT_EQ(ret, true);
}

TEST_F(AutobootInterfaceTest, getAppInfo)
{
    AutoApp ret = m_pAutoStartInterface->getAppInfo("/usr/share/applications/kylin-video.desktop");
    ASSERT_STREQ(ret.bname.toStdString().c_str(), "kylin-video.desktop");
}

TEST_F(AutobootInterfaceTest, setAppHiddenInfo)
{
    bool ret = m_pAutoStartInterface->setAppHiddenInfo("kylin-video.desktop", true);
    ASSERT_EQ(ret, true);
}

TEST_F(AutobootInterfaceTest, saveAppStatus)
{
    bool ret = m_pAutoStartInterface->saveAppStatus("/usr/share/applications/kylin-video.desktop", false);
    ASSERT_EQ(ret, false);
}

TEST_F(AutobootInterfaceTest, setApplist)
{
    QStringList oldValue = m_pAutoStartInterface->getAppList();
    QStringList strList = {"kylin-weather.desktop", "sogouImeService.desktop", "kylin-video.desktop"};
    bool ret = m_pAutoStartInterface->setApplist(strList);
    ASSERT_EQ(ret, true);
    QStringList newValue = m_pAutoStartInterface->getAppList();
    ASSERT_STREQ(newValue.at(0).toStdString().c_str(), "kylin-weather.desktop");
    m_pAutoStartInterface->setApplist(oldValue);
}

TEST_F(AutobootInterfaceTest, getDisplayStatus)
{
    bool ret = m_pAutoStartInterface->getDisplayStatus("/usr/share/applications/kylin-video.desktop");
    ASSERT_EQ(ret, false);
}

TEST_F(AutobootInterfaceTest, deleteLocalFile)
{
    bool ret = m_pAutoStartInterface->deleteLocalFile("kylin-video.desktop");
    ASSERT_EQ(ret, true);
}

TEST_F(AutobootInterfaceTest, deleteLocalFileFalse)
{
    bool ret = m_pAutoStartInterface->deleteLocalFile("");
    ASSERT_EQ(ret, false);
}

TEST_F(AutobootInterfaceTest, getAllAppMap)
{
    QMap<QString, AutoApp> ret = m_pAutoStartInterface->getAllAppMap();
    ASSERT_GT(ret.size(), 1);
}

TEST_F(AutobootInterfaceTest, getServiceMap)
{
    QMap<QString, AutoApp> ret = m_pAutoStartInterface->getServiceMap();
    ASSERT_GT(ret.size(), 0);
}

TEST_F(AutobootInterfaceTest, getLocalAppMap)
{
    QMap<QString, AutoApp> ret = m_pAutoStartInterface->getLocalAppMap();
    ASSERT_GE(ret.size(), 0);
}

TEST_F(AutobootInterfaceTest, getStatusMap)
{
    QMap<QString, QVariant> ret = m_pAutoStartInterface->getStatusMap();
    ASSERT_GE(ret.size(), 0);
}
