// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later

#include "themeappicon.h"

#include <QPixmap>
#include <QDebug>
#include <QApplication>
#include <QFile>
#include <QDate>

#include <gtest/gtest.h>

class Ut_ThemeAppIcon : public ::testing::Test
{
public:
    virtual void SetUp() override;
    virtual void TearDown() override;
};

void Ut_ThemeAppIcon::SetUp()
{
    ThemeAppIcon icon;
}

void Ut_ThemeAppIcon::TearDown()
{
}

TEST_F(Ut_ThemeAppIcon, getIcon_test1)
{
    QPixmap pix;

    // 无效图标
    QString name = "123";
    ThemeAppIcon::getIcon(name);

    // 有效图标
    ThemeAppIcon::getIcon("dde-calendar");

    ThemeAppIcon::getIcon(pix, "", 50);
    ThemeAppIcon::getIcon(pix, "", 50, true);

    // 获取base64编码的png图片数据
    const QString &iconName = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAIhklEQVR4nNRZa0xb5xl+fGx88AVzSebcDV5o0gGJuKWiKpGSLBNlSaN0Uicide2SSdklP5a1EvlRNmlUatnWreu6dU2WaFWn7Me6tipjdFmrToKYZGRAbqxRgqm4JAGH2LMx9jm+Tu+HP9eXY0gcEPSVPh3OOd/led73ed/vO1gDZVNleL7UFk19kEhAXV9fb9q+ffszWq3WvAxJRAOBwGRXV9fbNpttGkA48WVOR0fHHlmW5egyN1mWpc7OzkbCHEdfWVm5SpKkZQ+emyRJUnl5OakEAslo9+7dh0RR1C6BLLIyURTFxsbGQ4SdCGj1ev2GpQZ1v6bX6y2EnQgIKpUqUzVathbDLAixaiMsNaAsjGHnwJdbybwXY5gXRTrRaJS1+EoqFWuLYQtKgEBHIhF2DYVC7ErANRoN1Gr1opBYEALc2+FwGMFgkIGXJIkqBQNP9wReEJJTbSEILUjyEgECL8syfD4fPB4PwmEVuruHEQgE2Dveh8jwKC2EPVAECAj3OgElAl5vEAMDN/H3jsvYt68KXq8XBoOBveMkuKxyc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R5Ap+fnw+32x0sLi7+qtvt7qV3tIWWNjU1tTmdzuBS/wo/n929ezfY1NT0EmEm7HwLNQD4sslk2nTgwIH9ZrPZLAiCepn8esm0HolEwg6HY/L06dMfeL3e6wCGAcxwgHTVAjCSzADkxxJ8Ofx+HI21EAA3gEkCDoC+kKL/DwAA///Rq3L66XsVjwAAAABJRU5ErkJggg==";
    ThemeAppIcon::getIcon(pix, iconName, 60);
}

TEST_F(Ut_ThemeAppIcon, getIcon_test2)
{
    QPixmap pix;
    ThemeAppIcon::getIcon(pix, "dde-calendar", 50);
    ASSERT_TRUE(true);
}

TEST_F(Ut_ThemeAppIcon, getIcon_test3)
{
    QPixmap pix;
    ThemeAppIcon::getIcon(pix, "data:image/test", 50);
    ASSERT_FALSE(pix.isNull());
}

TEST_F(Ut_ThemeAppIcon, getIcon_test4)
{
    QPixmap pix;
    ThemeAppIcon::getIcon(pix, ":/res/all_settings_on.png", 50);
    ASSERT_FALSE(pix.isNull());
}

TEST_F(Ut_ThemeAppIcon, createCalendarIcon_test)
{
    const QString &filePath = "/tmp/calendar.svg";
    ASSERT_TRUE(ThemeAppIcon::createCalendarIcon(QDate::currentDate(), filePath));
    QFile::remove(filePath);
}
