2021-02-16 12:20:04 +03:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2021 by Felix Weilbach <felix.weilbach@nextcloud.com>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <QTest>
|
|
|
|
|
|
|
|
#include "theme.h"
|
|
|
|
#include "themeutils.h"
|
2021-08-17 16:39:18 +03:00
|
|
|
#include "iconutils.h"
|
2024-04-30 11:04:32 +03:00
|
|
|
#include "logger.h"
|
|
|
|
|
|
|
|
#include <QStandardPaths>
|
2021-02-16 12:20:04 +03:00
|
|
|
|
|
|
|
class TestTheme : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
TestTheme()
|
|
|
|
{
|
|
|
|
Q_INIT_RESOURCE(resources);
|
|
|
|
Q_INIT_RESOURCE(theme);
|
|
|
|
}
|
|
|
|
|
|
|
|
private slots:
|
2024-04-30 11:04:32 +03:00
|
|
|
void initTestCase()
|
|
|
|
{
|
|
|
|
OCC::Logger::instance()->setLogFlush(true);
|
|
|
|
OCC::Logger::instance()->setLogDebug(true);
|
|
|
|
|
|
|
|
QStandardPaths::setTestModeEnabled(true);
|
|
|
|
}
|
|
|
|
|
2021-02-16 12:20:04 +03:00
|
|
|
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"
|