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 <QtLocation/QPlaceReview> |
33 | #include <QtLocation/QPlaceSupplier> |
34 | #include <QtLocation/QPlaceUser> |
35 | |
36 | #include "../utils/qlocationtestutils_p.h" |
37 | |
38 | QT_USE_NAMESPACE |
39 | |
40 | class tst_QPlaceReview : public QObject |
41 | { |
42 | Q_OBJECT |
43 | |
44 | public: |
45 | tst_QPlaceReview(); |
46 | |
47 | //needed for QLocationTestUtils::testConversion |
48 | QPlaceReview initialSubObject(); |
49 | bool checkType(const QPlaceContent &); |
50 | void detach(QPlaceContent *); |
51 | void setSubClassProperty(QPlaceReview *); |
52 | |
53 | private Q_SLOTS: |
54 | void constructorTest(); |
55 | void supplierTest(); |
56 | void dateTest(); |
57 | void textTest(); |
58 | void languageTest(); |
59 | void ratingTest(); |
60 | void reviewIdTest(); |
61 | void titleTest(); |
62 | void userTest(); |
63 | void operatorsTest(); |
64 | void conversionTest(); |
65 | }; |
66 | |
67 | tst_QPlaceReview::tst_QPlaceReview() |
68 | { |
69 | } |
70 | |
71 | QPlaceReview tst_QPlaceReview::initialSubObject() |
72 | { |
73 | QPlaceUser user; |
74 | user.setName("user 1" ); |
75 | user.setUserId("0001" ); |
76 | |
77 | QPlaceSupplier supplier; |
78 | supplier.setName("supplier" ); |
79 | supplier.setSupplierId("1" ); |
80 | |
81 | QPlaceReview review; |
82 | review.setTitle("title" ); |
83 | review.setText("text" ); |
84 | review.setRating(4.5); |
85 | review.setLanguage("en" ); |
86 | review.setDateTime(QDateTime::fromString(s: "01:02 03/04/2000" , |
87 | format: "hh:mm dd/MM/yyyy" )); |
88 | review.setUser(user); |
89 | review.setSupplier(supplier); |
90 | review.setAttribution("attribution" ); |
91 | |
92 | return review; |
93 | } |
94 | |
95 | bool tst_QPlaceReview::checkType(const QPlaceContent &content) |
96 | { |
97 | return content.type() == QPlaceContent::ReviewType; |
98 | } |
99 | |
100 | void tst_QPlaceReview::detach(QPlaceContent *content) |
101 | { |
102 | content->setAttribution("attribution" ); |
103 | } |
104 | |
105 | void tst_QPlaceReview::setSubClassProperty(QPlaceReview *review) |
106 | { |
107 | review->setTitle("new title" ); |
108 | } |
109 | |
110 | void tst_QPlaceReview::constructorTest() |
111 | { |
112 | QPlaceReview testObj; |
113 | testObj.setLanguage("testId" ); |
114 | QPlaceReview *testObjPtr = new QPlaceReview(testObj); |
115 | QVERIFY2(testObjPtr != NULL, "Copy constructor - null" ); |
116 | QVERIFY2(*testObjPtr == testObj, "Copy constructor - compare" ); |
117 | delete testObjPtr; |
118 | } |
119 | |
120 | void tst_QPlaceReview::supplierTest() |
121 | { |
122 | QPlaceReview testObj; |
123 | QVERIFY2(testObj.supplier().supplierId() == QString(), "Wrong default value" ); |
124 | QPlaceSupplier sup; |
125 | sup.setName("testName1" ); |
126 | sup.setSupplierId("testId" ); |
127 | testObj.setSupplier(sup); |
128 | QVERIFY2(testObj.supplier() == sup, "Wrong value returned" ); |
129 | } |
130 | |
131 | void tst_QPlaceReview::dateTest() |
132 | { |
133 | QPlaceReview testObj; |
134 | QCOMPARE(testObj.dateTime(), QDateTime()); |
135 | |
136 | QDateTime dt = QDateTime::currentDateTime(); |
137 | testObj.setDateTime(dt); |
138 | QCOMPARE(testObj.dateTime(), dt); |
139 | } |
140 | |
141 | void tst_QPlaceReview::textTest() |
142 | { |
143 | QPlaceReview testObj; |
144 | QVERIFY2(testObj.text() == QString(), "Wrong default value" ); |
145 | testObj.setText("testText" ); |
146 | QVERIFY2(testObj.text() == "testText" , "Wrong value returned" ); |
147 | } |
148 | |
149 | void tst_QPlaceReview::languageTest() |
150 | { |
151 | QPlaceReview testObj; |
152 | QVERIFY2(testObj.language() == QString(), "Wrong default value" ); |
153 | testObj.setLanguage("testText" ); |
154 | QVERIFY2(testObj.language() == "testText" , "Wrong value returned" ); |
155 | } |
156 | |
157 | void tst_QPlaceReview::ratingTest() |
158 | { |
159 | QPlaceReview testObj; |
160 | QVERIFY2(testObj.rating() == 0, "Wrong default value" ); |
161 | testObj.setRating(-10); |
162 | QCOMPARE(testObj.rating(), -10.0); |
163 | testObj.setRating(3.4); |
164 | QCOMPARE(testObj.rating(), 3.4); |
165 | } |
166 | |
167 | void tst_QPlaceReview::operatorsTest() |
168 | { |
169 | QPlaceReview testObj; |
170 | testObj.setText("testValue" ); |
171 | QPlaceReview testObj2; |
172 | testObj2 = testObj; |
173 | QVERIFY2(testObj == testObj2, "Not copied correctly" ); |
174 | testObj2.setLanguage("testValue2" ); |
175 | QVERIFY2(testObj != testObj2, "Object should be different" ); |
176 | } |
177 | |
178 | void tst_QPlaceReview::reviewIdTest() |
179 | { |
180 | QPlaceReview testObj; |
181 | QVERIFY2(testObj.reviewId() == QString(), "Wrong default value" ); |
182 | testObj.setReviewId("testText" ); |
183 | QVERIFY2(testObj.reviewId() == "testText" , "Wrong value returned" ); |
184 | } |
185 | void tst_QPlaceReview::titleTest() |
186 | { |
187 | QPlaceReview testObj; |
188 | QVERIFY2(testObj.title() == QString(), "Wrong default value" ); |
189 | testObj.setTitle("testText" ); |
190 | QVERIFY2(testObj.title() == "testText" , "Wrong value returned" ); |
191 | } |
192 | |
193 | void tst_QPlaceReview::userTest() |
194 | { |
195 | QPlaceReview review; |
196 | QVERIFY(review.user().userId().isEmpty()); |
197 | QVERIFY(review.user().name().isEmpty()); |
198 | QPlaceUser user; |
199 | user.setUserId(QStringLiteral("11111" )); |
200 | user.setName(QStringLiteral("Bob" )); |
201 | |
202 | review.setUser(user); |
203 | QCOMPARE(review.user().userId(), QStringLiteral("11111" )); |
204 | QCOMPARE(review.user().name(), QStringLiteral("Bob" )); |
205 | |
206 | review.setUser(QPlaceUser()); |
207 | QVERIFY(review.user().userId().isEmpty()); |
208 | QVERIFY(review.user().name().isEmpty()); |
209 | } |
210 | |
211 | void tst_QPlaceReview::conversionTest() |
212 | { |
213 | QLocationTestUtils::testConversion<tst_QPlaceReview, |
214 | QPlaceContent, |
215 | QPlaceReview>(tc: this); |
216 | } |
217 | |
218 | QTEST_APPLESS_MAIN(tst_QPlaceReview) |
219 | |
220 | #include "tst_qplacereview.moc" |
221 | |