summaryrefslogtreecommitdiffstats
path: root/tests/auto/network/access/qhttpheadershelper/tst_qhttpheadershelper.cpp
blob: b204d0cbe3c2c02c8ca97e480d0c768f47949d6d (plain)
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
// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only

#include <QtNetwork/qhttpheaders.h>
#include <QtNetwork/private/qhttpheadershelper_p.h>

#include <QtTest/qtest.h>

using namespace Qt::StringLiterals;

class tst_QHttpHeadersHelper : public QObject
{
    Q_OBJECT

private slots:
    void testCompareStrict();

private:
    static constexpr QAnyStringView n1{"name1"};
    static constexpr QAnyStringView n2{"name2"};
    static constexpr QAnyStringView v1{"value1"};
    static constexpr QAnyStringView v2{"value2"};
    static constexpr QAnyStringView N1{"NAME1"};
    static constexpr QAnyStringView N2{"NAME2"};
    static constexpr QAnyStringView V1{"VALUE1"};
    static constexpr QAnyStringView V2{"VALUE2"};
};

void tst_QHttpHeadersHelper::testCompareStrict()
{
    using namespace QHttpHeadersHelper;

    // Basic comparisons
    QHttpHeaders h1;
    QHttpHeaders h2;
    QVERIFY(compareStrict(h1, h2)); // empties
    h1.append(n1, v1);
    QVERIFY(compareStrict(h1, h1)); // self
    h2.append(n1, v1);
    QVERIFY(compareStrict(h1, h2));
    h1.append(n2, v2);
    QVERIFY(!compareStrict(h1, h2));
    h1.removeAll(n2);
    QVERIFY(compareStrict(h1, h2));

    // Order-sensitivity
    h1.clear();
    h2.clear();
    // Same headers but in different order
    h1.append(n1, v1);
    h1.append(n2, v2);
    h2.append(n2, v2);
    h2.append(n1, v1);
    QVERIFY(!compareStrict(h1, h2));

    // Different number of headers
    h1.clear();
    h2.clear();
    h1.append(n1, v1);
    h2.append(n1, v1);
    h2.append(n2, v2);
    QVERIFY(!compareStrict(h1, h2));

    // Same header name, multiple values
    h1.clear();
    h2.clear();
    h1.append(n1, v1);
    h1.append(n1, v2);
    h2.append(n1, v1);
    QVERIFY(!compareStrict(h1, h2));
    h2.append(n1, v2);
    QVERIFY(compareStrict(h1, h2));
}

QTEST_MAIN(tst_QHttpHeadersHelper)
#include "tst_qhttpheadershelper.moc"