Files
nextcloud-desktop/test/testtheme.cpp
Andy Scherzinger 00994aa9e8 docs(reuse): Migrate to SPDX header
Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
2025-04-16 15:19:26 +02:00

115 lines
2.8 KiB
C++

/*
* SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include <QTest>
#include "theme.h"
#include "themeutils.h"
#include "iconutils.h"
#include "logger.h"
#include <QStandardPaths>
class TestTheme : public QObject
{
Q_OBJECT
public:
TestTheme()
{
Q_INIT_RESOURCE(resources);
Q_INIT_RESOURCE(theme);
}
private slots:
void initTestCase()
{
OCC::Logger::instance()->setLogFlush(true);
OCC::Logger::instance()->setLogDebug(true);
QStandardPaths::setTestModeEnabled(true);
}
void testHidpiFileName_darkBackground_returnPathToWhiteIcon()
{
FakePaintDevice paintDevice;
const QColor backgroundColor("#000000");
const QString iconName("icon-name");
const auto iconPath = OCC::Theme::hidpiFileName(iconName + ".png", backgroundColor, &paintDevice);
QCOMPARE(iconPath, ":/client/theme/white/" + iconName + ".png");
}
void testHidpiFileName_lightBackground_returnPathToBlackIcon()
{
FakePaintDevice paintDevice;
const QColor backgroundColor("#ffffff");
const QString iconName("icon-name");
const auto iconPath = OCC::Theme::hidpiFileName(iconName + ".png", backgroundColor, &paintDevice);
QCOMPARE(iconPath, ":/client/theme/black/" + iconName + ".png");
}
void testHidpiFileName_hidpiDevice_returnHidpiIconPath()
{
FakePaintDevice paintDevice;
paintDevice.setHidpi(true);
const QColor backgroundColor("#000000");
const QString iconName("wizard-files");
const auto iconPath = OCC::Theme::hidpiFileName(iconName + ".png", backgroundColor, &paintDevice);
QCOMPARE(iconPath, ":/client/theme/white/" + iconName + "@2x.png");
}
void testIsDarkColor_nextcloudBlue_returnTrue()
{
const QColor color(0, 130, 201);
const auto result = OCC::Theme::isDarkColor(color);
QCOMPARE(result, true);
}
void testIsDarkColor_lightColor_returnFalse()
{
const QColor color(255, 255, 255);
const auto result = OCC::Theme::isDarkColor(color);
QCOMPARE(result, false);
}
void testIsDarkColor_darkColor_returnTrue()
{
const QColor color(0, 0, 0);
const auto result = OCC::Theme::isDarkColor(color);
QCOMPARE(result, true);
}
void testIsHidpi_hidpi_returnTrue()
{
FakePaintDevice paintDevice;
paintDevice.setHidpi(true);
QCOMPARE(OCC::Theme::isHidpi(&paintDevice), true);
}
void testIsHidpi_lowdpi_returnFalse()
{
FakePaintDevice paintDevice;
paintDevice.setHidpi(false);
QCOMPARE(OCC::Theme::isHidpi(&paintDevice), false);
}
};
QTEST_GUILESS_MAIN(TestTheme)
#include "testtheme.moc"