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/QPlaceContactDetail> |
33 | |
34 | QT_USE_NAMESPACE |
35 | |
36 | class tst_QPlaceContactDetail : public QObject |
37 | { |
38 | Q_OBJECT |
39 | |
40 | public: |
41 | tst_QPlaceContactDetail(); |
42 | |
43 | private Q_SLOTS: |
44 | void constructorTest(); |
45 | void labelTest(); |
46 | void valueTest(); |
47 | void clearTest(); |
48 | void operatorsTest(); |
49 | void operatorsTest_data(); |
50 | }; |
51 | |
52 | tst_QPlaceContactDetail::tst_QPlaceContactDetail() |
53 | { |
54 | } |
55 | |
56 | void tst_QPlaceContactDetail::constructorTest() |
57 | { |
58 | QPlaceContactDetail detail; |
59 | QVERIFY(detail.label().isEmpty()); |
60 | QVERIFY(detail.value().isEmpty()); |
61 | |
62 | detail.setLabel(QStringLiteral("Emergency Services")); |
63 | detail.setValue(QStringLiteral("0118 999")); |
64 | |
65 | QPlaceContactDetail detail2(detail); |
66 | QCOMPARE(detail2.label(), QStringLiteral("Emergency Services")); |
67 | QCOMPARE(detail2.value(), QStringLiteral("0118 999")); |
68 | } |
69 | |
70 | void tst_QPlaceContactDetail::labelTest() |
71 | { |
72 | QPlaceContactDetail detail; |
73 | detail.setLabel(QStringLiteral("home")); |
74 | QCOMPARE(detail.label(), QStringLiteral("home")); |
75 | detail.setLabel(QString()); |
76 | QVERIFY(detail.label().isEmpty()); |
77 | } |
78 | |
79 | void tst_QPlaceContactDetail::valueTest() |
80 | { |
81 | QPlaceContactDetail detail; |
82 | detail.setValue(QStringLiteral("555-5555")); |
83 | QCOMPARE(detail.value(), QStringLiteral("555-5555")); |
84 | detail.setValue(QString()); |
85 | QVERIFY(detail.value().isEmpty()); |
86 | } |
87 | |
88 | void tst_QPlaceContactDetail::clearTest() |
89 | { |
90 | QPlaceContactDetail detail; |
91 | detail.setLabel(QStringLiteral("Ghostbusters")); |
92 | detail.setValue(QStringLiteral("555-2368")); |
93 | detail.clear(); |
94 | QVERIFY(detail.label().isEmpty()); |
95 | QVERIFY(detail.value().isEmpty()); |
96 | } |
97 | |
98 | void tst_QPlaceContactDetail::operatorsTest() |
99 | { |
100 | QPlaceContactDetail detail1; |
101 | detail1.setLabel(QStringLiteral("Kramer")); |
102 | detail1.setValue(QStringLiteral("555-filk")); |
103 | |
104 | QPlaceContactDetail detail2; |
105 | detail2.setLabel(QStringLiteral("Kramer")); |
106 | detail2.setValue(QStringLiteral("555-filk")); |
107 | |
108 | QVERIFY(detail1 == detail2); |
109 | QVERIFY(!(detail1 != detail2)); |
110 | QVERIFY(detail2 == detail1); |
111 | QVERIFY(!(detail2 != detail1)); |
112 | |
113 | QPlaceContactDetail detail3; |
114 | QVERIFY(!(detail1 == detail3)); |
115 | QVERIFY(detail1 != detail3); |
116 | QVERIFY(!(detail1 == detail3)); |
117 | QVERIFY(detail1 != detail3); |
118 | |
119 | detail3 = detail1; |
120 | QVERIFY(detail1 == detail3); |
121 | QVERIFY(!(detail1 != detail3)); |
122 | QVERIFY(detail3 == detail1); |
123 | QVERIFY(!(detail3 != detail1)); |
124 | |
125 | QFETCH(QString, field); |
126 | if (field == QStringLiteral("label")) |
127 | detail3.setLabel(QStringLiteral("Cosmo")); |
128 | else if (field == QStringLiteral("value")) |
129 | detail3.setValue(QStringLiteral("555-5555")); |
130 | |
131 | QVERIFY(!(detail1 == detail3)); |
132 | QVERIFY(detail1 != detail3); |
133 | QVERIFY(!(detail3 == detail1)); |
134 | QVERIFY(detail3 != detail1); |
135 | } |
136 | |
137 | void tst_QPlaceContactDetail::operatorsTest_data() |
138 | { |
139 | QTest::addColumn<QString>(name: "field"); |
140 | QTest::newRow(dataTag: "label") << "label"; |
141 | QTest::newRow(dataTag: "value") << "value"; |
142 | } |
143 | |
144 | QTEST_APPLESS_MAIN(tst_QPlaceContactDetail) |
145 | |
146 | #include "tst_qplacecontactdetail.moc" |
147 |