File indexing completed on 2024-12-22 04:12:51
0001 /* 0002 * SPDX-FileCopyrightText: 2016 Dmitry Kazakov <dimula73@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "kis_derived_resources_test.h" 0008 0009 #include <simpletest.h> 0010 #include <brushengine/kis_paintop_preset.h> 0011 0012 #include <QApplication> 0013 0014 #include <KoCanvasResourceProvider.h> 0015 0016 #include "kis_canvas_resource_provider.h" 0017 #include <util.h> 0018 #include <KisMainWindow.h> 0019 #include <KisDocument.h> 0020 #include <KisPart.h> 0021 #include <KisView.h> 0022 #include <KisViewManager.h> 0023 #include <kis_paintop_settings.h> 0024 #include <KoResourcePaths.h> 0025 #include <kis_config.h> 0026 #include <testutil.h> 0027 #include "opengl/kis_opengl.h" 0028 #include <KisGlobalResourcesInterface.h> 0029 0030 #include <testui.h> 0031 0032 void KisDerivedResourcesTest::test() 0033 { 0034 QScopedPointer<KoCanvasResourceProvider> manager(new KoCanvasResourceProvider()); 0035 KisViewManager::initializeResourceManager(manager.data()); 0036 0037 QApplication::processEvents(); 0038 0039 QString presetFileName = "autobrush_300px.kpp"; 0040 0041 QVariant i; 0042 0043 KisPaintOpPresetSP preset; 0044 if (!presetFileName.isEmpty()) { 0045 QString fullFileName = TestUtil::fetchDataFileLazy(presetFileName); 0046 preset = KisPaintOpPresetSP(new KisPaintOpPreset(fullFileName)); 0047 bool presetValid = preset->load(KisGlobalResourcesInterface::instance()); 0048 Q_ASSERT(presetValid); Q_UNUSED(presetValid); 0049 0050 i.setValue(preset); 0051 } 0052 0053 QVERIFY(i.isValid()); 0054 0055 QSignalSpy spy(manager.data(), SIGNAL(canvasResourceChanged(int,QVariant))); 0056 0057 manager->setResource(KoCanvasResource::CurrentPaintOpPreset, i); 0058 0059 QMap<int, QVariant> expectedSignals; 0060 expectedSignals[KoCanvasResource::CurrentPaintOpPreset] = QVariant::fromValue(preset); 0061 expectedSignals[KoCanvasResource::EraserMode] = false; 0062 expectedSignals[KoCanvasResource::LodSizeThresholdSupported] = true; 0063 expectedSignals[KoCanvasResource::LodSizeThreshold] = 100; 0064 expectedSignals[KoCanvasResource::LodAvailability] = true; 0065 expectedSignals[KoCanvasResource::Opacity] = 1.0; 0066 expectedSignals[KoCanvasResource::Size] = 300.0; 0067 expectedSignals[KoCanvasResource::BrushRotation] = 0.0; 0068 expectedSignals[KoCanvasResource::Flow] = 1.0; 0069 expectedSignals[KoCanvasResource::Fade] = 0.25; 0070 expectedSignals[KoCanvasResource::Scatter] = 0.0; 0071 expectedSignals[KoCanvasResource::CurrentEffectiveCompositeOp] = COMPOSITE_OVER; 0072 expectedSignals[KoCanvasResource::CurrentCompositeOp] = COMPOSITE_OVER; 0073 expectedSignals[KoCanvasResource::PatternSize] = 0.5; 0074 expectedSignals[KoCanvasResource::CurrentPaintOpPresetName] = "autobrush-300px"; 0075 0076 // this signal is not generated by the derived resources, but by GUI elements, 0077 // which are not available in the unittest 0078 // expectedSignals[KoCanvasResource::EffectiveLodAvailability] = true; 0079 0080 auto it = spy.begin(); 0081 for (; it != spy.end(); ++it) { 0082 const int id = (*it)[0].toInt(); 0083 const QVariant value = (*it)[1]; 0084 0085 if (!expectedSignals.contains(id)) { 0086 qDebug() << ppVar(id) << ppVar(value); 0087 QFAIL("Unexpected signal!"); 0088 } else { 0089 if (expectedSignals[id] != value) { 0090 qDebug() << ppVar(id) << ppVar(value) << ppVar(expectedSignals[id]); 0091 QFAIL("Unexpected value!"); 0092 } 0093 } 0094 } 0095 0096 QCOMPARE(spy.size(), expectedSignals.size()); 0097 0098 spy.clear(); 0099 0100 preset->settings()->setPaintOpOpacity(0.8); 0101 0102 QTest::qWait(200); 0103 0104 QCOMPARE(spy.size(), 1); 0105 QCOMPARE(spy[0][0].toInt(), (int)KoCanvasResource::Opacity); 0106 QCOMPARE(spy[0][1].toDouble(), 0.8); 0107 spy.clear(); 0108 } 0109 0110 KISTEST_MAIN(KisDerivedResourcesTest)