1
0
mirror of https://github.com/altlinux/admc.git synced 2025-03-24 06:50:13 +03:00

add expiry edit tests

This commit is contained in:
Dmitry Degtyarev 2021-07-09 13:52:22 +04:00
parent d4e395852c
commit e6c77b4ab6
5 changed files with 177 additions and 0 deletions

View File

@ -84,6 +84,7 @@ Tests for ADMC
%_bindir/admc_test_select_object_dialog
%_bindir/admc_test_logon_hours_dialog
%_bindir/admc_test_logon_computers
%_bindir/admc_test_expiry_edit
%changelog
* Fri Jul 09 2021 Dmitry Degtyarev <kevl@altlinux.org> 0.6.0-alt1

View File

@ -39,12 +39,16 @@ ExpiryWidget::ExpiryWidget()
setFrameShape(QFrame::Box);
never_check = new QCheckBox(tr("Never"));
never_check->setObjectName("never_check");
end_of_check = new QCheckBox(tr("End of:"));
end_of_check->setObjectName("end_of_check");
never_check->setAutoExclusive(true);
end_of_check->setAutoExclusive(true);
edit = new QDateEdit();
edit->setObjectName("date_edit");
auto button_group = new QButtonGroup(this);
button_group->addButton(never_check);

View File

@ -48,6 +48,7 @@ set(TEST_TARGETS
admc_test_select_object_dialog
admc_test_logon_hours_dialog
admc_test_logon_computers
admc_test_expiry_edit
)
foreach(target ${TEST_TARGETS})

View File

@ -0,0 +1,121 @@
/*
* ADMC - AD Management Center
*
* Copyright (C) 2020-2021 BaseALT Ltd.
* Copyright (C) 2020-2021 Dmitry Degtyarev
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "admc_test_expiry_edit.h"
#include "edits/expiry_edit.h"
#include "globals.h"
#include <QFormLayout>
#include <QCheckBox>
#include <QDateEdit>
void ADMCTestExpiryEdit::init() {
ADMCTest::init();
// Embed unlock edit in parent widget
QList<AttributeEdit *> edits;
edit = new ExpiryEdit(&edits, parent_widget);
auto layout = new QFormLayout();
parent_widget->setLayout(layout);
edit->add_to_layout(layout);
parent_widget->show();
QVERIFY(QTest::qWaitForWindowExposed(parent_widget, 1000));
never_check = parent_widget->findChild<QCheckBox *>("never_check");
end_of_check = parent_widget->findChild<QCheckBox *>("end_of_check");
date_edit = parent_widget->findChild<QDateEdit *>("date_edit");
// Create test user
const QString name = TEST_USER;
dn = test_object_dn(name, CLASS_USER);
const bool create_success = ad.object_add(dn, CLASS_USER);
QVERIFY(create_success);
}
void ADMCTestExpiryEdit::edited_signal_from_check() {
bool edited_signal_emitted = false;
connect(
edit, &AttributeEdit::edited,
[&edited_signal_emitted]() {
edited_signal_emitted = true;
});
end_of_check->setChecked(true);
QVERIFY(edited_signal_emitted);
}
void ADMCTestExpiryEdit::edited_signal_from_date() {
end_of_check->setChecked(true);
bool edited_signal_emitted = false;
connect(
edit, &AttributeEdit::edited,
[&edited_signal_emitted]() {
edited_signal_emitted = true;
});
const QDate date = date_edit->date();
const QDate new_date = date.addDays(1);
date_edit->setDate(new_date);
QVERIFY(edited_signal_emitted);
}
void ADMCTestExpiryEdit::load() {
const AdObject object = ad.search_object(dn);
edit->load(ad, object);
QVERIFY(never_check->isChecked());
QVERIFY(!end_of_check->isChecked());
}
void ADMCTestExpiryEdit::apply_date() {
load();
end_of_check->setChecked(true);
// NOTE: Skyrim release date
const QDate new_date = QDate(2011, 11, 11);
date_edit->setDate(new_date);
const bool apply_success = edit->apply(ad, dn);
QVERIFY(apply_success);
const AdObject updated_object = ad.search_object(dn);
const QDateTime datetime = updated_object.get_datetime(ATTRIBUTE_ACCOUNT_EXPIRES, g_adconfig);
const QDate date = datetime.date();
QVERIFY(date == new_date);
}
void ADMCTestExpiryEdit::apply_never() {
apply_date();
never_check->setChecked(true);
const bool apply_success = edit->apply(ad, dn);
QVERIFY(apply_success);
const AdObject updated_object = ad.search_object(dn);
const QString expiry_string = updated_object.get_string(ATTRIBUTE_ACCOUNT_EXPIRES);
QVERIFY(expiry_string == AD_LARGE_INTEGER_DATETIME_NEVER_1 || expiry_string == AD_LARGE_INTEGER_DATETIME_NEVER_2);
}
QTEST_MAIN(ADMCTestExpiryEdit)

View File

@ -0,0 +1,50 @@
/*
* ADMC - AD Management Center
*
* Copyright (C) 2020-2021 BaseALT Ltd.
* Copyright (C) 2020-2021 Dmitry Degtyarev
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ADMC_TEST_EXPIRY_EDIT_H
#define ADMC_TEST_EXPIRY_EDIT_H
#include "admc_test.h"
class ExpiryEdit;
class QCheckBox;
class QDateEdit;
class ADMCTestExpiryEdit : public ADMCTest {
Q_OBJECT
private slots:
void init() override;
void edited_signal_from_check();
void edited_signal_from_date();
void load();
void apply_date();
void apply_never();
private:
ExpiryEdit *edit;
QString dn;
QCheckBox *never_check;
QCheckBox *end_of_check;
QDateEdit *date_edit;
};
#endif /* ADMC_TEST_EXPIRY_EDIT_H */