File indexing completed on 2024-04-21 03:52:24

0001 /*
0002     This file is part of the KDE libraries
0003     SPDX-FileCopyrightText: 2013 Alejandro Fiestas Olivares <afiestas@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0006 */
0007 
0008 #include "kdeplatformtheme_config.h"
0009 #include "kstyle.h"
0010 
0011 #include <QApplication>
0012 #include <QDir>
0013 #include <QFile>
0014 #include <QStandardPaths>
0015 #include <QTest>
0016 #include <QToolBar>
0017 #include <QToolButton>
0018 
0019 #include <QDebug>
0020 
0021 static void prepareEnvironment()
0022 {
0023     QStandardPaths::setTestModeEnabled(true);
0024 
0025     QString configPath = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation);
0026 
0027     if (!QDir(configPath).mkpath(QStringLiteral("."))) {
0028         qFatal("Failed to create test configuration directory.");
0029     }
0030 
0031     configPath.append("/kdeglobals");
0032 
0033     QFile::remove(configPath);
0034     if (!QFile::copy(CONFIGFILE, configPath)) {
0035         qFatal("Failed to copy kdeglobals required for tests.");
0036     }
0037 }
0038 
0039 Q_COREAPP_STARTUP_FUNCTION(prepareEnvironment)
0040 
0041 class KStyle_UnitTest : public QObject
0042 {
0043     Q_OBJECT
0044 private Q_SLOTS:
0045     void initTestCase()
0046     {
0047         qApp->setStyle(new KStyle);
0048     }
0049     void cleanupTestCase()
0050     {
0051         QString configPath = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation);
0052         configPath.append("/kdeglobals");
0053         QFile::remove(configPath);
0054     }
0055 
0056     void testToolButtonStyleHint()
0057     {
0058         QToolBar *toolbar = new QToolBar();
0059         QToolButton *btn = new QToolButton(toolbar);
0060 
0061         QCOMPARE(qApp->style()->styleHint(QStyle::SH_ToolButtonStyle, nullptr, btn), (int)Qt::ToolButtonTextOnly);
0062 
0063         toolbar->setProperty("otherToolbar", true);
0064         QCOMPARE(qApp->style()->styleHint(QStyle::SH_ToolButtonStyle, nullptr, btn), (int)Qt::ToolButtonTextUnderIcon);
0065     }
0066 };
0067 
0068 QTEST_MAIN(KStyle_UnitTest)
0069 
0070 #include "kstyle_unittest.moc"