File: dcbsettingtest.cpp

package info (click to toggle)
kf6-networkmanager-qt 6.13.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,120 kB
  • sloc: cpp: 27,725; xml: 1,079; sh: 13; makefile: 7
file content (131 lines) | stat: -rw-r--r-- 6,681 bytes parent folder | download | duplicates (2)
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
    SPDX-FileCopyrightText: 2018 Pranav Gade <pranavgade20@gmail.com>

    SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/

#include "dcbsettingtest.h"

#include "settings/dcbsetting.h"

#include <libnm/NetworkManager.h>

#include <QTest>

void DcbSettingTest::testSetting_data()
{
    QTest::addColumn<QString>("appFcoeMode");
    QTest::addColumn<qint32>("appFcoePriority");
    QTest::addColumn<qint32>("appFipPriority");
    QTest::addColumn<qint32>("appIscsiPriority");
    QTest::addColumn<qint32>("appFcoeFlags");
    QTest::addColumn<qint32>("appFipFlags");
    QTest::addColumn<qint32>("appIscsiFlags");
    QTest::addColumn<qint32>("priorityGroupFlags");
    QTest::addColumn<qint32>("priorityFlowControlFlags");
    QTest::addColumn<UIntList>("priorityFlowControl");
    QTest::addColumn<UIntList>("priorityBandwidth");
    QTest::addColumn<UIntList>("priorityGroupBandwidth");
    QTest::addColumn<UIntList>("priorityGroupId");
    QTest::addColumn<UIntList>("priorityStrictBandwidth");
    QTest::addColumn<UIntList>("priorityTrafficClass");

    UIntList priorityFlowControl = {1, 1, 1, 1, 1, 1, 1, 1};
    UIntList priorityBandwidth = {6, 5, 6, 4, 6, 3, 6, 2};
    UIntList priorityGroupBandwidth = {6, 5, 6, 4, 6, 3, 6, 2};
    UIntList priorityGroupId = {6, 5, 6, 4, 6, 3, 6, 2};
    UIntList priorityStrictBandwidth = {1, 1, 1, 1, 1, 1, 1, 1};
    UIntList priorityTrafficClass = {6, 5, 6, 4, 6, 3, 6, 2};

    QTest::newRow("setting1") << QString("vn2vn") // appFcoeMode
                              << (qint32)2 // appFcoePriority
                              << (qint32)2 // appFipPriority
                              << (qint32)2 // appIscsiPriority
                              << (qint32)2 // appFcoeFlags
                              << (qint32)2 // appFipFlags
                              << (qint32)2 // appIscsiFlags
                              << (qint32)2 // priorityGroupFlags
                              << (qint32)2 // priorityFlowControlFlags
                              << priorityFlowControl // priorityFlowControl
                              << priorityBandwidth // priorityBandwidth
                              << priorityGroupBandwidth // priorityGroupBandwidth
                              << priorityGroupId // priorityGroupId
                              << priorityStrictBandwidth // priorityStrictBandwidth
                              << priorityTrafficClass; // priorityTrafficClass
}

void DcbSettingTest::testSetting()
{
    QFETCH(QString, appFcoeMode);
    QFETCH(qint32, appFcoePriority);
    QFETCH(qint32, appFipPriority);
    QFETCH(qint32, appIscsiPriority);
    QFETCH(qint32, appFcoeFlags);
    QFETCH(qint32, appFipFlags);
    QFETCH(qint32, appIscsiFlags);
    QFETCH(qint32, priorityGroupFlags);
    QFETCH(qint32, priorityFlowControlFlags);

    QFETCH(UIntList, priorityFlowControl);
    QFETCH(UIntList, priorityBandwidth);
    QFETCH(UIntList, priorityGroupBandwidth);
    QFETCH(UIntList, priorityGroupId);
    QFETCH(UIntList, priorityStrictBandwidth);
    QFETCH(UIntList, priorityTrafficClass);

    QVariantMap map;

    map.insert(QLatin1String(NM_SETTING_DCB_APP_FCOE_MODE), appFcoeMode);
    map.insert(QLatin1String(NM_SETTING_DCB_APP_FCOE_PRIORITY), appFcoePriority);
    map.insert(QLatin1String(NM_SETTING_DCB_APP_FIP_PRIORITY), appFipPriority);
    map.insert(QLatin1String(NM_SETTING_DCB_APP_ISCSI_PRIORITY), appIscsiPriority);
    map.insert(QLatin1String(NM_SETTING_DCB_APP_FCOE_FLAGS), appFcoeFlags);
    map.insert(QLatin1String(NM_SETTING_DCB_APP_FIP_FLAGS), appFipFlags);
    map.insert(QLatin1String(NM_SETTING_DCB_APP_ISCSI_FLAGS), appIscsiFlags);
    map.insert(QLatin1String(NM_SETTING_DCB_PRIORITY_GROUP_FLAGS), priorityGroupFlags);
    map.insert(QLatin1String(NM_SETTING_DCB_PRIORITY_FLOW_CONTROL_FLAGS), priorityFlowControlFlags);

    map.insert(QLatin1String(NM_SETTING_DCB_PRIORITY_FLOW_CONTROL), QVariant::fromValue(priorityFlowControl));
    map.insert(QLatin1String(NM_SETTING_DCB_PRIORITY_BANDWIDTH), QVariant::fromValue(priorityBandwidth));
    map.insert(QLatin1String(NM_SETTING_DCB_PRIORITY_GROUP_BANDWIDTH), QVariant::fromValue(priorityGroupBandwidth));
    map.insert(QLatin1String(NM_SETTING_DCB_PRIORITY_GROUP_ID), QVariant::fromValue(priorityGroupId));
    map.insert(QLatin1String(NM_SETTING_DCB_PRIORITY_STRICT_BANDWIDTH), QVariant::fromValue(priorityStrictBandwidth));
    map.insert(QLatin1String(NM_SETTING_DCB_PRIORITY_TRAFFIC_CLASS), QVariant::fromValue(priorityTrafficClass));

    NetworkManager::DcbSetting setting;
    setting.fromMap(map);

    QVariantMap map1 = setting.toMap();

    // Will fail if set some default values, because they are skipped in toMap() method
    QVariantMap::const_iterator it = map.constBegin();
    while (it != map.constEnd()) {
        /* clang-format off */
        if (it.key() != QLatin1String(NM_SETTING_DCB_PRIORITY_FLOW_CONTROL)
            && it.key() != QLatin1String(NM_SETTING_DCB_PRIORITY_BANDWIDTH)
            && it.key() != QLatin1String(NM_SETTING_DCB_PRIORITY_GROUP_BANDWIDTH)
            && it.key() != QLatin1String(NM_SETTING_DCB_PRIORITY_GROUP_ID)
            && it.key() != QLatin1String(NM_SETTING_DCB_PRIORITY_STRICT_BANDWIDTH)
            && it.key() != QLatin1String(NM_SETTING_DCB_PRIORITY_TRAFFIC_CLASS)) { /* clang-format on */
            QCOMPARE(it.value(), map1.value(it.key()));
        }
        ++it;
    }

    QCOMPARE(map.value(QLatin1String(NM_SETTING_DCB_PRIORITY_FLOW_CONTROL)).value<UIntList>(),
             map1.value(QLatin1String(NM_SETTING_DCB_PRIORITY_FLOW_CONTROL)).value<UIntList>());
    QCOMPARE(map.value(QLatin1String(NM_SETTING_DCB_PRIORITY_BANDWIDTH)).value<UIntList>(),
             map1.value(QLatin1String(NM_SETTING_DCB_PRIORITY_BANDWIDTH)).value<UIntList>());
    QCOMPARE(map.value(QLatin1String(NM_SETTING_DCB_PRIORITY_GROUP_BANDWIDTH)).value<UIntList>(),
             map1.value(QLatin1String(NM_SETTING_DCB_PRIORITY_GROUP_BANDWIDTH)).value<UIntList>());
    QCOMPARE(map.value(QLatin1String(NM_SETTING_DCB_PRIORITY_GROUP_ID)).value<UIntList>(),
             map1.value(QLatin1String(NM_SETTING_DCB_PRIORITY_GROUP_ID)).value<UIntList>());
    QCOMPARE(map.value(QLatin1String(NM_SETTING_DCB_PRIORITY_STRICT_BANDWIDTH)).value<UIntList>(),
             map1.value(QLatin1String(NM_SETTING_DCB_PRIORITY_STRICT_BANDWIDTH)).value<UIntList>());
    QCOMPARE(map.value(QLatin1String(NM_SETTING_DCB_PRIORITY_TRAFFIC_CLASS)).value<UIntList>(),
             map1.value(QLatin1String(NM_SETTING_DCB_PRIORITY_TRAFFIC_CLASS)).value<UIntList>());
}

QTEST_MAIN(DcbSettingTest)

#include "moc_dcbsettingtest.cpp"