// 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"