1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
/*
* 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"
|