| 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 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/QPlaceResult> |
| 31 | #include <QtLocation/QPlaceIcon> |
| 32 | #include <QtTest/QtTest> |
| 33 | |
| 34 | #include "../utils/qlocationtestutils_p.h" |
| 35 | |
| 36 | QT_USE_NAMESPACE |
| 37 | |
| 38 | class tst_QPlaceResult : public QObject |
| 39 | { |
| 40 | Q_OBJECT |
| 41 | |
| 42 | public: |
| 43 | QPlaceResult initialSubObject(); |
| 44 | bool checkType(const QPlaceSearchResult &); |
| 45 | void detach(QPlaceSearchResult *); |
| 46 | void setSubClassProperty(QPlaceResult *); |
| 47 | |
| 48 | private Q_SLOTS: |
| 49 | void constructorTest(); |
| 50 | void title(); |
| 51 | void icon(); |
| 52 | void distance(); |
| 53 | void place(); |
| 54 | void sponsored(); |
| 55 | void conversion(); |
| 56 | }; |
| 57 | |
| 58 | QPlaceResult tst_QPlaceResult::initialSubObject() |
| 59 | { |
| 60 | QPlaceResult placeResult; |
| 61 | placeResult.setTitle(QStringLiteral("title" )); |
| 62 | |
| 63 | QPlaceIcon icon; |
| 64 | QVariantMap parameters; |
| 65 | parameters.insert(akey: QPlaceIcon::SingleUrl, |
| 66 | avalue: QUrl(QStringLiteral("file:///opt/icons/icon.png" ))); |
| 67 | icon.setParameters(parameters); |
| 68 | placeResult.setIcon(icon); |
| 69 | |
| 70 | QPlace place; |
| 71 | place.setName(QStringLiteral("place" )); |
| 72 | placeResult.setPlace(place); |
| 73 | |
| 74 | placeResult.setDistance(5); |
| 75 | placeResult.setSponsored(true); |
| 76 | |
| 77 | return placeResult; |
| 78 | } |
| 79 | |
| 80 | bool tst_QPlaceResult::checkType(const QPlaceSearchResult &result) |
| 81 | { |
| 82 | return result.type() == QPlaceSearchResult::PlaceResult; |
| 83 | } |
| 84 | |
| 85 | void tst_QPlaceResult::detach(QPlaceSearchResult * result) |
| 86 | { |
| 87 | result->setTitle("title" ); |
| 88 | } |
| 89 | |
| 90 | void tst_QPlaceResult::setSubClassProperty(QPlaceResult *result) |
| 91 | { |
| 92 | result->setSponsored(false); |
| 93 | } |
| 94 | |
| 95 | void tst_QPlaceResult::constructorTest() |
| 96 | { |
| 97 | QPlaceResult result; |
| 98 | QCOMPARE(result.type(), QPlaceSearchResult::PlaceResult); |
| 99 | |
| 100 | result.setTitle(QStringLiteral("title" )); |
| 101 | |
| 102 | QPlaceIcon icon; |
| 103 | QVariantMap parameters; |
| 104 | parameters.insert(QStringLiteral("paramKey" ), QStringLiteral("paramValue" )); |
| 105 | icon.setParameters(parameters); |
| 106 | result.setIcon(icon); |
| 107 | |
| 108 | QPlace place; |
| 109 | place.setName("place" ); |
| 110 | result.setPlace(place); |
| 111 | |
| 112 | result.setDistance(500); |
| 113 | result.setSponsored(true); |
| 114 | |
| 115 | //check copy constructor |
| 116 | QPlaceResult result2(result); |
| 117 | QCOMPARE(result2.title(), QStringLiteral("title" )); |
| 118 | QCOMPARE(result2.icon(), icon); |
| 119 | QCOMPARE(result2.place(), place); |
| 120 | QVERIFY(qFuzzyCompare(result.distance(), 500)); |
| 121 | QCOMPARE(result2.isSponsored(), true); |
| 122 | |
| 123 | QVERIFY(QLocationTestUtils::compareEquality(result, result2)); |
| 124 | |
| 125 | //check results are the same after detachment of underlying shared data pointer |
| 126 | result2.setTitle("title" ); |
| 127 | QVERIFY(QLocationTestUtils::compareEquality(result, result2)); |
| 128 | |
| 129 | //check construction of SearchResult using a PlaceResult |
| 130 | QPlaceSearchResult searchResult(result); |
| 131 | QCOMPARE(searchResult.title(), QStringLiteral("title" )); |
| 132 | QCOMPARE(searchResult.icon(), icon); |
| 133 | QVERIFY(QLocationTestUtils::compareEquality(searchResult, result)); |
| 134 | QVERIFY(searchResult.type() == QPlaceSearchResult::PlaceResult); |
| 135 | result2 = searchResult; |
| 136 | QVERIFY(QLocationTestUtils::compareEquality(result, result2)); |
| 137 | |
| 138 | //check construction of a SearchResult using a SearchResult |
| 139 | //that is actually a PlaceResult underneath |
| 140 | QPlaceSearchResult searchResult2(searchResult); |
| 141 | QCOMPARE(searchResult2.title(), QStringLiteral("title" )); |
| 142 | QCOMPARE(searchResult2.icon(), icon); |
| 143 | QVERIFY(QLocationTestUtils::compareEquality(searchResult2, result)); |
| 144 | QVERIFY(QLocationTestUtils::compareEquality(searchResult, searchResult2)); |
| 145 | QVERIFY(searchResult2.type() == QPlaceSearchResult::PlaceResult); |
| 146 | result2 = searchResult2; |
| 147 | QVERIFY(QLocationTestUtils::compareEquality(result, result2)); |
| 148 | } |
| 149 | |
| 150 | void tst_QPlaceResult::title() |
| 151 | { |
| 152 | QPlaceResult result; |
| 153 | QVERIFY(result.title().isEmpty()); |
| 154 | |
| 155 | result.setTitle(QStringLiteral("title" )); |
| 156 | QCOMPARE(result.title(), QStringLiteral("title" )); |
| 157 | |
| 158 | result.setTitle(QString()); |
| 159 | QVERIFY(result.title().isEmpty()); |
| 160 | |
| 161 | QPlaceResult result2; |
| 162 | QVERIFY(QLocationTestUtils::compareEquality(result, result2)); |
| 163 | |
| 164 | result2.setTitle("title" ); |
| 165 | QVERIFY(QLocationTestUtils::compareInequality(result, result2)); |
| 166 | |
| 167 | result.setTitle("title" ); |
| 168 | QVERIFY(QLocationTestUtils::compareEquality(result, result2)); |
| 169 | } |
| 170 | |
| 171 | void tst_QPlaceResult::icon() |
| 172 | { |
| 173 | QPlaceResult result; |
| 174 | QVERIFY(result.icon().isEmpty()); |
| 175 | |
| 176 | QPlaceIcon icon; |
| 177 | QVariantMap iconParams; |
| 178 | iconParams.insert(QStringLiteral("paramKey" ), QStringLiteral("paramValue" )); |
| 179 | icon.setParameters(iconParams); |
| 180 | result.setIcon(icon); |
| 181 | QCOMPARE(result.icon(), icon); |
| 182 | |
| 183 | result.setIcon(QPlaceIcon()); |
| 184 | QVERIFY(result.icon().isEmpty()); |
| 185 | |
| 186 | QPlaceResult result2; |
| 187 | QVERIFY(QLocationTestUtils::compareEquality(result, result2)); |
| 188 | |
| 189 | result2.setIcon(icon); |
| 190 | QVERIFY(QLocationTestUtils::compareInequality(result, result2)); |
| 191 | |
| 192 | result.setIcon(icon); |
| 193 | QVERIFY(QLocationTestUtils::compareEquality(result, result2)); |
| 194 | } |
| 195 | |
| 196 | void tst_QPlaceResult::distance() |
| 197 | { |
| 198 | QPlaceResult result; |
| 199 | QVERIFY(qIsNaN(result.distance())); |
| 200 | |
| 201 | result.setDistance(3.14); |
| 202 | QVERIFY(qFuzzyCompare(result.distance(), 3.14)); |
| 203 | |
| 204 | result.setDistance(qQNaN()); |
| 205 | QVERIFY(qIsNaN(result.distance())); |
| 206 | |
| 207 | QPlaceResult result2; |
| 208 | QVERIFY(QLocationTestUtils::compareEquality(result, result2)); |
| 209 | |
| 210 | result2.setDistance(3.14); |
| 211 | QVERIFY(QLocationTestUtils::compareInequality(result, result2)); |
| 212 | |
| 213 | result.setDistance(3.14); |
| 214 | QVERIFY(QLocationTestUtils::compareEquality(result, result2)); |
| 215 | } |
| 216 | |
| 217 | void tst_QPlaceResult::place() |
| 218 | { |
| 219 | QPlaceResult result; |
| 220 | QCOMPARE(result.place(), QPlace()); |
| 221 | |
| 222 | QPlace place; |
| 223 | place.setName("place" ); |
| 224 | result.setPlace (place); |
| 225 | QCOMPARE(result.place(), place); |
| 226 | |
| 227 | result.setPlace(QPlace()); |
| 228 | QCOMPARE(result.place(), QPlace()); |
| 229 | |
| 230 | QPlaceResult result2; |
| 231 | QVERIFY(QLocationTestUtils::compareEquality(result, result2)); |
| 232 | |
| 233 | result2.setPlace(place); |
| 234 | QVERIFY(QLocationTestUtils::compareInequality(result, result2)); |
| 235 | |
| 236 | result.setPlace(place); |
| 237 | QVERIFY(QLocationTestUtils::compareEquality(result, result2)); |
| 238 | } |
| 239 | |
| 240 | void tst_QPlaceResult::() |
| 241 | { |
| 242 | QPlaceResult result; |
| 243 | QCOMPARE(result.isSponsored(), false); |
| 244 | |
| 245 | result.setSponsored(true); |
| 246 | QCOMPARE(result.isSponsored(), true); |
| 247 | |
| 248 | result.setSponsored(false); |
| 249 | QCOMPARE(result.isSponsored(), false); |
| 250 | |
| 251 | QPlaceResult result2; |
| 252 | QVERIFY(QLocationTestUtils::compareEquality(result, result2)); |
| 253 | |
| 254 | result2.setSponsored(true); |
| 255 | QVERIFY(QLocationTestUtils::compareInequality(result, result2)); |
| 256 | |
| 257 | result.setSponsored(true); |
| 258 | QVERIFY(QLocationTestUtils::compareEquality(result, result2)); |
| 259 | } |
| 260 | |
| 261 | void tst_QPlaceResult::conversion() |
| 262 | { |
| 263 | QLocationTestUtils::testConversion<tst_QPlaceResult, |
| 264 | QPlaceSearchResult, |
| 265 | QPlaceResult>(tc: this); |
| 266 | } |
| 267 | |
| 268 | QTEST_APPLESS_MAIN(tst_QPlaceResult) |
| 269 | |
| 270 | #include "tst_qplaceresult.moc" |
| 271 | |