summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDavid Redondo <qt@david-redondo.de>2022-03-22 09:27:07 +0100
committerDavid Redondo <qt@david-redondo.de>2023-04-11 16:17:42 +0200
commit42a6cdd6788d0b25cfc5844ed4982a4e9214e605 (patch)
treee83711efafb3159fbc4205ee8c6a40e72128e908 /tests
parent9130a67c5981abc35be406da593f3a4b7f8e281f (diff)
downloadqtwayland-42a6cdd6788d0b25cfc5844ed4982a4e9214e605.tar.gz
QWaylandClientExtension: Allow specifying destructor for wayland objects
While the template takes care of creating proxies automatically, destroying them is harder since an interface can have 0 to multiple destructors. However in the most common case there is only one or always calling one is sufficient. An additional template parameter is introduced that allows user code to specify a callable taking a pointer to the scanner generated class that should be called when the wayland object is to be be destroyed. This is done when the global is removed or upon destruction of the C++ object itself. The clientextension test is changed how it can be used. Since it works via a non-type template parameter a pointer to a (member) function can be passed or when compiled in c++20 mode a lambda or for example a function object. This new functionality is opt-in and the default behavior is unchanged. The default value is nullptr used as a tag to do not enable the new behavior. Change-Id: I8043f7106fec0cd6f2a79682e5872cfa8da3d11b Reviewed-by: David Edmundson <davidedmundson@kde.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/client/clientextension/tst_clientextension.cpp13
1 files changed, 4 insertions, 9 deletions
diff --git a/tests/auto/client/clientextension/tst_clientextension.cpp b/tests/auto/client/clientextension/tst_clientextension.cpp
index 91b02e3b..c1cd1cb1 100644
--- a/tests/auto/client/clientextension/tst_clientextension.cpp
+++ b/tests/auto/client/clientextension/tst_clientextension.cpp
@@ -14,17 +14,12 @@
using namespace MockCompositor;
-class TestExtension : public QWaylandClientExtensionTemplate<TestExtension>,
- public QtWayland::test_interface
+class TestExtension
+ : public QWaylandClientExtensionTemplate<TestExtension, &QtWayland::test_interface::release>,
+ public QtWayland::test_interface
{
public:
- TestExtension() : QWaylandClientExtensionTemplate<TestExtension>(1) { }
- ~TestExtension()
- {
- if (object()) {
- release();
- }
- }
+ TestExtension() : QWaylandClientExtensionTemplate(1){};
void initialize() { QWaylandClientExtension::initialize(); }
};