Warning, file /graphics/krita/sdk/tests/kistest.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 * SPDX-FileCopyrightText: 2018 Boudewijn Rempt <boud@valdyas.org> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef KISTEST 0008 #define KISTEST 0009 0010 #include <KoTestConfig.h> 0011 #include <QApplication> 0012 #include <simpletest.h> 0013 #include <QStandardPaths> 0014 #include <QLoggingCategory> 0015 #include <QtTest/qtestsystem.h> 0016 #include <set> 0017 #include <QLocale> 0018 0019 /** 0020 * There is a hierarchy of libraries built on the kritaresources library 0021 * that provide resources: 0022 * 0023 * pigment: kocolorset, kosegmentgradient, kostopgradient, kopattern 0024 * flake: koseexprscript, kogamutmask, kosvgsymbolcollection 0025 * image: kispaintoppreset, kispsdlayerstyle 0026 * brush: kisgbrbrush, kisimagepipebrush, kissvgbrush, kispngbrush 0027 * ui: kiswindowloyout, kissession, kisworkspace 0028 * 0029 * Depending on which library the test links again, it should use 0030 * 0031 * testresources.h 0032 * testpigment.h 0033 * testflake.h 0034 * testimage.h 0035 * testbrush.h 0036 * testui.h 0037 * 0038 * To get the right KISTEST_MAIN for the resources it needs access to. 0039 * 0040 * This means that adding a new resource means not only adding it in 0041 * KisApplication, but also this file. 0042 */ 0043 0044 0045 0046 #if defined(QT_NETWORK_LIB) 0047 # include <QtTest/qtest_network.h> 0048 #endif 0049 #include <QtTest/qtest_widgets.h> 0050 0051 #ifdef QT_KEYPAD_NAVIGATION 0052 # define QTEST_DISABLE_KEYPAD_NAVIGATION QApplication::setNavigationMode(Qt::NavigationModeNone); 0053 #else 0054 # define QTEST_DISABLE_KEYPAD_NAVIGATION 0055 #endif 0056 0057 #if defined(TESTRESOURCES) || defined(TESTPIGMENT) || defined (TESTFLAKE) || defined(TESTBRUSH) || defined(TESTIMAGE) || defined(TESTUI) 0058 #include <QImageReader> 0059 #include <QList> 0060 #include <QByteArray> 0061 #include <QStringList> 0062 #include <QStandardPaths> 0063 #include <QString> 0064 #include <QDir> 0065 #include <QStandardPaths> 0066 #include <QImageWriter> 0067 0068 #include <KisResourceTypes.h> 0069 #include <KisResourceLoaderRegistry.h> 0070 #include <KisMimeDatabase.h> 0071 #include <KisResourceLoader.h> 0072 #include <KisResourceCacheDb.h> 0073 #include <KisResourceLocator.h> 0074 #include <KoResourcePaths.h> 0075 0076 0077 0078 #if defined(TESTRESOURCES) || defined(TESTPIGMENT) || defined (TESTFLAKE) || defined(TESTIMAGE) || defined(TESTBRUSH) || defined(TESTUI) 0079 #include <resources/KoSegmentGradient.h> 0080 #include <resources/KoStopGradient.h> 0081 #include <resources/KoColorSet.h> 0082 #include <resources/KoPattern.h> 0083 #endif 0084 0085 #if defined (TESTFLAKE) || defined(TESTIMAGE) || defined(TESTBRUSH) || defined(TESTUI) 0086 #if defined HAVE_SEEXPR 0087 #include <KisSeExprScript.h> 0088 #endif 0089 #include <resources/KoGamutMask.h> 0090 #include <resources/KoSvgSymbolCollectionResource.h> 0091 #endif 0092 0093 #if defined(TESTIMAGE) || defined(TESTBRUSH) || defined(TESTUI) 0094 #include <kis_paintop_preset.h> 0095 #include <kis_psd_layer_style.h> 0096 #endif 0097 0098 #if defined(TESTBRUSH) || defined(TESTUI) 0099 #include <kis_gbr_brush.h> 0100 #include <kis_imagepipe_brush.h> 0101 #include <kis_svg_brush.h> 0102 #include <kis_png_brush.h> 0103 #endif 0104 0105 #if defined(TESTUI) 0106 #include <KisWindowLayoutResource.h> 0107 #include <kis_workspace_resource.h> 0108 #include <KisSessionResource.h> 0109 #endif 0110 0111 namespace { 0112 0113 void addResourceTypes() 0114 { 0115 #if defined(TESTRESOURCES) || defined(TESTPIGMENT) || defined (TESTFLAKE) || defined(TESTIMAGE) || defined(TESTBRUSH) || defined(TESTUI) 0116 // All Krita's resource types 0117 KoResourcePaths::addAssetType("markers", "data", "/styles/"); 0118 KoResourcePaths::addAssetType("kis_pics", "data", "/pics/"); 0119 KoResourcePaths::addAssetType("kis_images", "data", "/images/"); 0120 KoResourcePaths::addAssetType("metadata_schema", "data", "/metadata/schemas/"); 0121 KoResourcePaths::addAssetType("gmic_definitions", "data", "/gmic/"); 0122 KoResourcePaths::addAssetType("kis_defaultpresets", "data", "/defaultpresets/"); 0123 KoResourcePaths::addAssetType("psd_layer_style_collections", "data", "/asl"); 0124 KoResourcePaths::addAssetType("kis_shortcuts", "data", "/shortcuts/"); 0125 KoResourcePaths::addAssetType("kis_actions", "data", "/actions"); 0126 KoResourcePaths::addAssetType("kis_actions", "data", "/pykrita"); 0127 KoResourcePaths::addAssetType("icc_profiles", "data", "/color/icc"); 0128 KoResourcePaths::addAssetType("icc_profiles", "data", "/profiles/"); 0129 KoResourcePaths::addAssetType("tags", "data", "/tags/"); 0130 KoResourcePaths::addAssetType("templates", "data", "/templates"); 0131 KoResourcePaths::addAssetType("pythonscripts", "data", "/pykrita"); 0132 KoResourcePaths::addAssetType("preset_icons", "data", "/preset_icons"); 0133 0134 // Make directories for all resources we can save, and tags 0135 QDir d; 0136 d.mkpath(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/tags/"); 0137 d.mkpath(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/asl/"); 0138 d.mkpath(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/bundles/"); 0139 d.mkpath(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/brushes/"); 0140 d.mkpath(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/gradients/"); 0141 d.mkpath(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/paintoppresets/"); 0142 d.mkpath(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/palettes/"); 0143 d.mkpath(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/patterns/"); 0144 // between 4.2.x and 4.3.0 there was a change from 'taskset' to 'tasksets' 0145 // so to make older resource folders compatible with the new version, let's rename the folder 0146 // so no tasksets are lost. 0147 if (d.exists(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/taskset/")) { 0148 d.rename(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/taskset/", 0149 QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/tasksets/"); 0150 } 0151 d.mkpath(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/tasksets/"); 0152 d.mkpath(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/workspaces/"); 0153 d.mkpath(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/input/"); 0154 d.mkpath(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/pykrita/"); 0155 d.mkpath(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/symbols/"); 0156 d.mkpath(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/color-schemes/"); 0157 d.mkpath(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/preset_icons/"); 0158 d.mkpath(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/preset_icons/tool_icons/"); 0159 d.mkpath(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/preset_icons/emblem_icons/"); 0160 d.mkpath(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/gamutmasks/"); 0161 #if defined HAVE_SEEXPR 0162 d.mkpath(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/seexpr_scripts/"); 0163 #endif 0164 #endif 0165 0166 } 0167 0168 void registerResources() 0169 { 0170 0171 #if defined(TESTRESOURCES) || defined(TESTPIGMENT) || defined (TESTFLAKE) || defined(TESTIMAGE) || defined(TESTBRUSH) || defined(TESTUI) 0172 0173 addResourceTypes(); 0174 0175 KisResourceLoaderRegistry *reg = KisResourceLoaderRegistry::instance(); 0176 0177 QList<QByteArray> src = QImageReader::supportedMimeTypes(); 0178 QStringList allImageMimes; 0179 Q_FOREACH(const QByteArray ba, src) { 0180 if (QImageWriter::supportedMimeTypes().contains(ba)) { 0181 allImageMimes << QString::fromUtf8(ba); 0182 } 0183 } 0184 allImageMimes << KisMimeDatabase::mimeTypeForSuffix("pat"); 0185 0186 reg->add(new KisResourceLoader<KoPattern>(ResourceType::Patterns, ResourceType::Patterns, i18n("Patterns"), allImageMimes)); 0187 reg->add(new KisResourceLoader<KoSegmentGradient>(ResourceSubType::SegmentedGradients, ResourceType::Gradients, i18n("Gradients"), QStringList() << "application/x-gimp-gradient")); 0188 reg->add(new KisResourceLoader<KoStopGradient>(ResourceSubType::StopGradients, ResourceType::Gradients, i18n("Gradients"), QStringList() << "image/svg+xml")); 0189 0190 reg->add(new KisResourceLoader<KoColorSet>(ResourceType::Palettes, ResourceType::Palettes, i18n("Palettes"), 0191 QStringList() << KisMimeDatabase::mimeTypeForSuffix("kpl") 0192 << KisMimeDatabase::mimeTypeForSuffix("gpl") 0193 << KisMimeDatabase::mimeTypeForSuffix("pal") 0194 << KisMimeDatabase::mimeTypeForSuffix("act") 0195 << KisMimeDatabase::mimeTypeForSuffix("aco") 0196 << KisMimeDatabase::mimeTypeForSuffix("css") 0197 << KisMimeDatabase::mimeTypeForSuffix("colors") 0198 << KisMimeDatabase::mimeTypeForSuffix("xml") 0199 << KisMimeDatabase::mimeTypeForSuffix("sbz"))); 0200 #endif 0201 0202 #if defined (TESTFLAKE) || defined(TESTIMAGE) || defined(TESTBRUSH) || defined(TESTUI) 0203 #if defined HAVE_SEEXPR 0204 reg->add(new KisResourceLoader<KisSeExprScript>(ResourceType::SeExprScripts, ResourceType::SeExprScripts, i18n("SeExpr Scripts"), QStringList() << "application/x-krita-seexpr-script")); 0205 #endif 0206 reg->add(new KisResourceLoader<KoGamutMask>(ResourceType::GamutMasks, ResourceType::GamutMasks, i18n("Gamut masks"), QStringList() << "application/x-krita-gamutmasks")); 0207 reg->add(new KisResourceLoader<KoSvgSymbolCollectionResource>(ResourceType::Symbols, ResourceType::Symbols, i18n("SVG symbol libraries"), QStringList() << "image/svg+xml")); 0208 #endif 0209 0210 0211 #if defined(TESTIMAGE) || defined(TESTBRUSH) || defined(TESTUI) 0212 reg->add(new KisResourceLoader<KisPaintOpPreset>(ResourceType::PaintOpPresets, ResourceType::PaintOpPresets, i18n("Brush presets"), QStringList() << "application/x-krita-paintoppreset")); 0213 reg->add(new KisResourceLoader<KisPSDLayerStyle>(ResourceType::LayerStyles, 0214 ResourceType::LayerStyles, 0215 ResourceType::LayerStyles, 0216 QStringList() << "application/x-photoshop-style")); 0217 #endif 0218 0219 #if defined(TESTBRUSH) || defined(TESTUI) 0220 0221 reg->add(new KisResourceLoader<KisGbrBrush>(ResourceSubType::GbrBrushes, ResourceType::Brushes, i18n("Brush tips"), QStringList() << "image/x-gimp-brush")); 0222 reg->add(new KisResourceLoader<KisImagePipeBrush>(ResourceSubType::GihBrushes, ResourceType::Brushes, i18n("Brush tips"), QStringList() << "image/x-gimp-brush-animated")); 0223 reg->add(new KisResourceLoader<KisSvgBrush>(ResourceSubType::SvgBrushes, ResourceType::Brushes, i18n("Brush tips"), QStringList() << "image/svg+xml")); 0224 reg->add(new KisResourceLoader<KisPngBrush>(ResourceSubType::PngBrushes, ResourceType::Brushes, i18n("Brush tips"), QStringList() << "image/png")); 0225 0226 #endif 0227 0228 #if defined(TESTUI) 0229 reg->add(new KisResourceLoader<KisWindowLayoutResource>(ResourceType::WindowLayouts, ResourceType::WindowLayouts, i18n("Window layouts"), QStringList() << "application/x-krita-windowlayout")); 0230 reg->add(new KisResourceLoader<KisSessionResource>(ResourceType::Sessions, ResourceType::Sessions, i18n("Sessions"), QStringList() << "application/x-krita-session")); 0231 reg->add(new KisResourceLoader<KisWorkspaceResource>(ResourceType::Workspaces, ResourceType::Workspaces, i18n("Workspaces"), QStringList() << "application/x-krita-workspace")); 0232 #endif 0233 0234 #if defined(TESTRESOURCES) || defined(TESTPIGMENT) || defined (TESTFLAKE) || defined(TESTBRUSH) || defined(TESTIMAGE) || defined(TESTUI) 0235 if (!KisResourceCacheDb::initialize(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation))) { 0236 qFatal("Could not initialize the resource cachedb"); 0237 } 0238 0239 KisResourceLocator::instance()->initialize(KoResourcePaths::getApplicationRoot() + "/share/krita"); 0240 #endif 0241 0242 } 0243 0244 #define KISTEST_MAIN(TestObject) \ 0245 int main(int argc, char *argv[]) \ 0246 { \ 0247 qputenv("LANGUAGE", "en"); \ 0248 QLocale::setDefault(QLocale(QLocale::English, QLocale::UnitedStates)); \ 0249 qputenv("QT_LOGGING_RULES", ""); \ 0250 QStandardPaths::setTestModeEnabled(true); \ 0251 qputenv("EXTRA_RESOURCE_DIRS", QByteArray(KRITA_RESOURCE_DIRS_FOR_TESTS)); \ 0252 qputenv("KRITA_PLUGIN_PATH", QByteArray(KRITA_PLUGINS_DIR_FOR_TESTS)); \ 0253 QApplication app(argc, argv); \ 0254 app.setAttribute(Qt::AA_Use96Dpi, true); \ 0255 QTEST_DISABLE_KEYPAD_NAVIGATION \ 0256 registerResources(); \ 0257 TestObject tc; \ 0258 QTEST_SET_MAIN_SOURCE_PATH \ 0259 return QTest::qExec(&tc, argc, argv); \ 0260 } 0261 0262 } 0263 #else 0264 #define KISTEST_MAIN(TestObject) \ 0265 int main(int argc, char *argv[]) \ 0266 { \ 0267 qputenv("LANGUAGE", "en"); \ 0268 QLocale::setDefault(QLocale(QLocale::English, QLocale::UnitedStates)); \ 0269 qputenv("QT_LOGGING_RULES", ""); \ 0270 qputenv("EXTRA_RESOURCE_DIRS", QByteArray(KRITA_RESOURCE_DIRS_FOR_TESTS)); \ 0271 qputenv("KRITA_PLUGIN_PATH", QByteArray(KRITA_PLUGINS_DIR_FOR_TESTS)); \ 0272 QStandardPaths::setTestModeEnabled(true); \ 0273 QApplication app(argc, argv); \ 0274 app.setAttribute(Qt::AA_Use96Dpi, true); \ 0275 QTEST_DISABLE_KEYPAD_NAVIGATION \ 0276 TestObject tc; \ 0277 QTEST_SET_MAIN_SOURCE_PATH \ 0278 return QTest::qExec(&tc, argc, argv); \ 0279 } 0280 #endif 0281 0282 0283 #endif