Issue #73 Unittest for CIdentifier dbus object path conversion

This commit is contained in:
Mat Sutcliffe
2020-08-16 00:28:33 +01:00
parent 97fe8069b0
commit 2f22904540
2 changed files with 13 additions and 1 deletions

View File

@@ -80,7 +80,7 @@ namespace BlackMisc
QString toDBusObjectPath(const QString &root = {}) const; QString toDBusObjectPath(const QString &root = {}) const;
//! Reconstruct an identifier from a DBus object path. //! 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 //! Name
const QString &getName() const { return m_name; } const QString &getName() const { return m_name; }

View File

@@ -34,6 +34,9 @@ namespace BlackMiscTest
//! Machine unique id tests //! Machine unique id tests
void machineUniqueId(); void machineUniqueId();
//! Conversion to dbus object path
void dbusObjectPath();
}; };
//! Test identifiable object //! 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!"); 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) CTestIdentifiable::CTestIdentifiable(QObject *nameObject) : CIdentifiable(nameObject)
{ } { }