#include <gtest/gtest.h>
#include <gtest/gtest-death-test.h>
#include <QDBusReply>
#include <QStringList>
#include <QDBusInterface>
#include "../../registeredSession/plugins/default/defaultinterface.h"
#include "stubext.h"

using namespace stub_ext;

class DefaultInterfaceTest : public testing::Test
{
protected:
    static void SetUpTestSuite()
    {
       m_pDefaultDbus = new QDBusInterface("org.ukui.ukcc.session",
                         "/Default", "org.ukui.ukcc.session.Default",
                        QDBusConnection::sessionBus());
    }

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

    static QDBusInterface* m_pDefaultDbus;
};

QDBusInterface *DefaultInterfaceTest::m_pDefaultDbus = nullptr;

TEST_F(DefaultInterfaceTest, getDefaultAppSize)
{
    if (!m_pDefaultDbus || !m_pDefaultDbus->isValid()) {
       return;
    }
    QDBusReply<QVariantList> ret = m_pDefaultDbus->call("getDefaultApp", "x-scheme-handler/http");
    ASSERT_GT(ret.value().size(), 0);
}

TEST_F(DefaultInterfaceTest, getAppListSize)
{
    if (!m_pDefaultDbus || !m_pDefaultDbus->isValid()) {
       return;
    }
    QDBusReply<QVariantList> ret = m_pDefaultDbus->call("getAppList", "x-scheme-handler/http");
    ASSERT_GT(ret.value().size(), 0);
}

TEST_F(DefaultInterfaceTest, setDefaultApp)
{
    if (!m_pDefaultDbus || !m_pDefaultDbus->isValid()) {
       return;
    }
    QDBusReply<void> ret = m_pDefaultDbus->call("setDefaultApp", "kylin-music.desktop", "audio/x-vorbis+ogg");
    ASSERT_EQ(ret.isValid(), true);
}
