Debian Codegraph @

tests/auto/publishsubscribe/qvaluespace/tst_qvaluespace.cpp

raw symbols SCIP
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 #include <QtTest/QtTest>
30 #include "qvaluespace.h"
31 #include "qvaluespacepublisher.h"
32 #include "qvaluespacesubscriber.h"
33
34 QT_USE_NAMESPACE
35
36 class tst_QValueSpace : public QObject
37 {
38 Q_OBJECT
39
40 private slots:
41 void tst_availableLayers();
42
43 void tst_PublisherPath_data();
44 void tst_PublisherPath();
45
46 void tst_PublishSubscribe_data();
47 void tst_PublishSubscribe();
48 };
49
50 void tst_QValueSpace::tst_availableLayers()
51 {
52 QList<QUuid> layers = QValueSpace::availableLayers();
53
54 if (layers.size() == 0)
55 QSKIP("No value space layer available, thus skip all the test cases.");
56
57 #if defined(Q_OS_LINUX)
58 #if !defined(QT_NO_GCONFLAYER)
59 QVERIFY(layers.contains(QVALUESPACE_GCONF_LAYER));
60 #endif
61 #elif defined(Q_OS_WIN)
62 QVERIFY(layers.contains(QVALUESPACE_VOLATILEREGISTRY_LAYER));
63 QVERIFY(layers.contains(QVALUESPACE_NONVOLATILEREGISTRY_LAYER));
64 #endif
65 }
66
67 void tst_QValueSpace::tst_PublisherPath_data()
68 {
69 QTest::addColumn<QString>("path");
70
71 QTest::newRow("root") << QString(QStringLiteral("/"));
72 QTest::newRow("non existing path") << QString(QStringLiteral("/a/path/that/doesnt/exist"));
73 }
74
75 void tst_QValueSpace::tst_PublisherPath()
76 {
77 if (QValueSpace::availableLayers().size() == 0)
78 QSKIP("No value space layer available, thus skip all the test cases.");
79
80 QFETCH(QString, path);
81
82 QValueSpacePublisher publisher(path);
83 QVERIFY(publisher.isConnected());
84 QCOMPARE(publisher.path(), path);
85 }
86
87 void tst_QValueSpace::tst_PublishSubscribe_data()
88 {
89 QTest::addColumn<QString>("path");
90 QTest::addColumn<QString>("name");
91 QTest::addColumn<QVariant>("value");
92
93 QTest::newRow("root") << QString(QStringLiteral("/")) << QString(QStringLiteral("myName")) << QVariant::fromValue(QString(QStringLiteral("myValue")));
94 QTest::newRow("non existing path") << QString(QStringLiteral("/a/path/that/doesnt/exist")) << QString(QStringLiteral("propertyName")) << QVariant::fromValue(QString(QStringLiteral("propertyValue")));
95 }
96
97 void tst_QValueSpace::tst_PublishSubscribe()
98 {
99 if (QValueSpace::availableLayers().size() == 0)
100 QSKIP("No value space layer available, thus skip all the test cases.");
101
102 QFETCH(QString, path);
103 QFETCH(QString, name);
104 QFETCH(QVariant, value);
105
106 QValueSpacePublisher publisher(path);
107 QVERIFY(publisher.isConnected());
108 publisher.setValue(name, value);
109 publisher.sync();
110
111 QValueSpaceSubscriber subscriber(path);
112 QVERIFY(subscriber.isConnected());
113 QCOMPARE(subscriber.value(name), value);
114
115 subscriber.setPath(path + QStringLiteral("/") + name);
116 QCOMPARE(subscriber.value(), value);
117
118 publisher.resetValue(name);
119 publisher.sync();
120 }
121
122 QTEST_MAIN(tst_QValueSpace)
123 #include "tst_qvaluespace.moc"