From 1c0194de975af81cf4ce66cfc0e6255cc3da1bbc Mon Sep 17 00:00:00 2001 From: Dmitry Degtyarev Date: Fri, 17 Jun 2022 13:22:23 +0400 Subject: [PATCH] add Gplink::get_gpo_order() and tests needed for other tests, not for normal usage --- src/adldap/gplink.cpp | 7 +++++++ src/adldap/gplink.h | 2 ++ tests/admc_test_gplink.cpp | 31 +++++++++++++++++++++++++++++++ tests/admc_test_gplink.h | 2 ++ 4 files changed, 42 insertions(+) diff --git a/src/adldap/gplink.cpp b/src/adldap/gplink.cpp index 032c46e8..6486a1b4 100644 --- a/src/adldap/gplink.cpp +++ b/src/adldap/gplink.cpp @@ -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; +} diff --git a/src/adldap/gplink.h b/src/adldap/gplink.h index d38aab0f..e289fa88 100644 --- a/src/adldap/gplink.h +++ b/src/adldap/gplink.h @@ -62,6 +62,8 @@ public: bool equals(const Gplink &other) const; + int get_gpo_order(const QString &gpo) const; + private: QList gpo_list; QHash options; diff --git a/tests/admc_test_gplink.cpp b/tests/admc_test_gplink.cpp index d18a6a33..11df1732 100644 --- a/tests/admc_test_gplink.cpp +++ b/tests/admc_test_gplink.cpp @@ -263,4 +263,35 @@ void ADMCTestGplink::get_gpo_list() { QCOMPARE(actual_output, expected_output); } +void ADMCTestGplink::get_gpo_order_data() { + QTest::addColumn>("input"); + QTest::addColumn("target_gpo"); + QTest::addColumn("expected_order"); + + const QList 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, 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) diff --git a/tests/admc_test_gplink.h b/tests/admc_test_gplink.h index 9d1da056..e09fec29 100644 --- a/tests/admc_test_gplink.h +++ b/tests/admc_test_gplink.h @@ -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 */