1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
|
#include <QtCore/QString>
#include <QtTest/QtTest>
#include <qplacesearchrequest.h>
#include <qgeoboundingcircle.h>
#include <qgeoboundingbox.h>
QT_USE_NAMESPACE
class tst_QPlaceSearchRequest : public QObject
{
Q_OBJECT
public:
tst_QPlaceSearchRequest();
private Q_SLOTS:
void constructorTest();
void searchTermTest();
void categoriesTest();
void boundingCircleTest();
void boundingBoxTest();
void searchAreaTest();
void didYouMeanSuggestionNumberTest();
void visibilityScopeTest();
void operatorsTest();
void clearTest();
};
tst_QPlaceSearchRequest::tst_QPlaceSearchRequest()
{
}
void tst_QPlaceSearchRequest::constructorTest()
{
QPlaceSearchRequest testObj;
Q_UNUSED(testObj);
QPlaceSearchRequest *testObjPtr = new QPlaceSearchRequest(testObj);
QVERIFY2(testObjPtr != NULL, "Copy constructor - null");
QVERIFY2(*testObjPtr == testObj, "Copy constructor - compare");
delete testObjPtr;
}
void tst_QPlaceSearchRequest::searchTermTest()
{
QPlaceSearchRequest testObj;
QVERIFY2(testObj.searchTerm() == QString(), "Wrong default value");
testObj.setSearchTerm("testText");
QVERIFY2(testObj.searchTerm() == "testText", "Wrong value returned");
}
void tst_QPlaceSearchRequest::categoriesTest()
{
QPlaceSearchRequest testObj;
QVERIFY2(testObj.categories().count() == 0, "Wrong default value");
QPlaceCategory cat;
cat.setCategoryId("45346");
testObj.setCategory(cat);
QVERIFY2(testObj.categories().count() == 1, "Wrong categories count returned");
QVERIFY2(testObj.categories()[0] == cat, "Wrong category returned");
testObj.setCategory(QPlaceCategory());
QVERIFY(testObj.categories().isEmpty());
}
void tst_QPlaceSearchRequest::boundingCircleTest()
{
QPlaceSearchRequest query;
QVERIFY2(query.searchArea() == NULL, "Wrong default value");
QGeoBoundingCircle *circle = new QGeoBoundingCircle;
circle->setCenter(QGeoCoordinate(30,20));
circle->setRadius(500.0);
query.setSearchArea(circle);
QVERIFY(query.searchArea() != NULL);
QVERIFY(query.searchArea()->type() == QGeoBoundingArea::CircleType);
QVERIFY(query.searchArea() == circle);
QGeoBoundingCircle *retrievedCircle = static_cast<QGeoBoundingCircle *>(query.searchArea());
QVERIFY2(retrievedCircle->center() == QGeoCoordinate(30,20), "Wrong value returned");
QVERIFY2(retrievedCircle->radius() == 500.0, "Wrong value returned");
query.clear();
QVERIFY2(query.searchArea() == NULL, "Search area not cleared");
}
void tst_QPlaceSearchRequest::boundingBoxTest()
{
QPlaceSearchRequest query;
QVERIFY2(query.searchArea() == NULL, "Wrong default value");
QGeoBoundingBox *box = new QGeoBoundingBox;
box->setTopLeft(QGeoCoordinate(30,20));
box->setBottomRight(QGeoCoordinate(10,50));
query.setSearchArea(box);
QVERIFY(query.searchArea() != NULL);
QVERIFY(query.searchArea()->type() == QGeoBoundingArea::BoxType);
QVERIFY(query.searchArea() == box);
QGeoBoundingBox *retrievedBox = static_cast<QGeoBoundingBox*>(query.searchArea());
QVERIFY2(retrievedBox->topLeft() == QGeoCoordinate(30,20), "Wrong value returned");
QVERIFY2(retrievedBox->bottomRight() == QGeoCoordinate(10,50), "Wrong value returned");
query.clear();
QVERIFY2(query.searchArea() == NULL, "Wrong cleared value returned");
}
void tst_QPlaceSearchRequest::searchAreaTest()
{
//test assignment of new search area over an old search area
QPlaceSearchRequest *query = new QPlaceSearchRequest;
QGeoBoundingCircle *circle = new QGeoBoundingCircle;
circle->setCenter(QGeoCoordinate(30,20));
circle->setRadius(500.0);
query->setSearchArea(circle);
QVERIFY(query->searchArea() == circle);
QGeoBoundingBox *box = new QGeoBoundingBox;
box->setTopLeft(QGeoCoordinate(30,20));
box->setBottomRight(QGeoCoordinate(10,50));
query->setSearchArea(box);
QVERIFY2(query->searchArea() == box, "New search area not assigned");
}
void tst_QPlaceSearchRequest::didYouMeanSuggestionNumberTest()
{
QPlaceSearchRequest testObj;
QVERIFY2(testObj.didYouMeanSuggestionNumber() == 0, "Wrong default value");
testObj.setDidYouMeanSuggestionNumber(10);
QVERIFY2(testObj.didYouMeanSuggestionNumber() == 10, "Wrong value returned");
testObj.clear();
QVERIFY2(testObj.didYouMeanSuggestionNumber() == 0, "Wrong cleared value returned");
}
void tst_QPlaceSearchRequest::visibilityScopeTest()
{
QPlaceSearchRequest query;
QVERIFY2(query.visibilityScope() == QPlaceManager::NoScope, "Wrong default value");
query.setVisibilityScope(QPlaceManager::PublicScope);
QCOMPARE(query.visibilityScope(), QPlaceManager::PublicScope);
query.setVisibilityScope(QPlaceManager::PublicAndPrivateScope);
QVERIFY(query.visibilityScope() & QPlaceManager::PublicScope);
QVERIFY(query.visibilityScope() & QPlaceManager::PrivateScope);
}
void tst_QPlaceSearchRequest::operatorsTest()
{
QPlaceSearchRequest testObj;
testObj.setSearchTerm("testValue");
QPlaceSearchRequest testObj2;
testObj2 = testObj;
QVERIFY2(testObj == testObj2, "Not copied correctly");
testObj2.setDidYouMeanSuggestionNumber(-5);
QVERIFY2(testObj != testObj2, "Object should be different");
testObj2.setDidYouMeanSuggestionNumber(0);
QVERIFY(testObj == testObj2);
QGeoBoundingBox *b1 = new QGeoBoundingBox(QGeoCoordinate(20,20), QGeoCoordinate(10,30));
QGeoBoundingBox *b2 = new QGeoBoundingBox(QGeoCoordinate(20,20), QGeoCoordinate(10,30));
QGeoBoundingBox *b3 = new QGeoBoundingBox(QGeoCoordinate(40,40), QGeoCoordinate(10,40));
//testing that identical boxes match
testObj.setSearchArea(b1);
testObj2.setSearchArea(b2);
QVERIFY2(testObj == testObj2, "Identical box areas are not identified as matching");
//test that different boxes do not match
testObj2.setSearchArea(b3);
QVERIFY2(testObj != testObj2, "Different box areas identified as matching");
QGeoBoundingCircle *c1 = new QGeoBoundingCircle(QGeoCoordinate(5,5),500);
QGeoBoundingCircle *c2 = new QGeoBoundingCircle(QGeoCoordinate(5,5),500);
QGeoBoundingCircle *c3 = new QGeoBoundingCircle(QGeoCoordinate(9,9),600);
//test that identical cirlces match
testObj.setSearchArea(c1);
testObj2.setSearchArea(c2);
QVERIFY2(testObj == testObj2, "Identical circle areas are not identified as matching");
//test that different circle don't match
testObj2.setSearchArea(c3);
QVERIFY2(testObj != testObj2, "Different circle areas identified as matching");
//test that circles and boxes do not match
QGeoBoundingBox *b4 = new QGeoBoundingBox(QGeoCoordinate(20,20),QGeoCoordinate(10,30));
QGeoBoundingCircle *c4 = new QGeoBoundingCircle(QGeoCoordinate(20,20),500);
testObj.setSearchArea(b4);
testObj2.setSearchArea(c4);
QVERIFY2(testObj != testObj2, "Circle and box identified as matching");
//test that identical visibility scopes match
testObj.clear();
testObj2.clear();
testObj.setVisibilityScope(QPlaceManager::PublicScope);
testObj2.setVisibilityScope(QPlaceManager::PublicScope);
QVERIFY2(testObj == testObj2, "Identical scopes not identified as matching");
//test that different scopes do not match
testObj2.setVisibilityScope(QPlaceManager::PublicScope | QPlaceManager::PrivateScope);
QVERIFY2(testObj != testObj2, "Different scopes identified as matching");
}
void tst_QPlaceSearchRequest::clearTest()
{
QPlaceSearchRequest req;
req.setSearchTerm("pizza");
req.setSearchArea(new QGeoBoundingCircle(QGeoCoordinate(1,1), 5000));
QPlaceCategory category;
category.setName("Fast Food");
req.setCategory(category);
req.setDidYouMeanSuggestionNumber(5);
req.setLimit(100);
req.setOffset(5);
req.clear();
QVERIFY(req.searchTerm().isEmpty());
QVERIFY(req.searchArea() == 0);
QVERIFY(req.categories().isEmpty());
QVERIFY(req.didYouMeanSuggestionNumber() == 0);
QVERIFY(req.limit() == -1);
QVERIFY(req.offset() == 0);
}
QTEST_APPLESS_MAIN(tst_QPlaceSearchRequest);
#include "tst_qplacesearchrequest.moc"
|