File indexing completed on 2025-02-02 04:15:01
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 "TestShapeStrokeCommand.h" 0007 0008 #include <MockShapes.h> 0009 #include "KoShapeStrokeModel.h" 0010 #include "KoShapeStroke.h" 0011 #include "KoShapeStrokeCommand.h" 0012 #include <KoInsets.h> 0013 0014 #include <simpletest.h> 0015 0016 void TestShapeStrokeCommand::refCounting() 0017 { 0018 MockShape * shape1 = new MockShape(); 0019 KoShapeStrokeModelSP whiteStroke(new KoShapeStroke(1.0, QColor(Qt::white))); 0020 KoShapeStrokeModelSP blackStroke(new KoShapeStroke(1.0, QColor(Qt::black))); 0021 KoShapeStrokeModelSP redStroke(new KoShapeStroke(1.0, QColor(Qt::red))); 0022 0023 shape1->setStroke(whiteStroke); 0024 QVERIFY(shape1->stroke() == whiteStroke); 0025 0026 // old stroke is white, new stroke is black 0027 KUndo2Command *cmd1 = new KoShapeStrokeCommand(shape1, blackStroke); 0028 cmd1->redo(); 0029 QVERIFY(shape1->stroke() == blackStroke); 0030 0031 // change stroke back to white stroke 0032 cmd1->undo(); 0033 QVERIFY(shape1->stroke() == whiteStroke); 0034 0035 // old stroke is white, new stroke is red 0036 KUndo2Command *cmd2 = new KoShapeStrokeCommand(shape1, redStroke); 0037 cmd2->redo(); 0038 QVERIFY(shape1->stroke() == redStroke); 0039 0040 // this command has the white stroke as the old stroke 0041 delete cmd1; 0042 0043 // set stroke back to white stroke 0044 cmd2->undo(); 0045 QVERIFY(shape1->stroke() == whiteStroke); 0046 0047 // if white is deleted when deleting cmd1 this will crash 0048 KoInsets insets; 0049 whiteStroke->strokeInsets(shape1, insets); 0050 0051 delete cmd2; 0052 delete shape1; 0053 } 0054 0055 SIMPLE_TEST_MAIN(TestShapeStrokeCommand)