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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
// Copyright 2017-2021 The Mumble Developers. All rights reserved.
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file at the root of the
// Mumble source tree or at <https://www.mumble.info/LICENSE>.
#include <QtCore>
#include <QtTest>
#include "UnresolvedServerAddress.h"
class TestUnresolvedServerAddress : public QObject {
Q_OBJECT
private slots:
void defaultCtor();
void isValid();
void ctor();
void caseInsensitive();
void equals();
void lessThan();
void qhash();
};
void TestUnresolvedServerAddress::defaultCtor() {
UnresolvedServerAddress unresolved;
QVERIFY(unresolved.hostname.isEmpty());
QVERIFY(unresolved.port == 0);
QVERIFY(!unresolved.isValid());
}
void TestUnresolvedServerAddress::isValid() {
UnresolvedServerAddress invalid1;
QVERIFY(!invalid1.isValid());
UnresolvedServerAddress invalid2(QString(), 0);
QVERIFY(!invalid2.isValid());
UnresolvedServerAddress invalid3(QString(), 64738);
QVERIFY(!invalid3.isValid());
UnresolvedServerAddress invalid4(QLatin1String("mumble.info"), 0);
QVERIFY(!invalid4.isValid());
UnresolvedServerAddress valid(QLatin1String("mumble.info"), 443);
QVERIFY(valid.isValid());
}
void TestUnresolvedServerAddress::ctor() {
UnresolvedServerAddress usa(QLatin1String("mumble.info"), 443);
QCOMPARE(usa.hostname, QString::fromLatin1("mumble.info"));
QCOMPARE(usa.port, static_cast< unsigned short >(443));
}
void TestUnresolvedServerAddress::caseInsensitive() {
UnresolvedServerAddress a(QLatin1String("mumble.info"), 443);
UnresolvedServerAddress b(QLatin1String("MUMBLE.INFO"), 443);
UnresolvedServerAddress c(QLatin1String("MuMbLe.iNFo"), 443);
QVERIFY(a == b);
QVERIFY(a == c);
}
void TestUnresolvedServerAddress::equals() {
UnresolvedServerAddress a1(QLatin1String("mumble.info"), 443);
UnresolvedServerAddress a2(QLatin1String("mumble.info"), 443);
UnresolvedServerAddress b(QLatin1String("mumble.info"), 64738);
UnresolvedServerAddress c(QLatin1String("mumble.hive.no"), 80);
QVERIFY(a1 == a2);
QVERIFY(a1 != b);
QVERIFY(a1 != c);
QVERIFY(b != c);
}
void TestUnresolvedServerAddress::lessThan() {
QList< UnresolvedServerAddress > testdata;
testdata << UnresolvedServerAddress();
testdata << UnresolvedServerAddress(QString(), 1);
testdata << UnresolvedServerAddress(QString(), 999);
testdata << UnresolvedServerAddress(QLatin1String("aaaaa"), 0);
testdata << UnresolvedServerAddress(QLatin1String("baaaa"), 0);
testdata << UnresolvedServerAddress(QLatin1String("baaaa"), 1);
testdata << UnresolvedServerAddress(QLatin1String("maaaa"), 0);
testdata << UnresolvedServerAddress(QLatin1String("maaaa"), 100);
testdata << UnresolvedServerAddress(QLatin1String("maaaa"), 64738);
testdata << UnresolvedServerAddress(QLatin1String("naaaa"), 64738);
testdata << UnresolvedServerAddress(QLatin1String("zaaaa"), 0);
testdata << UnresolvedServerAddress(QLatin1String("zaaaa"), 65535);
QList< UnresolvedServerAddress > sorted(testdata);
std::sort(sorted.begin(), sorted.end());
int i = 0;
foreach (const UnresolvedServerAddress &unresolved, sorted) {
qWarning("%i -> %s:%i", i, qPrintable(unresolved.hostname), unresolved.port);
i += 1;
}
QVERIFY(testdata == sorted);
}
void TestUnresolvedServerAddress::qhash() {
UnresolvedServerAddress a1(QLatin1String("mumble.info"), 443);
UnresolvedServerAddress a2(QLatin1String("mumble.info"), 443);
UnresolvedServerAddress b(QLatin1String("mumble.info"), 64738);
UnresolvedServerAddress c(QLatin1String("mumble.hive.no"), 80);
QVERIFY(qHash(a1) == qHash(a2));
QVERIFY(qHash(a1) != qHash(b));
QVERIFY(qHash(a1) != qHash(c));
QVERIFY(qHash(b) != qHash(c));
}
QTEST_MAIN(TestUnresolvedServerAddress)
#include "TestUnresolvedServerAddress.moc"
|