File indexing completed on 2024-04-21 03:57:10

0001 /*
0002     This file is part of the KDE libraries
0003     SPDX-FileCopyrightText: 2017 Dominik Haumann <dhaumann@kde.de>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #include "configinterface_test.h"
0009 #include "moc_configinterface_test.cpp"
0010 
0011 #include <KSyntaxHighlighting/Repository>
0012 #include <KSyntaxHighlighting/Theme>
0013 #include <katedocument.h>
0014 #include <kateglobal.h>
0015 #include <katesyntaxmanager.h>
0016 #include <kateview.h>
0017 
0018 #include <QFont>
0019 #include <QTest>
0020 
0021 using namespace KTextEditor;
0022 
0023 QTEST_MAIN(KateConfigInterfaceTest)
0024 
0025 KateConfigInterfaceTest::KateConfigInterfaceTest()
0026     : QObject()
0027 {
0028     KTextEditor::EditorPrivate::enableUnitTestMode();
0029 }
0030 
0031 KateConfigInterfaceTest::~KateConfigInterfaceTest()
0032 {
0033 }
0034 
0035 void KateConfigInterfaceTest::testDocument()
0036 {
0037     KTextEditor::DocumentPrivate doc(false, false);
0038     QVERIFY(!doc.configKeys().isEmpty());
0039 
0040     doc.setConfigValue(QStringLiteral("backup-on-save-local"), true);
0041     QCOMPARE(doc.configValue(QLatin1String("backup-on-save-local")).toBool(), true);
0042     doc.setConfigValue(QStringLiteral("backup-on-save-local"), false);
0043     QCOMPARE(doc.configValue(QLatin1String("backup-on-save-local")).toBool(), false);
0044 
0045     doc.setConfigValue(QStringLiteral("backup-on-save-remote"), true);
0046     QCOMPARE(doc.configValue(QLatin1String("backup-on-save-remote")).toBool(), true);
0047     doc.setConfigValue(QStringLiteral("backup-on-save-remote"), false);
0048     QCOMPARE(doc.configValue(QLatin1String("backup-on-save-remote")).toBool(), false);
0049 
0050     doc.setConfigValue(QStringLiteral("replace-tabs"), true);
0051     QCOMPARE(doc.configValue(QLatin1String("replace-tabs")).toBool(), true);
0052     doc.setConfigValue(QStringLiteral("replace-tabs"), false);
0053     QCOMPARE(doc.configValue(QLatin1String("replace-tabs")).toBool(), false);
0054 
0055     doc.setConfigValue(QStringLiteral("indent-pasted-text"), true);
0056     QCOMPARE(doc.configValue(QLatin1String("indent-pasted-text")).toBool(), true);
0057     doc.setConfigValue(QStringLiteral("indent-pasted-text"), false);
0058     QCOMPARE(doc.configValue(QLatin1String("indent-pasted-text")).toBool(), false);
0059 
0060     doc.setConfigValue(QStringLiteral("on-the-fly-spellcheck"), true);
0061     QCOMPARE(doc.configValue(QLatin1String("on-the-fly-spellcheck")).toBool(), true);
0062     doc.setConfigValue(QStringLiteral("on-the-fly-spellcheck"), false);
0063     QCOMPARE(doc.configValue(QLatin1String("on-the-fly-spellcheck")).toBool(), false);
0064 
0065     doc.setConfigValue(QStringLiteral("indent-width"), 13);
0066     QCOMPARE(doc.configValue(QLatin1String("indent-width")).toInt(), 13);
0067     doc.setConfigValue(QStringLiteral("indent-width"), 4);
0068     QCOMPARE(doc.configValue(QLatin1String("indent-width")).toInt(), 4);
0069 
0070     doc.setConfigValue(QStringLiteral("tab-width"), 13);
0071     QCOMPARE(doc.configValue(QLatin1String("tab-width")).toInt(), 13);
0072     doc.setConfigValue(QStringLiteral("tab-width"), 4);
0073     QCOMPARE(doc.configValue(QLatin1String("tab-width")).toInt(), 4);
0074 
0075     doc.setConfigValue(QStringLiteral("backup-on-save-suffix"), QLatin1String("_tmp"));
0076     QCOMPARE(doc.configValue(QLatin1String("backup-on-save-suffix")).toString(), QLatin1String("_tmp"));
0077 
0078     doc.setConfigValue(QStringLiteral("backup-on-save-prefix"), QLatin1String("abc_"));
0079     QCOMPARE(doc.configValue(QLatin1String("backup-on-save-prefix")).toString(), QLatin1String("abc_"));
0080 }
0081 
0082 void KateConfigInterfaceTest::testView()
0083 {
0084     KTextEditor::DocumentPrivate doc(false, false);
0085     auto view = static_cast<KTextEditor::View *>(doc.createView(nullptr));
0086     QVERIFY(view);
0087     QVERIFY(!view->configKeys().isEmpty());
0088 
0089     view->setConfigValue(QStringLiteral("line-numbers"), true);
0090     QCOMPARE(view->configValue(QLatin1String("line-numbers")).toBool(), true);
0091     view->setConfigValue(QStringLiteral("line-numbers"), false);
0092     QCOMPARE(view->configValue(QLatin1String("line-numbers")).toBool(), false);
0093 
0094     view->setConfigValue(QStringLiteral("icon-bar"), true);
0095     QCOMPARE(view->configValue(QLatin1String("icon-bar")).toBool(), true);
0096     view->setConfigValue(QStringLiteral("icon-bar"), false);
0097     QCOMPARE(view->configValue(QLatin1String("icon-bar")).toBool(), false);
0098 
0099     view->setConfigValue(QStringLiteral("folding-bar"), true);
0100     QCOMPARE(view->configValue(QLatin1String("folding-bar")).toBool(), true);
0101     view->setConfigValue(QStringLiteral("folding-bar"), false);
0102     QCOMPARE(view->configValue(QLatin1String("folding-bar")).toBool(), false);
0103 
0104     view->setConfigValue(QStringLiteral("folding-preview"), true);
0105     QCOMPARE(view->configValue(QLatin1String("folding-preview")).toBool(), true);
0106     view->setConfigValue(QStringLiteral("folding-preview"), false);
0107     QCOMPARE(view->configValue(QLatin1String("folding-preview")).toBool(), false);
0108 
0109     view->setConfigValue(QStringLiteral("dynamic-word-wrap"), true);
0110     QCOMPARE(view->configValue(QLatin1String("dynamic-word-wrap")).toBool(), true);
0111     view->setConfigValue(QStringLiteral("dynamic-word-wrap"), false);
0112     QCOMPARE(view->configValue(QLatin1String("dynamic-word-wrap")).toBool(), false);
0113 
0114     view->setConfigValue(QStringLiteral("background-color"), QColor(0, 255, 0));
0115     QCOMPARE(view->configValue(QLatin1String("background-color")).value<QColor>(), QColor(0, 255, 0));
0116 
0117     view->setConfigValue(QStringLiteral("selection-color"), QColor(0, 255, 0));
0118     QCOMPARE(view->configValue(QLatin1String("selection-color")).value<QColor>(), QColor(0, 255, 0));
0119 
0120     view->setConfigValue(QStringLiteral("search-highlight-color"), QColor(0, 255, 0));
0121     QCOMPARE(view->configValue(QLatin1String("search-highlight-color")).value<QColor>(), QColor(0, 255, 0));
0122 
0123     view->setConfigValue(QStringLiteral("replace-highlight-color"), QColor(0, 255, 0));
0124     QCOMPARE(view->configValue(QLatin1String("replace-highlight-color")).value<QColor>(), QColor(0, 255, 0));
0125 
0126     view->setConfigValue(QStringLiteral("default-mark-type"), 6);
0127     QCOMPARE(view->configValue(QLatin1String("default-mark-type")).toInt(), 6);
0128 
0129     view->setConfigValue(QStringLiteral("allow-mark-menu"), true);
0130     QCOMPARE(view->configValue(QLatin1String("allow-mark-menu")).toBool(), true);
0131     view->setConfigValue(QStringLiteral("allow-mark-menu"), false);
0132     QCOMPARE(view->configValue(QLatin1String("allow-mark-menu")).toBool(), false);
0133 
0134     view->setConfigValue(QStringLiteral("icon-border-color"), QColor(0, 255, 0));
0135     QCOMPARE(view->configValue(QLatin1String("icon-border-color")).value<QColor>(), QColor(0, 255, 0));
0136 
0137     view->setConfigValue(QStringLiteral("folding-marker-color"), QColor(0, 255, 0));
0138     QCOMPARE(view->configValue(QLatin1String("folding-marker-color")).value<QColor>(), QColor(0, 255, 0));
0139 
0140     view->setConfigValue(QStringLiteral("line-number-color"), QColor(0, 255, 0));
0141     QCOMPARE(view->configValue(QLatin1String("line-number-color")).value<QColor>(), QColor(0, 255, 0));
0142 
0143     view->setConfigValue(QStringLiteral("current-line-number-color"), QColor(0, 255, 0));
0144     QCOMPARE(view->configValue(QLatin1String("current-line-number-color")).value<QColor>(), QColor(0, 255, 0));
0145 
0146     view->setConfigValue(QStringLiteral("modification-markers"), true);
0147     QCOMPARE(view->configValue(QLatin1String("modification-markers")).toBool(), true);
0148     view->setConfigValue(QStringLiteral("modification-markers"), false);
0149     QCOMPARE(view->configValue(QLatin1String("modification-markers")).toBool(), false);
0150 
0151     view->setConfigValue(QStringLiteral("word-count"), true);
0152     QCOMPARE(view->configValue(QLatin1String("word-count")).toBool(), true);
0153     view->setConfigValue(QStringLiteral("word-count"), false);
0154     QCOMPARE(view->configValue(QLatin1String("word-count")).toBool(), false);
0155 
0156     view->setConfigValue(QStringLiteral("line-count"), true);
0157     QCOMPARE(view->configValue(QLatin1String("line-count")).toBool(), true);
0158     view->setConfigValue(QStringLiteral("line-count"), false);
0159     QCOMPARE(view->configValue(QLatin1String("line-count")).toBool(), false);
0160 
0161     view->setConfigValue(QStringLiteral("scrollbar-minimap"), true);
0162     QCOMPARE(view->configValue(QLatin1String("scrollbar-minimap")).toBool(), true);
0163     view->setConfigValue(QStringLiteral("scrollbar-minimap"), false);
0164     QCOMPARE(view->configValue(QLatin1String("scrollbar-minimap")).toBool(), false);
0165 
0166     view->setConfigValue(QStringLiteral("scrollbar-preview"), true);
0167     QCOMPARE(view->configValue(QLatin1String("scrollbar-preview")).toBool(), true);
0168     view->setConfigValue(QStringLiteral("scrollbar-preview"), false);
0169     QCOMPARE(view->configValue(QLatin1String("scrollbar-preview")).toBool(), false);
0170 
0171     view->setConfigValue(QStringLiteral("font"), QFont(QStringLiteral("Times"), 10, QFont::Bold));
0172     QCOMPARE(view->configValue(QLatin1String("font")).value<QFont>(), QFont(QStringLiteral("Times"), 10, QFont::Bold));
0173 
0174     {
0175         KSyntaxHighlighting::Repository &repository = KTextEditor::EditorPrivate::self()->hlManager()->repository();
0176 
0177         auto lightTheme = repository.defaultTheme(KSyntaxHighlighting::Repository::LightTheme);
0178         view->setConfigValue(QStringLiteral("theme"), lightTheme.name());
0179         QCOMPARE(view->configValue(QLatin1String("theme")).value<QString>(), lightTheme.name());
0180 
0181         auto darkTheme = repository.defaultTheme(KSyntaxHighlighting::Repository::DarkTheme);
0182         view->setConfigValue(QStringLiteral("theme"), darkTheme.name());
0183         QCOMPARE(view->configValue(QLatin1String("theme")).value<QString>(), darkTheme.name());
0184     }
0185 }
0186 
0187 // kate: indent-mode cstyle; indent-width 4; replace-tabs on;