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 <QtLocation/QPlaceImage> |
31 | #include <QtLocation/QPlaceUser> |
32 | #include <QtTest/QtTest> |
33 | |
34 | #include "../utils/qlocationtestutils_p.h" |
35 | |
36 | QT_USE_NAMESPACE |
37 | |
38 | class tst_QPlaceImage : public QObject |
39 | { |
40 | Q_OBJECT |
41 | |
42 | public: |
43 | tst_QPlaceImage(); |
44 | |
45 | //needed for QLocationTestUtils::testConversion |
46 | QPlaceImage initialSubObject(); |
47 | bool checkType(const QPlaceContent &); |
48 | void detach(QPlaceContent *); |
49 | void setSubClassProperty(QPlaceImage *); |
50 | |
51 | private Q_SLOTS: |
52 | void constructorTest(); |
53 | void supplierTest(); |
54 | void idTest(); |
55 | void mimeTypeTest(); |
56 | void attributionTest(); |
57 | void operatorsTest(); |
58 | void conversionTest(); |
59 | }; |
60 | |
61 | tst_QPlaceImage::tst_QPlaceImage() |
62 | { |
63 | } |
64 | |
65 | QPlaceImage tst_QPlaceImage::initialSubObject() |
66 | { |
67 | QPlaceUser user; |
68 | user.setName("user 1" ); |
69 | user.setUserId("0001" ); |
70 | |
71 | QPlaceSupplier supplier; |
72 | supplier.setName("supplier" ); |
73 | supplier.setSupplierId("1" ); |
74 | |
75 | QPlaceImage image; |
76 | image.setUrl(QUrl(QStringLiteral("file:///opt/icon/img.png" ))); |
77 | image.setImageId("0001" ); |
78 | image.setMimeType("image/png" ); |
79 | image.setUser(user); |
80 | image.setSupplier(supplier); |
81 | image.setAttribution("attribution" ); |
82 | |
83 | return image; |
84 | } |
85 | |
86 | bool tst_QPlaceImage::checkType(const QPlaceContent &content) |
87 | { |
88 | return content.type() == QPlaceContent::ImageType; |
89 | } |
90 | |
91 | void tst_QPlaceImage::detach(QPlaceContent *content) |
92 | { |
93 | content->setAttribution("attribution" ); |
94 | } |
95 | |
96 | void tst_QPlaceImage::setSubClassProperty(QPlaceImage *image) |
97 | { |
98 | image->setImageId("0002" ); |
99 | } |
100 | |
101 | void tst_QPlaceImage::constructorTest() |
102 | { |
103 | QPlaceImage testObj; |
104 | testObj.setImageId("testId" ); |
105 | QPlaceImage *testObjPtr = new QPlaceImage(testObj); |
106 | QVERIFY2(testObjPtr != NULL, "Copy constructor - null" ); |
107 | QVERIFY2(*testObjPtr == testObj, "Copy constructor - compare" ); |
108 | delete testObjPtr; |
109 | } |
110 | |
111 | void tst_QPlaceImage::supplierTest() |
112 | { |
113 | QPlaceImage testObj; |
114 | QVERIFY2(testObj.supplier().supplierId() == QString(), "Wrong default value" ); |
115 | QPlaceSupplier sup; |
116 | sup.setName("testName1" ); |
117 | sup.setSupplierId("testId" ); |
118 | testObj.setSupplier(sup); |
119 | QVERIFY2(testObj.supplier() == sup, "Wrong value returned" ); |
120 | } |
121 | |
122 | void tst_QPlaceImage::idTest() |
123 | { |
124 | QPlaceImage testObj; |
125 | QVERIFY2(testObj.imageId() == QString(), "Wrong default value" ); |
126 | testObj.setImageId("testText" ); |
127 | QVERIFY2(testObj.imageId() == "testText" , "Wrong value returned" ); |
128 | } |
129 | |
130 | void tst_QPlaceImage::mimeTypeTest() |
131 | { |
132 | QPlaceImage testObj; |
133 | QVERIFY2(testObj.mimeType() == QString(), "Wrong default value" ); |
134 | testObj.setMimeType("testText" ); |
135 | QVERIFY2(testObj.mimeType() == "testText" , "Wrong value returned" ); |
136 | } |
137 | |
138 | void tst_QPlaceImage::attributionTest() |
139 | { |
140 | QPlaceImage image; |
141 | QVERIFY(image.attribution().isEmpty()); |
142 | image.setAttribution(QStringLiteral("Brought to you by acme" )); |
143 | QCOMPARE(image.attribution(), QStringLiteral("Brought to you by acme" )); |
144 | image.setAttribution(QString()); |
145 | QVERIFY(image.attribution().isEmpty()); |
146 | } |
147 | |
148 | void tst_QPlaceImage::operatorsTest() |
149 | { |
150 | QPlaceImage testObj; |
151 | testObj.setMimeType("testValue" ); |
152 | QPlaceImage testObj2; |
153 | testObj2 = testObj; |
154 | QVERIFY2(testObj == testObj2, "Not copied correctly" ); |
155 | testObj2.setImageId("testValue2" ); |
156 | QVERIFY2(testObj != testObj2, "Object should be different" ); |
157 | } |
158 | |
159 | void tst_QPlaceImage::conversionTest() |
160 | { |
161 | QLocationTestUtils::testConversion<tst_QPlaceImage, |
162 | QPlaceContent, |
163 | QPlaceImage>(tc: this); |
164 | } |
165 | |
166 | QTEST_APPLESS_MAIN(tst_QPlaceImage); |
167 | |
168 | #include "tst_qplaceimage.moc" |
169 | |