summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorIvan Solovev <[email protected]>2025-06-17 16:14:09 +0200
committerIvan Solovev <[email protected]>2025-06-18 18:05:07 +0200
commit2f12e0d1ebbe173ac2d9dd4f7bd4e02a2cce243e (patch)
tree23d1eff0c4324d08c7caac82240163af2a242c85 /tests
parenta8d91092193d3c62a0a9ced86f6805cbf37a2746 (diff)
Test QDBusMessage move-assignment operator
Pick-to: 6.10 6.9 6.8 6.5 Change-Id: Ic7fec96c13c1a1b8c4b748070fbe656fdff6e24c Reviewed-by: Marc Mutz <[email protected]>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/dbus/CMakeLists.txt1
-rw-r--r--tests/auto/dbus/qdbusmessage/CMakeLists.txt20
-rw-r--r--tests/auto/dbus/qdbusmessage/tst_qdbusmessage.cpp56
3 files changed, 77 insertions, 0 deletions
diff --git a/tests/auto/dbus/CMakeLists.txt b/tests/auto/dbus/CMakeLists.txt
index d67877a0b36..8b9671d6344 100644
--- a/tests/auto/dbus/CMakeLists.txt
+++ b/tests/auto/dbus/CMakeLists.txt
@@ -10,6 +10,7 @@ add_subdirectory(qdbusconnection_signalorder)
add_subdirectory(qdbusconnection_spyhook)
add_subdirectory(qdbuscontext)
add_subdirectory(qdbuslocalcalls)
+add_subdirectory(qdbusmessage)
add_subdirectory(qdbusmetaobject)
add_subdirectory(qdbusmetatype)
add_subdirectory(qdbuspendingcall)
diff --git a/tests/auto/dbus/qdbusmessage/CMakeLists.txt b/tests/auto/dbus/qdbusmessage/CMakeLists.txt
new file mode 100644
index 00000000000..eb4dab17224
--- /dev/null
+++ b/tests/auto/dbus/qdbusmessage/CMakeLists.txt
@@ -0,0 +1,20 @@
+# Copyright (C) 2025 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+#####################################################################
+## tst_qdbusmessage Test:
+#####################################################################
+
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qdbusmessage LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
+qt_internal_add_test(tst_qdbusmessage
+ SOURCES
+ tst_qdbusmessage.cpp
+ LIBRARIES
+ Qt::Core
+ Qt::DBus
+)
diff --git a/tests/auto/dbus/qdbusmessage/tst_qdbusmessage.cpp b/tests/auto/dbus/qdbusmessage/tst_qdbusmessage.cpp
new file mode 100644
index 00000000000..475dbcec0bb
--- /dev/null
+++ b/tests/auto/dbus/qdbusmessage/tst_qdbusmessage.cpp
@@ -0,0 +1,56 @@
+// Copyright (C) 2025 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#include <QTest>
+#include <QDBusMessage>
+
+using namespace Qt::StringLiterals;
+
+// incomplete, but enough for the test
+#define COMPARE_MESSAGES(lhs, rhs) \
+ do { \
+ QCOMPARE_EQ(lhs.service(), rhs.service()); \
+ QCOMPARE_EQ(lhs.path(), rhs.path()); \
+ QCOMPARE_EQ(lhs.interface(), rhs.interface()); \
+ QCOMPARE_EQ(lhs.member(), rhs.member()); \
+ QCOMPARE_EQ(lhs.type(), rhs.type()); \
+ QCOMPARE_EQ(lhs.signature(), rhs.signature()); \
+ QCOMPARE_EQ(lhs.arguments(), rhs.arguments()); \
+ } while (false)
+
+class tst_QDBusMessage : public QObject
+{
+ Q_OBJECT
+private Q_SLOTS:
+ void moveAssign();
+};
+
+void tst_QDBusMessage::moveAssign()
+{
+ QDBusMessage referenceMessage =
+ QDBusMessage::createMethodCall("org.kde.selftest"_L1, "/org/kde/selftest"_L1,
+ "org.kde.selftest"_L1, "Ping"_L1);
+ referenceMessage << "ping"_L1;
+
+ {
+ QDBusMessage copy = referenceMessage;
+
+ // move-assign into another message
+ QDBusMessage other;
+ other = std::move(copy);
+ COMPARE_MESSAGES(other, referenceMessage);
+
+ // modify
+ other << "other_arg"_L1; // also affects referenceMessage
+
+ // and move-assign back
+ copy = std::move(other);
+ COMPARE_MESSAGES(copy, referenceMessage);
+ }
+}
+
+#undef COMPARE_MESSAGES
+
+QTEST_MAIN(tst_QDBusMessage)
+
+#include "tst_qdbusmessage.moc"