| 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 <qplacecategory.h> |
| 33 | #include <qplaceicon.h> |
| 34 | |
| 35 | QT_USE_NAMESPACE |
| 36 | |
| 37 | class tst_QPlaceCategory : public QObject |
| 38 | { |
| 39 | Q_OBJECT |
| 40 | |
| 41 | public: |
| 42 | tst_QPlaceCategory(); |
| 43 | |
| 44 | private Q_SLOTS: |
| 45 | void constructorTest(); |
| 46 | void categoryIdTest(); |
| 47 | void nameTest(); |
| 48 | void visibilityTest(); |
| 49 | void operatorsTest(); |
| 50 | void isEmptyTest(); |
| 51 | }; |
| 52 | |
| 53 | tst_QPlaceCategory::tst_QPlaceCategory() |
| 54 | { |
| 55 | } |
| 56 | |
| 57 | void tst_QPlaceCategory::constructorTest() |
| 58 | { |
| 59 | QPlaceCategory testObj; |
| 60 | Q_UNUSED(testObj); |
| 61 | |
| 62 | testObj.setCategoryId("testId" ); |
| 63 | QPlaceCategory *testObjPtr = new QPlaceCategory(testObj); |
| 64 | QVERIFY2(testObjPtr != NULL, "Copy constructor - null" ); |
| 65 | QVERIFY2(*testObjPtr == testObj, "Copy constructor - compare" ); |
| 66 | delete testObjPtr; |
| 67 | } |
| 68 | |
| 69 | void tst_QPlaceCategory::categoryIdTest() |
| 70 | { |
| 71 | QPlaceCategory testObj; |
| 72 | QVERIFY2(testObj.categoryId() == QString(), "Wrong default value" ); |
| 73 | testObj.setCategoryId("testText" ); |
| 74 | QVERIFY2(testObj.categoryId() == "testText" , "Wrong value returned" ); |
| 75 | } |
| 76 | |
| 77 | void tst_QPlaceCategory::nameTest() |
| 78 | { |
| 79 | QPlaceCategory testObj; |
| 80 | QVERIFY2(testObj.name() == QString(), "Wrong default value" ); |
| 81 | testObj.setName("testText" ); |
| 82 | QVERIFY2(testObj.name() == "testText" , "Wrong value returned" ); |
| 83 | } |
| 84 | |
| 85 | void tst_QPlaceCategory::visibilityTest() |
| 86 | { |
| 87 | QPlaceCategory category; |
| 88 | |
| 89 | QCOMPARE(category.visibility(), QLocation::UnspecifiedVisibility); |
| 90 | |
| 91 | category.setVisibility(QLocation::DeviceVisibility); |
| 92 | |
| 93 | QCOMPARE(category.visibility(), QLocation::DeviceVisibility); |
| 94 | } |
| 95 | |
| 96 | void tst_QPlaceCategory::operatorsTest() |
| 97 | { |
| 98 | QPlaceCategory testObj; |
| 99 | testObj.setName("testValue" ); |
| 100 | QPlaceCategory testObj2; |
| 101 | testObj2 = testObj; |
| 102 | QVERIFY2(testObj == testObj2, "Not copied correctly" ); |
| 103 | testObj2.setCategoryId("a3rfg" ); |
| 104 | QVERIFY2(testObj != testObj2, "Object should be different" ); |
| 105 | } |
| 106 | |
| 107 | void tst_QPlaceCategory::isEmptyTest() |
| 108 | { |
| 109 | QPlaceIcon icon; |
| 110 | QVariantMap parameters; |
| 111 | parameters.insert(QStringLiteral("para" ), QStringLiteral("meter" )); |
| 112 | icon.setParameters(parameters); |
| 113 | QVERIFY(!icon.isEmpty()); |
| 114 | |
| 115 | QPlaceCategory category; |
| 116 | |
| 117 | QVERIFY(category.isEmpty()); |
| 118 | |
| 119 | category.setName(QStringLiteral("name" )); |
| 120 | QVERIFY(!category.isEmpty()); |
| 121 | category.setName(QString()); |
| 122 | QVERIFY(category.isEmpty()); |
| 123 | |
| 124 | category.setCategoryId(QStringLiteral("id" )); |
| 125 | QVERIFY(!category.isEmpty()); |
| 126 | category.setCategoryId(QString()); |
| 127 | QVERIFY(category.isEmpty()); |
| 128 | |
| 129 | category.setVisibility(QLocation::PublicVisibility); |
| 130 | QVERIFY(!category.isEmpty()); |
| 131 | category.setVisibility(QLocation::UnspecifiedVisibility); |
| 132 | QVERIFY(category.isEmpty()); |
| 133 | |
| 134 | category.setIcon(icon); |
| 135 | QVERIFY(!category.isEmpty()); |
| 136 | category.setIcon(QPlaceIcon()); |
| 137 | QVERIFY(category.isEmpty()); |
| 138 | } |
| 139 | |
| 140 | QTEST_APPLESS_MAIN(tst_QPlaceCategory); |
| 141 | |
| 142 | #include "tst_qplacecategory.moc" |
| 143 | |