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 <QtPositioning/QGeoCircle> |
33 | #include <QtLocation/QPlaceSearchRequest> |
34 | #include <QtLocation/QPlaceSearchReply> |
35 | #include <QtLocation/QPlaceResult> |
36 | |
37 | |
38 | QT_USE_NAMESPACE |
39 | |
40 | class TestSearchReply : public QPlaceSearchReply |
41 | { |
42 | Q_OBJECT |
43 | public: |
44 | TestSearchReply(QObject *parent) : QPlaceSearchReply(parent) {} |
45 | TestSearchReply() {} |
46 | |
47 | void setResults(const QList<QPlaceSearchResult> &results) { |
48 | QPlaceSearchReply::setResults(results); |
49 | } |
50 | |
51 | void setRequest(const QPlaceSearchRequest &request) { |
52 | QPlaceSearchReply::setRequest(request); |
53 | } |
54 | }; |
55 | |
56 | class tst_QPlaceSearchReply : public QObject |
57 | { |
58 | Q_OBJECT |
59 | |
60 | public: |
61 | tst_QPlaceSearchReply(); |
62 | |
63 | private Q_SLOTS: |
64 | void constructorTest(); |
65 | void typeTest(); |
66 | void requestTest(); |
67 | void resultsTest(); |
68 | }; |
69 | |
70 | tst_QPlaceSearchReply::tst_QPlaceSearchReply() |
71 | { |
72 | } |
73 | |
74 | void tst_QPlaceSearchReply::constructorTest() |
75 | { |
76 | TestSearchReply *reply = new TestSearchReply(this); |
77 | QVERIFY(reply->parent() == this); |
78 | delete reply; |
79 | } |
80 | |
81 | void tst_QPlaceSearchReply::typeTest() |
82 | { |
83 | TestSearchReply *reply = new TestSearchReply(this); |
84 | QVERIFY(reply->type() == QPlaceReply::SearchReply); |
85 | delete reply; |
86 | } |
87 | |
88 | void tst_QPlaceSearchReply::requestTest() |
89 | { |
90 | TestSearchReply *reply = new TestSearchReply(this); |
91 | QPlaceSearchRequest request; |
92 | request.setLimit(10); |
93 | |
94 | QGeoCircle circle; |
95 | circle.setCenter(QGeoCoordinate(10,20)); |
96 | request.setSearchArea(circle); |
97 | |
98 | request.setSearchTerm("pizza"); |
99 | |
100 | reply->setRequest(request); |
101 | QCOMPARE(reply->request(), request); |
102 | reply->setRequest(QPlaceSearchRequest()); |
103 | QCOMPARE(reply->request(), QPlaceSearchRequest()); |
104 | delete reply; |
105 | } |
106 | |
107 | void tst_QPlaceSearchReply::resultsTest() |
108 | { |
109 | TestSearchReply *reply = new TestSearchReply(this); |
110 | QList<QPlaceSearchResult> results; |
111 | QPlace winterfell; |
112 | winterfell.setName("Winterfell"); |
113 | QPlace casterlyRock; |
114 | casterlyRock.setName("Casterly Rock"); |
115 | QPlace stormsEnd; |
116 | stormsEnd.setName("Storm's end"); |
117 | |
118 | QPlaceResult result1; |
119 | result1.setPlace(winterfell); |
120 | QPlaceResult result2; |
121 | result2.setPlace(casterlyRock); |
122 | QPlaceResult result3; |
123 | result3.setPlace(stormsEnd); |
124 | results << result1 << result2 << result3; |
125 | |
126 | reply->setResults(results); |
127 | QCOMPARE(reply->results(), results); |
128 | reply->setResults(QList<QPlaceSearchResult>()); |
129 | QCOMPARE(reply->results(), QList<QPlaceSearchResult>()); |
130 | delete reply; |
131 | } |
132 | |
133 | QTEST_APPLESS_MAIN(tst_QPlaceSearchReply) |
134 | |
135 | #include "tst_qplacesearchreply.moc" |
136 |