예제 #1
0
void tst_IrcMessage::testNoticeMessage()
{
    QFETCH(bool, valid);
    QFETCH(QByteArray, data);
    QFETCH(QString, target);
    QFETCH(QString, content);
    QFETCH(bool, priv);
    QFETCH(bool, reply);

    IrcConnection connection;
    connection.setNickName("communi");
    IrcMessage* message = IrcMessage::fromData(data, &connection);
    QCOMPARE(message->type(), IrcMessage::Notice);
    QCOMPARE(message->command(), QString("NOTICE"));
    QCOMPARE(message->property("valid").toBool(), valid);
    QCOMPARE(message->property("target").toString(), target);
    QCOMPARE(message->property("content").toString(), content);
    QCOMPARE(message->property("private").toBool(), priv);
    QCOMPARE(message->property("reply").toBool(), reply);

    IrcNoticeMessage* noticeMessage = qobject_cast<IrcNoticeMessage*>(message);
    QVERIFY(noticeMessage);
    QCOMPARE(noticeMessage->isValid(), valid);
    QCOMPARE(noticeMessage->target(), target);
    QCOMPARE(noticeMessage->content(), content);
    QCOMPARE(noticeMessage->isPrivate(), priv);
    QCOMPARE(noticeMessage->isReply(), reply);
}
예제 #2
0
void tst_IrcMessage::testPongMessage()
{
    IrcConnection connection;
    IrcMessage* message = IrcMessage::fromData("PONG tgt :arg", &connection);
    QCOMPARE(message->type(), IrcMessage::Pong);
    QCOMPARE(message->command(), QString("PONG"));
    QCOMPARE(message->property("command").toString(), QString("PONG"));
    QVERIFY(message->property("valid").toBool());
    QCOMPARE(message->property("argument").toString(), QString("arg"));

    IrcPongMessage* pongMessage = qobject_cast<IrcPongMessage*>(message);
    QVERIFY(pongMessage);
    QVERIFY(pongMessage->isValid());
    QCOMPARE(pongMessage->argument(), QString("arg"));
}
예제 #3
0
void tst_IrcMessage::testQuitMessage()
{
    QFETCH(bool, valid);
    QFETCH(QByteArray, data);
    QFETCH(QString, reason);

    IrcConnection connection;
    IrcMessage* message = IrcMessage::fromData(data, &connection);
    QCOMPARE(message->type(), IrcMessage::Quit);
    QCOMPARE(message->command(), QString("QUIT"));
    QCOMPARE(message->property("valid").toBool(), valid);
    QCOMPARE(message->property("reason").toString(), reason);

    IrcQuitMessage* quitMessage = qobject_cast<IrcQuitMessage*>(message);
    QVERIFY(quitMessage);
    QCOMPARE(quitMessage->isValid(), valid);
    QCOMPARE(quitMessage->reason(), reason);
}
예제 #4
0
void tst_IrcMessage::testNumericMessage()
{
    QFETCH(bool, valid);
    QFETCH(QByteArray, data);
    QFETCH(int, code);

    IrcConnection connection;
    IrcMessage* message = IrcMessage::fromData(data, &connection);
    QCOMPARE(message->type(), IrcMessage::Numeric);
    QVERIFY(message->command().toInt() > 0);
    QCOMPARE(message->property("valid").toBool(), valid);
    QCOMPARE(message->property("code").toInt(), code);

    IrcNumericMessage* numericMessage = qobject_cast<IrcNumericMessage*>(message);
    QVERIFY(numericMessage);
    QCOMPARE(numericMessage->isValid(), valid);
    QCOMPARE(numericMessage->code(), code);
}
예제 #5
0
void tst_IrcMessage::testJoinMessage()
{
    QFETCH(bool, valid);
    QFETCH(QByteArray, data);
    QFETCH(QString, channel);

    IrcConnection connection;
    IrcMessage* message = IrcMessage::fromData(data, &connection);
    QCOMPARE(message->type(), IrcMessage::Join);
    QCOMPARE(message->command(), QString("JOIN"));
    QCOMPARE(message->property("valid").toBool(), valid);
    QCOMPARE(message->property("channel").toString(), channel);

    IrcJoinMessage* joinMessage = qobject_cast<IrcJoinMessage*>(message);
    QVERIFY(joinMessage);
    QCOMPARE(joinMessage->isValid(), valid);
    QCOMPARE(joinMessage->channel(), channel);
}
예제 #6
0
void tst_IrcMessage::testErrorMessage()
{
    QFETCH(bool, valid);
    QFETCH(QByteArray, data);
    QFETCH(QString, error);

    IrcConnection connection;
    IrcMessage* message = IrcMessage::fromData(data, &connection);
    QCOMPARE(message->type(), IrcMessage::Error);
    QCOMPARE(message->command(), QString("ERROR"));
    QCOMPARE(message->property("valid").toBool(), valid);
    QCOMPARE(message->property("error").toString(), error);

    IrcErrorMessage* errorMessage = qobject_cast<IrcErrorMessage*>(message);
    QVERIFY(errorMessage);
    QCOMPARE(errorMessage->isValid(), valid);
    QCOMPARE(errorMessage->error(), error);
}
예제 #7
0
void tst_IrcMessage::testPartMessage()
{
    QFETCH(bool, valid);
    QFETCH(QByteArray, data);
    QFETCH(QString, channel);
    QFETCH(QString, reason);

    IrcConnection connection;
    IrcMessage* message = IrcMessage::fromData(data, &connection);
    QCOMPARE(message->type(), IrcMessage::Part);
    QCOMPARE(message->command(), QString("PART"));
    QCOMPARE(message->property("valid").toBool(), valid);
    QCOMPARE(message->property("channel").toString(), channel);
    QCOMPARE(message->property("reason").toString(), reason);

    IrcPartMessage* partMessage = qobject_cast<IrcPartMessage*>(message);
    QVERIFY(partMessage);
    QCOMPARE(partMessage->isValid(), valid);
    QCOMPARE(partMessage->channel(), channel);
    QCOMPARE(partMessage->reason(), reason);
}
예제 #8
0
void tst_IrcMessage::testNickMessage()
{
    QFETCH(bool, valid);
    QFETCH(QByteArray, data);
    QFETCH(QString, oldNick);
    QFETCH(QString, newNick);

    IrcConnection connection;
    IrcMessage* message = IrcMessage::fromData(data, &connection);
    QCOMPARE(message->type(), IrcMessage::Nick);
    QCOMPARE(message->command(), QString("NICK"));
    QCOMPARE(message->property("valid").toBool(), valid);
    QCOMPARE(message->property("oldNick").toString(), oldNick);
    QCOMPARE(message->property("newNick").toString(), newNick);

    IrcNickMessage* nickMessage = qobject_cast<IrcNickMessage*>(message);
    QVERIFY(nickMessage);
    QCOMPARE(nickMessage->isValid(), valid);
    QCOMPARE(nickMessage->oldNick(), oldNick);
    QCOMPARE(nickMessage->newNick(), newNick);
}
예제 #9
0
void tst_IrcMessage::testInviteMessage()
{
    QFETCH(bool, valid);
    QFETCH(QByteArray, data);
    QFETCH(QString, channel);
    QFETCH(QString, user);

    IrcConnection connection;
    IrcMessage* message = IrcMessage::fromData(data, &connection);
    QCOMPARE(message->type(), IrcMessage::Invite);
    QCOMPARE(message->command(), QString("INVITE"));
    QCOMPARE(message->property("valid").toBool(), valid);
    QCOMPARE(message->property("channel").toString(), channel);
    QCOMPARE(message->property("user").toString(), user);

    IrcInviteMessage* inviteMessage = qobject_cast<IrcInviteMessage*>(message);
    QVERIFY(inviteMessage);
    QCOMPARE(inviteMessage->isValid(), valid);
    QCOMPARE(inviteMessage->channel(), channel);
    QCOMPARE(inviteMessage->user(), user);
}
예제 #10
0
void tst_IrcMessage::testCapabilityMessage()
{
    QFETCH(bool, valid);
    QFETCH(QByteArray, data);
    QFETCH(QString, subCommand);
    QFETCH(QStringList, capabilities);

    IrcConnection connection;
    IrcMessage* message = IrcMessage::fromData(data, &connection);
    QCOMPARE(message->type(), IrcMessage::Capability);
    QCOMPARE(message->command(), QString("CAP"));
    QCOMPARE(message->property("valid").toBool(), valid);
    QCOMPARE(message->property("subCommand").toString(), subCommand);
    QCOMPARE(message->property("capabilities").toStringList(), capabilities);

    IrcCapabilityMessage* capabilityMessage = qobject_cast<IrcCapabilityMessage*>(message);
    QVERIFY(capabilityMessage);
    QCOMPARE(capabilityMessage->isValid(), valid);
    QCOMPARE(capabilityMessage->subCommand(), subCommand);
    QCOMPARE(capabilityMessage->capabilities(), capabilities);
}
예제 #11
0
void tst_IrcMessage::testPrivateMessage()
{
    QFETCH(bool, valid);
    QFETCH(QString, cap);
    QFETCH(QByteArray, data);
    QFETCH(QString, target);
    QFETCH(QString, content);
    QFETCH(bool, priv);
    QFETCH(bool, action);
    QFETCH(bool, request);
    QFETCH(uint, flags);

    IrcConnection connection;
    connection.setNickName("communi");
    TestProtocol protocol(cap, &connection);
    static_cast<FriendConnection*>(&connection)->setProtocol(&protocol);

    IrcMessage* message = IrcMessage::fromData(data, &connection);
    QCOMPARE(message->type(), IrcMessage::Private);
    QCOMPARE(message->command(), QString("PRIVMSG"));
    QCOMPARE(message->property("valid").toBool(), valid);
    QCOMPARE(message->property("target").toString(), target);
    QCOMPARE(message->property("content").toString(), content);
    QCOMPARE(message->property("private").toBool(), priv);
    QCOMPARE(message->property("action").toBool(), action);
    QCOMPARE(message->property("request").toBool(), request);
    QCOMPARE(message->property("flags").toUInt(), flags);

    IrcPrivateMessage* privateMessage = qobject_cast<IrcPrivateMessage*>(message);
    QVERIFY(privateMessage);
    QCOMPARE(privateMessage->isValid(), valid);
    QCOMPARE(privateMessage->target(), target);
    QCOMPARE(privateMessage->content(), content);
    QCOMPARE(privateMessage->isPrivate(), priv);
    QCOMPARE(privateMessage->isAction(), action);
    QCOMPARE(privateMessage->isRequest(), request);
    QCOMPARE(static_cast<uint>(privateMessage->flags()), flags);
}
예제 #12
0
void tst_IrcMessage::testTopicMessage()
{
    QFETCH(bool, valid);
    QFETCH(QByteArray, data);
    QFETCH(QString, channel);
    QFETCH(QString, topic);
    QFETCH(bool, reply);

    IrcConnection connection;
    IrcMessage* message = IrcMessage::fromData(data, &connection);
    QCOMPARE(message->type(), IrcMessage::Topic);
    QCOMPARE(message->command(), QString("TOPIC"));
    QCOMPARE(message->property("valid").toBool(), valid);
    QCOMPARE(message->property("channel").toString(), channel);
    QCOMPARE(message->property("topic").toString(), topic);
    QCOMPARE(message->property("reply").toBool(), reply);

    IrcTopicMessage* topicMessage = qobject_cast<IrcTopicMessage*>(message);
    QVERIFY(topicMessage);
    QCOMPARE(topicMessage->isValid(), valid);
    QCOMPARE(topicMessage->channel(), channel);
    QCOMPARE(topicMessage->topic(), topic);
    QCOMPARE(topicMessage->isReply(), reply);
}
예제 #13
0
void tst_IrcMessage::testModeMessage()
{
    QFETCH(bool, valid);
    QFETCH(QByteArray, data);
    QFETCH(QString, target);
    QFETCH(QString, mode);
    QFETCH(QString, argument);

    IrcConnection connection;
    IrcMessage* message = IrcMessage::fromData(data, &connection);
    QCOMPARE(message->type(), IrcMessage::Mode);
    QCOMPARE(message->command(), QString("MODE"));
    QCOMPARE(message->property("valid").toBool(), valid);
    QCOMPARE(message->property("target").toString(), target);
    QCOMPARE(message->property("mode").toString(), mode);
    QCOMPARE(message->property("argument").toString(), argument);

    IrcModeMessage* modeMessage = qobject_cast<IrcModeMessage*>(message);
    QVERIFY(modeMessage);
    QCOMPARE(modeMessage->isValid(), valid);
    QCOMPARE(modeMessage->target(), target);
    QCOMPARE(modeMessage->mode(), mode);
    QCOMPARE(modeMessage->argument(), argument);
}
예제 #14
0
void tst_IrcMessage::testKickMessage()
{
    QFETCH(bool, valid);
    QFETCH(QByteArray, data);
    QFETCH(QString, channel);
    QFETCH(QString, user);
    QFETCH(QString, reason);

    IrcConnection connection;
    IrcMessage* message = IrcMessage::fromData(data, &connection);
    QCOMPARE(message->type(), IrcMessage::Kick);
    QCOMPARE(message->command(), QString("KICK"));
    QCOMPARE(message->property("valid").toBool(), valid);
    QCOMPARE(message->property("channel").toString(), channel);
    QCOMPARE(message->property("user").toString(), user);
    QCOMPARE(message->property("reason").toString(), reason);

    IrcKickMessage* kickMessage = qobject_cast<IrcKickMessage*>(message);
    QVERIFY(kickMessage);
    QCOMPARE(kickMessage->isValid(), valid);
    QCOMPARE(kickMessage->channel(), channel);
    QCOMPARE(kickMessage->user(), user);
    QCOMPARE(kickMessage->reason(), reason);
}
예제 #15
0
void IrcSessionPrivate::processLine(const QByteArray& line)
{
    Q_Q(IrcSession);

    QString encoded = encoder.encode(line);
    static bool dbg = qgetenv("COMMUNI_DEBUG").toInt();
    if (dbg) qDebug() << encoded;

    IrcMessage* msg = IrcMessage::fromString(encoded);
    if (msg)
    {
        switch (msg->type())
        {
        case IrcMessage::Numeric:
            if (static_cast<IrcNumericMessage*>(msg)->code() == Irc::RPL_WELCOME)
            {
                setNick(msg->parameters().value(0));
                connected = true;
                emit q->connected();
                emit q->connectedChanged(true);
            }
            else if (static_cast<IrcNumericMessage*>(msg)->code() == Irc::RPL_ISUPPORT)
            {
                foreach (const QString& param, msg->parameters().mid(1))
                {
                    const QStringList keyValue = param.split("=", QString::SkipEmptyParts);
                    info.insert(keyValue.value(0), keyValue.value(1));
                }
            }
            break;
        case IrcMessage::Ping:
            q->sendRaw("PONG " + static_cast<IrcPingMessage*>(msg)->argument());
            break;
        case IrcMessage::Private: {
            IrcPrivateMessage* privMsg = static_cast<IrcPrivateMessage*>(msg);
            if (privMsg->isRequest())
            {
                QString reply;
                QString request = privMsg->message().split(" ", QString::SkipEmptyParts).value(0).toUpper();
                if (request == "PING")
                    reply = privMsg->message();
                else if (request == "TIME")
                    reply = "TIME " + QLocale().toString(QDateTime::currentDateTime(), QLocale::ShortFormat);
                else if (request == "VERSION")
                    reply = QString("VERSION Communi ") + Irc::version();
                if (!reply.isNull())
                    q->sendCommand(IrcCommand::createCtcpReply(msg->sender().name(), reply));
            }
            break;
            }
        case IrcMessage::Nick:
            if (msg->sender().name() == nickName)
                setNick(static_cast<IrcNickMessage*>(msg)->nick());
            break;
        default:
            break;
        }

        emit q->messageReceived(msg);
        msg->deleteLater();
    }
예제 #16
0
void IrcSessionPrivate::processLine(const QByteArray& line)
{
    Q_Q(IrcSession);

    static bool dbg = qgetenv("COMMUNI_DEBUG").toInt();
    if (dbg) qDebug() << line;

    IrcMessage* msg = IrcMessage::fromData(line, encoding, q);
    if (msg)
    {
        switch (msg->type())
        {
        case IrcMessage::Numeric:
            if (static_cast<IrcNumericMessage*>(msg)->code() == Irc::RPL_WELCOME)
            {
                setNick(msg->parameters().value(0));
                setConnected(true);
            }
            break;
        case IrcMessage::Ping:
            q->sendRaw("PONG " + static_cast<IrcPingMessage*>(msg)->argument());
            break;
        case IrcMessage::Private: {
            IrcPrivateMessage* privMsg = static_cast<IrcPrivateMessage*>(msg);
            if (privMsg->isRequest())
            {
                IrcCommand* reply = q->createCtcpReply(privMsg);
                if (reply)
                    q->sendCommand(reply);
            }
            break;
            }
        case IrcMessage::Nick:
            if (msg->isOwn())
                setNick(static_cast<IrcNickMessage*>(msg)->nick());
            break;
        case IrcMessage::Capability:
            if (!connected)
            {
                IrcCapabilityMessage* capMsg = static_cast<IrcCapabilityMessage*>(msg);
                QString subCommand = capMsg->subCommand();
                if (subCommand == "LS")
                {
                    foreach (const QString& cap, capMsg->capabilities())
                        capabilities.insert(cap);

                    QStringList params = capMsg->parameters();
                    if (params.value(params.count() - 1) != QLatin1String("*"))
                    {
                        QStringList request;
                        emit q->capabilities(capabilities.toList(), &request);
                        if (!request.isEmpty())
                            q->sendCommand(IrcCommand::createCapability("REQ", request));
                        else
                            q->sendData("CAP END");
                    }
                }
                else if (subCommand == "ACK" || subCommand == "NAK")
                {
                    q->sendData("CAP END");
                }
            }