| 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 | #ifndef PLACEMANAGER_UTILS_H |
| 30 | #define PLACEMANAGER_UTILS_H |
| 31 | |
| 32 | #include <QtCore/QString> |
| 33 | #include <QtLocation/QPlaceReply> |
| 34 | #include <QtLocation/QLocation> |
| 35 | #include <QtLocation/QPlaceContent> |
| 36 | |
| 37 | #ifndef WAIT_UNTIL |
| 38 | #define WAIT_UNTIL(__expr) \ |
| 39 | do { \ |
| 40 | const int __step = 50; \ |
| 41 | const int __timeout = 25000; \ |
| 42 | if (!(__expr)) { \ |
| 43 | QTest::qWait(0); \ |
| 44 | } \ |
| 45 | for (int __i = 0; __i < __timeout && !(__expr); __i+=__step) { \ |
| 46 | QTest::qWait(__step); \ |
| 47 | } \ |
| 48 | } while (0) |
| 49 | #endif |
| 50 | |
| 51 | QT_BEGIN_NAMESPACE |
| 52 | |
| 53 | class QPlaceManager; |
| 54 | class QPlace; |
| 55 | class QPlaceSearchResult; |
| 56 | class QPlaceSearchRequest; |
| 57 | class QPlaceCategory; |
| 58 | class QPlaceContentRequest; |
| 59 | class QPlaceMatchRequest; |
| 60 | |
| 61 | QT_END_NAMESPACE |
| 62 | |
| 63 | class PlaceManagerUtils : public QObject |
| 64 | { |
| 65 | Q_OBJECT |
| 66 | public: |
| 67 | PlaceManagerUtils(QObject *parent = 0); |
| 68 | |
| 69 | static bool doSavePlace(QPlaceManager *manager, |
| 70 | const QPlace &place, |
| 71 | QPlaceReply::Error expectedError = QPlaceReply::NoError, |
| 72 | QString *placeId = 0); |
| 73 | |
| 74 | static void doSavePlaces(QPlaceManager *manager, QList<QPlace> &places); |
| 75 | |
| 76 | //sets the id for saved places |
| 77 | static void doSavePlaces(QPlaceManager *manager, const QList<QPlace *> &places); |
| 78 | |
| 79 | static bool doSearch(QPlaceManager *manager, const QPlaceSearchRequest &request, |
| 80 | QList<QPlaceSearchResult> *results, |
| 81 | QPlaceReply::Error expectedError = QPlaceReply::NoError); |
| 82 | |
| 83 | static bool doSearch(QPlaceManager *manager, const QPlaceSearchRequest &request, |
| 84 | QList<QPlace> *results, |
| 85 | QPlaceReply::Error expectedError = QPlaceReply::NoError); |
| 86 | |
| 87 | static bool doSearchSuggestions(QPlaceManager *manager, |
| 88 | const QPlaceSearchRequest &request, |
| 89 | QStringList *results, |
| 90 | QPlaceReply::Error expectedError = QPlaceReply::NoError); |
| 91 | |
| 92 | static bool doRemovePlace(QPlaceManager *manager, const QPlace &place, |
| 93 | QPlaceReply::Error expectedError = QPlaceReply::NoError); |
| 94 | |
| 95 | static bool doFetchDetails(QPlaceManager *manager, |
| 96 | QString placeId, |
| 97 | QPlace *place, |
| 98 | QPlaceReply::Error expectedError = QPlaceReply::NoError); |
| 99 | |
| 100 | static bool doInitializeCategories(QPlaceManager *manager, |
| 101 | QPlaceReply::Error expectedError = QPlaceReply::NoError); |
| 102 | |
| 103 | static bool doSaveCategory(QPlaceManager *manager, |
| 104 | const QPlaceCategory &category, |
| 105 | const QString &parentId, |
| 106 | QPlaceReply::Error expectedError = QPlaceReply::NoError, |
| 107 | QString *categoryId = 0); |
| 108 | |
| 109 | static bool doRemoveCategory(QPlaceManager *manager, const QPlaceCategory &category, |
| 110 | QPlaceReply::Error expectedError = QPlaceReply::NoError); |
| 111 | |
| 112 | static bool doFetchCategory(QPlaceManager *manager, |
| 113 | const QString &categoryId, |
| 114 | QPlaceCategory *category, |
| 115 | QPlaceReply::Error expectedError = QPlaceReply::NoError); |
| 116 | |
| 117 | static bool doFetchContent(QPlaceManager *manager, |
| 118 | const QPlaceContentRequest &request, |
| 119 | QPlaceContent::Collection *results, |
| 120 | QPlaceReply::Error expectedError = QPlaceReply::NoError); |
| 121 | |
| 122 | static bool doMatch(QPlaceManager *manager, |
| 123 | const QPlaceMatchRequest &request, |
| 124 | QList<QPlace> *places, |
| 125 | QPlaceReply::Error expectedError = QPlaceReply::NoError); |
| 126 | |
| 127 | static bool checkSignals(QPlaceReply *reply, QPlaceReply::Error expectedError, |
| 128 | QPlaceManager *manager); |
| 129 | |
| 130 | static bool compare(const QList<QPlace> &actualResults, |
| 131 | const QList<QPlace> &expectedResults); |
| 132 | |
| 133 | static void setVisibility(QList<QPlace *>places, QLocation::Visibility visibility); |
| 134 | |
| 135 | static const int Timeout; |
| 136 | |
| 137 | protected: |
| 138 | bool doSavePlace(const QPlace &place, |
| 139 | QPlaceReply::Error expectedError = QPlaceReply::NoError, |
| 140 | QString *placeId = 0) { |
| 141 | return doSavePlace(manager: placeManager, place, expectedError, placeId); |
| 142 | } |
| 143 | |
| 144 | void doSavePlaces(QList<QPlace> &places) { |
| 145 | return doSavePlaces(manager: placeManager, places); |
| 146 | } |
| 147 | |
| 148 | void doSavePlaces(const QList<QPlace *> &places) { |
| 149 | return doSavePlaces(manager: placeManager, places); |
| 150 | } |
| 151 | |
| 152 | bool doRemovePlace(const QPlace &place, |
| 153 | QPlaceReply::Error expectedError = QPlaceReply::NoError) |
| 154 | { |
| 155 | return doRemovePlace(manager: placeManager, place, expectedError); |
| 156 | } |
| 157 | |
| 158 | bool doSearch(const QPlaceSearchRequest &request, |
| 159 | QList<QPlace> *results, |
| 160 | QPlaceReply::Error expectedError = QPlaceReply::NoError) { |
| 161 | return doSearch(manager: placeManager, request, results,expectedError); |
| 162 | } |
| 163 | |
| 164 | bool doSearchSuggestions(const QPlaceSearchRequest &request, |
| 165 | QStringList *results, |
| 166 | QPlaceReply::Error expectedError) { |
| 167 | return doSearchSuggestions(manager: placeManager, request, results, expectedError); |
| 168 | } |
| 169 | |
| 170 | bool doFetchDetails(QString placeId, |
| 171 | QPlace *place, |
| 172 | QPlaceReply::Error expectedError = QPlaceReply::NoError) { |
| 173 | return doFetchDetails(manager: placeManager, placeId, place, expectedError); |
| 174 | } |
| 175 | |
| 176 | bool doInitializeCategories(QPlaceReply::Error expectedError = QPlaceReply::NoError) { |
| 177 | return doInitializeCategories(manager: placeManager, expectedError); |
| 178 | } |
| 179 | |
| 180 | bool doSaveCategory(const QPlaceCategory &category, |
| 181 | QPlaceReply::Error expectedError = QPlaceReply::NoError, |
| 182 | QString *categoryId = 0) { |
| 183 | return doSaveCategory(manager: placeManager, category, parentId: QString(), |
| 184 | expectedError,categoryId); |
| 185 | } |
| 186 | |
| 187 | bool doSaveCategory(const QPlaceCategory &category, |
| 188 | const QString &parentId, |
| 189 | QPlaceReply::Error expectedError = QPlaceReply::NoError, |
| 190 | QString *categoryId = 0) { |
| 191 | return doSaveCategory(manager: placeManager, category, parentId, |
| 192 | expectedError, categoryId); |
| 193 | } |
| 194 | |
| 195 | bool doRemoveCategory(const QPlaceCategory &category, |
| 196 | QPlaceReply::Error expectedError = QPlaceReply::NoError) |
| 197 | { |
| 198 | return doRemoveCategory(manager: placeManager, category, expectedError); |
| 199 | } |
| 200 | |
| 201 | bool doFetchCategory(const QString &categoryId, |
| 202 | QPlaceCategory *category, |
| 203 | QPlaceReply::Error expectedError = QPlaceReply::NoError) { |
| 204 | return doFetchCategory(manager: placeManager, categoryId, |
| 205 | category, expectedError); |
| 206 | } |
| 207 | |
| 208 | bool doFetchContent(const QPlaceContentRequest &request, |
| 209 | QPlaceContent::Collection *results, |
| 210 | QPlaceReply::Error expectedError = QPlaceReply::NoError) |
| 211 | { |
| 212 | return doFetchContent(manager: placeManager, request, results, expectedError); |
| 213 | } |
| 214 | |
| 215 | bool doMatch(const QPlaceMatchRequest &request, |
| 216 | QList<QPlace> *places, |
| 217 | QPlaceReply::Error expectedError = QPlaceReply::NoError) { |
| 218 | return doMatch(manager: placeManager, request, |
| 219 | places, expectedError); |
| 220 | } |
| 221 | |
| 222 | bool checkSignals(QPlaceReply *reply, QPlaceReply::Error expectedError) { |
| 223 | return checkSignals(reply, expectedError, manager: placeManager); |
| 224 | } |
| 225 | |
| 226 | QPlaceManager *placeManager; |
| 227 | }; |
| 228 | |
| 229 | #endif |
| 230 | |
| 231 | |