File indexing completed on 2025-01-26 04:05:03
0001 /* This file is part of the KDE project 0002 * SPDX-FileCopyrightText: 2008 Jan Hambrecht <jaham@gmx.net> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 #include "TestShapeShadowCommand.h" 0007 0008 #include <MockShapes.h> 0009 #include "KoShapeShadow.h" 0010 #include "KoShapeShadowCommand.h" 0011 #include "KoInsets.h" 0012 0013 #include <simpletest.h> 0014 0015 void TestShapeShadowCommand::refCounting() 0016 { 0017 MockShape * shape1 = new MockShape(); 0018 KoShapeShadow * shadow1 = new KoShapeShadow(); 0019 KoShapeShadow * shadow2 = new KoShapeShadow(); 0020 KoShapeShadow * shadow3 = new KoShapeShadow(); 0021 0022 shape1->setShadow(shadow1); 0023 QVERIFY(shape1->shadow() == shadow1); 0024 QCOMPARE(shadow1->useCount(), 1); 0025 0026 // old shadow1, new shadow2 0027 KUndo2Command *cmd1 = new KoShapeShadowCommand(shape1, shadow2); 0028 cmd1->redo(); 0029 QVERIFY(shape1->shadow() == shadow2); 0030 0031 // change back to shadow1 0032 cmd1->undo(); 0033 QVERIFY(shape1->shadow() == shadow1); 0034 0035 // old shadow1, new shadow3 0036 KUndo2Command *cmd2 = new KoShapeShadowCommand(shape1, shadow3); 0037 cmd2->redo(); 0038 QVERIFY(shape1->shadow() == shadow3); 0039 0040 // this command has the shadow1 as the old one 0041 delete cmd1; 0042 0043 // set back to shadow1 0044 cmd2->undo(); 0045 QVERIFY(shape1->shadow() == shadow1); 0046 0047 // if shadow1 is deleted when deleting cmd1 this will crash 0048 KoInsets insets; 0049 shadow1->insets(insets); 0050 0051 delete cmd2; 0052 delete shape1; 0053 } 0054 0055 SIMPLE_TEST_MAIN(TestShapeShadowCommand)