From 7587dfafe8917fccf5917682a7e5e9657cfa6d08 Mon Sep 17 00:00:00 2001 From: Melvin Keskin Date: Thu, 2 Sep 2021 23:24:07 +0200 Subject: Add QXmppOmemoDeviceElement MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Germán Márquez Mejía --- tests/CMakeLists.txt | 1 + tests/qxmppomemodata/tst_qxmppomemodata.cpp | 105 ++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 tests/qxmppomemodata/tst_qxmppomemodata.cpp (limited to 'tests') diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 0b7efc43..8a4f278d 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -36,6 +36,7 @@ add_simple_test(qxmppmessage) add_simple_test(qxmppmessagereceiptmanager) add_simple_test(qxmppmixiq) add_simple_test(qxmppnonsaslauthiq) +add_simple_test(qxmppomemodata) add_simple_test(qxmppoutgoingclient) add_simple_test(qxmpppushenableiq) add_simple_test(qxmpppresence) diff --git a/tests/qxmppomemodata/tst_qxmppomemodata.cpp b/tests/qxmppomemodata/tst_qxmppomemodata.cpp new file mode 100644 index 00000000..4084a8c7 --- /dev/null +++ b/tests/qxmppomemodata/tst_qxmppomemodata.cpp @@ -0,0 +1,105 @@ +/* + * Copyright (C) 2008-2021 The QXmpp developers + * + * Authors: + * Germán Márquez Mejía + * Melvin Keskin + * + * 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. + * + */ + +#include "QXmppOmemoDeviceElement.h" + +#include "util.h" +#include + +class tst_QXmppOmemoData : public QObject +{ + Q_OBJECT + +private slots: + void testIsOmemoDeviceElement_data(); + void testIsOmemoDeviceElement(); + void testOmemoDeviceElement_data(); + void testOmemoDeviceElement(); +}; + +void tst_QXmppOmemoData::testIsOmemoDeviceElement_data() +{ + QTest::addColumn("xml"); + QTest::addColumn("isValid"); + + QTest::newRow("valid") + << QByteArrayLiteral("") + << true; + QTest::newRow("invalidTag") + << QByteArrayLiteral("") + << false; + QTest::newRow("invalidNamespace") + << QByteArrayLiteral("") + << false; +} + +void tst_QXmppOmemoData::testIsOmemoDeviceElement() +{ + QFETCH(QByteArray, xml); + QFETCH(bool, isValid); + + QDomDocument doc; + QCOMPARE(doc.setContent(xml, true), true); + const QDomElement element = doc.documentElement(); + QCOMPARE(QXmppOmemoDeviceElement::isOmemoDeviceElement(element), isValid); +} + +void tst_QXmppOmemoData::testOmemoDeviceElement_data() +{ + QTest::addColumn("xml"); + QTest::addColumn("id"); + QTest::addColumn("label"); + + QTest::newRow("id") + << QByteArrayLiteral("") + << uint32_t(12345) + << QString(); + QTest::newRow("idAndLabel") + << QByteArrayLiteral("") + << uint32_t(4223) + << QStringLiteral("Gajim on Ubuntu Linux"); +} + +void tst_QXmppOmemoData::testOmemoDeviceElement() +{ + QFETCH(QByteArray, xml); + QFETCH(uint32_t, id); + QFETCH(QString, label); + + QXmppOmemoDeviceElement deviceElement1; + parsePacket(deviceElement1, xml); + QCOMPARE(deviceElement1.id(), id); + QCOMPARE(deviceElement1.label(), label); + serializePacket(deviceElement1, xml); + + QXmppOmemoDeviceElement deviceElement2; + deviceElement2.setId(id); + deviceElement2.setLabel(label); + QCOMPARE(deviceElement2.id(), id); + QCOMPARE(deviceElement2.label(), label); + serializePacket(deviceElement2, xml); +} + +QTEST_MAIN(tst_QXmppOmemoData) +#include "tst_qxmppomemodata.moc" -- cgit v1.2.3