swift
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 
18 using namespace swift::misc;
19 
20 namespace MiscTest
21 {
23  class CTestIdentifier : public QObject
24  {
25  Q_OBJECT
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  {
65  CIdentifier o;
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 
81  CTestIdentifiable::CTestIdentifiable(QObject *nameObject) : CIdentifiable(nameObject) {}
82 
83 } // namespace MiscTest
84 
87 
88 #include "testidentifier.moc"
89 
Test identifiable object.
Testing object identifier.
Base class with a member CIdentifier to be inherited by a class which has an identity in the environm...
Definition: identifiable.h:24
Value object encapsulating information identifying a component of a modular distributed swift process...
Definition: identifier.h:29
QByteArray getMachineId() const
Get machine id.
Definition: identifier.cpp:126
static CIdentifier fromDBusObjectPath(const QString &path, const QString &root={})
Reconstruct an identifier from a DBus object path.
Definition: identifier.cpp:143
Free functions in swift::misc.
SWIFTTEST_APPLESS_MAIN(MiscTest::CTestIdentifier)
main