1 /* This file is part of KDE
2 Copyright 2007 David Faure <faure@kde.org>
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.
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.
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.
20 #include <konqcloseditem.h>
21 #include <qtest_kde.h>
22 #include <konqundomanager.h>
24 class UndoManagerTest
: public QObject
30 void testAddClosedTabItem();
31 void testUndoLastClosedTab();
35 QTEST_KDEMAIN( UndoManagerTest
, GUI
)
37 void UndoManagerTest::initTestCase()
39 // Make sure we start clean
40 KonqUndoManager
manager(0);
41 QSignalSpy
spyUndoAvailable(&manager
, SIGNAL(undoAvailable(bool)) );
42 QVERIFY(spyUndoAvailable
.isValid());
43 manager
.clearClosedItemsList();
44 QCOMPARE(spyUndoAvailable
.count(), 1);
45 QCOMPARE(spyUndoAvailable
[0][0], QVariant(false));
46 QVERIFY(!manager
.undoAvailable());
49 void UndoManagerTest::testAddClosedTabItem()
51 KonqUndoManager
manager(0);
52 QVERIFY(!manager
.undoAvailable());
53 KonqClosedTabItem
* item
= new KonqClosedTabItem("url", "title", 0, manager
.newCommandSerialNumber());
54 QCOMPARE(item
->url(), QString("url"));
55 QCOMPARE(item
->serialNumber(), (quint64
)1);
56 QCOMPARE(item
->pos(), 0);
57 KConfigGroup configGroup
= item
->configGroup();
58 QVERIFY(!configGroup
.exists());
60 QSignalSpy
spyUndoAvailable(&manager
, SIGNAL(undoAvailable(bool)) );
61 QVERIFY(spyUndoAvailable
.isValid());
62 QSignalSpy
spyTextChanged(&manager
, SIGNAL(undoTextChanged(QString
)) );
63 QVERIFY( spyTextChanged
.isValid() );
64 manager
.addClosedTabItem(item
);
66 QVERIFY(manager
.undoAvailable());
67 QCOMPARE(spyUndoAvailable
.count(), 1);
68 QCOMPARE(spyTextChanged
.count(), 1);
69 QCOMPARE(manager
.closedItemsList().count(), 1);
70 configGroup
.writeEntry( "RootItem", "test" );
71 QVERIFY(!configGroup
.keyList().isEmpty());
73 // This requires a default constructor...
74 //qRegisterMetaType<KonqClosedTabItem>("KonqClosedTabItem");
75 QSignalSpy
spyOpenClosedTab(&manager
, SIGNAL(openClosedTab(KonqClosedTabItem
)) );
77 QCOMPARE(spyUndoAvailable
.count(), 2);
78 QVERIFY(!manager
.undoAvailable());
79 QCOMPARE(spyOpenClosedTab
.count(), 1);
80 QCOMPARE(manager
.closedItemsList().count(), 0);
81 QVERIFY(configGroup
.keyList().isEmpty()); // was deleted by the KonqClosedTabItem destructor
84 void UndoManagerTest::testUndoLastClosedTab()
89 #include "undomanagertest.moc"