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