1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2015 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:LGPL21$ |
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 http://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at http://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 2.1 or version 3 as published by the Free |
20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and |
21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the |
22 | ** following information to ensure the GNU Lesser General Public License |
23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and |
24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
25 | ** |
26 | ** As a special exception, The Qt Company gives you certain additional |
27 | ** rights. These rights are described in The Qt Company LGPL Exception |
28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
29 | ** |
30 | ** $QT_END_LICENSE$ |
31 | ** |
32 | ****************************************************************************/ |
33 | |
34 | #include <QtTest/QtTest> |
35 | #include "qvaluespace.h" |
36 | #include "qvaluespacepublisher.h" |
37 | #include "qvaluespacesubscriber.h" |
38 | |
39 | QT_USE_NAMESPACE |
40 | |
41 | class tst_QValueSpace : public QObject |
42 | { |
43 | Q_OBJECT |
44 | |
45 | private slots: |
46 | void tst_availableLayers(); |
47 | |
48 | void tst_PublisherPath_data(); |
49 | void tst_PublisherPath(); |
50 | |
51 | void tst_PublishSubscribe_data(); |
52 | void tst_PublishSubscribe(); |
53 | }; |
54 | |
55 | void tst_QValueSpace::tst_availableLayers() |
56 | { |
57 | QList<QUuid> layers = QValueSpace::availableLayers(); |
58 | |
59 | if (layers.size() == 0) |
60 | QSKIP("No value space layer available, thus skip all the test cases." ); |
61 | |
62 | #if defined(Q_OS_LINUX) |
63 | #if !defined(QT_NO_GCONFLAYER) |
64 | QVERIFY(layers.contains(QVALUESPACE_GCONF_LAYER)); |
65 | #endif |
66 | #elif defined(Q_OS_WIN) |
67 | QVERIFY(layers.contains(QVALUESPACE_VOLATILEREGISTRY_LAYER)); |
68 | QVERIFY(layers.contains(QVALUESPACE_NONVOLATILEREGISTRY_LAYER)); |
69 | #endif |
70 | } |
71 | |
72 | void tst_QValueSpace::tst_PublisherPath_data() |
73 | { |
74 | QTest::addColumn<QString>(name: "path" ); |
75 | |
76 | QTest::newRow(dataTag: "root" ) << QString(QStringLiteral("/" )); |
77 | QTest::newRow(dataTag: "non existing path" ) << QString(QStringLiteral("/a/path/that/doesnt/exist" )); |
78 | } |
79 | |
80 | void tst_QValueSpace::tst_PublisherPath() |
81 | { |
82 | if (QValueSpace::availableLayers().size() == 0) |
83 | QSKIP("No value space layer available, thus skip all the test cases." ); |
84 | |
85 | QFETCH(QString, path); |
86 | |
87 | QValueSpacePublisher publisher(path); |
88 | QVERIFY(publisher.isConnected()); |
89 | QCOMPARE(publisher.path(), path); |
90 | } |
91 | |
92 | void tst_QValueSpace::tst_PublishSubscribe_data() |
93 | { |
94 | QTest::addColumn<QString>(name: "path" ); |
95 | QTest::addColumn<QString>(name: "name" ); |
96 | QTest::addColumn<QVariant>(name: "value" ); |
97 | |
98 | QTest::newRow(dataTag: "root" ) << QString(QStringLiteral("/" )) << QString(QStringLiteral("myName" )) << QVariant::fromValue(value: QString(QStringLiteral("myValue" ))); |
99 | QTest::newRow(dataTag: "non existing path" ) << QString(QStringLiteral("/a/path/that/doesnt/exist" )) << QString(QStringLiteral("propertyName" )) << QVariant::fromValue(value: QString(QStringLiteral("propertyValue" ))); |
100 | } |
101 | |
102 | void tst_QValueSpace::tst_PublishSubscribe() |
103 | { |
104 | if (QValueSpace::availableLayers().size() == 0) |
105 | QSKIP("No value space layer available, thus skip all the test cases." ); |
106 | |
107 | QFETCH(QString, path); |
108 | QFETCH(QString, name); |
109 | QFETCH(QVariant, value); |
110 | |
111 | QValueSpacePublisher publisher(path); |
112 | QVERIFY(publisher.isConnected()); |
113 | publisher.setValue(name, data: value); |
114 | publisher.sync(); |
115 | |
116 | QValueSpaceSubscriber subscriber(path); |
117 | QVERIFY(subscriber.isConnected()); |
118 | QCOMPARE(subscriber.value(name), value); |
119 | |
120 | subscriber.setPath(path + QStringLiteral("/" ) + name); |
121 | QCOMPARE(subscriber.value(), value); |
122 | |
123 | publisher.resetValue(name); |
124 | publisher.sync(); |
125 | } |
126 | |
127 | QTEST_MAIN(tst_QValueSpace) |
128 | #include "tst_qvaluespace.moc" |
129 | |