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/QPlaceUser> 33 34 QT_USE_NAMESPACE 35 36 class tst_QPlaceUser : public QObject 37 { 38 Q_OBJECT 39 40 public: 41 tst_QPlaceUser(); 42 43 private Q_SLOTS: 44 void constructorTest(); 45 void nameTest(); 46 void userIdTest(); 47 void operatorsTest(); 48 void operatorsTest_data(); 49 }; 50 tst_QPlaceUser()51tst_QPlaceUser::tst_QPlaceUser() 52 { 53 } 54 constructorTest()55void tst_QPlaceUser::constructorTest() 56 { 57 QPlaceUser user; 58 QVERIFY(user.name().isEmpty()); 59 QVERIFY(user.userId().isEmpty()); 60 61 user.setName(QStringLiteral("Thomas Anderson")); 62 user.setUserId(QStringLiteral("Neo")); 63 64 QPlaceUser user2(user); 65 QCOMPARE(user2.name(), QStringLiteral("Thomas Anderson")); 66 QCOMPARE(user2.userId(), QStringLiteral("Neo")); 67 } 68 nameTest()69void tst_QPlaceUser::nameTest() 70 { 71 QPlaceUser user; 72 user.setName(QStringLiteral("Thomas Anderson")); 73 QCOMPARE(user.name(), QStringLiteral("Thomas Anderson")); 74 user.setName(QString()); 75 QVERIFY(user.name().isEmpty()); 76 } 77 userIdTest()78void tst_QPlaceUser::userIdTest() 79 { 80 QPlaceUser user; 81 user.setUserId(QStringLiteral("Neo")); 82 QCOMPARE(user.userId(), QStringLiteral("Neo")); 83 user.setUserId(QString()); 84 QVERIFY(user.userId().isEmpty()); 85 } 86 operatorsTest()87void tst_QPlaceUser::operatorsTest() 88 { 89 QPlaceUser user1; 90 user1.setName(QStringLiteral("Thomas Anderson")); 91 user1.setUserId(QStringLiteral("Neo")); 92 93 QPlaceUser user2; 94 user2.setName(QStringLiteral("Thomas Anderson")); 95 user2.setUserId(QStringLiteral("Neo")); 96 97 QVERIFY(user1 == user2); 98 QVERIFY(!(user1 != user2)); 99 QVERIFY(user2 == user1); 100 QVERIFY(!(user2 != user1)); 101 102 QPlaceUser user3; 103 QVERIFY(!(user1 == user3)); 104 QVERIFY(user1 != user3); 105 QVERIFY(!(user3 == user1)); 106 QVERIFY(user3 != user1); 107 108 user3 = user1; 109 QVERIFY(user1 == user3); 110 QVERIFY(!(user1 != user3)); 111 QVERIFY(user3 == user1); 112 QVERIFY(!(user3 != user1)); 113 114 QFETCH(QString, field); 115 116 if (field == QStringLiteral("name")) 117 user3.setName(QStringLiteral("bob")); 118 else if (field == QStringLiteral("userId")) 119 user3.setUserId(QStringLiteral("Morpheus")); 120 else 121 qFatal("Unknown data field"); 122 123 QVERIFY(!(user1 == user3)); 124 QVERIFY(user1 != user3); 125 QVERIFY(!(user3 == user1)); 126 QVERIFY(user3 != user1); 127 } 128 operatorsTest_data()129void tst_QPlaceUser::operatorsTest_data() 130 { 131 QTest::addColumn<QString>("field"); 132 133 QTest::newRow("user name") << "name"; 134 QTest::newRow("user id") << "userId"; 135 } 136 137 QTEST_APPLESS_MAIN(tst_QPlaceUser) 138 139 #include "tst_qplaceuser.moc" 140