1 /* This file is part of the KDE project
2 * Copyright (C) 2008 Jan Hambrecht <jaham@gmx.net>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB.  If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19 #include "TestShapeShadowCommand.h"
20 
21 #include <MockShapes.h>
22 #include "KoShapeShadow.h"
23 #include "KoShapeShadowCommand.h"
24 #include "KoInsets.h"
25 
26 #include <QTest>
27 
refCounting()28 void TestShapeShadowCommand::refCounting()
29 {
30     MockShape * shape1 = new MockShape();
31     KoShapeShadow * shadow1 = new KoShapeShadow();
32     KoShapeShadow * shadow2 = new KoShapeShadow();
33     KoShapeShadow * shadow3 = new KoShapeShadow();
34 
35     shape1->setShadow(shadow1);
36     QVERIFY(shape1->shadow() == shadow1);
37     QCOMPARE(shadow1->useCount(), 1);
38 
39     // old shadow1, new shadow2
40     KUndo2Command *cmd1 = new KoShapeShadowCommand(shape1, shadow2);
41     cmd1->redo();
42     QVERIFY(shape1->shadow() == shadow2);
43 
44     // change back to shadow1
45     cmd1->undo();
46     QVERIFY(shape1->shadow() == shadow1);
47 
48     // old shadow1, new shadow3
49     KUndo2Command *cmd2 = new KoShapeShadowCommand(shape1, shadow3);
50     cmd2->redo();
51     QVERIFY(shape1->shadow() == shadow3);
52 
53     // this command has the shadow1 as the old one
54     delete cmd1;
55 
56     // set back to shadow1
57     cmd2->undo();
58     QVERIFY(shape1->shadow() == shadow1);
59 
60     // if shadow1 is deleted when deleting cmd1 this will crash
61     KoInsets insets;
62     shadow1->insets(insets);
63 
64     delete cmd2;
65     delete shape1;
66 }
67 
68 QTEST_MAIN(TestShapeShadowCommand)
69