From 7e7eadb44fa5851a17d4b5dee52b819817660a40 Mon Sep 17 00:00:00 2001 From: David Edmundson Date: Thu, 30 Aug 2018 12:48:23 +0100 Subject: [PATCH] [autotests] Make lifespan of EffectsHandler outlive Effect Summary: In loading tests. Effects are deleted in a deleteLater potentially outside the scope of our test. Our MockEffectsHandler (which contains the global static "effects") has the lifespan of the test. Fixes failing unit test. Test Plan: Ran test Reviewers: #kwin Subscribers: kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D15167 --- autotests/test_builtin_effectloader.cpp | 7 ++++--- autotests/test_plugin_effectloader.cpp | 10 +++++----- autotests/test_scripted_effectloader.cpp | 10 +++++----- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/autotests/test_builtin_effectloader.cpp b/autotests/test_builtin_effectloader.cpp index cf6a1219a5..ce5e3079f4 100644 --- a/autotests/test_builtin_effectloader.cpp +++ b/autotests/test_builtin_effectloader.cpp @@ -28,6 +28,7 @@ along with this program. If not, see . // Qt #include #include +#include Q_DECLARE_METATYPE(KWin::CompositingType) Q_DECLARE_METATYPE(KWin::LoadEffectFlag) Q_DECLARE_METATYPE(KWin::LoadEffectFlags) @@ -362,7 +363,7 @@ void TestBuiltInEffectLoader::testLoadEffect() QFETCH(bool, expected); QFETCH(KWin::CompositingType, type); - MockEffectsHandler mockHandler(type); + QScopedPointer mockHandler(new MockEffectsHandler(type)); KWin::BuiltInEffectLoader loader; KSharedConfig::Ptr config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig); loader.setConfig(config); @@ -451,7 +452,7 @@ void TestBuiltInEffectLoader::testLoadBuiltInEffect() QFETCH(KWin::CompositingType, type); QFETCH(KWin::LoadEffectFlags, loadFlags); - MockEffectsHandler mockHandler(type); + QScopedPointer mockHandler(new MockEffectsHandler(type)); KWin::BuiltInEffectLoader loader; KSharedConfig::Ptr config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig); loader.setConfig(config); @@ -498,7 +499,7 @@ void TestBuiltInEffectLoader::testLoadBuiltInEffect() void TestBuiltInEffectLoader::testLoadAllEffects() { - MockEffectsHandler mockHandler(KWin::XRenderCompositing); + QScopedPointermockHandler(new MockEffectsHandler(KWin::XRenderCompositing)); KWin::BuiltInEffectLoader loader; KSharedConfig::Ptr config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig); diff --git a/autotests/test_plugin_effectloader.cpp b/autotests/test_plugin_effectloader.cpp index 841c9bf5cd..05752449a5 100644 --- a/autotests/test_plugin_effectloader.cpp +++ b/autotests/test_plugin_effectloader.cpp @@ -201,7 +201,7 @@ void TestPluginEffectLoader::testLoadEffect() QFETCH(bool, expected); QFETCH(KWin::CompositingType, type); - MockEffectsHandler mockHandler(type); + QScopedPointer mockHandler(new MockEffectsHandler(type)); KWin::PluginEffectLoader loader; loader.setPluginSubDirectory(QString()); KSharedConfig::Ptr config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig); @@ -285,8 +285,8 @@ void TestPluginEffectLoader::testLoadPluginEffect() QFETCH(KWin::LoadEffectFlags, loadFlags); QFETCH(bool, enabledByDefault); - MockEffectsHandler mockHandler(type); - mockHandler.setProperty("testEnabledByDefault", enabledByDefault); + QScopedPointer mockHandler(new MockEffectsHandler(type)); + mockHandler->setProperty("testEnabledByDefault", enabledByDefault); KWin::PluginEffectLoader loader; loader.setPluginSubDirectory(QString()); KSharedConfig::Ptr config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig); @@ -341,8 +341,8 @@ void TestPluginEffectLoader::testLoadPluginEffect() void TestPluginEffectLoader::testLoadAllEffects() { - MockEffectsHandler mockHandler(KWin::OpenGL2Compositing); - mockHandler.setProperty("testEnabledByDefault", true); + QScopedPointer mockHandler(new MockEffectsHandler(KWin::OpenGL2Compositing)); + mockHandler->setProperty("testEnabledByDefault", true); KWin::PluginEffectLoader loader; loader.setPluginSubDirectory(QString()); diff --git a/autotests/test_scripted_effectloader.cpp b/autotests/test_scripted_effectloader.cpp index c7aef31c7a..f1a729d98b 100644 --- a/autotests/test_scripted_effectloader.cpp +++ b/autotests/test_scripted_effectloader.cpp @@ -159,7 +159,7 @@ void TestScriptedEffectLoader::testHasEffect() QFETCH(QString, name); QFETCH(bool, expected); - MockEffectsHandler mockHandler(KWin::XRenderCompositing); + QScopedPointer mockHandler(new MockEffectsHandler(KWin::XRenderCompositing)); KWin::ScriptedEffectLoader loader; QCOMPARE(loader.hasEffect(name), expected); @@ -167,7 +167,7 @@ void TestScriptedEffectLoader::testHasEffect() QCOMPARE(loader.isEffectSupported(name), expected); if (expected) { - mockHandler.setAnimationsSupported(false); + mockHandler->setAnimationsSupported(false); QVERIFY(!loader.isEffectSupported(name)); } } @@ -216,7 +216,7 @@ void TestScriptedEffectLoader::testLoadEffect() QFETCH(QString, name); QFETCH(bool, expected); - MockEffectsHandler mockHandler(KWin::XRenderCompositing); + QScopedPointer mockHandler(new MockEffectsHandler(KWin::XRenderCompositing)); KWin::ScriptedEffectLoader loader; KSharedConfig::Ptr config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig); loader.setConfig(config); @@ -289,7 +289,7 @@ void TestScriptedEffectLoader::testLoadScriptedEffect() QFETCH(bool, expected); QFETCH(KWin::LoadEffectFlags, loadFlags); - MockEffectsHandler mockHandler(KWin::XRenderCompositing); + QScopedPointer mockHandler(new MockEffectsHandler(KWin::XRenderCompositing)); KWin::ScriptedEffectLoader loader; KSharedConfig::Ptr config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig); loader.setConfig(config); @@ -343,7 +343,7 @@ void TestScriptedEffectLoader::testLoadScriptedEffect() void TestScriptedEffectLoader::testLoadAllEffects() { - MockEffectsHandler mockHandler(KWin::XRenderCompositing); + QScopedPointer mockHandler(new MockEffectsHandler(KWin::XRenderCompositing)); KWin::ScriptedEffectLoader loader; KSharedConfig::Ptr config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig);