File indexing completed on 2024-09-01 13:31:51
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 "macsecsettingtest.h" 0008 0009 #include "settings/macsecsetting.h" 0010 0011 #include <libnm/NetworkManager.h> 0012 0013 #include <QTest> 0014 0015 #if !NM_CHECK_VERSION(1, 6, 0) 0016 #define NM_SETTING_MACSEC_PARENT "parent" 0017 #define NM_SETTING_MACSEC_MODE "mode" 0018 #define NM_SETTING_MACSEC_ENCRYPT "encrypt" 0019 #define NM_SETTING_MACSEC_MKA_CAK "mka-cak" 0020 #define NM_SETTING_MACSEC_MKA_CAK_FLAGS "mka-cak-flags" 0021 #define NM_SETTING_MACSEC_MKA_CKN "mka-ckn" 0022 #define NM_SETTING_MACSEC_PORT "port" 0023 #define NM_SETTING_MACSEC_VALIDATION "validation" 0024 #endif 0025 0026 #if !NM_CHECK_VERSION(1, 12, 0) 0027 #define NM_SETTING_MACSEC_SEND_SCI "send-sci" 0028 #endif 0029 0030 void MacsecSettingTest::testSetting_data() 0031 { 0032 QTest::addColumn<bool>("encrypt"); 0033 QTest::addColumn<QString>("mkaCak"); 0034 QTest::addColumn<QString>("mkaCkn"); 0035 QTest::addColumn<qint32>("mode"); 0036 QTest::addColumn<QString>("parent"); 0037 QTest::addColumn<qint32>("port"); 0038 QTest::addColumn<bool>("sendSci"); 0039 QTest::addColumn<qint32>("validation"); 0040 QTest::addColumn<quint32>("mkaCakFlags"); 0041 0042 QTest::newRow("setting1") << false // encrypt 0043 << QString("abc") // mkaCak 0044 << QString("abc") // mkaCkn 0045 << (qint32)1 // mode 0046 << QString("abc") // parent 0047 << (qint32)666 // port 0048 << false // sendSci 0049 << (qint32)4 // validation 0050 << (quint32)6; // mkaCakFlags 0051 } 0052 0053 void MacsecSettingTest::testSetting() 0054 { 0055 QFETCH(bool, encrypt); 0056 QFETCH(QString, mkaCak); 0057 QFETCH(QString, mkaCkn); 0058 QFETCH(qint32, mode); 0059 QFETCH(QString, parent); 0060 QFETCH(qint32, port); 0061 QFETCH(bool, sendSci); 0062 QFETCH(qint32, validation); 0063 QFETCH(quint32, mkaCakFlags); 0064 0065 QVariantMap map; 0066 0067 map.insert(QLatin1String(NM_SETTING_MACSEC_ENCRYPT), encrypt); 0068 map.insert(QLatin1String(NM_SETTING_MACSEC_MKA_CAK), mkaCak); 0069 map.insert(QLatin1String(NM_SETTING_MACSEC_MKA_CKN), mkaCkn); 0070 map.insert(QLatin1String(NM_SETTING_MACSEC_MODE), mode); 0071 map.insert(QLatin1String(NM_SETTING_MACSEC_PARENT), parent); 0072 map.insert(QLatin1String(NM_SETTING_MACSEC_PORT), port); 0073 map.insert(QLatin1String(NM_SETTING_MACSEC_SEND_SCI), sendSci); 0074 map.insert(QLatin1String(NM_SETTING_MACSEC_VALIDATION), validation); 0075 map.insert(QLatin1String(NM_SETTING_MACSEC_MKA_CAK_FLAGS), mkaCakFlags); 0076 0077 NetworkManager::MacsecSetting setting; 0078 setting.fromMap(map); 0079 0080 QVariantMap map1 = setting.toMap(); 0081 0082 // Will fail if set some default values, because they are skipped in toMap() method 0083 QVariantMap::const_iterator it = map.constBegin(); 0084 while (it != map.constEnd()) { 0085 QCOMPARE(it.value(), map1.value(it.key())); 0086 ++it; 0087 } 0088 } 0089 0090 QTEST_MAIN(MacsecSettingTest) 0091 0092 #include "moc_macsecsettingtest.cpp"