1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the test suite 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 <QtCore/QString>
30#include <QtTest/QtTest>
31
32#include <QtLocation/QPlaceMatchRequest>
33#include <QtLocation/QPlaceResult>
34
35QT_USE_NAMESPACE
36
37class tst_QPlaceMatchRequest : public QObject
38{
39 Q_OBJECT
40
41public:
42 tst_QPlaceMatchRequest();
43
44private Q_SLOTS:
45 void constructorTest();
46 void placesTest();
47 void resultsTest();
48 void parametersTest();
49 void clearTest();
50};
51
52tst_QPlaceMatchRequest::tst_QPlaceMatchRequest()
53{
54}
55
56void tst_QPlaceMatchRequest::constructorTest()
57{
58 QPlaceMatchRequest request;
59 QVariantMap params;
60 params.insert(QStringLiteral("key"), QStringLiteral("val"));
61
62 QPlace place1;
63 place1.setName(QStringLiteral("place1"));
64
65 QPlace place2;
66 place2.setName(QStringLiteral("place2"));
67
68 QList<QPlace> places;
69 places << place1 << place2;
70
71 request.setPlaces(places);
72 request.setParameters(params);
73
74 QPlaceMatchRequest copy(request);
75 QCOMPARE(copy, request);
76 QCOMPARE(copy.places(), places);
77 QCOMPARE(copy.parameters(), params);
78}
79
80void tst_QPlaceMatchRequest::placesTest()
81{
82 QPlaceMatchRequest request;
83 QCOMPARE(request.places().count(), 0);
84
85 QPlace place1;
86 place1.setName(QStringLiteral("place1"));
87
88 QPlace place2;
89 place2.setName(QStringLiteral("place2"));
90
91 QList<QPlace> places;
92 places << place1 << place2;
93
94 request.setPlaces(places);
95 QCOMPARE(request.places(), places);
96
97 request.setPlaces(QList<QPlace>());
98 QCOMPARE(request.places().count(), 0);
99}
100
101void tst_QPlaceMatchRequest::resultsTest()
102{
103 QPlaceMatchRequest request;
104 QCOMPARE(request.places().count(), 0);
105
106 QPlace place1;
107 place1.setName(QStringLiteral("place1"));
108 QPlaceResult result1;
109 result1.setPlace(place1);
110
111 QPlace place2;
112 place2.setName(QStringLiteral("place2"));
113 QPlaceResult result2;
114 result2.setPlace(place2);
115
116 QList<QPlaceSearchResult> results;
117 results << result1 << result2;
118
119 request.setResults(results);
120
121 QCOMPARE(request.places().count(), 2);
122 QCOMPARE(request.places().at(0), place1);
123 QCOMPARE(request.places().at(1), place2);
124
125 request.setResults(QList<QPlaceSearchResult>());
126 QCOMPARE(request.places().count(), 0);
127}
128
129void tst_QPlaceMatchRequest::parametersTest()
130{
131 QPlaceMatchRequest request;
132 QVERIFY(request.parameters().isEmpty());
133
134 QVariantMap params;
135 params.insert(QStringLiteral("key"), QStringLiteral("value"));
136
137 request.setParameters(params);
138 QCOMPARE(request.parameters(), params);
139}
140
141void tst_QPlaceMatchRequest::clearTest()
142{
143 QPlaceMatchRequest request;
144 QVariantMap params;
145 params.insert(QStringLiteral("key"), QStringLiteral("value"));
146
147 QPlace place1;
148 place1.setName(QStringLiteral("place1"));
149
150 QPlace place2;
151 place2.setName(QStringLiteral("place2"));
152
153 QList<QPlace> places;
154 places << place1 << place2;
155
156 request.setPlaces(places);
157 request.setParameters(params);
158
159 request.clear();
160 QVERIFY(request.places().isEmpty());
161 QVERIFY(request.parameters().isEmpty());
162}
163
164QTEST_APPLESS_MAIN(tst_QPlaceMatchRequest)
165
166#include "tst_qplacematchrequest.moc"
167

source code of qtlocation/tests/auto/qplacematchrequest/tst_qplacematchrequest.cpp