aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Jahn <lnj@kaidan.im>2020-10-10 20:57:08 +0200
committerLNJ <lnj@kaidan.im>2020-10-10 22:33:41 +0200
commit3fce512b43b00f1f0b30a79d849597682ab9098f (patch)
tree6f4cfc8824ead78d3cc58c0cc1328816cfb977fa
parentaaa64971fcf3d72d8b66ebf37b8c1005017a5ea4 (diff)
downloadqxmpp-3fce512b43b00f1f0b30a79d849597682ab9098f.tar.gz
tests: Add OutgoingClient::parseHostAddress() test
-rw-r--r--src/client/QXmppOutgoingClient.h2
-rw-r--r--tests/CMakeLists.txt1
-rw-r--r--tests/qxmppoutgoingclient/tst_qxmppoutgoingclient.cpp86
3 files changed, 89 insertions, 0 deletions
diff --git a/src/client/QXmppOutgoingClient.h b/src/client/QXmppOutgoingClient.h
index 8693c877..e740babc 100644
--- a/src/client/QXmppOutgoingClient.h
+++ b/src/client/QXmppOutgoingClient.h
@@ -108,6 +108,8 @@ private:
static std::pair<QString, int> parseHostAddress(const QString &address);
friend class QXmppOutgoingClientPrivate;
+ friend class tst_QXmppOutgoingClient;
+
QXmppOutgoingClientPrivate *const d;
};
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 3b94bcc6..cb65d2bc 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -37,6 +37,7 @@ add_simple_test(qxmppmessage)
add_simple_test(qxmppmessagereceiptmanager)
add_simple_test(qxmppmixiq)
add_simple_test(qxmppnonsaslauthiq)
+add_simple_test(qxmppoutgoingclient)
add_simple_test(qxmpppushenableiq)
add_simple_test(qxmpppresence)
add_simple_test(qxmpppubsubiq)
diff --git a/tests/qxmppoutgoingclient/tst_qxmppoutgoingclient.cpp b/tests/qxmppoutgoingclient/tst_qxmppoutgoingclient.cpp
new file mode 100644
index 00000000..606fc0fc
--- /dev/null
+++ b/tests/qxmppoutgoingclient/tst_qxmppoutgoingclient.cpp
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2008-2020 The QXmpp developers
+ *
+ * Authors:
+ * 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.
+ *
+ */
+
+#include "QXmppOutgoingClient.h"
+
+#include "util.h"
+
+class tst_QXmppOutgoingClient : public QObject
+{
+ Q_OBJECT
+
+private:
+ Q_SLOT void testParseHostAddress_data();
+ Q_SLOT void testParseHostAddress();
+};
+
+void tst_QXmppOutgoingClient::testParseHostAddress_data()
+{
+ QTest::addColumn<QString>("input");
+ QTest::addColumn<QString>("resultHost");
+ QTest::addColumn<int>("resultPort");
+
+ QTest::newRow("host-and-port")
+ << QStringLiteral("qxmpp.org:443")
+ << QStringLiteral("qxmpp.org")
+ << 443;
+
+ QTest::newRow("no-port")
+ << QStringLiteral("qxmpp.org")
+ << QStringLiteral("qxmpp.org")
+ << -1;
+
+ QTest::newRow("ipv4-with-port")
+ << QStringLiteral("127.0.0.1:443")
+ << QStringLiteral("127.0.0.1")
+ << 443;
+
+ QTest::newRow("ipv4-no-port")
+ << QStringLiteral("127.0.0.1")
+ << QStringLiteral("127.0.0.1")
+ << -1;
+
+ QTest::newRow("ipv6-with-port")
+ << QStringLiteral("[2001:41D0:1:A49b::1]:9222")
+ << QStringLiteral("2001:41d0:1:a49b::1")
+ << 9222;
+
+ QTest::newRow("ipv6-no-port")
+ << QStringLiteral("[2001:41D0:1:A49b::1]")
+ << QStringLiteral("2001:41d0:1:a49b::1")
+ << -1;
+}
+
+void tst_QXmppOutgoingClient::testParseHostAddress()
+{
+ QFETCH(QString, input);
+ QFETCH(QString, resultHost);
+ QFETCH(int, resultPort);
+
+ const auto address = QXmppOutgoingClient::parseHostAddress(input);
+ QCOMPARE(address.first, resultHost);
+ QCOMPARE(address.second, resultPort);
+}
+
+QTEST_MAIN(tst_QXmppOutgoingClient)
+#include "tst_qxmppoutgoingclient.moc"