1/****************************************************************************
2**
3** Copyright (C) 2016 Aaron McCarthy <mccarthy.aaron@gmail.com>
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the test suite 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 <QtCore/QString>
30#include <QtLocation/QPlaceProposedSearchResult>
31#include <QtLocation/QPlaceIcon>
32#include <QtLocation/QPlaceSearchRequest>
33#include <QtTest/QtTest>
34
35#include "../utils/qlocationtestutils_p.h"
36
37QT_USE_NAMESPACE
38
39class tst_QPlaceProposedSearchResult : public QObject
40{
41 Q_OBJECT
42
43public:
44 QPlaceProposedSearchResult initialSubObject();
45 bool checkType(const QPlaceSearchResult &result);
46 void detach(QPlaceSearchResult *result);
47 void setSubClassProperty(QPlaceProposedSearchResult *result);
48
49private Q_SLOTS:
50 void constructorTest();
51 void title();
52 void icon();
53 void searchRequest();
54 void conversion();
55};
56
57QPlaceProposedSearchResult tst_QPlaceProposedSearchResult::initialSubObject()
58{
59 QPlaceProposedSearchResult proposedSearchResult;
60 proposedSearchResult.setTitle(QStringLiteral("title"));
61
62 QPlaceIcon icon;
63 QVariantMap parameters;
64 parameters.insert(akey: QPlaceIcon::SingleUrl,
65 avalue: QUrl(QStringLiteral("file:///opt/icons/icon.png")));
66 icon.setParameters(parameters);
67 proposedSearchResult.setIcon(icon);
68
69 QPlaceSearchRequest searchRequest;
70 searchRequest.setSearchContext(QUrl(QStringLiteral("http://www.example.com/")));
71 proposedSearchResult.setSearchRequest(searchRequest);
72
73 return proposedSearchResult;
74}
75
76bool tst_QPlaceProposedSearchResult::checkType(const QPlaceSearchResult &result)
77{
78 return result.type() == QPlaceSearchResult::ProposedSearchResult;
79}
80
81void tst_QPlaceProposedSearchResult::detach(QPlaceSearchResult *result)
82{
83 result->setTitle(QStringLiteral("title"));
84}
85
86void tst_QPlaceProposedSearchResult::setSubClassProperty(QPlaceProposedSearchResult *result)
87{
88 QPlaceSearchRequest request;
89 request.setSearchContext(QUrl(QStringLiteral("http://www.example.com/place-search")));
90 result->setSearchRequest(request);
91}
92
93void tst_QPlaceProposedSearchResult::constructorTest()
94{
95 QPlaceProposedSearchResult result;
96 QCOMPARE(result.type(), QPlaceSearchResult::ProposedSearchResult);
97
98 result.setTitle(QStringLiteral("title"));
99
100 QPlaceIcon icon;
101 QVariantMap parameters;
102 parameters.insert(QStringLiteral("paramKey"), QStringLiteral("paramValue"));
103 icon.setParameters(parameters);
104 result.setIcon(icon);
105
106 QPlaceSearchRequest searchRequest;
107 searchRequest.setSearchContext(QUrl(QStringLiteral("http://www.example.com/place-search")));
108 result.setSearchRequest(searchRequest);
109
110 //check copy constructor
111 QPlaceProposedSearchResult result2(result);
112 QCOMPARE(result2.title(), QStringLiteral("title"));
113 QCOMPARE(result2.icon(), icon);
114 QCOMPARE(result2.searchRequest(), searchRequest);
115
116 QVERIFY(QLocationTestUtils::compareEquality(result, result2));
117
118 //check results are the same after detachment of underlying shared data pointer
119 result2.setTitle(QStringLiteral("title"));
120 QVERIFY(QLocationTestUtils::compareEquality(result, result2));
121
122 //check construction of SearchResult using a ProposedSearchResult
123 QPlaceSearchResult searchResult(result);
124 QCOMPARE(searchResult.title(), QStringLiteral("title"));
125 QCOMPARE(searchResult.icon(), icon);
126 QVERIFY(QLocationTestUtils::compareEquality(searchResult, result));
127 QVERIFY(searchResult.type() == QPlaceSearchResult::ProposedSearchResult);
128 result2 = searchResult;
129 QVERIFY(QLocationTestUtils::compareEquality(result, result2));
130
131 //check construction of a SearchResult using a SearchResult
132 //that is actually a PlaceResult underneath
133 QPlaceSearchResult searchResult2(searchResult);
134 QCOMPARE(searchResult2.title(), QStringLiteral("title"));
135 QCOMPARE(searchResult2.icon(), icon);
136 QVERIFY(QLocationTestUtils::compareEquality(searchResult2, result));
137 QVERIFY(QLocationTestUtils::compareEquality(searchResult, searchResult2));
138 QVERIFY(searchResult2.type() == QPlaceSearchResult::ProposedSearchResult);
139 result2 = searchResult2;
140 QVERIFY(QLocationTestUtils::compareEquality(result, result2));
141}
142
143void tst_QPlaceProposedSearchResult::title()
144{
145 QPlaceProposedSearchResult result;
146 QVERIFY(result.title().isEmpty());
147
148 result.setTitle(QStringLiteral("title"));
149 QCOMPARE(result.title(), QStringLiteral("title"));
150
151 result.setTitle(QString());
152 QVERIFY(result.title().isEmpty());
153
154 QPlaceProposedSearchResult result2;
155 QVERIFY(QLocationTestUtils::compareEquality(result, result2));
156
157 result2.setTitle("title");
158 QVERIFY(QLocationTestUtils::compareInequality(result, result2));
159
160 result.setTitle("title");
161 QVERIFY(QLocationTestUtils::compareEquality(result, result2));
162}
163
164void tst_QPlaceProposedSearchResult::icon()
165{
166 QPlaceProposedSearchResult result;
167 QVERIFY(result.icon().isEmpty());
168
169 QPlaceIcon icon;
170 QVariantMap iconParams;
171 iconParams.insert(QStringLiteral("paramKey"), QStringLiteral("paramValue"));
172 icon.setParameters(iconParams);
173 result.setIcon(icon);
174 QCOMPARE(result.icon(), icon);
175
176 result.setIcon(QPlaceIcon());
177 QVERIFY(result.icon().isEmpty());
178
179 QPlaceProposedSearchResult result2;
180 QVERIFY(QLocationTestUtils::compareEquality(result, result2));
181
182 result2.setIcon(icon);
183 QVERIFY(QLocationTestUtils::compareInequality(result, result2));
184
185 result.setIcon(icon);
186 QVERIFY(QLocationTestUtils::compareEquality(result, result2));
187}
188
189void tst_QPlaceProposedSearchResult::searchRequest()
190{
191 QPlaceProposedSearchResult result;
192 QCOMPARE(result.searchRequest(), QPlaceSearchRequest());
193
194 QPlaceSearchRequest placeSearchRequest;
195 placeSearchRequest.setSearchContext(QUrl(QStringLiteral("http://www.example.com/")));
196 result.setSearchRequest(placeSearchRequest);
197 QCOMPARE(result.searchRequest(), placeSearchRequest);
198
199 result.setSearchRequest(QPlaceSearchRequest());
200 QCOMPARE(result.searchRequest(), QPlaceSearchRequest());
201
202 QPlaceProposedSearchResult result2;
203 QVERIFY(QLocationTestUtils::compareEquality(result, result2));
204
205 result2.setSearchRequest(placeSearchRequest);
206 QVERIFY(QLocationTestUtils::compareInequality(result, result2));
207
208 result.setSearchRequest(placeSearchRequest);
209 QVERIFY(QLocationTestUtils::compareEquality(result, result2));
210}
211
212void tst_QPlaceProposedSearchResult::conversion()
213{
214 QLocationTestUtils::testConversion<tst_QPlaceProposedSearchResult,
215 QPlaceSearchResult,
216 QPlaceProposedSearchResult>(tc: this);
217}
218
219QTEST_APPLESS_MAIN(tst_QPlaceProposedSearchResult)
220
221#include "tst_qproposedsearchresult.moc"
222

source code of qtlocation/tests/auto/qproposedsearchresult/tst_qproposedsearchresult.cpp