From 08a67a6a06b09a6b1e4fe0c6277b4a77e66b770a Mon Sep 17 00:00:00 2001 From: Linus Jahn Date: Tue, 4 Aug 2020 17:25:20 +0200 Subject: tests: Add PubSub utilities header --- tests/pubsubutil.h | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 tests/pubsubutil.h diff --git a/tests/pubsubutil.h b/tests/pubsubutil.h new file mode 100644 index 00000000..b927f0f5 --- /dev/null +++ b/tests/pubsubutil.h @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2008-2021 The QXmpp developers + * + * Author: + * Linus Jahn + * + * Source: + * https://github.com/qxmpp-project/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. + * + */ + +#ifndef PUBSUBUTIL_H +#define PUBSUBUTIL_H + +#include "QXmppPubSubItem.h" + +#include +#include +#include + +class TestItem : public QXmppPubSubItem +{ +public: + TestItem(const QString &id = {}) + : QXmppPubSubItem(id) + { + } + + void parsePayload(const QDomElement &payloadElement) override + { + parseCalled = true; + QCOMPARE(payloadElement.tagName(), QStringLiteral("test-payload")); + } + + void serializePayload(QXmlStreamWriter *writer) const override + { + serializeCalled = true; + writer->writeEmptyElement("test-payload"); + } + + static bool isItem(const QDomElement &element) + { + isItemCalled = true; + return QXmppPubSubItem::isItem(element, [](const QDomElement &payload) { + return payload.tagName() == "test-payload"; + }); + } + + bool parseCalled = false; + mutable bool serializeCalled = false; + static bool isItemCalled; +}; + +bool TestItem::isItemCalled = false; + +#endif // PUBSUBUTIL_H -- cgit v1.2.3