From bd9d878d065785d5922052d43be42299ffa09e34 Mon Sep 17 00:00:00 2001 From: Linus Jahn Date: Wed, 9 Mar 2022 11:20:30 +0100 Subject: Add tests for UserLocationManager --- tests/CMakeLists.txt | 1 + .../tst_qxmppuserlocationmanager.cpp | 132 +++++++++++++++++++++ 2 files changed, 133 insertions(+) create mode 100644 tests/qxmppuserlocationmanager/tst_qxmppuserlocationmanager.cpp (limited to 'tests') diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index e11079fc..960e09a4 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -67,6 +67,7 @@ add_simple_test(qxmppstreamfeatures) add_simple_test(qxmppstunmessage) add_simple_test(qxmpptrustmessages) add_simple_test(qxmpptrustmemorystorage) +add_simple_test(qxmppuserlocationmanager TestClient.h) add_simple_test(qxmppusertunemanager TestClient.h) add_simple_test(qxmppvcardiq) add_simple_test(qxmppvcardmanager) diff --git a/tests/qxmppuserlocationmanager/tst_qxmppuserlocationmanager.cpp b/tests/qxmppuserlocationmanager/tst_qxmppuserlocationmanager.cpp new file mode 100644 index 00000000..3ff30a28 --- /dev/null +++ b/tests/qxmppuserlocationmanager/tst_qxmppuserlocationmanager.cpp @@ -0,0 +1,132 @@ +// SPDX-FileCopyrightText: 2021 Linus Jahn +// SPDX-FileCopyrightText: 2021 Germán Márquez Mejía +// +// SPDX-License-Identifier: LGPL-2.1-or-later + +#include "QXmppGeolocItem.h" +#include "QXmppPubSubManager.h" +#include "QXmppUserLocationManager.h" + +#include "TestClient.h" + +using PSManager = QXmppPubSubManager; + +#define COMPARE_OPT(ACTUAL, EXPECTED) \ + QVERIFY(ACTUAL.has_value()); \ + QCOMPARE(ACTUAL.value(), EXPECTED); + +class tst_QXmppUserLocationManager : public QObject +{ + Q_OBJECT + +private: + Q_SLOT void initTestCase(); + Q_SLOT void testRequest(); + Q_SLOT void testPublish(); + Q_SLOT void testEvents(); +}; + +void tst_QXmppUserLocationManager::initTestCase() +{ + qRegisterMetaType(); +} + +void tst_QXmppUserLocationManager::testRequest() +{ + TestClient test; + test.addNewExtension(); + auto *tuneManager = test.addNewExtension(); + + auto future = tuneManager->request("anthony@qxmpp.org"); + test.expect(""); + test.inject("" + "" + "" + "" + "20" + "Italy" + "45.44" + "Venice" + "12.33" + "" + "" + ""); + + QCoreApplication::processEvents(); + auto item = expectFutureVariant(future); + QCOMPARE(item.id(), QString("abc3")); + COMPARE_OPT(item.accuracy(), 20.0); + COMPARE_OPT(item.longitude(), 12.33); + COMPARE_OPT(item.latitude(), 45.44); + QCOMPARE(item.locality(), QStringLiteral("Venice")); + QCOMPARE(item.country(), QStringLiteral("Italy")); +} + +void tst_QXmppUserLocationManager::testPublish() +{ + TestClient test; + test.configuration().setJid("stpeter@jabber.org"); + test.addNewExtension(); + auto *manager = test.addNewExtension(); + + QXmppGeolocItem item; + item.setId("abc3"); + item.setAccuracy(20); + item.setCountry("Italy"); + item.setLatitude(45.44); + item.setLongitude(12.33); + item.setLocality("Venice"); + + auto future = manager->publish(item); + test.expect("" + "" + "" + "" + "20" + "Italy" + "45.44" + "Venice" + "12.33" + "" + "" + ""); + test.inject("" + "" + "" + "" + ""); + + QCOMPARE(expectFutureVariant(future), QString("some-id")); +} + +void tst_QXmppUserLocationManager::testEvents() +{ + TestClient test; + test.configuration().setJid("stpeter@jabber.org"); + auto *psManager = test.addNewExtension(); + auto *manager = test.addNewExtension(); + + QSignalSpy spy(manager, &QXmppUserLocationManager::itemReceived); + + const QString event = "" + "" + "" + "" + "" + "20" + "Italy" + "45.44" + "Venice" + "12.33" + "" + ""; + psManager->handleStanza(xmlToDom(event)); + + QCOMPARE(spy.count(), 1); + QCOMPARE(spy.constFirst().at(0).toString(), QString("stpeter@jabber.org")); + QCOMPARE(spy.constFirst().at(1).value().id(), QString("bffe6584-0f9c-11dc-84ba-001143d5d5db")); + QCOMPARE(spy.constFirst().at(1).value().country(), QString("Italy")); +} + +QTEST_MAIN(tst_QXmppUserLocationManager) +#include "tst_qxmppuserlocationmanager.moc" -- cgit v1.2.3