1
0
mirror of https://github.com/altlinux/admc.git synced 2025-03-17 02:50:12 +03:00

handle non-existing gpo's in gplink

This commit is contained in:
Dmitry Degtyarev 2021-04-07 13:42:34 +04:00
parent a0c4f48abd
commit 4fbe721215
2 changed files with 25 additions and 0 deletions

View File

@ -95,6 +95,9 @@ void Gplink::add(const QString &gpo_case) {
void Gplink::remove(const QString &gpo_case) {
const QString gpo = gpo_case.toLower();
if (!gpo_case_map.contains(gpo)) {
return;
}
gpos_in_order.removeAll(gpo);
options.remove(gpo);
@ -103,6 +106,9 @@ void Gplink::remove(const QString &gpo_case) {
void Gplink::move_up(const QString &gpo_case) {
const QString gpo = gpo_case.toLower();
if (!gpo_case_map.contains(gpo)) {
return;
}
const int current_index = gpos_in_order.indexOf(gpo);
@ -114,6 +120,9 @@ void Gplink::move_up(const QString &gpo_case) {
void Gplink::move_down(const QString &gpo_case) {
const QString gpo = gpo_case.toLower();
if (!gpo_case_map.contains(gpo)) {
return;
}
const int current_index = gpos_in_order.indexOf(gpo);
@ -126,6 +135,9 @@ void Gplink::move_down(const QString &gpo_case) {
bool Gplink::get_option(const QString &gpo_case, const GplinkOption option) const {
const QString gpo = gpo_case.toLower();
if (!gpo_case_map.contains(gpo)) {
return false;
}
const int option_bits = options[gpo];
const bool is_set = bit_is_set(option_bits, (int) option);
@ -135,6 +147,9 @@ bool Gplink::get_option(const QString &gpo_case, const GplinkOption option) cons
void Gplink::set_option(const QString &gpo_case, const GplinkOption option, const bool value) {
const QString gpo = gpo_case.toLower();
if (!gpo_case_map.contains(gpo)) {
return;
}
const int option_bits = options[gpo];
const int option_bits_new = bit_set(option_bits, (int) option, value);

View File

@ -80,6 +80,8 @@ void ADMCTestGplink::test_remove() {
gplink.remove("b");
gplink.remove("non existing gpo");
const QString correct_gplink_string = "[LDAP://a;0][LDAP://c;0][LDAP://UPPER;0]";
test_gplink_equality(gplink, correct_gplink_string);
@ -91,6 +93,8 @@ void ADMCTestGplink::test_move_up() {
gplink.move_up("b");
gplink.move_up("non existing gpo");
const QString correct_gplink_string = "[LDAP://b;0][LDAP://a;0][LDAP://c;0][LDAP://UPPER;0]";
test_gplink_equality(gplink, correct_gplink_string);
@ -102,6 +106,8 @@ void ADMCTestGplink::test_move_down() {
gplink.move_down("b");
gplink.move_down("non existing gpo");
const QString correct_gplink_string = "[LDAP://a;0][LDAP://c;0][LDAP://b;0][LDAP://UPPER;0]";
test_gplink_equality(gplink, correct_gplink_string);
@ -116,6 +122,10 @@ void ADMCTestGplink::test_get_option() {
const bool c_option = gplink.get_option("c", GplinkOption_Disabled);
QVERIFY(c_option == true);
// Should return for non-existing gpo
const bool non_existing_option = gplink.get_option("non_existing_option", GplinkOption_Disabled);
QVERIFY(non_existing_option == false);
}
void ADMCTestGplink::test_set_option() {