From 2f229045401f328811a61ddd8bc394d5202037f7 Mon Sep 17 00:00:00 2001 From: Mat Sutcliffe Date: Sun, 16 Aug 2020 00:28:33 +0100 Subject: [PATCH] Issue #73 Unittest for CIdentifier dbus object path conversion --- src/blackmisc/identifier.h | 2 +- tests/blackmisc/testidentifier/testidentifier.cpp | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/blackmisc/identifier.h b/src/blackmisc/identifier.h index 3b5c80041..1386391b1 100644 --- a/src/blackmisc/identifier.h +++ b/src/blackmisc/identifier.h @@ -80,7 +80,7 @@ namespace BlackMisc QString toDBusObjectPath(const QString &root = {}) const; //! Reconstruct an identifier from a DBus object path. - CIdentifier fromDBusObjectPath(const QString &path, const QString &root = {}); + static CIdentifier fromDBusObjectPath(const QString &path, const QString &root = {}); //! Name const QString &getName() const { return m_name; } diff --git a/tests/blackmisc/testidentifier/testidentifier.cpp b/tests/blackmisc/testidentifier/testidentifier.cpp index 2329abf38..e0e3048d8 100644 --- a/tests/blackmisc/testidentifier/testidentifier.cpp +++ b/tests/blackmisc/testidentifier/testidentifier.cpp @@ -34,6 +34,9 @@ namespace BlackMiscTest //! Machine unique id tests void machineUniqueId(); + + //! Conversion to dbus object path + void dbusObjectPath(); }; //! Test identifiable object @@ -67,6 +70,15 @@ namespace BlackMiscTest QVERIFY2(!o.getMachineId().isEmpty(), "Machine id shall never be empty! If this test failed on a supported platform, get a fallback solution!"); } + void CTestIdentifier::dbusObjectPath() + { + QObject q; + q.setObjectName("!@#$%^&*()_+"); + CTestIdentifiable id(&q); + QString s(id.identifier().toDBusObjectPath()); + QVERIFY2(id.identifier() == CIdentifier::fromDBusObjectPath(s), "Conversion from dbus object path and back compares equal"); + } + CTestIdentifiable::CTestIdentifiable(QObject *nameObject) : CIdentifiable(nameObject) { }