swift
Loading...
Searching...
No Matches
testidentifier.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (C) 2013 swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
7
8#include <QObject>
9#include <QString>
10#include <QTest>
11
12#include "test.h"
13
14#include "misc/identifiable.h"
15#include "misc/identifier.h"
17
18using namespace swift::misc;
19
20namespace MiscTest
21{
23 class CTestIdentifier : public QObject
24 {
26
27 private slots:
29 void identifierBasics();
30
32 void machineUniqueId();
33
35 void dbusObjectPath();
36 };
37
40 {
41 public:
43 CTestIdentifiable(QObject *nameObject);
44 };
45
46 void CTestIdentifier::identifierBasics()
47 {
48 CIdentifier o1;
49 CIdentifier o2;
50 CIdentifier o3("foobar");
51 QVERIFY2(o1 == o2, "Two default identifiers shall be equal");
52 QVERIFY2(o1 != o3, "Those identifiers shall be unequal");
53
54 // test object name change
55 QObject q;
56 q.setObjectName("foo");
57 CTestIdentifiable oa(&q);
58 QVERIFY2(oa.identifier().getName() == q.objectName(), "Names shall be equal");
59 q.setObjectName("bar");
60 QVERIFY2(oa.identifier().getName() == q.objectName(), "Names shall be equal");
61 }
62
63 void CTestIdentifier::machineUniqueId()
64 {
66 QVERIFY2(
67 !o.getMachineId().isEmpty(),
68 "Machine id shall never be empty! If this test failed on a supported platform, get a fallback solution!");
69 }
70
71 void CTestIdentifier::dbusObjectPath()
72 {
73 QObject q;
74 q.setObjectName(QString::fromUtf16(u"!@#$%^&*()_+\u263a"));
75 CTestIdentifiable id(&q);
76 QString s(id.identifier().toDBusObjectPath());
77 QVERIFY2(id.identifier() == CIdentifier::fromDBusObjectPath(s),
78 "Conversion from dbus object path and back compares equal");
79 }
80
82
83} // namespace MiscTest
84
87
88#include "testidentifier.moc"
89
Test identifiable object.
CTestIdentifiable(QObject *nameObject)
Constructor.
Testing object identifier.
Base class with a member CIdentifier to be inherited by a class which has an identity in the environm...
CIdentifiable(const QString &objectName)
Use literal based object name.
Value object encapsulating information identifying a component of a modular distributed swift process...
Definition identifier.h:29
QByteArray getMachineId() const
Get machine id.
static CIdentifier fromDBusObjectPath(const QString &path, const QString &root={})
Reconstruct an identifier from a DBus object path.
Free functions in swift::misc.
bool isEmpty() const const
QObject(QObject *parent)
Q_OBJECTQ_OBJECT
void setObjectName(QAnyStringView name)
QString fromUtf16(const char16_t *unicode, qsizetype size)
QVERIFY2(condition, message)
#define SWIFTTEST_APPLESS_MAIN(TestObject)
Implements a main() function that executes all tests in TestObject without instantiating a QApplicati...
Definition test.h:39