From 817de698a08060f1054dc336f03deba4f5e1f5fc Mon Sep 17 00:00:00 2001 From: Script Kiddy Date: Sun, 22 Jul 2012 10:49:48 +0200 Subject: [PATCH 1/3] SVN_SILENT made messages (.desktop file) --- kcmkwin/kwindesktop/desktop.desktop | 1 + kcmkwin/kwinscreenedges/kwinscreenedges.desktop | 1 + kwin.notifyrc | 4 ++++ 3 files changed, 6 insertions(+) diff --git a/kcmkwin/kwindesktop/desktop.desktop b/kcmkwin/kwindesktop/desktop.desktop index d8798bd94b..7318dc532e 100644 --- a/kcmkwin/kwindesktop/desktop.desktop +++ b/kcmkwin/kwindesktop/desktop.desktop @@ -164,6 +164,7 @@ Comment[zh_TW]=您可以在這裡設定要有多少個虛擬桌面。 X-KDE-Keywords=desktop,desktops,number,virtual desktop,multiple desktops,pager,pager widget,pager applet,pager settings X-KDE-Keywords[ca]=escriptori,escriptoris,nombre,escriptori virtual,escriptoris múltiples,paginador,estri paginador,miniaplicació de paginació,arranjament de paginador X-KDE-Keywords[da]=skrivebord,skriveborde,desktop,desktops,virtuelt skrivebord,flere skriveborde,spaces,pager,skrivebordsvælger,pager widget,pager applet +X-KDE-Keywords[es]=escritorio,escritorios,número,escritorio virtual,múltiples escritorios,paginador,control de paginación,miniaplicación del paginador,preferencias del paginador X-KDE-Keywords[et]=töölaud,töölauad,arv,virtuaalne töölaud,mitu töölauda,töölauavahetaja,töölaudade vahetaja,töölauavahetaja aplett,töölauavahetaja vidin,töölauavahetaja seadistused X-KDE-Keywords[fi]=työpöytä,työpöydät,lukumäärä,virtuaalityöpöytä,monta työpöytää,sivutin,sivutinsovelma,sivuttimen asetukset X-KDE-Keywords[hu]=asztal,asztalok,szám,virtuális asztal,több asztal,papír,papír felületi elem,papír kisalkalmazás,papírbeállítások diff --git a/kcmkwin/kwinscreenedges/kwinscreenedges.desktop b/kcmkwin/kwinscreenedges/kwinscreenedges.desktop index 63638e283d..94d383deed 100644 --- a/kcmkwin/kwinscreenedges/kwinscreenedges.desktop +++ b/kcmkwin/kwinscreenedges/kwinscreenedges.desktop @@ -151,6 +151,7 @@ Comment[zh_TW]=設定作用的螢幕邊緣 X-KDE-Keywords=kwin,window,manager,effect,edge,border,action,switch,desktop,kwin screen edges,desktop edges,screen edges,maximize windows,tile windows,side of screen,screen behavior,switch desktop,virtual desktop,screen corners X-KDE-Keywords[ca]=kwin,finestra,gestor,efecte,vora,borde,acció,canvi,escriptori,vores de pantalla del kwin,vores d'escriptori,vores de pantalla,maximitza finestres,mosaic de finestres,costat de pantalla,comportament de pantalla,canvi d'escriptori,escriptori virtual,cantonades de pantalla X-KDE-Keywords[da]=kwin,vindue,håndtering,manager,effekt,kant,handling,skift,skrivebord,kwin skærmkanter,skrivebordskanter,skærmkanter,maksimer vinduer,tile windows,fliser,felter,siden af skærmen,skærmens opførsel,skift skrivebord,virtuelle skriveborde,skærmhjørner,hjørner +X-KDE-Keywords[es]=kwin,ventana,gestor,efecto,borde,acción,cambiar,escritorio,bordes de pantalla de kwin,bordes del escritorio,bordes de la pantalla,maximizar ventanas,ventanas en mosaico,lado de la pantalla,comportamiento de la pantalla,cambiar escritorio,escritorio virtual,esquinas de la pantalla X-KDE-Keywords[et]=kwin,aken,haldur,efekt.serv,piire,toiming,lülitamine,töölaud,kwini ekraani servad,töölaua servad,ekraani servad,akende maksimeerimine,akende paanimine,ekraani äär,ekraani käitumine,töölaua lülitamine,virtuaalne töölaud,ekraani nurgad X-KDE-Keywords[fi]=kwin,window,manager,effect,edge,border,action,switch,desktop,kwin screen edges,desktop edges,screen edges,maximize windows,tile windows,side of screen,screen behavior,switch desktop,virtual desktop,screen corners,ikkunamanageri,ikkunaohjelma,tehoste,reuna,vaihda,vaihto,työpöytä,näytön reunat,työpöydän reunat,suurenna ikkuna,kasaa ikkunat,näytön toiminta,vaihda työpöytää,virtuaalityöpöytä,näytön reunat X-KDE-Keywords[hu]=kwin,ablak,kezelő,effektus,szél,szegély,művelet,váltás,asztal,kwin képernyőszél,asztalszél,képernyőszél,ablakok maximalizálása,ablakcím,képernyőoldal,képernyő működése,asztalváltás,virtuális asztal,képernyősarkok diff --git a/kwin.notifyrc b/kwin.notifyrc index 45d0df72a4..ab64eed16a 100644 --- a/kwin.notifyrc +++ b/kwin.notifyrc @@ -7477,6 +7477,7 @@ Name[ia]=Fixation de fenestra a schermo plen Name[it]=Finestra a schermo pieno Name[kk]=Толық экранды терезе Name[km]=កំណត់​បង្អួច​ពេញអេក្រង់ +Name[nb]=Fullskjerm slått på Name[nl]=Venster in modus volledig scherm Name[pa]=ਵਿੰਡੋ ਪੂਰੀਸਕਰੀਨ ਸੈੱਟ Name[pl]=Ustawienie okna na pełnoekranowe @@ -7505,6 +7506,7 @@ Comment[ia]=Un fenestra ha essite fixate al modo de schermo plen Comment[it]=La finestra è stata impostata a schermo pieno Comment[kk]=Толық экранды терезе орнатылды Comment[km]=បង្អួច​ត្រូវ​បាន​កំណត់​ទៅ​ពេញអេក្រង់ +Comment[nb]=Et vindu har blitt satt som fullskjermvindu Comment[nl]=Een venster is ingesteld op volledig scherm Comment[pa]=ਵਿੰਡੋ ਪੂਰੀ ਸਕਰੀਨ ਲਈ ਸੈੱਟ ਕੀਤੀ ਜਾ ਚੁੱਕੀ ਹੈ Comment[pl]=Okno zostało ustawione jako pełnoekranowe @@ -7535,6 +7537,7 @@ Name[ia]=Fenestra de schermo plen restabilite Name[it]=Finestra a schermo pieno ripristinata Name[kk]=Кәдімгі (толық экранды емес) терезе Name[km]=បានស្ដារ​បង្អួច​ពេញអេក្រង់ +Name[nb]=Fullskjerm slått av Name[nl]=Venster terug uit modus volledig scherm Name[pa]=ਵਿੰਡੋ ਪੂਰੀ ਸਕਰੀਨ ਰੀ-ਸਟੋਰ ਕੀਤੀ Name[pl]=Przywrócenie okna z pełnoekranowego @@ -7563,6 +7566,7 @@ Comment[ia]=Un fenestra ha essite restabilite ab schermo plen Comment[it]=La finestra è stata ripristinata da schermo pieno Comment[kk]=Терезе толық экранды күйінен қайтарылды Comment[km]=បង្អួច​ត្រូវ​បាន​ស្ដារ​ពី​ទិដ្ឋភាព​ពេញអេក្រង់ +Comment[nb]=Et vindu er tilbakestilt fra fullskjermvindu Comment[nl]=Een venster is teruggebracht uit de instelling volledig scherm Comment[pa]=ਵਿੰਡੋ ਨੂੰ ਪੂਰੀ ਸਕਰੀਨ ਨੂੰ ਮੁੜ ਕੇ ਸਟੋਰ ਕੀਤਾ ਗਿਆ Comment[pl]=Okno zostało przywrócone z pełnoekranowego From ddd2b117b1043f67a6e996b6bbe8e8b8c4de6478 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20L=C3=BCbking?= Date: Mon, 9 Jul 2012 22:42:56 +0200 Subject: [PATCH 2/3] introduce KDecorationPlugins::canLoad() so we don't mess up our plugins on reload also invoke it by loadPlugin() and fix some KLibrary memleaks REVIEW: 105499 BUG: 303247 (cherry picked from commit fd272b06954029b554197be1d10e252b01f56502) --- kcmkwin/kwindecoration/decorationmodel.cpp | 13 +- libkdecorations/kdecoration_plugins_p.cpp | 155 +++++++++++++-------- libkdecorations/kdecoration_plugins_p.h | 5 +- 3 files changed, 107 insertions(+), 66 deletions(-) diff --git a/kcmkwin/kwindecoration/decorationmodel.cpp b/kcmkwin/kwindecoration/decorationmodel.cpp index b945606092..3d3bb862f8 100644 --- a/kcmkwin/kwindecoration/decorationmodel.cpp +++ b/kcmkwin/kwindecoration/decorationmodel.cpp @@ -94,9 +94,7 @@ void DecorationModel::findDecorations() findAuroraeThemes(); continue; } - if (m_plugins->loadPlugin(libName)) - m_plugins->destroyPreviousPlugin(); - else + if (!m_plugins->canLoad(libName)) continue; DecorationModelData data; data.name = desktopFile.readName(); @@ -197,7 +195,8 @@ QVariant DecorationModel::data(const QModelIndex& index, int role) const if (m_plugins->loadPlugin(m_decorations[ index.row()].libraryName) && m_plugins->factory() != NULL) { foreach (KDecorationDefines::BorderSize size, m_plugins->factory()->borderSizes()) // krazy:exclude=foreach - sizes << int(size) ; + sizes << int(size); + m_plugins->destroyPreviousPlugin(); } return sizes; } @@ -312,13 +311,15 @@ void DecorationModel::regeneratePreview(const QModelIndex& index, const QSize& s document.setHtml(html); bool enabled = false; - if (m_plugins->loadPlugin(data.libraryName) && m_preview->recreateDecoration(m_plugins)) { + bool loaded; + if ((loaded = m_plugins->loadPlugin(data.libraryName)) && m_preview->recreateDecoration(m_plugins)) { enabled = true; m_preview->enablePreview(); } else { m_preview->disablePreview(); } - m_plugins->destroyPreviousPlugin(); + if (loaded) + m_plugins->destroyPreviousPlugin(); if (enabled) { m_preview->resize(size); m_preview->setTempButtons(m_plugins, m_customButtons, m_leftButtons, m_rightButtons); diff --git a/libkdecorations/kdecoration_plugins_p.cpp b/libkdecorations/kdecoration_plugins_p.cpp index 04df26e51f..c131a41ff9 100644 --- a/libkdecorations/kdecoration_plugins_p.cpp +++ b/libkdecorations/kdecoration_plugins_p.cpp @@ -98,71 +98,60 @@ KDecoration* KDecorationPlugins::createDecoration(KDecorationBridge* bridge) return NULL; } -// returns true if plugin was loaded successfully -bool KDecorationPlugins::loadPlugin(QString nameStr) +// tests whether the plugin can be loaded +bool KDecorationPlugins::canLoad(QString nameStr, KLibrary **loadedLib) { - KConfigGroup group(config, QString("Style")); - if (nameStr.isEmpty()) { - nameStr = group.readEntry("PluginLib", defaultPlugin); + if (nameStr.isEmpty()) + return false; // we can't load that + + // Check if this library is not already loaded. + if (pluginStr == nameStr) { + if (loadedLib) { + *loadedLib = library; + } + return true; } + + KConfigGroup group(config, QString("Style")); if (group.readEntry("NoPlugin", false)) { error(i18n("Loading of window decoration plugin library disabled in configuration.")); return false; } - KLibrary *oldLibrary = library; - KDecorationFactory* oldFactory = fact; - KLibrary libToFind(nameStr); QString path = libToFind.fileName(); kDebug(1212) << "kwin : path " << path << " for " << nameStr; - // If the plugin was not found, try to find the default if (path.isEmpty()) { - nameStr = defaultPlugin; - KLibrary libToFind(nameStr); - path = libToFind.fileName(); - } - - // If no library was found, exit kwin with an error message - if (path.isEmpty()) { - error(i18n("No window decoration plugin library was found.")); return false; } - // Check if this library is not already loaded. - if (pluginStr == nameStr) - return true; - // Try loading the requested plugin - library = new KLibrary(path); + KLibrary *lib = new KLibrary(path); - // If that fails, fall back to the default plugin -trydefaultlib: - if (!library) { - kDebug(1212) << " could not load library, try default plugin again"; - nameStr = defaultPlugin; - if (pluginStr == nameStr) - return true; - KLibrary libToFind(nameStr); - path = libToFind.fileName(); - if (!path.isEmpty()) - library = new KLibrary(path); - } - - if (!library) { - error(i18n("The default decoration plugin is corrupt " - "and could not be loaded.")); + if (!lib) return false; - } - create_ptr = NULL; - version_ptr = 0; + // TODO this would be a nice shortcut, but for "some" reason QtCurve with wrong ABI slips through + // TODO figure where it's loaded w/o being unloaded and check whether that can be fixed. +#if 0 + if (lib->isLoaded()) { + if (loadedLib) { + *loadedLib = lib; + } + return true; + } +#endif + // so we check whether this lib was loaded before and don't unload it in case + bool wasLoaded = lib->isLoaded(); + + KDecorationFactory*(*cptr)() = NULL; + int (*vptr)() = NULL; int deco_version = 0; - KLibrary::void_function_ptr version_func = library->resolveFunction("decoration_version"); + KLibrary::void_function_ptr version_func = lib->resolveFunction("decoration_version"); if (version_func) { - version_ptr = (int(*)())version_func; - deco_version = version_ptr(); + vptr = (int(*)())version_func; + deco_version = vptr(); } else { // block some decos known to link the unstable API but (for now) let through other legacy stuff const bool isLegacyStableABI = !(nameStr.contains("qtcurve", Qt::CaseInsensitive) || @@ -178,30 +167,77 @@ trydefaultlib: kWarning(1212) << "****** Please use the KWIN_DECORATION macro in extern \"C\" to get this decoration loaded in future versions of kwin"; } if (deco_version != KWIN_DECORATION_API_VERSION) { - if (nameStr != defaultPlugin) { - if (version_func) - kWarning(1212) << i18n("The library %1 has wrong API version %2", path, deco_version); - library->unload(); - library = NULL; - goto trydefaultlib; + if (version_func) + kWarning(1212) << i18n("The library %1 has wrong API version %2", path, deco_version); + lib->unload(); + delete lib; + return false; + } + + KLibrary::void_function_ptr create_func = lib->resolveFunction("create_factory"); + if (create_func) + cptr = (KDecorationFactory * (*)())create_func; + + if (!cptr) { + kDebug(1212) << i18n("The library %1 is not a KWin plugin.", path); + lib->unload(); + delete lib; + return false; + } + + if (loadedLib) { + *loadedLib = lib; + } else { + if (!wasLoaded) + lib->unload(); + delete lib; + } + return true; +} + +// returns true if plugin was loaded successfully +bool KDecorationPlugins::loadPlugin(QString nameStr) +{ + KConfigGroup group(config, QString("Style")); + if (nameStr.isEmpty()) { + nameStr = group.readEntry("PluginLib", defaultPlugin); + } + + // Check if this library is not already loaded. + if (pluginStr == nameStr) + return true; + + KLibrary *oldLibrary = library; + KDecorationFactory* oldFactory = fact; + + if (!canLoad(nameStr, &library)) { + // If that fails, fall back to the default plugin + nameStr = defaultPlugin; + if (!canLoad(nameStr, &library)) { + // big time trouble! + // -> exit kwin with an error message + error(i18n("The default decoration plugin is corrupt and could not be loaded.")); + return false; } } + // guarded by "canLoad" KLibrary::void_function_ptr create_func = library->resolveFunction("create_factory"); if (create_func) create_ptr = (KDecorationFactory * (*)())create_func; - - if (!create_ptr) { + if (!create_ptr) { // this means someone probably attempted to load "some" kwin plugin/lib as deco + // and thus cheated on the "isLoaded" shortcut -> try the default and yell a warning if (nameStr != defaultPlugin) { - kDebug(1212) << i18n("The library %1 is not a KWin plugin.", path); - library->unload(); - library = NULL; - goto trydefaultlib; + kWarning(1212) << i18n("The library %1 was attempted to be load as decoration plugin but is NOT", nameStr); + return loadPlugin(defaultPlugin); + } else { + // big time trouble! + // -> exit kwin with an error message + error(i18n("The default decoration plugin is corrupt and could not be loaded.")); + return false; } - error(i18n("The library %1 is not a KWin plugin.", path)); - library->unload(); - return false; } + fact = create_ptr(); fact->checkRequirements(this); // let it check what is supported @@ -231,6 +267,7 @@ void KDecorationPlugins::destroyPreviousPlugin() delete old_fact; old_fact = NULL; old_library->unload(); + delete old_library; old_library = NULL; } } diff --git a/libkdecorations/kdecoration_plugins_p.h b/libkdecorations/kdecoration_plugins_p.h index 27873efa8d..e23e332067 100644 --- a/libkdecorations/kdecoration_plugins_p.h +++ b/libkdecorations/kdecoration_plugins_p.h @@ -48,6 +48,10 @@ class KWIN_EXPORT KDecorationPlugins public: KDecorationPlugins(const KSharedConfigPtr &cfg); virtual ~KDecorationPlugins(); + /** Whether the plugin with @p name can be loaded + * if @p loadedLib is passed, the library is NOT unloaded and freed + * what is now your resposibility (intended for and used by below loadPlugin mainly) */ + bool canLoad(QString name, KLibrary ** loadedLib = 0); bool loadPlugin(QString name); void destroyPreviousPlugin(); KDecorationFactory* factory(); @@ -59,7 +63,6 @@ protected: QString defaultPlugin; // FRAME normalne protected? private: KDecorationFactory*(*create_ptr)(); - int (*version_ptr)(); KLibrary *library; KDecorationFactory* fact; KLibrary *old_library; From bd7958392dc040ee003523a68758cb061f4a5747 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Sat, 21 Jul 2012 11:25:17 +0200 Subject: [PATCH 3/3] Verify pointer is valid when calculating the longest caption The method was missing a check whether the weak pointers in the internal list got deleted. This could in very unlikely cases lead to a crash. In order to verify that adding the null pointer check fixes the crash a unit test is added to simulate the situation of a pointer being deleted. This required to add a mock a few classes of TabBox. A MockTabBoxHandler and MockTabBoxClient are added implementing the specific interfaces. The DeclarativeView is completely mocked to make the linker happy. Including the actual implementation is not possible as it pulls in half of KWin core. BUG: 303840 FIXED-IN: 4.9.0 REVIEW: 105645 --- tabbox/CMakeLists.txt | 1 + tabbox/clientmodel.cpp | 3 + tabbox/tests/CMakeLists.txt | 17 ++++ tabbox/tests/mock_declarative.cpp | 94 ++++++++++++++++++++++ tabbox/tests/mock_tabboxclient.cpp | 38 +++++++++ tabbox/tests/mock_tabboxclient.h | 67 ++++++++++++++++ tabbox/tests/mock_tabboxhandler.cpp | 99 ++++++++++++++++++++++++ tabbox/tests/mock_tabboxhandler.h | 93 ++++++++++++++++++++++ tabbox/tests/test_tabbox_clientmodel.cpp | 47 +++++++++++ tabbox/tests/test_tabbox_clientmodel.h | 38 +++++++++ 10 files changed, 497 insertions(+) create mode 100644 tabbox/tests/CMakeLists.txt create mode 100644 tabbox/tests/mock_declarative.cpp create mode 100644 tabbox/tests/mock_tabboxclient.cpp create mode 100644 tabbox/tests/mock_tabboxclient.h create mode 100644 tabbox/tests/mock_tabboxhandler.cpp create mode 100644 tabbox/tests/mock_tabboxhandler.h create mode 100644 tabbox/tests/test_tabbox_clientmodel.cpp create mode 100644 tabbox/tests/test_tabbox_clientmodel.h diff --git a/tabbox/CMakeLists.txt b/tabbox/CMakeLists.txt index e222b6a63f..2ef58101fa 100644 --- a/tabbox/CMakeLists.txt +++ b/tabbox/CMakeLists.txt @@ -1,4 +1,5 @@ add_subdirectory( qml ) +add_subdirectory( tests ) # Install the KWin/WindowSwitcher service type install( FILES kwinwindowswitcher.desktop DESTINATION ${SERVICETYPES_INSTALL_DIR} ) diff --git a/tabbox/clientmodel.cpp b/tabbox/clientmodel.cpp index 06a0c1a869..b78c1f5ce4 100644 --- a/tabbox/clientmodel.cpp +++ b/tabbox/clientmodel.cpp @@ -93,6 +93,9 @@ QString ClientModel::longestCaption() const QString caption; foreach (QWeakPointer clientPointer, m_clientList) { QSharedPointer client = clientPointer.toStrongRef(); + if (!client) { + continue; + } if (client->caption().size() > caption.size()) { caption = client->caption(); } diff --git a/tabbox/tests/CMakeLists.txt b/tabbox/tests/CMakeLists.txt new file mode 100644 index 0000000000..f8377ac929 --- /dev/null +++ b/tabbox/tests/CMakeLists.txt @@ -0,0 +1,17 @@ +######################################################## +# Test TabBox::ClientModel +######################################################## +set( testTabBoxClientModel_SRCS + ../clientmodel.cpp + ../desktopmodel.cpp + ../tabboxconfig.cpp + ../tabboxhandler.cpp + test_tabbox_clientmodel.cpp + mock_declarative.cpp + mock_tabboxhandler.cpp + mock_tabboxclient.cpp +) + +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} ) diff --git a/tabbox/tests/mock_declarative.cpp b/tabbox/tests/mock_declarative.cpp new file mode 100644 index 0000000000..67ac56a9be --- /dev/null +++ b/tabbox/tests/mock_declarative.cpp @@ -0,0 +1,94 @@ +/******************************************************************** +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 "declarative.h" + +namespace KWin +{ +namespace TabBox +{ +DeclarativeView::DeclarativeView(QAbstractItemModel *model, TabBoxConfig::TabBoxMode mode, QWidget *parent) + : QDeclarativeView(parent) +{ + Q_UNUSED(model) + Q_UNUSED(mode) +} + +void DeclarativeView::currentIndexChanged(int row) +{ + Q_UNUSED(row) +} + +void DeclarativeView::updateQmlSource(bool force) +{ + Q_UNUSED(force) +} + +void DeclarativeView::setCurrentIndex(const QModelIndex &index, bool disableAnimation) +{ + Q_UNUSED(index) + Q_UNUSED(disableAnimation) +} + +bool DeclarativeView::sendKeyEvent(QKeyEvent *e) +{ + Q_UNUSED(e) + return false; +} + +void DeclarativeView::slotEmbeddedChanged(bool enabled) +{ + Q_UNUSED(enabled) +} + +void DeclarativeView::slotUpdateGeometry() +{ +} + +void DeclarativeView::slotWindowChanged(WId wId, unsigned int properties) +{ + Q_UNUSED(wId) + Q_UNUSED(properties) +} + +void DeclarativeView::showEvent(QShowEvent *event) +{ + Q_UNUSED(event) +} + +void DeclarativeView::resizeEvent(QResizeEvent *event) +{ + Q_UNUSED(event) +} + +void DeclarativeView::hideEvent(QHideEvent *event) +{ + Q_UNUSED(event) +} + +bool DeclarativeView::x11Event(XEvent *e) +{ + Q_UNUSED(e) + return false; +} + +} // namespace Tabbox +} // namespace KWin + +#include "../declarative.moc" diff --git a/tabbox/tests/mock_tabboxclient.cpp b/tabbox/tests/mock_tabboxclient.cpp new file mode 100644 index 0000000000..5b5f09ec01 --- /dev/null +++ b/tabbox/tests/mock_tabboxclient.cpp @@ -0,0 +1,38 @@ +/******************************************************************** +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_tabboxclient.h" +#include "mock_tabboxhandler.h" + +namespace KWin +{ + +MockTabBoxClient::MockTabBoxClient(QString caption, WId id) + : TabBoxClient() + , m_caption(caption) + , m_wId(id) +{ +} + +void MockTabBoxClient::close() +{ + static_cast(TabBox::tabBox)->closeWindow(this); +} + +} // namespace KWin diff --git a/tabbox/tests/mock_tabboxclient.h b/tabbox/tests/mock_tabboxclient.h new file mode 100644 index 0000000000..ec438e603e --- /dev/null +++ b/tabbox/tests/mock_tabboxclient.h @@ -0,0 +1,67 @@ +/******************************************************************** +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 . +*********************************************************************/ +#ifndef KWIN_MOCK_TABBOX_CLIENT_H +#define KWIN_MOCK_TABBOX_CLIENT_H + +#include "../tabboxhandler.h" +namespace KWin +{ +class MockTabBoxClient : public TabBox::TabBoxClient +{ +public: + explicit MockTabBoxClient(QString caption, WId id); + virtual bool isMinimized() const { + return false; + } + virtual QString caption() const { + return m_caption; + } + virtual void close(); + virtual int height() const { + return 100; + } + virtual QPixmap icon(const QSize &size = QSize(32, 32)) const { + return QPixmap(size); + } + virtual bool isCloseable() const { + return true; + } + virtual bool isFirstInTabBox() const { + return false; + } + virtual int width() const { + return 100; + } + virtual WId window() const { + return m_wId; + } + virtual int x() const { + return 0; + } + virtual int y() const { + return 0; + } + +private: + QString m_caption; + WId m_wId; +}; +} // namespace KWin +#endif diff --git a/tabbox/tests/mock_tabboxhandler.cpp b/tabbox/tests/mock_tabboxhandler.cpp new file mode 100644 index 0000000000..1d27dc752b --- /dev/null +++ b/tabbox/tests/mock_tabboxhandler.cpp @@ -0,0 +1,99 @@ +/******************************************************************** +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 "mock_tabboxclient.h" + +namespace KWin +{ + +MockTabBoxHandler::MockTabBoxHandler() + : TabBoxHandler() +{ +} + +MockTabBoxHandler::~MockTabBoxHandler() +{ +} + +void MockTabBoxHandler::grabbedKeyEvent(QKeyEvent *event) const +{ + Q_UNUSED(event) +} + +QWeakPointer< TabBox::TabBoxClient > MockTabBoxHandler::activeClient() const +{ + if (!m_windows.isEmpty()) { + return QWeakPointer< TabBox::TabBoxClient >(m_windows.first()); + } + return QWeakPointer(); +} + +QWeakPointer< TabBox::TabBoxClient > MockTabBoxHandler::clientToAddToList(TabBox::TabBoxClient *client, int desktop) const +{ + Q_UNUSED(desktop) + QList< QSharedPointer< TabBox::TabBoxClient > >::const_iterator it = m_windows.constBegin(); + for (; it != m_windows.constEnd(); ++it) { + if ((*it).data() == client) { + return QWeakPointer< TabBox::TabBoxClient >(*it); + } + } + return QWeakPointer< TabBox::TabBoxClient >(); +} + +QWeakPointer< TabBox::TabBoxClient > MockTabBoxHandler::nextClientFocusChain(TabBox::TabBoxClient *client) const +{ + if (!client) { + if (!m_windows.isEmpty()) { + return QWeakPointer< TabBox::TabBoxClient >(m_windows.first()); + } + } + QList< QSharedPointer< TabBox::TabBoxClient > >::const_iterator it = m_windows.constBegin(); + for (; it != m_windows.constEnd(); ++it) { + if ((*it).data() == client) { + ++it; + if (it == m_windows.constEnd()) { + return QWeakPointer< TabBox::TabBoxClient >(m_windows.first()); + } else { + return QWeakPointer< TabBox::TabBoxClient >(*it); + } + } + } + return QWeakPointer< TabBox::TabBoxClient >(); +} + +QWeakPointer< TabBox::TabBoxClient > MockTabBoxHandler::createMockWindow(const QString &caption, WId id) +{ + QSharedPointer< TabBox::TabBoxClient > client(new MockTabBoxClient(caption, id)); + m_windows.append(client); + return QWeakPointer< TabBox::TabBoxClient >(client); +} + +void MockTabBoxHandler::closeWindow(TabBox::TabBoxClient *client) +{ + QList< QSharedPointer< TabBox::TabBoxClient > >::iterator it = m_windows.begin(); + for (; it != m_windows.end(); ++it) { + if ((*it).data() == client) { + m_windows.erase(it); + return; + } + } +} + +} // namespace KWin diff --git a/tabbox/tests/mock_tabboxhandler.h b/tabbox/tests/mock_tabboxhandler.h new file mode 100644 index 0000000000..f13a820aac --- /dev/null +++ b/tabbox/tests/mock_tabboxhandler.h @@ -0,0 +1,93 @@ +/******************************************************************** +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 . +*********************************************************************/ +#ifndef KWIN_MOCK_TABBOX_HANDLER_H +#define KWIN_MOCK_TABBOX_HANDLER_H + +#include "../tabboxhandler.h" +namespace KWin +{ +class MockTabBoxHandler : public TabBox::TabBoxHandler +{ + Q_OBJECT +public: + MockTabBoxHandler(); + virtual ~MockTabBoxHandler(); + virtual void activateAndClose() { + } + virtual QWeakPointer< TabBox::TabBoxClient > activeClient() const; + virtual int activeScreen() const { + return 0; + } + virtual QWeakPointer< TabBox::TabBoxClient > clientToAddToList(TabBox::TabBoxClient *client, int desktop) const; + virtual int currentDesktop() const { + return 1; + } + virtual QWeakPointer< TabBox::TabBoxClient > desktopClient() const { + return QWeakPointer(); + } + virtual QString desktopName(int desktop) const { + Q_UNUSED(desktop) + return "desktop 1"; + } + virtual QString desktopName(TabBox::TabBoxClient *client) const { + Q_UNUSED(client) + return "desktop"; + } + virtual void elevateClient(TabBox::TabBoxClient *c, WId tabbox, bool elevate) const { + Q_UNUSED(c) + Q_UNUSED(tabbox) + Q_UNUSED(elevate) + } + virtual void hideOutline() { + } + virtual QWeakPointer< TabBox::TabBoxClient > nextClientFocusChain(TabBox::TabBoxClient *client) const; + virtual int nextDesktopFocusChain(int desktop) const { + Q_UNUSED(desktop) + return 1; + } + virtual int numberOfDesktops() const { + return 1; + } + virtual QVector< Window > outlineWindowIds() const { + return QVector(); + } + virtual void raiseClient(TabBox::TabBoxClient *c) const { + Q_UNUSED(c) + } + virtual void restack(TabBox::TabBoxClient *c, TabBox::TabBoxClient *under) { + Q_UNUSED(c) + Q_UNUSED(under) + } + virtual void showOutline(const QRect &outline) { + Q_UNUSED(outline) + } + virtual TabBox::TabBoxClientList stackingOrder() const { + return TabBox::TabBoxClientList(); + } + virtual void grabbedKeyEvent(QKeyEvent *event) const; + + // mock methods + QWeakPointer createMockWindow(const QString &caption, WId id); + void closeWindow(TabBox::TabBoxClient *client); +private: + QList< QSharedPointer > m_windows; +}; +} // namespace KWin +#endif diff --git a/tabbox/tests/test_tabbox_clientmodel.cpp b/tabbox/tests/test_tabbox_clientmodel.cpp new file mode 100644 index 0000000000..cd2c963629 --- /dev/null +++ b/tabbox/tests/test_tabbox_clientmodel.cpp @@ -0,0 +1,47 @@ +/******************************************************************** +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 "test_tabbox_clientmodel.h" +#include "mock_tabboxhandler.h" +#include "clientmodel.h" + +#include +using namespace KWin; + +void TestTabBoxClientModel::testLongestCaptionWithNullClient() +{ + MockTabBoxHandler tabboxhandler; + TabBox::ClientModel *clientModel = new TabBox::ClientModel(&tabboxhandler); + clientModel->createClientList(); + QCOMPARE(clientModel->longestCaption(), QString()); + // add a window to the mock + tabboxhandler.createMockWindow(QString("test"), 1); + clientModel->createClientList(); + QCOMPARE(clientModel->longestCaption(), QString("test")); + // delete the one client in the list + QModelIndex index = clientModel->index(0, 0); + QVERIFY(index.isValid()); + TabBox::TabBoxClient *client = static_cast(clientModel->data(index, TabBox::ClientModel::ClientRole).value()); + client->close(); + // internal model of ClientModel now contains a deleted pointer + // longestCaption should behave just as if the window were not in the list + QCOMPARE(clientModel->longestCaption(), QString()); +} + +QTEST_MAIN(TestTabBoxClientModel) diff --git a/tabbox/tests/test_tabbox_clientmodel.h b/tabbox/tests/test_tabbox_clientmodel.h new file mode 100644 index 0000000000..1bdf0d4aa4 --- /dev/null +++ b/tabbox/tests/test_tabbox_clientmodel.h @@ -0,0 +1,38 @@ +/******************************************************************** +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 . +*********************************************************************/ +#ifndef TEST_TABBOX_CLIENT_MODEL_H +#define TEST_TABBOX_CLIENT_MODEL_H +#include + +class TestTabBoxClientModel : public QObject +{ + Q_OBJECT +private slots: + /** + * Tests that calculating the longest caption does not + * crash in case the internal m_clientList contains a weak + * pointer to a deleted TabBoxClient. + * + * See bug #303840 + **/ + void testLongestCaptionWithNullClient(); +}; + +#endif