aboutsummaryrefslogtreecommitdiff
path: root/tests/qxmppmessage/tst_qxmppmessage.cpp
diff options
context:
space:
mode:
authorLinus Jahn <lnj@kaidan.im>2020-03-30 01:46:38 +0200
committerLNJ <lnj@kaidan.im>2020-03-31 00:17:06 +0200
commit1cef71d96857825407be192788105a43eb5e1846 (patch)
tree7c83952e9dd830409c626b8c83a54ba842c7fa7f /tests/qxmppmessage/tst_qxmppmessage.cpp
parent7f080d08252dfb699d4e3ae072cc3db0d2de129d (diff)
downloadqxmpp-1cef71d96857825407be192788105a43eb5e1846.tar.gz
Implement XEP-0245: The /me Command
This adds parsing for recognizing /me commands in message bodies. It complies with version 1.0 of XEP-0245: The /me Command. https://xmpp.org/extensions/xep-0245.html
Diffstat (limited to 'tests/qxmppmessage/tst_qxmppmessage.cpp')
-rw-r--r--tests/qxmppmessage/tst_qxmppmessage.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/qxmppmessage/tst_qxmppmessage.cpp b/tests/qxmppmessage/tst_qxmppmessage.cpp
index 147b0c22..bfd4daec 100644
--- a/tests/qxmppmessage/tst_qxmppmessage.cpp
+++ b/tests/qxmppmessage/tst_qxmppmessage.cpp
@@ -61,6 +61,8 @@ private slots:
void testBobData();
void testFallbackIndication();
void testStanzaIds();
+ void testSlashMe_data();
+ void testSlashMe();
};
void tst_QXmppMessage::testBasic_data()
@@ -1011,5 +1013,51 @@ void tst_QXmppMessage::testStanzaIds()
serializePacket(msg2, xml);
}
+void tst_QXmppMessage::testSlashMe_data()
+{
+ QTest::addColumn<QString>("body");
+ QTest::addColumn<QString>("actionText");
+ QTest::addColumn<bool>("expected");
+
+#define POSTIIVE(name, body, actionText) \
+ QTest::newRow(QT_STRINGIFY(name)) << body << actionText << true
+
+#define NEGATIVE(name, body) \
+ QTest::newRow(QT_STRINGIFY(name)) << body << QString() << false
+
+ POSTIIVE(correct, "/me is having lunch.", "is having lunch.");
+ POSTIIVE(correct without text, "/me ", QString());
+
+ NEGATIVE(empty, "");
+ NEGATIVE(null, QString());
+ NEGATIVE(missing space, "/meshrugs in disgust");
+ NEGATIVE(with apostrophe, "/me's disgusted");
+ NEGATIVE(space at the beginning, " /me shrugs in disgust");
+ NEGATIVE(in quotation marks, R"("/me shrugs in disgust")");
+ NEGATIVE(display interpretation, "* Atlas shrugs in disgust");
+ NEGATIVE(quote, "Why did you say \"/me sleeps\"?");
+
+#undef POSTIIVE
+#undef NEGATIVE
+}
+
+void tst_QXmppMessage::testSlashMe()
+{
+ QFETCH(QString, body);
+ QFETCH(QString, actionText);
+ QFETCH(bool, expected);
+
+ QCOMPARE(QXmppMessage::isSlashMeCommand(body), expected);
+ QCOMPARE(QXmppMessage::slashMeCommandText(body), actionText);
+
+ QXmppMessage msg;
+ QVERIFY(!msg.isSlashMeCommand());
+ QVERIFY(msg.slashMeCommandText().isNull());
+
+ msg.setBody(body);
+ QCOMPARE(msg.isSlashMeCommand(), expected);
+ QCOMPARE(msg.slashMeCommandText(), actionText);
+}
+
QTEST_MAIN(tst_QXmppMessage)
#include "tst_qxmppmessage.moc"