mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
test: add regression test for #2119
Also modify the test to test highlighting via public key
This commit is contained in:
parent
641fba3553
commit
4d84db1a4e
|
@ -22,6 +22,7 @@
|
||||||
#include <tox/tox.h>
|
#include <tox/tox.h>
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
#include <QStringBuilder>
|
||||||
#include <QtTest/QtTest>
|
#include <QtTest/QtTest>
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -53,44 +54,69 @@ private slots:
|
||||||
void TestMessageProcessor::testSelfMention()
|
void TestMessageProcessor::testSelfMention()
|
||||||
{
|
{
|
||||||
MessageProcessor::SharedParams sharedParams;
|
MessageProcessor::SharedParams sharedParams;
|
||||||
sharedParams.onUserNameSet("MyUserName");
|
const QLatin1Literal testUserName{"MyUserName"};
|
||||||
|
const QLatin1Literal testToxPk{
|
||||||
|
"0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF"};
|
||||||
|
sharedParams.onUserNameSet(testUserName);
|
||||||
|
sharedParams.setPublicKey(testToxPk);
|
||||||
|
|
||||||
auto messageProcessor = MessageProcessor(sharedParams);
|
auto messageProcessor = MessageProcessor(sharedParams);
|
||||||
messageProcessor.enableMentions();
|
messageProcessor.enableMentions();
|
||||||
|
|
||||||
// Using my name should match
|
for (const auto& str : {testUserName, testToxPk}) {
|
||||||
auto processedMessage = messageProcessor.processIncomingMessage(false, "MyUserName hi");
|
|
||||||
QVERIFY(messageHasSelfMention(processedMessage));
|
|
||||||
|
|
||||||
// Action messages should match too
|
// Using my name or public key should match
|
||||||
processedMessage = messageProcessor.processIncomingMessage(true, "MyUserName hi");
|
auto processedMessage = messageProcessor.processIncomingMessage(false, str % " hi");
|
||||||
QVERIFY(messageHasSelfMention(processedMessage));
|
QVERIFY(messageHasSelfMention(processedMessage));
|
||||||
|
|
||||||
// Too much text shouldn't match
|
// Action messages should match too
|
||||||
processedMessage = messageProcessor.processIncomingMessage(false, "MyUserName2");
|
processedMessage = messageProcessor.processIncomingMessage(true, str % " hi");
|
||||||
QVERIFY(!messageHasSelfMention(processedMessage));
|
QVERIFY(messageHasSelfMention(processedMessage));
|
||||||
|
|
||||||
// Unless it's a colon
|
// Too much text shouldn't match
|
||||||
processedMessage = messageProcessor.processIncomingMessage(false, "MyUserName: test");
|
processedMessage = messageProcessor.processIncomingMessage(false, str % "2");
|
||||||
QVERIFY(messageHasSelfMention(processedMessage));
|
QVERIFY(!messageHasSelfMention(processedMessage));
|
||||||
|
|
||||||
// Too little text shouldn't match
|
// Unless it's a colon
|
||||||
processedMessage = messageProcessor.processIncomingMessage(false, "MyUser");
|
processedMessage = messageProcessor.processIncomingMessage(false, str % ": test");
|
||||||
QVERIFY(!messageHasSelfMention(processedMessage));
|
QVERIFY(messageHasSelfMention(processedMessage));
|
||||||
|
|
||||||
// The regex should be case insensitive
|
// remove last character
|
||||||
processedMessage = messageProcessor.processIncomingMessage(false, "myusername hi");
|
QString chopped = str;
|
||||||
QVERIFY(messageHasSelfMention(processedMessage));
|
chopped.chop(1);
|
||||||
|
// Too little text shouldn't match
|
||||||
|
processedMessage = messageProcessor.processIncomingMessage(false, chopped);
|
||||||
|
QVERIFY(!messageHasSelfMention(processedMessage));
|
||||||
|
|
||||||
|
// make lower case
|
||||||
|
QString lower = QString(str).toLower();
|
||||||
|
|
||||||
|
// The regex should be case insensitive
|
||||||
|
processedMessage = messageProcessor.processIncomingMessage(false, lower % " hi");
|
||||||
|
QVERIFY(messageHasSelfMention(processedMessage));
|
||||||
|
}
|
||||||
|
|
||||||
// New user name changes should be detected
|
// New user name changes should be detected
|
||||||
sharedParams.onUserNameSet("NewUserName");
|
sharedParams.onUserNameSet("NewUserName");
|
||||||
processedMessage = messageProcessor.processIncomingMessage(false, "NewUserName: hi");
|
auto processedMessage = messageProcessor.processIncomingMessage(false, "NewUserName: hi");
|
||||||
QVERIFY(messageHasSelfMention(processedMessage));
|
QVERIFY(messageHasSelfMention(processedMessage));
|
||||||
|
|
||||||
// Special characters should be removed
|
// Special characters should be removed
|
||||||
sharedParams.onUserNameSet("New\nUserName");
|
sharedParams.onUserNameSet("New\nUserName");
|
||||||
processedMessage = messageProcessor.processIncomingMessage(false, "NewUserName: hi");
|
processedMessage = messageProcessor.processIncomingMessage(false, "NewUserName: hi");
|
||||||
QVERIFY(messageHasSelfMention(processedMessage));
|
QVERIFY(messageHasSelfMention(processedMessage));
|
||||||
|
|
||||||
|
// Regression tests for: https://github.com/qTox/qTox/issues/2119
|
||||||
|
{
|
||||||
|
// Empty usernames should not match
|
||||||
|
sharedParams.onUserNameSet("");
|
||||||
|
processedMessage = messageProcessor.processIncomingMessage(false, "");
|
||||||
|
QVERIFY(!messageHasSelfMention(processedMessage));
|
||||||
|
|
||||||
|
// Empty usernames matched on everything, ensure this is not the case
|
||||||
|
processedMessage = messageProcessor.processIncomingMessage(false, "a");
|
||||||
|
QVERIFY(!messageHasSelfMention(processedMessage));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue
Block a user