diff --git a/tabbox/tabboxhandler.cpp b/tabbox/tabboxhandler.cpp index 242dcb3f15..66d2acb1af 100644 --- a/tabbox/tabboxhandler.cpp +++ b/tabbox/tabboxhandler.cpp @@ -124,7 +124,11 @@ void TabBoxHandlerPrivate::updateOutline() q->hideOutline(); return; } - TabBoxClient* c = static_cast< TabBoxClient* >(m_clientModel->data(index, ClientModel::ClientRole).value()); + const QVariant client = m_clientModel->data(index, ClientModel::ClientRole); + if (!client.isValid()) { + return; + } + TabBoxClient* c = static_cast< TabBoxClient* >(client.value()); q->showOutline(QRect(c->x(), c->y(), c->width(), c->height())); } diff --git a/tabbox/tests/CMakeLists.txt b/tabbox/tests/CMakeLists.txt index 3478e99265..b090785df7 100644 --- a/tabbox/tests/CMakeLists.txt +++ b/tabbox/tests/CMakeLists.txt @@ -15,3 +15,21 @@ set( testTabBoxClientModel_SRCS kde4_add_unit_test( testTabBoxClientModel TESTNAME testTabBoxClientModel ${testTabBoxClientModel_SRCS} ) target_link_libraries( testTabBoxClientModel ${KDE4_KDEUI_LIBS} ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTDECLARATIVE_LIBRARY} ${QT_QTTEST_LIBRARY} ${X11_LIBRARIES} ) + +######################################################## +# Test TabBox::TabBoxHandler +######################################################## +set( testTabBoxHandler_SRCS + ../clientmodel.cpp + ../desktopmodel.cpp + ../tabboxconfig.cpp + ../tabboxhandler.cpp + test_tabbox_handler.cpp + mock_declarative.cpp + mock_tabboxhandler.cpp + mock_tabboxclient.cpp +) + +kde4_add_unit_test( testTabBoxHandler TESTNAME testTabBoxHandler ${testTabBoxHandler_SRCS} ) + +target_link_libraries( testTabBoxHandler ${KDE4_KDEUI_LIBS} ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTDECLARATIVE_LIBRARY} ${QT_QTTEST_LIBRARY} ${X11_LIBRARIES} ) diff --git a/tabbox/tests/test_tabbox_handler.cpp b/tabbox/tests/test_tabbox_handler.cpp new file mode 100644 index 0000000000..5c081774a7 --- /dev/null +++ b/tabbox/tests/test_tabbox_handler.cpp @@ -0,0 +1,55 @@ +/******************************************************************** +KWin - the KDE window manager +This file is part of the KDE project. + +Copyright (C) 2012 Martin Gräßlin + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*********************************************************************/ +#include "mock_tabboxhandler.h" +#include "clientmodel.h" +#include + +using namespace KWin; + +class TestTabBoxHandler : public QObject +{ + Q_OBJECT +private slots: + /** + * Test to verify that update outline does not crash + * if the ModelIndex for which the outline should be + * shown is not valid. That is accessing the Pointer + * to the Client returns an invalid QVariant. + * BUG: 304620 + **/ + void testDontCrashUpdateOutlineNullClient(); +}; + +void TestTabBoxHandler::testDontCrashUpdateOutlineNullClient() +{ + MockTabBoxHandler tabboxhandler; + TabBox::TabBoxConfig config; + config.setTabBoxMode(TabBox::TabBoxConfig::ClientTabBox); + config.setShowOutline(true); + config.setShowTabBox(false); + config.setHighlightWindows(false); + tabboxhandler.setConfig(config); + // now show the tabbox which will attempt to show the outline + tabboxhandler.show(); +} + +QTEST_MAIN(TestTabBoxHandler) + +#include "test_tabbox_handler.moc"