Debian Codegraph @

tests/auto/serviceframework/servicedeletion/tst_servicedeletion.cpp

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 /****************************************************************************
2 **
3 ** Copyright (C) 2018 The Qt Company Ltd and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtSystems module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21 ** included in the packaging of this file. Please review the following
22 ** information to ensure the GNU General Public License requirements will
23 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24 **
25 ** $QT_END_LICENSE$
26 **
27 ****************************************************************************/
28
29 //TESTED_COMPONENT=src/serviceframework
30
31 #include <qservicemanager.h>
32 #include <qremoteserviceregister.h>
33
34 #include <QtTest/QtTest>
35 #include <QtCore>
36 #include <QSettings>
37 #include <QFileInfo>
38 #include <QDir>
39 #include <QPair>
40 #include <QTimer>
41
42 #define PRINT_ERR(a) qPrintable(QString("error = %1").arg(a.error()))
43 QT_USE_NAMESPACE
44
45 class TestService : public QObject
46 {
47 Q_OBJECT
48 Q_PROPERTY(qint64 time READ time WRITE setTime NOTIFY timeChanged)
49
50 public:
51 explicit TestService(QObject *parent = 0)
52 : QObject(parent), m_time(42)
53 {
54 }
55
56 ~TestService()
57 {
58 }
59
60 Q_INVOKABLE void setTime(qint64 time) { m_time = time; emit timeChanged(); }
61 qint64 time() const {
62 return m_time;
63 }
64
65 signals:
66 void timeChanged();
67
68 private:
69 qint64 m_time;
70 };
71
72 static int sigs = 0;
73
74 class tst_QServiceDeletion: public QObject
75 {
76 Q_OBJECT
77
78 private:
79 QObject *connectToService(const QString &serviceName);
80
81 private slots:
82 void initTestCase();
83
84 void publishService();
85
86 void cleanupTestCase();
87
88 public slots:
89 void error(QService::UnrecoverableIPCError);
90 void timeChanged();
91
92 };
93
94 void tst_QServiceDeletion::initTestCase()
95 {
96
97 }
98
99 void tst_QServiceDeletion::cleanupTestCase()
100 {
101
102 }
103
104 void tst_QServiceDeletion::publishService()
105 {
•106 QSKIP("LP: #1261411 fails due to missing /etc/machine-id");
107 QRemoteServiceRegister *serviceRegister = new QRemoteServiceRegister(this);
108
109 QString serviceName = "TestService";
110 QString xmlFilename = QFINDTESTDATA("xmldata/testdeletion.xml");
111 QString interfaceName = "com.nokia.test.services.TestService";
112 QString interfaceVersion = "1.0";
113 QString ipcAddress = "test_service";
114
115 QServiceManager serviceManager(QService::UserScope);
116 serviceManager.removeService(serviceName);
117
118 QRemoteServiceRegister::Entry entry =
119 serviceRegister->createEntry<TestService>(
120 serviceName,
121 interfaceName,
122 interfaceVersion);
123 entry.setInstantiationType(QRemoteServiceRegister::GlobalInstance);
124
125 QVERIFY(serviceManager.addService(xmlFilename));
126
127 serviceRegister->publishEntries(ipcAddress);
128
129 // Two connections are created and one of them is deleted later
130 QObject *conn1 = connectToService(serviceName);
131 QVERIFY(conn1);
132 QObject *conn2 = connectToService(serviceName);
133 QVERIFY(conn2);
134
135 connect(conn1, SIGNAL(errorUnrecoverableIPCFault(QService::UnrecoverableIPCError)),
136 this, SLOT(error(QService::UnrecoverableIPCError)));
137 connect(conn2, SIGNAL(errorUnrecoverableIPCFault(QService::UnrecoverableIPCError)),
138 this, SLOT(error(QService::UnrecoverableIPCError)));
139 connect(conn1, SIGNAL(timeChanged()),
140 this, SLOT(timeChanged()));
141 connect(conn2, SIGNAL(timeChanged()),
142 this, SLOT(timeChanged()));
143
144 QCOMPARE(conn1->property("time").toInt(), 42);
145 QCOMPARE(conn2->property("time").toInt(), 42);
146
147 QVERIFY(QMetaObject::invokeMethod(conn2, "setTime", Q_ARG(qint64, 21)));
148
149 QTRY_VERIFY(sigs == 2);
150 QCOMPARE(conn2->property("time").toInt(), 21);
151
152 delete conn2;
153 QCOMPARE(conn1->property("time").toInt(), 21);
154
155 sigs = 0;
156 QVERIFY(QMetaObject::invokeMethod(conn1, "setTime", Q_ARG(qint64, 42)));
157 QTRY_VERIFY(sigs == 1);
158 QCOMPARE(conn1->property("time").toInt(), 42);
159
160
161 delete conn1;
162 serviceManager.removeService(serviceName);
163 }
164
165 QObject *tst_QServiceDeletion::connectToService(const QString &serviceName)
166 {
167 QServiceManager manager;
168 QList<QServiceInterfaceDescriptor> list = manager.findInterfaces(serviceName);
169 if (list.isEmpty()) {
170 qWarning() << "Couldn't find service" << serviceName;
171 return 0;
172 }
173
174 // Get the interface descriptor
175 QServiceInterfaceDescriptor desc = list.at(0);
176 if (!desc.isValid()) {
177 qWarning() << "Warning: Invalid service interface descriptor for" << serviceName;
178 return 0;
179 }
180
181 QObject* service = manager.loadInterface(desc);
182 if (!service) {
183 qWarning() << "Couldn't load service interface for" << serviceName;
184 return 0;
185 }
186 return service;
187 }
188
189 void tst_QServiceDeletion::error(QService::UnrecoverableIPCError)
190 {
191 qDebug() << "Error received from IPC";
192 }
193
194 void tst_QServiceDeletion::timeChanged()
195 {
196 qDebug() << "time changed";
197 sigs++;
198 }
199
200 QTEST_MAIN(tst_QServiceDeletion)
201
202 #include "tst_servicedeletion.moc"