1
0
mirror of https://github.com/altlinux/admc.git synced 2025-01-09 05:18:22 +03:00

add Gplink::get_gpo_order()

and tests
needed for other tests, not for normal usage
This commit is contained in:
Dmitry Degtyarev 2022-06-17 13:22:23 +04:00
parent b07173bf8b
commit 1c0194de97
4 changed files with 42 additions and 0 deletions

View File

@ -269,3 +269,10 @@ void Gplink::set_option(const QString &gpo_case, const GplinkOption option, cons
bool Gplink::equals(const Gplink &other) const {
return (to_string() == other.to_string());
}
int Gplink::get_gpo_order(const QString &gpo_case) const {
const QString gpo = gpo_case.toLower();
const int out = gpo_list.indexOf(gpo);
return out;
}

View File

@ -62,6 +62,8 @@ public:
bool equals(const Gplink &other) const;
int get_gpo_order(const QString &gpo) const;
private:
QList<QString> gpo_list;
QHash<QString, int> options;

View File

@ -263,4 +263,35 @@ void ADMCTestGplink::get_gpo_list() {
QCOMPARE(actual_output, expected_output);
}
void ADMCTestGplink::get_gpo_order_data() {
QTest::addColumn<QList<QString>>("input");
QTest::addColumn<QString>("target_gpo");
QTest::addColumn<int>("expected_order");
const QList<QString> gpo_list = {
dn_A,
dn_B,
dn_C,
};
QTest::newRow("A") << gpo_list << dn_A << 0;
QTest::newRow("B") << gpo_list << dn_B << 1;
QTest::newRow("C") << gpo_list << dn_C << 2;
}
void ADMCTestGplink::get_gpo_order() {
QFETCH(QList<QString>, input);
QFETCH(QString, target_gpo);
QFETCH(int, expected_order);
Gplink gplink;
for (const QString &gpo : input) {
gplink.add(gpo);
}
const int actual_order = gplink.get_gpo_order(target_gpo);
QCOMPARE(actual_order, expected_order);
}
QTEST_MAIN(ADMCTestGplink)

View File

@ -52,6 +52,8 @@ private slots:
void set_option();
void get_gpo_list_data();
void get_gpo_list();
void get_gpo_order_data();
void get_gpo_order();
};
#endif /* ADMC_TEST_GPLINK_H */