diff options
author | Felix Weilbach <felix.weilbach@nextcloud.com> | 2021-02-16 12:20:04 +0300 |
---|---|---|
committer | Felix Weilbach <felix.weilbach@nextcloud.com> | 2021-03-10 11:55:40 +0300 |
commit | 91859560697970a188a16c343e0aec1e32208875 (patch) | |
tree | fded17ecdb6f7f70e0634ad3021aeed0cd896b89 /test | |
parent | 05d2a8784096b7def57c19f324ba79dfb60d48f3 (diff) |
Split out wizard welcome page
Signed-off-by: Felix Weilbach <felix.weilbach@nextcloud.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/CMakeLists.txt | 2 | ||||
-rw-r--r-- | test/testtheme.cpp | 111 | ||||
-rw-r--r-- | test/themeutils.cpp | 40 | ||||
-rw-r--r-- | test/themeutils.h | 34 |
4 files changed, 187 insertions, 0 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 2297eb0da..9dcc1730d 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -9,6 +9,7 @@ add_library(testutils STATIC syncenginetestutils.cpp pushnotificationstestutils.cpp + themeutils.cpp ) target_link_libraries(testutils PUBLIC ${APPLICATION_EXECUTABLE}sync Qt5::Test) @@ -54,6 +55,7 @@ nextcloud_add_test(LockedFiles) nextcloud_add_test(FolderWatcher) nextcloud_add_test(Capabilities) nextcloud_add_test(PushNotifications) +nextcloud_add_test(Theme) if( UNIX AND NOT APPLE ) nextcloud_add_test(InotifyWatcher) diff --git a/test/testtheme.cpp b/test/testtheme.cpp new file mode 100644 index 000000000..52bc7b324 --- /dev/null +++ b/test/testtheme.cpp @@ -0,0 +1,111 @@ +/* + * 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" + +class TestTheme : public QObject +{ + Q_OBJECT + +public: + TestTheme() + { + Q_INIT_RESOURCE(resources); + Q_INIT_RESOURCE(theme); + } + +private slots: + 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" diff --git a/test/themeutils.cpp b/test/themeutils.cpp new file mode 100644 index 000000000..763d58a1f --- /dev/null +++ b/test/themeutils.cpp @@ -0,0 +1,40 @@ +/* + * 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 "themeutils.h" + +FakePaintDevice::FakePaintDevice() = default; + +QPaintEngine *FakePaintDevice::paintEngine() const +{ + return nullptr; +} + +void FakePaintDevice::setHidpi(bool value) +{ + _hidpi = value; +} + +int FakePaintDevice::metric(QPaintDevice::PaintDeviceMetric metric) const +{ + switch (metric) { + case QPaintDevice::PdmDevicePixelRatio: + if (_hidpi) { + return 2; + } + return 1; + default: + return QPaintDevice::metric(metric); + } +} diff --git a/test/themeutils.h b/test/themeutils.h new file mode 100644 index 000000000..4e8327e54 --- /dev/null +++ b/test/themeutils.h @@ -0,0 +1,34 @@ +/* + * Copyright (C) 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. + */ + +#pragma once + +#include <QPaintDevice> +#include <QTest> + +class FakePaintDevice : public QPaintDevice +{ +public: + FakePaintDevice(); + + QPaintEngine *paintEngine() const override; + + void setHidpi(bool value); + +protected: + int metric(QPaintDevice::PaintDeviceMetric metric) const override; + +private: + bool _hidpi = false; +}; |