This repository has been archived by the owner on Oct 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
tracker_test.cpp
49 lines (40 loc) · 1.7 KB
/
tracker_test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// SPDX-FileCopyrightText: 2015-2023 Alexey Rochev
//
// SPDX-License-Identifier: GPL-3.0-or-later
#include <array>
#include <QTest>
#include "tracker.h"
using namespace libtremotesf::impl;
class TrackerTest final : public QObject {
Q_OBJECT
private slots:
void registrableDomainTest() {
QCOMPARE(registrableDomainFromUrl(QUrl("https://doc.qt.io")), QString("qt.io"));
QCOMPARE(registrableDomainFromUrl(QUrl("https://github.com")), QString("github.com"));
QCOMPARE(registrableDomainFromUrl(QUrl("https://www.bbc.co.uk/")), QString("bbc.co.uk"));
QCOMPARE(registrableDomainFromUrl(QUrl("https://en.wikipedia.org/wiki/Main_Page")), QString("wikipedia.org"));
QCOMPARE(registrableDomainFromUrl(QUrl("https://forgot.his.name")), QString("forgot.his.name"));
}
void registrableDomainIpTest() {
constexpr std::array ips{"127.0.0.1", "2001:0db8:0000:0000:0000:ff00:0042:8329"};
for (const auto& ip : ips) {
const QHostAddress expectedIp(ip);
QUrl url{};
url.setScheme("https");
if (expectedIp.protocol() == QAbstractSocket::IPv6Protocol) {
url.setHost(fmt::format("[{}]", ip).c_str());
} else {
url.setHost(ip);
}
const auto actualIpString = registrableDomainFromUrl(url);
const QHostAddress actualIp(actualIpString);
QCOMPARE(actualIp, expectedIp);
}
}
void registrableDomainUnknownTest() {
QCOMPARE(registrableDomainFromUrl(QUrl("https://foobar")), QString("foobar"));
QCOMPARE(registrableDomainFromUrl(QUrl("https://")), QString());
}
};
QTEST_MAIN(TrackerTest)
#include "tracker_test.moc"