Debian Codegraph @

tests/auto/serviceframework/servicedeletion/tst_servicedeletion.cpp

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
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 QRemoteServiceRegister *serviceRegister = new QRemoteServiceRegister(this);
107
108 QString serviceName = "TestService";
109 QString xmlFilename = QFINDTESTDATA("xmldata/testdeletion.xml");
110 QString interfaceName = "com.nokia.test.services.TestService";
111 QString interfaceVersion = "1.0";
112 QString ipcAddress = "test_service";
113
114 QServiceManager serviceManager(QService::UserScope);
115 serviceManager.removeService(serviceName);
116
117 QRemoteServiceRegister::Entry entry =
118 serviceRegister->createEntry<TestService>(
119 serviceName,
120 interfaceName,
121 interfaceVersion);
122 entry.setInstantiationType(QRemoteServiceRegister::GlobalInstance);
123
124 QVERIFY(serviceManager.addService(xmlFilename));
125
126 serviceRegister->publishEntries(ipcAddress);
127
128 // Two connections are created and one of them is deleted later
129 QObject *conn1 = connectToService(serviceName);
130 QVERIFY(conn1);
131 QObject *conn2 = connectToService(serviceName);
132 QVERIFY(conn2);
133
134 connect(conn1, SIGNAL(errorUnrecoverableIPCFault(QService::UnrecoverableIPCError)),
135 this, SLOT(error(QService::UnrecoverableIPCError)));
136 connect(conn2, SIGNAL(errorUnrecoverableIPCFault(QService::UnrecoverableIPCError)),
137 this, SLOT(error(QService::UnrecoverableIPCError)));
138 connect(conn1, SIGNAL(timeChanged()),
139 this, SLOT(timeChanged()));
140 connect(conn2, SIGNAL(timeChanged()),
141 this, SLOT(timeChanged()));
142
143 QCOMPARE(conn1->property("time").toInt(), 42);
144 QCOMPARE(conn2->property("time").toInt(), 42);
145
146 QVERIFY(QMetaObject::invokeMethod(conn2, "setTime", Q_ARG(qint64, 21)));
147
148 QTRY_VERIFY(sigs == 2);
149 QCOMPARE(conn2->property("time").toInt(), 21);
150
151 delete conn2;
152 QCOMPARE(conn1->property("time").toInt(), 21);
153
154 sigs = 0;
155 QVERIFY(QMetaObject::invokeMethod(conn1, "setTime", Q_ARG(qint64, 42)));
156 QTRY_VERIFY(sigs == 1);
157 QCOMPARE(conn1->property("time").toInt(), 42);
158
159
160 delete conn1;
161 serviceManager.removeService(serviceName);
162 }
163
164 QObject *tst_QServiceDeletion::connectToService(const QString &serviceName)
165 {
166 QServiceManager manager;
167 QList<QServiceInterfaceDescriptor> list = manager.findInterfaces(serviceName);
168 if (list.isEmpty()) {
169 qWarning() << "Couldn't find service" << serviceName;
170 return 0;
171 }
172
173 // Get the interface descriptor
174 QServiceInterfaceDescriptor desc = list.at(0);
175 if (!desc.isValid()) {
176 qWarning() << "Warning: Invalid service interface descriptor for" << serviceName;
177 return 0;
178 }
179
180 QObject* service = manager.loadInterface(desc);
181 if (!service) {
182 qWarning() << "Couldn't load service interface for" << serviceName;
183 return 0;
184 }
185 return service;
186 }
187
188 void tst_QServiceDeletion::error(QService::UnrecoverableIPCError)
189 {
190 qDebug() << "Error received from IPC";
191 }
192
193 void tst_QServiceDeletion::timeChanged()
194 {
195 qDebug() << "time changed";
196 sigs++;
197 }
198
199 QTEST_MAIN(tst_QServiceDeletion)
200
201 #include "tst_servicedeletion.moc"