| 1 | /* |
| 2 | This file is part of the KDE libraries |
| 3 | SPDX-FileCopyrightText: 2013 Alejandro Fiestas Olivares <[email protected]> |
| 4 | |
| 5 | SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
| 6 | */ |
| 7 | |
| 8 | #include "kdeplatformtheme_config.h" |
| 9 | #include "kstyle.h" |
| 10 | |
| 11 | #include <QApplication> |
| 12 | #include <QDir> |
| 13 | #include <QFile> |
| 14 | #include <QStandardPaths> |
| 15 | #include <QTest> |
| 16 | #include <QToolBar> |
| 17 | #include <QToolButton> |
| 18 | |
| 19 | #include <QDebug> |
| 20 | |
| 21 | static void prepareEnvironment() |
| 22 | { |
| 23 | QStandardPaths::setTestModeEnabled(true); |
| 24 | |
| 25 | QString configPath = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation); |
| 26 | |
| 27 | if (!QDir(configPath).mkpath(QStringLiteral("."))) { |
| 28 | qFatal("Failed to create test configuration directory."); |
| 29 | } |
| 30 | |
| 31 | configPath.append("/kdeglobals"); |
| 32 | |
| 33 | QFile::remove(configPath); |
| 34 | if (!QFile::copy(CONFIGFILE, configPath)) { |
| 35 | qFatal("Failed to copy kdeglobals required for tests."); |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | Q_COREAPP_STARTUP_FUNCTION(prepareEnvironment) |
| 40 | |
| 41 | class KStyle_UnitTest : public QObject |
| 42 | { |
| 43 | Q_OBJECT |
| 44 | private Q_SLOTS: |
| 45 | void initTestCase() |
| 46 | { |
| 47 | qApp->setStyle(new KStyle); |
| 48 | } |
| 49 | void cleanupTestCase() |
| 50 | { |
| 51 | QString configPath = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation); |
| 52 | configPath.append("/kdeglobals"); |
| 53 | QFile::remove(configPath); |
| 54 | } |
| 55 | |
| 56 | void testToolButtonStyleHint() |
| 57 | { |
| 58 | QToolBar *toolbar = new QToolBar(); |
| 59 | QToolButton *btn = new QToolButton(toolbar); |
| 60 | |
| 61 | QCOMPARE(qApp->style()->styleHint(QStyle::SH_ToolButtonStyle, nullptr, btn), (int)Qt::ToolButtonTextOnly); |
| 62 | |
| 63 | toolbar->setProperty("otherToolbar", true); |
| 64 | QCOMPARE(qApp->style()->styleHint(QStyle::SH_ToolButtonStyle, nullptr, btn), (int)Qt::ToolButtonTextUnderIcon); |
| 65 | } |
| 66 | }; |
| 67 | |
| 68 | QTEST_MAIN(KStyle_UnitTest) |
| 69 | |
| 70 | #include "kstyle_unittest.moc" |