// SPDX-FileCopyrightText: 2021 Linus Jahn // SPDX-FileCopyrightText: 2021 Germán Márquez Mejía // // SPDX-License-Identifier: LGPL-2.1-or-later #include "QXmppPubSubManager.h" #include "QXmppUserTuneItem.h" #include "QXmppUserTuneManager.h" #include "TestClient.h" using PSManager = QXmppPubSubManager; class tst_QXmppUserTuneManager : public QObject { Q_OBJECT private: Q_SLOT void initTestCase(); Q_SLOT void testRequest(); Q_SLOT void testPublish(); Q_SLOT void testEvents(); }; void tst_QXmppUserTuneManager::initTestCase() { qRegisterMetaType(); } void tst_QXmppUserTuneManager::testRequest() { TestClient test; test.addNewExtension(); auto *tuneManager = test.addNewExtension(); auto future = tuneManager->request("anthony@qxmpp.org"); test.expect(""); test.inject(QStringLiteral("" "" "" "I Kiste girl" "" "")); QCoreApplication::processEvents(); auto item = expectFutureVariant(future); QCOMPARE(item.id(), QString("abc3")); QCOMPARE(item.title(), QString("I Kiste girl")); } void tst_QXmppUserTuneManager::testPublish() { TestClient test; test.configuration().setJid("stpeter@jabber.org"); test.addNewExtension(); auto *tuneManager = test.addNewExtension(); QXmppTuneItem item; item.setArtist("Yes"); item.setLength(686); item.setRating(8); item.setSource("Yessongs"); item.setTitle("Heart of the Sunrise"); item.setTrack("3"); item.setUri({ "http://www.yesworld.com/lyrics/Fragile.html#9" }); auto future = tuneManager->publish(item); test.expect("" "" "" "" "Yes6868YessongsHeart of the Sunrise3http://www.yesworld.com/lyrics/Fragile.html#9" "" ""); test.inject(QStringLiteral("" "" "" "" "")); QCOMPARE(expectFutureVariant(future), QString("abcdf")); } void tst_QXmppUserTuneManager::testEvents() { TestClient test; test.configuration().setJid("stpeter@jabber.org"); auto *psManager = test.addNewExtension(); auto *tuneManager = test.addNewExtension(); QSignalSpy spy(tuneManager, &QXmppUserTuneManager::itemReceived); psManager->handleStanza(xmlToDom(QStringLiteral("" "" "" "" "" "Yes6868YessongsHeart of the Sunrise3http://www.yesworld.com/lyrics/Fragile.html#9" "" ""))); QCOMPARE(spy.count(), 1); QCOMPARE(spy.constFirst().at(0).toString(), QString("stpeter@jabber.org")); QCOMPARE(spy.constFirst().at(1).value().artist(), QString("Yes")); } QTEST_MAIN(tst_QXmppUserTuneManager) #include "tst_qxmppusertunemanager.moc"