File indexing completed on 2024-06-09 04:22:08

0001 /*
0002  *  SPDX-FileCopyrightText: 2015 Dmitry Kazakov <dimula73@gmail.com>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #include "kis_layer_style_filter_environment_test.h"
0008 
0009 #include "layerstyles/kis_layer_style_filter_environment.h"
0010 #include "kis_pixel_selection.h"
0011 #include <testutil.h>
0012 
0013 
0014 #include <simpletest.h>
0015 
0016 void KisLayerStyleFilterEnvironmentTest::testRandomSelectionCaching()
0017 {
0018     TestUtil::MaskParent p;
0019     KisLayerStyleFilterEnvironment env(p.layer.data());
0020 
0021     const QRect r1 = QRect(0,0,100,100);
0022     const QRect r2 = QRect(0,0,101,101);
0023 
0024     KisPixelSelectionSP selection1 = env.cachedRandomSelection(r1);
0025 
0026     QCOMPARE(selection1->selectedExactRect(), r1);
0027 
0028     KisPixelSelectionSP selection2 = env.cachedRandomSelection(r1);
0029 
0030     QVERIFY(selection1 == selection2);
0031 
0032     KisPixelSelectionSP selection3 = env.cachedRandomSelection(r2);
0033 
0034     QVERIFY(selection1 != selection3);
0035     QCOMPARE(selection3->selectedExactRect(), r2);
0036 }
0037 
0038 void KisLayerStyleFilterEnvironmentTest::benchmarkRandomSelectionGeneration()
0039 {
0040     TestUtil::MaskParent p;
0041     KisLayerStyleFilterEnvironment env(p.layer.data());
0042 
0043     QBENCHMARK_ONCE {
0044         const QRect r1 = QRect(0,0,10000,10000);
0045         KisPixelSelectionSP selection1 = env.cachedRandomSelection(r1);
0046     }
0047 }
0048 
0049 SIMPLE_TEST_MAIN(KisLayerStyleFilterEnvironmentTest)