/* -*- 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 "../../libnm-kylin/libnm-icon-kylin/kynetworkicon.h"

#include "stubext.h"
using namespace stub_ext;

class KyNetworkIconTest : public testing::Test
{
protected:
    static void SetUpTestSuite()
    {
        m_pKyNetworkIconTest = new KyNetworkIcon();
    }

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

    static KyNetworkIcon *m_pKyNetworkIconTest;
};

KyNetworkIcon *KyNetworkIconTest::m_pKyNetworkIconTest = nullptr;

TEST_F(KyNetworkIconTest, checkIconIsHidden)
{
    // get current value
    bool currentValue = m_pKyNetworkIconTest->checkIconIsHidden();
    // test the current value and the value you have set
    ASSERT_EQ(currentValue, false);
}

TEST_F(KyNetworkIconTest, testAllFunc)
{
    m_pKyNetworkIconTest->initConnect();
    m_pKyNetworkIconTest->startLoading();
    m_pKyNetworkIconTest->stopLoading();

    // onSetTrayIconLoading()
    m_pKyNetworkIconTest->currentIconIndex = 0;
    m_pKyNetworkIconTest->onSetTrayIconLoading();
    m_pKyNetworkIconTest->currentIconIndex = 12;
    m_pKyNetworkIconTest->onSetTrayIconLoading();

    // updateIcon();
    if (nullptr != m_pKyNetworkIconTest->loadingTimer) {
        m_pKyNetworkIconTest->loadingTimer->start();
        m_pKyNetworkIconTest->updateIcon();
    }

    m_pKyNetworkIconTest->iconStatus = KyConnectStatus::NOT_CONNECTED;
    m_pKyNetworkIconTest->updateIcon();
    m_pKyNetworkIconTest->iconStatus = KyConnectStatus::LAN_CONNECTED;
    m_pKyNetworkIconTest->updateIcon();
    m_pKyNetworkIconTest->iconStatus = KyConnectStatus::WLAN_CONNECTED;
    m_pKyNetworkIconTest->updateIcon();
    m_pKyNetworkIconTest->iconStatus = KyConnectStatus::LAN_CONNECTED_LIMITED;
    m_pKyNetworkIconTest->updateIcon();
    m_pKyNetworkIconTest->iconStatus = KyConnectStatus::WLAN_CONNECTED_LIMITED;
    m_pKyNetworkIconTest->updateIcon();

    // onWiredStateChange()
    m_pKyNetworkIconTest->onWiredStateChange(
        "en0", "ed773242-de2c-4903-889b-22a2f14723e0", KyConnectState::CONNECT_STATE_ACTIVATING);
    m_pKyNetworkIconTest->onWiredStateChange(
        "en0", "ed773242-de2c-4903-889b-22a2f14723e0", KyConnectState::CONNECT_STATE_ACTIVATED);

    // onWirelessStateChange
    m_pKyNetworkIconTest->onWirelessStateChange(
        "wlan0", "kylin-wifi", "ed773242-de2c-4903-889b-22a2f14723e0", KyConnectState::CONNECT_STATE_ACTIVATING);
    m_pKyNetworkIconTest->onWirelessStateChange(
        "wlan0", "kylin-wifi", "ed773242-de2c-4903-889b-22a2f14723e0", KyConnectState::CONNECT_STATE_ACTIVATED);

    //    QPaintEvent *event;
    //    m_pKyNetworkIconTest->paintEvent(event);
}
