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 <qplacesupplier.h>
33
34 QT_USE_NAMESPACE
35
36 class tst_QPlaceSupplier : public QObject
37 {
38 Q_OBJECT
39
40 public:
41 tst_QPlaceSupplier();
42
43 private Q_SLOTS:
44 void constructorTest();
45 void nameTest();
46 void supplierIdTest();
47 void urlTest();
48 void iconTest();
49 void operatorsTest();
50 void isEmptyTest();
51 };
52
tst_QPlaceSupplier()53 tst_QPlaceSupplier::tst_QPlaceSupplier()
54 {
55 }
56
constructorTest()57 void tst_QPlaceSupplier::constructorTest()
58 {
59 QPlaceSupplier testObj;
60 Q_UNUSED(testObj);
61
62 QPlaceSupplier *testObjPtr = new QPlaceSupplier(testObj);
63 QVERIFY2(testObjPtr != NULL, "Copy constructor - null");
64 QVERIFY2(*testObjPtr == testObj, "Copy constructor - compare");
65 delete testObjPtr;
66 }
67
nameTest()68 void tst_QPlaceSupplier::nameTest()
69 {
70 QPlaceSupplier testObj;
71 QVERIFY2(testObj.name() == QString(), "Wrong default value");
72 testObj.setName("testText");
73 QVERIFY2(testObj.name() == "testText", "Wrong value returned");
74 }
75
supplierIdTest()76 void tst_QPlaceSupplier::supplierIdTest()
77 {
78 QPlaceSupplier testObj;
79 QVERIFY2(testObj.supplierId() == QString(), "Wrong default value");
80 testObj.setSupplierId("testText");
81 QVERIFY2(testObj.supplierId() == "testText", "Wrong value returned");
82 }
83
urlTest()84 void tst_QPlaceSupplier::urlTest()
85 {
86 QPlaceSupplier testObj;
87 const QUrl testUrl = QUrl::fromEncoded("http://example.com/testUrl");
88 QVERIFY2(testObj.url() == QString(), "Wrong default value");
89 testObj.setUrl(testUrl);
90 QVERIFY2(testObj.url() == testUrl, "Wrong value returned");
91 }
92
iconTest()93 void tst_QPlaceSupplier::iconTest()
94 {
95 QPlaceSupplier testObj;
96 QVERIFY(testObj.icon().isEmpty());
97 QPlaceIcon icon;
98 QVariantMap iconParams;
99 iconParams.insert(QPlaceIcon::SingleUrl, QUrl::fromEncoded("http://example.com/icon.png"));
100 icon.setParameters(iconParams);
101 testObj.setIcon(icon);
102 QCOMPARE(testObj.icon(), icon);
103 QCOMPARE(testObj.icon().url(), QUrl::fromEncoded("http://example.com/icon.png"));
104
105 testObj.setIcon(QPlaceIcon());
106 QVERIFY(testObj.icon().isEmpty());
107 QCOMPARE(testObj.icon().url(), QUrl());
108 }
109
operatorsTest()110 void tst_QPlaceSupplier::operatorsTest()
111 {
112 QPlaceSupplier testObj;
113 testObj.setName(QStringLiteral("Acme"));
114 QPlaceIcon icon;
115 QVariantMap iconParams;
116 iconParams.insert(QPlaceIcon::SingleUrl, QUrl::fromEncoded("http://example.com/icon.png"));
117 icon.setParameters(iconParams);
118 testObj.setIcon(icon);
119 testObj.setSupplierId(QStringLiteral("34292"));
120
121 QPlaceSupplier testObj2;
122 testObj2 = testObj;
123 QVERIFY2(testObj == testObj2, "Not copied correctly");
124 testObj2.setSupplierId(QStringLiteral("testValue2"));
125 QVERIFY2(testObj != testObj2, "Object should be different");
126 }
127
isEmptyTest()128 void tst_QPlaceSupplier::isEmptyTest()
129 {
130 QPlaceIcon icon;
131 QVariantMap iconParametersMap;
132 iconParametersMap.insert(QStringLiteral("Para"), QStringLiteral("meter"));
133 icon.setParameters(iconParametersMap);
134 QVERIFY(!icon.isEmpty());
135
136 QPlaceSupplier supplier;
137
138 QVERIFY(supplier.isEmpty());
139
140 // name
141 supplier.setName(QStringLiteral("Name"));
142 QVERIFY(!supplier.isEmpty());
143 supplier.setName(QString());
144 QVERIFY(supplier.isEmpty());
145
146 // supplierId
147 supplier.setSupplierId(QStringLiteral("1"));
148 QVERIFY(!supplier.isEmpty());
149 supplier.setSupplierId(QString());
150 QVERIFY(supplier.isEmpty());
151
152 // url
153 supplier.setUrl(QUrl(QStringLiteral("www.example.com")));
154 QVERIFY(!supplier.isEmpty());
155 supplier.setUrl(QUrl());
156 QVERIFY(supplier.isEmpty());
157
158 // icon
159 supplier.setIcon(icon);
160 QVERIFY(!supplier.isEmpty());
161 supplier.setIcon(QPlaceIcon());
162 QVERIFY(supplier.isEmpty());
163 }
164
165 QTEST_APPLESS_MAIN(tst_QPlaceSupplier);
166
167 #include "tst_qplacesupplier.moc"
168