File indexing completed on 2024-12-08 12:26:15

0001 /*
0002     SPDX-FileCopyrightText: 2018 Pranav Gade <pranavgade20@gmail.com>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #include "dcbsettingtest.h"
0008 
0009 #include "settings/dcbsetting.h"
0010 
0011 #include <libnm/NetworkManager.h>
0012 
0013 #include <QTest>
0014 
0015 void DcbSettingTest::testSetting_data()
0016 {
0017     QTest::addColumn<QString>("appFcoeMode");
0018     QTest::addColumn<qint32>("appFcoePriority");
0019     QTest::addColumn<qint32>("appFipPriority");
0020     QTest::addColumn<qint32>("appIscsiPriority");
0021     QTest::addColumn<qint32>("appFcoeFlags");
0022     QTest::addColumn<qint32>("appFipFlags");
0023     QTest::addColumn<qint32>("appIscsiFlags");
0024     QTest::addColumn<qint32>("priorityGroupFlags");
0025     QTest::addColumn<qint32>("priorityFlowControlFlags");
0026     QTest::addColumn<UIntList>("priorityFlowControl");
0027     QTest::addColumn<UIntList>("priorityBandwidth");
0028     QTest::addColumn<UIntList>("priorityGroupBandwidth");
0029     QTest::addColumn<UIntList>("priorityGroupId");
0030     QTest::addColumn<UIntList>("priorityStrictBandwidth");
0031     QTest::addColumn<UIntList>("priorityTrafficClass");
0032 
0033     UIntList priorityFlowControl = {1, 1, 1, 1, 1, 1, 1, 1};
0034     UIntList priorityBandwidth = {6, 5, 6, 4, 6, 3, 6, 2};
0035     UIntList priorityGroupBandwidth = {6, 5, 6, 4, 6, 3, 6, 2};
0036     UIntList priorityGroupId = {6, 5, 6, 4, 6, 3, 6, 2};
0037     UIntList priorityStrictBandwidth = {1, 1, 1, 1, 1, 1, 1, 1};
0038     UIntList priorityTrafficClass = {6, 5, 6, 4, 6, 3, 6, 2};
0039 
0040     QTest::newRow("setting1") << QString("vn2vn") // appFcoeMode
0041                               << (qint32)2 // appFcoePriority
0042                               << (qint32)2 // appFipPriority
0043                               << (qint32)2 // appIscsiPriority
0044                               << (qint32)2 // appFcoeFlags
0045                               << (qint32)2 // appFipFlags
0046                               << (qint32)2 // appIscsiFlags
0047                               << (qint32)2 // priorityGroupFlags
0048                               << (qint32)2 // priorityFlowControlFlags
0049                               << priorityFlowControl // priorityFlowControl
0050                               << priorityBandwidth // priorityBandwidth
0051                               << priorityGroupBandwidth // priorityGroupBandwidth
0052                               << priorityGroupId // priorityGroupId
0053                               << priorityStrictBandwidth // priorityStrictBandwidth
0054                               << priorityTrafficClass; // priorityTrafficClass
0055 }
0056 
0057 void DcbSettingTest::testSetting()
0058 {
0059     QFETCH(QString, appFcoeMode);
0060     QFETCH(qint32, appFcoePriority);
0061     QFETCH(qint32, appFipPriority);
0062     QFETCH(qint32, appIscsiPriority);
0063     QFETCH(qint32, appFcoeFlags);
0064     QFETCH(qint32, appFipFlags);
0065     QFETCH(qint32, appIscsiFlags);
0066     QFETCH(qint32, priorityGroupFlags);
0067     QFETCH(qint32, priorityFlowControlFlags);
0068 
0069     QFETCH(UIntList, priorityFlowControl);
0070     QFETCH(UIntList, priorityBandwidth);
0071     QFETCH(UIntList, priorityGroupBandwidth);
0072     QFETCH(UIntList, priorityGroupId);
0073     QFETCH(UIntList, priorityStrictBandwidth);
0074     QFETCH(UIntList, priorityTrafficClass);
0075 
0076     QVariantMap map;
0077 
0078     map.insert(QLatin1String(NM_SETTING_DCB_APP_FCOE_MODE), appFcoeMode);
0079     map.insert(QLatin1String(NM_SETTING_DCB_APP_FCOE_PRIORITY), appFcoePriority);
0080     map.insert(QLatin1String(NM_SETTING_DCB_APP_FIP_PRIORITY), appFipPriority);
0081     map.insert(QLatin1String(NM_SETTING_DCB_APP_ISCSI_PRIORITY), appIscsiPriority);
0082     map.insert(QLatin1String(NM_SETTING_DCB_APP_FCOE_FLAGS), appFcoeFlags);
0083     map.insert(QLatin1String(NM_SETTING_DCB_APP_FIP_FLAGS), appFipFlags);
0084     map.insert(QLatin1String(NM_SETTING_DCB_APP_ISCSI_FLAGS), appIscsiFlags);
0085     map.insert(QLatin1String(NM_SETTING_DCB_PRIORITY_GROUP_FLAGS), priorityGroupFlags);
0086     map.insert(QLatin1String(NM_SETTING_DCB_PRIORITY_FLOW_CONTROL_FLAGS), priorityFlowControlFlags);
0087 
0088     map.insert(QLatin1String(NM_SETTING_DCB_PRIORITY_FLOW_CONTROL), QVariant::fromValue(priorityFlowControl));
0089     map.insert(QLatin1String(NM_SETTING_DCB_PRIORITY_BANDWIDTH), QVariant::fromValue(priorityBandwidth));
0090     map.insert(QLatin1String(NM_SETTING_DCB_PRIORITY_GROUP_BANDWIDTH), QVariant::fromValue(priorityGroupBandwidth));
0091     map.insert(QLatin1String(NM_SETTING_DCB_PRIORITY_GROUP_ID), QVariant::fromValue(priorityGroupId));
0092     map.insert(QLatin1String(NM_SETTING_DCB_PRIORITY_STRICT_BANDWIDTH), QVariant::fromValue(priorityStrictBandwidth));
0093     map.insert(QLatin1String(NM_SETTING_DCB_PRIORITY_TRAFFIC_CLASS), QVariant::fromValue(priorityTrafficClass));
0094 
0095     NetworkManager::DcbSetting setting;
0096     setting.fromMap(map);
0097 
0098     QVariantMap map1 = setting.toMap();
0099 
0100     // Will fail if set some default values, because they are skipped in toMap() method
0101     QVariantMap::const_iterator it = map.constBegin();
0102     while (it != map.constEnd()) {
0103         /* clang-format off */
0104         if (it.key() != QLatin1String(NM_SETTING_DCB_PRIORITY_FLOW_CONTROL)
0105             && it.key() != QLatin1String(NM_SETTING_DCB_PRIORITY_BANDWIDTH)
0106             && it.key() != QLatin1String(NM_SETTING_DCB_PRIORITY_GROUP_BANDWIDTH)
0107             && it.key() != QLatin1String(NM_SETTING_DCB_PRIORITY_GROUP_ID)
0108             && it.key() != QLatin1String(NM_SETTING_DCB_PRIORITY_STRICT_BANDWIDTH)
0109             && it.key() != QLatin1String(NM_SETTING_DCB_PRIORITY_TRAFFIC_CLASS)) { /* clang-format on */
0110             QCOMPARE(it.value(), map1.value(it.key()));
0111         }
0112         ++it;
0113     }
0114 
0115     QCOMPARE(map.value(QLatin1String(NM_SETTING_DCB_PRIORITY_FLOW_CONTROL)).value<UIntList>(),
0116              map1.value(QLatin1String(NM_SETTING_DCB_PRIORITY_FLOW_CONTROL)).value<UIntList>());
0117     QCOMPARE(map.value(QLatin1String(NM_SETTING_DCB_PRIORITY_BANDWIDTH)).value<UIntList>(),
0118              map1.value(QLatin1String(NM_SETTING_DCB_PRIORITY_BANDWIDTH)).value<UIntList>());
0119     QCOMPARE(map.value(QLatin1String(NM_SETTING_DCB_PRIORITY_GROUP_BANDWIDTH)).value<UIntList>(),
0120              map1.value(QLatin1String(NM_SETTING_DCB_PRIORITY_GROUP_BANDWIDTH)).value<UIntList>());
0121     QCOMPARE(map.value(QLatin1String(NM_SETTING_DCB_PRIORITY_GROUP_ID)).value<UIntList>(),
0122              map1.value(QLatin1String(NM_SETTING_DCB_PRIORITY_GROUP_ID)).value<UIntList>());
0123     QCOMPARE(map.value(QLatin1String(NM_SETTING_DCB_PRIORITY_STRICT_BANDWIDTH)).value<UIntList>(),
0124              map1.value(QLatin1String(NM_SETTING_DCB_PRIORITY_STRICT_BANDWIDTH)).value<UIntList>());
0125     QCOMPARE(map.value(QLatin1String(NM_SETTING_DCB_PRIORITY_TRAFFIC_CLASS)).value<UIntList>(),
0126              map1.value(QLatin1String(NM_SETTING_DCB_PRIORITY_TRAFFIC_CLASS)).value<UIntList>());
0127 }
0128 
0129 QTEST_MAIN(DcbSettingTest)
0130 
0131 #include "moc_dcbsettingtest.cpp"