Exemplo n.º 1
0
void tst_IrcCompleter::testReset()
{
    IrcBufferModel model(connection);
    connection->open();
    waitForOpened();
    waitForWritten(tst_IrcData::welcome());
    waitForWritten(tst_IrcData::join());
    IrcChannel* channel = model.get(0)->toChannel();
    QVERIFY(channel);

    IrcCompleter completer;
    completer.setBuffer(channel);

    QSignalSpy spy(&completer, SIGNAL(completed(QString,int)));
    QVERIFY(spy.isValid());

    completer.complete("Guest", 5);
    QCOMPARE(spy.count(), 1);
    QString guest1 = spy.last().at(0).toString();
    QVERIFY(guest1.startsWith("Guest"));

    completer.complete("Guest", 5);
    QCOMPARE(spy.count(), 2);
    QString guest2 = spy.last().at(0).toString();
    QVERIFY(guest2.startsWith("Guest"));
    QVERIFY(guest2 != guest1);

    completer.reset();
    completer.complete("Guest", 5);
    QCOMPARE(spy.count(), 3);
    QString guest3 = spy.last().at(0).toString();
    QCOMPARE(guest3, guest1);
}
Exemplo n.º 2
0
void tst_IrcLagTimer::testLag()
{
#if QT_VERSION >= 0x040700
    IrcLagTimer timer(connection);

    QSignalSpy lagSpy(&timer, SIGNAL(lagChanged(qint64)));
    QVERIFY(lagSpy.isValid());
    int lagCount = 0;

    connection->open();
    QVERIFY(waitForOpened());

    QCOMPARE(timer.lag(), -1ll);

    QVERIFY(waitForWritten(tst_IrcData::welcome()));

    // cheat a bit to avoid waiting a 1s interval at minimum...
    QMetaObject::invokeMethod(&timer, "_irc_pingServer");
    QVERIFY(clientSocket->waitForBytesWritten(1000));
    QVERIFY(serverSocket->waitForReadyRead(1000));

    QRegExp rx("PING communi/(\\d+)");
    QString written = QString::fromUtf8(serverSocket->readAll());
    QVERIFY(rx.indexIn(written) != -1);

    waitForWritten(QString(":irc.ser.ver PONG communi communi/%1").arg(QDateTime::currentMSecsSinceEpoch() - 1234ll).toUtf8());
    QVERIFY(timer.lag() >= 1234ll);
    QCOMPARE(lagSpy.count(), ++lagCount);
    QVERIFY(lagSpy.last().at(0).toLongLong() >= 1234ll);

    timer.setConnection(0);
    QCOMPARE(timer.lag(), -1ll);
    QCOMPARE(lagSpy.count(), ++lagCount);
    QCOMPARE(lagSpy.last().at(0).toLongLong(), -1ll);

    timer.setConnection(connection);
    QCOMPARE(timer.lag(), -1ll);
    QCOMPARE(lagSpy.count(), lagCount);

    waitForWritten(QString(":irc.ser.ver PONG communi communi/%1").arg(QDateTime::currentMSecsSinceEpoch() - 4321ll).toUtf8());
    QVERIFY(timer.lag() >= 4321ll);
    QCOMPARE(lagSpy.count(), ++lagCount);
    QVERIFY(lagSpy.last().at(0).toLongLong() >= 4321ll);

    connection->close();
    QCOMPARE(timer.lag(), -1ll);
    QCOMPARE(lagSpy.count(), ++lagCount);
    QCOMPARE(lagSpy.last().at(0).toLongLong(), -1ll);
#endif // QT_VERSION >= 0x040700
}
Exemplo n.º 3
0
void tst_IrcCompleter::testCompletion()
{
    QFETCH(QString, suffix);
    QFETCH(QString, text);
    QFETCH(int, cursor);
    QFETCH(QStringList, completions);
    QFETCH(QList<int>, positions);

    IrcBufferModel model(connection);

    connection->open();
    waitForOpened();
    waitForWritten(tst_IrcData::welcome());
    waitForWritten(tst_IrcData::join());

    model.add("qout");
    model.add("qtassistant");

    IrcCommandParser parser;
    parser.setTriggers(QStringList("/"));
    parser.addCommand(IrcCommand::Join, "JOIN <#channel> (<key>)");
    parser.addCommand(IrcCommand::Part, "PART (<#channel>) (<message...>)");
    parser.addCommand(IrcCommand::Kick, "KICK (<#channel>) <nick> (<reason...>)");
    parser.addCommand(IrcCommand::CtcpAction, "ME [target] <message...>");
    parser.addCommand(IrcCommand::CtcpAction, "ACTION <target> <message...>");
    parser.addCommand(IrcCommand::Custom, "QUERY <user>");
    parser.addCommand(IrcCommand::Quit, "QUIT (<message...>)");

    IrcCompleter completer;
    completer.setSuffix(suffix);
    completer.setBuffer(model.get(0));
    completer.setParser(&parser);

    QSignalSpy spy(&completer, SIGNAL(completed(QString,int)));
    QVERIFY(spy.isValid());

    for (int i = 0; i < completions.count(); ++i) {
        completer.complete(text, cursor);
        QCOMPARE(spy.count(), i + 1);
        QCOMPARE(spy.last().at(0).toString(), completions.at(i));
        QCOMPARE(spy.last().at(1).toInt(), positions.at(i));
    }
}
Exemplo n.º 4
0
void tst_IrcNetwork::testInfo()
{
    QFETCH(QByteArray, welcome);
    QFETCH(QString, name);
    QFETCH(QString, modes);
    QFETCH(QString, prefixes);
    QFETCH(QString, channelTypes);

    IrcNetwork* network = connection->network();

    QSignalSpy initSpy(network, SIGNAL(initialized()));
    QSignalSpy nameSpy(network, SIGNAL(nameChanged(QString)));
    QSignalSpy modesSpy(network, SIGNAL(modesChanged(QStringList)));
    QSignalSpy prefixesSpy(network, SIGNAL(prefixesChanged(QStringList)));
    QSignalSpy channelTypesSpy(network, SIGNAL(channelTypesChanged(QStringList)));

    QVERIFY(initSpy.isValid());
    QVERIFY(nameSpy.isValid());
    QVERIFY(modesSpy.isValid());
    QVERIFY(prefixesSpy.isValid());
    QVERIFY(channelTypesSpy.isValid());

    connection->open();
    QVERIFY(waitForOpened());
    QVERIFY(waitForWritten(welcome));

    QVERIFY(network->isInitialized());

    QCOMPARE(network->name(), name);
    QCOMPARE(network->modes(), modes.split("", QString::SkipEmptyParts));
    QCOMPARE(network->prefixes(), prefixes.split("", QString::SkipEmptyParts));
    QCOMPARE(network->channelTypes(), channelTypes.split("", QString::SkipEmptyParts));

    QCOMPARE(network->prefixes().count(), network->modes().count());
    for (int i = 0; i < network->prefixes().count(); ++i) {
        QString prefix = network->prefixes().at(i);
        QString mode = network->modes().at(i);
        QCOMPARE(network->prefixToMode(prefix), mode);
        QCOMPARE(network->modeToPrefix(mode), prefix);
    }

    QVERIFY(!network->channelTypes().isEmpty());
    QVERIFY(!network->isChannel("foo"));
    QVERIFY(network->isChannel(network->channelTypes().at(0) + "foo"));

    QVERIFY(!network->channelModes(IrcNetwork::TypeA).isEmpty());
    QVERIFY(!network->channelModes(IrcNetwork::TypeB).isEmpty());
    QVERIFY(!network->channelModes(IrcNetwork::TypeC).isEmpty());
    QVERIFY(!network->channelModes(IrcNetwork::TypeD).isEmpty());

    if (welcome.contains("NICKLEN="))
        QVERIFY(network->numericLimit(IrcNetwork::NickLength) != -1);
    else
        QCOMPARE(network->numericLimit(IrcNetwork::NickLength), -1);
    if (welcome.contains("CHANNELLEN="))
        QVERIFY(network->numericLimit(IrcNetwork::ChannelLength) != -1);
    else
        QCOMPARE(network->numericLimit(IrcNetwork::ChannelLength), -1);
    if (welcome.contains("TOPICLEN="))
        QVERIFY(network->numericLimit(IrcNetwork::TopicLength) != -1);
    else
        QCOMPARE(network->numericLimit(IrcNetwork::TopicLength), -1);
    if (welcome.contains("KICKLEN="))
        QVERIFY(network->numericLimit(IrcNetwork::KickReasonLength) != -1);
    else
        QCOMPARE(network->numericLimit(IrcNetwork::KickReasonLength), -1);
    if (welcome.contains("AWAYLEN="))
        QVERIFY(network->numericLimit(IrcNetwork::AwayReasonLength) != -1);
    else
        QCOMPARE(network->numericLimit(IrcNetwork::AwayReasonLength), -1);
    if (welcome.contains("MODES="))
        QVERIFY(network->numericLimit(IrcNetwork::ModeCount) != -1);
    else
        QCOMPARE(network->numericLimit(IrcNetwork::ModeCount), -1);
    if (welcome.contains("MONITOR="))
        QVERIFY(network->numericLimit(IrcNetwork::MonitorCount) != -1);
    else
        QCOMPARE(network->numericLimit(IrcNetwork::MonitorCount), -1);

    QCOMPARE(network->numericLimit(IrcNetwork::MessageLength), 512); // hard-coded :/

    if (welcome.contains("MAXLIST=")) {
        bool limited = false;
        foreach (const QString& mode, network->modes())
        if (network->modeLimit(mode) != -1)
            limited = true;
        QVERIFY(limited);
    }
Exemplo n.º 5
0
 inline AVFormatContext *getFormatCtx() const
 {
     return waitForOpened() ? m_formatCtx : nullptr;
 }