From 088c9cdd984a08d044064a24a4f898d290297b02 Mon Sep 17 00:00:00 2001 From: Jeremy Lainé Date: Wed, 18 Jul 2012 14:07:51 +0200 Subject: split result-set tests --- tests/rsm.cpp | 155 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100644 tests/rsm.cpp (limited to 'tests/rsm.cpp') diff --git a/tests/rsm.cpp b/tests/rsm.cpp new file mode 100644 index 00000000..fde8711f --- /dev/null +++ b/tests/rsm.cpp @@ -0,0 +1,155 @@ +/* + * Copyright (C) 2008-2012 The QXmpp developers + * + * Authors: + * Olivier Goffart + * Jeremy Lainé + * + * Source: + * http://code.google.com/p/qxmpp + * + * This file is a part of QXmpp library. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + */ + +#include "QXmppResultSet.h" + +#include "rsm.h" +#include "tests.h" + +void tst_QXmppResultSet::testQuery_data() +{ + QTest::addColumn("xml"); + QTest::addColumn("max"); + QTest::addColumn("index"); + QTest::addColumn("before"); + QTest::addColumn("after"); + + QTest::newRow("Example 3") << + QByteArray("" + "10" + "") + << 10 << -1 << QString() << QString(); + + QTest::newRow("Example 5") << + QByteArray("" + "10" + "peterpan@neverland.lit" + "") + << 10 << -1 << QString() << QString("peterpan@neverland.lit"); + + QTest::newRow("Example 5") << + QByteArray("" + "10" + "peter@pixyland.org" + "") + << 10 << -1 << QString("peter@pixyland.org") << QString(); + + QTest::newRow("Example 11") << + QByteArray("" + "10" + "" + "") + << 10 << -1 << QString("") << QString(); + + QTest::newRow("Example 12") << + QByteArray("" + "10" + "371" + "") + << 10 << 371 << QString() << QString(); + + + QTest::newRow("Example 15") << + QByteArray("" + "0" + "") + << 0 << -1 << QString() << QString(); +} + +void tst_QXmppResultSet::testQuery() +{ + QFETCH(QByteArray, xml); + QFETCH(int, max); + QFETCH(int, index); + QFETCH(QString, before); + QFETCH(QString, after); + + QXmppResultSetQuery iq; + parsePacket(iq, xml); + QCOMPARE(iq.max(), max); + QCOMPARE(iq.index(), index); + QCOMPARE(iq.before(), before); + QCOMPARE(iq.before().isNull(), before.isNull()); + QCOMPARE(iq.after(), after); + QCOMPARE(iq.after().isNull(), after.isNull()); + serializePacket(iq, xml); +} + +void tst_QXmppResultSet::testReply_data() +{ + QTest::addColumn("xml"); + QTest::addColumn("count"); + QTest::addColumn("index"); + QTest::addColumn("first"); + QTest::addColumn("last"); + + QTest::newRow("Example 4") << + QByteArray( "" + "stpeter@jabber.org" + "peterpan@neverland.lit" + "800" + "") + << 800 << 0 << QString("stpeter@jabber.org") << QString("peterpan@neverland.lit"); + + QTest::newRow("Example 6") << + QByteArray( "" + "stpeter@jabber.org" + "peterpan@neverland.lit" + "800" + "") + << 800 << 0 << QString("stpeter@jabber.org") << QString("peterpan@neverland.lit"); + QTest::newRow("Example 4") << + QByteArray( "" + "peter@pixyland.org" + "peter@rabbit.lit" + "800" + "") + << 800 << 10 << QString("peter@pixyland.org") << QString("peter@rabbit.lit"); + + QTest::newRow("Example 7") << + QByteArray( "" + "790" + "") + << 790 << -1 << QString() << QString(); +} + +void tst_QXmppResultSet::testReply() +{ + QFETCH(QByteArray, xml); + QFETCH(int, count); + QFETCH(int, index); + QFETCH(QString, first); + QFETCH(QString, last); + + QXmppResultSetReply iq; + parsePacket(iq, xml); + QCOMPARE(iq.count(), count); + QCOMPARE(iq.index(), index); + QCOMPARE(iq.first(), first); + QCOMPARE(iq.first().isNull(), first.isNull()); + QCOMPARE(iq.last(), last); + QCOMPARE(iq.last().isNull(), last.isNull()); + serializePacket(iq, xml); +} + -- cgit v1.2.3