Commit d8f4f103 authored by David Faure's avatar David Faure
Browse files

Unit tests code to check for proper layouting (e.g. after splitting)

Reduce debug output a bit

svn path=/trunk/KDE/kdebase/apps/; revision=678233
parent 3ff512ed
......@@ -308,9 +308,10 @@ KonqMainWindow::KonqMainWindow( const KUrl &initialURL, const QString& xmluiFile
KonqMainWindow::~KonqMainWindow()
{
kDebug(1202) << "KonqMainWindow::~KonqMainWindow " << this << endl;
//kDebug(1202) << "KonqMainWindow::~KonqMainWindow " << this << endl;
delete m_pViewManager;
delete m_pViewManager;
m_pViewManager = 0;
if ( s_lstViews )
{
......@@ -324,8 +325,6 @@ KonqMainWindow::~KonqMainWindow()
saveToolBarServicesMap();
// createShellGUI( false );
delete m_pBookmarkMenu;
delete m_paBookmarkBar;
delete m_pBookmarksOwner;
......@@ -345,7 +344,7 @@ KonqMainWindow::~KonqMainWindow()
delete m_locationLabel;
m_locationLabel = 0;
kDebug(1202) << "KonqMainWindow::~KonqMainWindow " << this << " done" << endl;
//kDebug(1202) << "KonqMainWindow::~KonqMainWindow " << this << " done" << endl;
}
QWidget * KonqMainWindow::createContainer( QWidget *parent, int index, const QDomElement &element, int &id )
......@@ -2250,7 +2249,7 @@ void KonqMainWindow::slotPartActivated( KParts::Part *part )
void KonqMainWindow::insertChildView( KonqView *childView )
{
kDebug(1202) << "KonqMainWindow::insertChildView " << childView << endl;
//kDebug(1202) << "KonqMainWindow::insertChildView " << childView << endl;
m_mapViews.insert( childView->part(), childView );
connect( childView, SIGNAL( viewCompleted( KonqView * ) ),
......@@ -2264,26 +2263,26 @@ void KonqMainWindow::insertChildView( KonqView *childView )
// Called by KonqViewManager, internal
void KonqMainWindow::removeChildView( KonqView *childView )
{
kDebug(1202) << "KonqMainWindow::removeChildView childView " << childView << endl;
//kDebug(1202) << "KonqMainWindow::removeChildView childView " << childView << endl;
disconnect( childView, SIGNAL( viewCompleted( KonqView * ) ),
this, SLOT( slotViewCompleted( KonqView * ) ) );
#ifndef NDEBUG
dumpViewList();
//dumpViewList();
#endif
MapViews::Iterator it = m_mapViews.begin();
MapViews::Iterator end = m_mapViews.end();
const MapViews::Iterator end = m_mapViews.end();
// find it in the map - can't use the key since childView->part() might be 0
kDebug(1202) << "Searching map" << endl;
//kDebug(1202) << "Searching map" << endl;
while ( it != end && it.value() != childView )
++it;
kDebug(1202) << "Verifying search results" << endl;
//kDebug(1202) << "Verifying search results" << endl;
if ( it == m_mapViews.end() )
{
......@@ -2310,7 +2309,7 @@ void KonqMainWindow::removeChildView( KonqView *childView )
void KonqMainWindow::viewCountChanged()
{
// This is called when the number of views changes.
kDebug(1202) << "KonqMainWindow::viewCountChanged" << endl;
//kDebug(1202) << "KonqMainWindow::viewCountChanged" << endl;
int lvc = linkableViewsCount();
m_paLinkView->setEnabled( lvc > 1 );
......
......@@ -22,8 +22,10 @@
#include <konqmainwindow.h>
#include <konqviewmanager.h>
#include <konqview.h>
#include <konqtabs.h>
#include <konqframevisitor.h>
#include <kstandarddirs.h>
#include <QLayout>
QTEST_KDEMAIN_WITH_COMPONENTNAME( ViewMgrTest, GUI, "konqueror" )
......@@ -41,6 +43,30 @@ public:
};
#endif
static void sendAllPendingResizeEvents( QWidget* mainWindow )
{
bool foundOne = true;
while ( foundOne ) {
foundOne = false;
QList<QWidget *> allChildWidgets = mainWindow->findChildren<QWidget *>();
allChildWidgets.prepend( mainWindow );
foreach( QWidget* w, allChildWidgets ) {
if (w->testAttribute(Qt::WA_PendingResizeEvent)) {
//qDebug() << "Resizing" << w << " to " << w->size() << endl;
QResizeEvent e(w->size(), QSize());
QApplication::sendEvent(w, &e);
w->setAttribute(Qt::WA_PendingResizeEvent, false);
// hack: make QTabWidget think it's visible; no layout otherwise
w->setAttribute(Qt::WA_WState_Visible, true);
foundOne = true;
}
}
// Process LayoutRequest events, in particular
qApp->sendPostedEvents();
//qDebug() << "Loop done, checking again";
}
}
class DebugFrameVisitor : public KonqFrameVisitor
{
public:
......@@ -81,6 +107,31 @@ void ViewMgrTest::testCreateFirstView()
// Use DebugFrameVisitor to find out the structure of the frame hierarchy
QCOMPARE( DebugFrameVisitor::inspect(&mainWindow), QString("MT[F].") ); // mainWindow, one tab, one frame
// Check widget parents: part's widget -> frame -> [tabwidget's stack] -> tabwidget -> mainwindow
QWidget* partWidget = view->part()->widget();
QCOMPARE( partWidget->topLevelWidget(), &mainWindow );
QWidget* frame = view->frame()->asQWidget();
QCOMPARE( partWidget->parentWidget(), frame );
QWidget* tabWidget = viewMgr.tabContainer()->asQWidget();
QCOMPARE( frame->parentWidget()->parentWidget(), tabWidget );
// Check frame geometry, to check that all layouts are there
// (the mainwindow is resized to 700x480 in its constructor)
// But pending resize events are only sent by show(), and we don't want to see
// widgets from unit tests.
// So we iterate over all widgets and ensure the pending resize events are sent.
sendAllPendingResizeEvents( &mainWindow );
//for ( QWidget* w = partWidget; w; w = w->parentWidget() )
// qDebug() << w << w->geometry();
QVERIFY( frame->width() > 680 );
QVERIFY( frame->height() > 300 );
//qDebug() << "partWidget geom:" << partWidget->geometry();
QVERIFY( partWidget->width() > 680 );
QVERIFY( partWidget->height() > 300 );
//qDebug() << "tabWidget geom: " << tabWidget->geometry();
QVERIFY( tabWidget->width() > 680 );
QVERIFY( tabWidget->height() > 300 );
}
void ViewMgrTest::testRemoveFirstView()
......@@ -99,14 +150,50 @@ void ViewMgrTest::testSplitView()
KonqMainWindow mainWindow;
KonqViewManager viewMgr( &mainWindow );
KonqView* view = viewMgr.createFirstView( "KonqAboutPage", "konq_aboutpage" );
QCOMPARE( DebugFrameVisitor::inspect(&mainWindow), QString("MT[F].") ); // mainWindow, tab widget, one frame
// TODO also test newOneFirst after improving the visitor... using 'F' + frame->objectName()[0]?
// Or registring views to the visitor... or to a registry used by the visitor, rather.
KonqView* view2 = viewMgr.splitView( view, Qt::Vertical );
KonqView* view2 = viewMgr.splitView( view, Qt::Horizontal );
QVERIFY( view2 );
QCOMPARE( view->frame()->parentContainer(), view2->frame()->parentContainer() );
QCOMPARE( DebugFrameVisitor::inspect(&mainWindow), QString("MT[C(FF)].") ); // mainWindow, tab widget, one splitter, two frames
// Check widget parents
//mainWindow.dumpObjectTree();
QWidget* partWidget = view->part()->widget();
QCOMPARE( partWidget->topLevelWidget(), &mainWindow );
QWidget* frame = view->frame()->asQWidget();
QCOMPARE( partWidget->parentWidget(), frame );
QWidget* part2Widget = view2->part()->widget();
QCOMPARE( part2Widget->topLevelWidget(), &mainWindow );
QWidget* frame2 = view2->frame()->asQWidget();
QCOMPARE( part2Widget->parentWidget(), frame2 );
// Check frame geometries
sendAllPendingResizeEvents( &mainWindow );
//for ( QWidget* w = partWidget; w; w = w->parentWidget() )
// qDebug() << w << w->geometry();
//qDebug() << "view geom:" << frame->geometry();
QVERIFY( frame->width() > 300 && frame->width() < 400 ); // horiz split, so half the mainwindow width
QVERIFY( frame->height() > 300 );
//qDebug() << "view2 geom:" << frame2->geometry();
QVERIFY( frame2->width() > 300 && frame2->width() < 400 ); // horiz split, so half the mainwindow width
QVERIFY( frame2->height() > 300 );
QCOMPARE( frame->size(), frame2->size() );
//qDebug() << "partWidget geom:" << partWidget->geometry();
QVERIFY( partWidget->width() > 300 && partWidget->width() < 400 ); // horiz split, so half the mainwindow width
QVERIFY( partWidget->height() > 300 );
QVERIFY( part2Widget->width() > 300 && part2Widget->width() < 400 ); // horiz split, so half the mainwindow width
QVERIFY( part2Widget->height() > 300 );
//KonqFrameContainerBase* container = view->frame()->parentContainer();
//QVERIFY( container );
//qDebug() << "container geom: " << container->asQWidget()->geometry();
// Split again
KonqView* view3 = viewMgr.splitView( view, Qt::Horizontal );
QVERIFY( view3 );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment