From 2fde987d39dc66f028ea3ff44929ebd6e2b37f90 Mon Sep 17 00:00:00 2001 From: Tibor Csötönyi Date: Wed, 3 May 2023 15:33:35 +0200 Subject: Add XEP-0353: Jingle Message Initiation data classes --- tests/qxmppjingleiq/tst_qxmppjingleiq.cpp | 284 ++++++++++++++++++++++++++++-- tests/qxmppmessage/tst_qxmppmessage.cpp | 24 +++ 2 files changed, 295 insertions(+), 13 deletions(-) (limited to 'tests') diff --git a/tests/qxmppjingleiq/tst_qxmppjingleiq.cpp b/tests/qxmppjingleiq/tst_qxmppjingleiq.cpp index 1aa88866..1d9c47fc 100644 --- a/tests/qxmppjingleiq/tst_qxmppjingleiq.cpp +++ b/tests/qxmppjingleiq/tst_qxmppjingleiq.cpp @@ -56,6 +56,10 @@ private: Q_SLOT void testPayloadTypeRtpFeedbackNegotiation(); Q_SLOT void testRtpErrorCondition_data(); Q_SLOT void testRtpErrorCondition(); + + Q_SLOT void testIsJingleMessageInitiationElement_data(); + Q_SLOT void testIsJingleMessageInitiationElement(); + Q_SLOT void testJingleMessageInitiationElement(); }; void tst_QXmppJingleIq::testIsSdpParameter_data() @@ -1390,34 +1394,288 @@ void tst_QXmppJingleIq::testRtpErrorCondition() iq2.setAction(QXmppJingleIq::SessionTerminate); switch (condition) { - case QXmppJingleIq::Reason::NoErrorCondition: - iq2.reason().setRtpErrorCondition(QXmppJingleIq::Reason::NoErrorCondition); + case QXmppJingleReason::NoErrorCondition: + iq2.reason().setRtpErrorCondition(QXmppJingleReason::NoErrorCondition); break; - case QXmppJingleIq::Reason::InvalidCrypto: - iq2.reason().setRtpErrorCondition(QXmppJingleIq::Reason::InvalidCrypto); + case QXmppJingleReason::InvalidCrypto: + iq2.reason().setRtpErrorCondition(QXmppJingleReason::InvalidCrypto); break; - case QXmppJingleIq::Reason::CryptoRequired: - iq2.reason().setRtpErrorCondition(QXmppJingleIq::Reason::CryptoRequired); + case QXmppJingleReason::CryptoRequired: + iq2.reason().setRtpErrorCondition(QXmppJingleReason::CryptoRequired); break; } - iq2.reason().setType(QXmppJingleIq::Reason::SecurityError); + iq2.reason().setType(QXmppJingleReason::SecurityError); const auto rtpErrorCondition2 = iq2.reason().rtpErrorCondition(); switch (condition) { - case QXmppJingleIq::Reason::NoErrorCondition: - QVERIFY(rtpErrorCondition2 == QXmppJingleIq::Reason::NoErrorCondition); + case QXmppJingleReason::NoErrorCondition: + QVERIFY(rtpErrorCondition2 == QXmppJingleReason::NoErrorCondition); break; - case QXmppJingleIq::Reason::InvalidCrypto: - QVERIFY(rtpErrorCondition2 == QXmppJingleIq::Reason::InvalidCrypto); + case QXmppJingleReason::InvalidCrypto: + QVERIFY(rtpErrorCondition2 == QXmppJingleReason::InvalidCrypto); break; - case QXmppJingleIq::Reason::CryptoRequired: - QVERIFY(rtpErrorCondition2 == QXmppJingleIq::Reason::CryptoRequired); + case QXmppJingleReason::CryptoRequired: + QVERIFY(rtpErrorCondition2 == QXmppJingleReason::CryptoRequired); break; } serializePacket(iq2, xml); } +void tst_QXmppJingleIq::testIsJingleMessageInitiationElement_data() +{ + QTest::addColumn("xml"); + QTest::addColumn("isValid"); + + // --- Propose --- + + QTest::newRow("validPropose") + << QByteArrayLiteral( + "" + "" + "") + << true; + QTest::newRow("invalidProposeIdMissing") + << QByteArrayLiteral( + "" + "" + "") + << false; + QTest::newRow("invalidProposeNamespaceMissing") + << QByteArrayLiteral( + "" + "" + "") + << false; + + // --- Ringing --- + + QTest::newRow("validRinging") + << QByteArrayLiteral("") + << true; + QTest::newRow("invalidRingingIdMissing") + << QByteArrayLiteral("") + << false; + QTest::newRow("invalidRingingNamespaceMissing") + << QByteArrayLiteral("") + << false; + + // --- Proceed --- + + QTest::newRow("validProceed") + << QByteArrayLiteral("") + << true; + QTest::newRow("invalidProceedIdMissing") + << QByteArrayLiteral("") + << false; + QTest::newRow("invalidProceedNamespaceMissing") + << QByteArrayLiteral("") + << false; + + // --- Reject --- + + QTest::newRow("validReject") + << QByteArrayLiteral( + "" + "" + "Busy" + "" + "" + "") + << true; + QTest::newRow("invalidRejectIdMissing") + << QByteArrayLiteral( + "" + "" + "Busy" + "" + "" + "") + << false; + QTest::newRow("invalidRejectNamespaceMissing") + << QByteArrayLiteral( + "" + "" + "Busy" + "" + "" + "") + << false; + + // --- Retract --- + + QTest::newRow("validRetract") + << QByteArrayLiteral( + "" + "" + "Retracted" + "" + "" + "") + << true; + QTest::newRow("invalidRetractIdMissing") + << QByteArrayLiteral( + "" + "" + "Retracted" + "" + "" + "") + << false; + QTest::newRow("invalidRetractNamespaceMissing") + << QByteArrayLiteral( + "" + "" + "Retracted" + "" + "" + "") + << false; + + // --- Finish --- + + QTest::newRow("validFinish") + << QByteArrayLiteral( + "" + "" + "Success" + "" + "" + "") + << true; + QTest::newRow("invalidFinishIdMissing") + << QByteArrayLiteral( + "" + "" + "Success" + "" + "" + "") + << false; + QTest::newRow("invalidFinishNamespaceMissing") + << QByteArrayLiteral( + "" + "" + "Success" + "" + "" + "") + << false; +} + +void tst_QXmppJingleIq::testIsJingleMessageInitiationElement() +{ + QFETCH(QByteArray, xml); + QFETCH(bool, isValid); + + QCOMPARE(QXmppJingleMessageInitiationElement::isJingleMessageInitiationElement(xmlToDom(xml)), isValid); +} + +void tst_QXmppJingleIq::testJingleMessageInitiationElement() +{ + using JmiType = QXmppJingleMessageInitiationElement::Type; + + // --- Propose --- + + const QByteArray proposeXml( + "" + "" + ""); + QXmppJingleMessageInitiationElement proposeElement; + proposeElement.setType(JmiType::Propose); + + parsePacket(proposeElement, proposeXml); + QCOMPARE(proposeElement.id(), QStringLiteral("ca3cf894-5325-482f-a412-a6e9f832298d")); + QCOMPARE(proposeElement.description()->type(), QStringLiteral("urn:xmpp:jingle:apps:rtp:1")); + QCOMPARE(proposeElement.description()->media(), QStringLiteral("audio")); + QCOMPARE(proposeElement.containsTieBreak(), false); // single check if containsTieBreak is set correctly when unused + QCOMPARE(proposeElement.reason(), std::nullopt); // single check if reason is set correctly when unused + serializePacket(proposeElement, proposeXml); + + // --- Ringing --- + + const QByteArray ringingXml(""); + QXmppJingleMessageInitiationElement ringingElement; + ringingElement.setType(JmiType::Ringing); + + parsePacket(ringingElement, ringingXml); + QCOMPARE(ringingElement.id(), QStringLiteral("ca3cf894-5325-482f-a412-a6e9f832298d")); + serializePacket(ringingElement, ringingXml); + + // --- Proceed --- + + const QByteArray proceedXml(""); + QXmppJingleMessageInitiationElement proceedElement; + proceedElement.setType(JmiType::Proceed); + + parsePacket(proceedElement, proceedXml); + QCOMPARE(proceedElement.id(), QStringLiteral("ca3cf894-5325-482f-a412-a6e9f832298d")); + serializePacket(proceedElement, proceedXml); + + // --- Reject --- + + using ReasonType = QXmppJingleReason::Type; + + const QByteArray rejectXml( + "" + "" + "Busy" + "" + "" + "" + ""); + QXmppJingleMessageInitiationElement rejectElement; + rejectElement.setType(JmiType::Reject); + + parsePacket(rejectElement, rejectXml); + QCOMPARE(rejectElement.id(), QStringLiteral("a73sjjvkla37jfea")); + QCOMPARE(rejectElement.reason()->text(), QStringLiteral("Busy")); + QCOMPARE(rejectElement.reason()->type(), ReasonType::Busy); + QCOMPARE(rejectElement.reason()->namespaceUri(), QStringLiteral("urn:xmpp:jingle:1")); + QCOMPARE(rejectElement.containsTieBreak(), true); + serializePacket(rejectElement, rejectXml); + + // --- Retract --- + + const QByteArray retractXml( + "" + "" + "Retracted" + "" + "" + ""); + QXmppJingleMessageInitiationElement retractElement; + retractElement.setType(JmiType::Retract); + + parsePacket(retractElement, retractXml); + QCOMPARE(retractElement.id(), QStringLiteral("a73sjjvkla37jfea")); + QCOMPARE(retractElement.reason()->text(), QStringLiteral("Retracted")); + QCOMPARE(retractElement.reason()->type(), ReasonType::Cancel); + QCOMPARE(retractElement.reason()->namespaceUri(), QStringLiteral("urn:xmpp:jingle:1")); + serializePacket(retractElement, retractXml); + + // --- Finish --- + + const QByteArray finishXml( + "" + "" + "Success" + "" + "" + "" + ""); + QXmppJingleMessageInitiationElement finishElement; + finishElement.setType(JmiType::Finish); + + parsePacket(finishElement, finishXml); + QCOMPARE(finishElement.id(), QStringLiteral("a73sjjvkla37jfea")); + QCOMPARE(finishElement.reason()->text(), QStringLiteral("Success")); + QCOMPARE(finishElement.reason()->type(), ReasonType::Success); + QCOMPARE(finishElement.reason()->namespaceUri(), QStringLiteral("urn:xmpp:jingle:1")); + QCOMPARE(finishElement.migratedTo(), QStringLiteral("989a46a6-f202-4910-a7c3-83c6ba3f3947")); + serializePacket(finishElement, finishXml); +} + QTEST_MAIN(tst_QXmppJingleIq) #include "tst_qxmppjingleiq.moc" diff --git a/tests/qxmppmessage/tst_qxmppmessage.cpp b/tests/qxmppmessage/tst_qxmppmessage.cpp index 98ca5670..61fbed6f 100644 --- a/tests/qxmppmessage/tst_qxmppmessage.cpp +++ b/tests/qxmppmessage/tst_qxmppmessage.cpp @@ -1,12 +1,14 @@ // SPDX-FileCopyrightText: 2012 Jeremy Lainé // SPDX-FileCopyrightText: 2012 Manjeet Dahiya // SPDX-FileCopyrightText: 2021 Melvin Keskin +// SPDX-FileCopyrightText: 2023 Tibor Csötönyi // // SPDX-License-Identifier: LGPL-2.1-or-later #include "QXmppBitsOfBinaryContentId.h" #include "QXmppBitsOfBinaryDataList.h" #include "QXmppEncryptedFileSource.h" +#include "QXmppJingleData.h" #include "QXmppMessage.h" #include "QXmppMessageReaction.h" #include "QXmppMixInvitation.h" @@ -58,6 +60,7 @@ private: Q_SLOT void testE2eeFallbackBody(); Q_SLOT void testFileSharing(); Q_SLOT void testEncryptedFileSource(); + Q_SLOT void testJingleMessageInitiationElement(); }; void tst_QXmppMessage::testBasic_data() @@ -1285,5 +1288,26 @@ void tst_QXmppMessage::testEncryptedFileSource() } } +void tst_QXmppMessage::testJingleMessageInitiationElement() +{ + const QByteArray xml( + "" + "" + "" + ""); + + QXmppMessage message1; + QVERIFY(!message1.jingleMessageInitiationElement()); + + parsePacket(message1, xml); + QVERIFY(message1.jingleMessageInitiationElement()); + serializePacket(message1, xml); + + QXmppMessage message2; + message2.addHint(QXmppMessage::Store); + message2.setJingleMessageInitiationElement(QXmppJingleMessageInitiationElement()); + QVERIFY(message2.jingleMessageInitiationElement()); +} + QTEST_MAIN(tst_QXmppMessage) #include "tst_qxmppmessage.moc" -- cgit v1.2.3