1
0
mirror of https://github.com/altlinux/admc.git synced 2025-03-21 02:50:43 +03:00
admc/tests/admc_test_expiry_edit.cpp

115 lines
3.3 KiB
C++
Raw Permalink Normal View History

2021-07-09 13:52:22 +04:00
/*
* ADMC - AD Management Center
*
2025-01-09 15:46:38 +04:00
* Copyright (C) 2020-2025 BaseALT Ltd.
* Copyright (C) 2020-2025 Dmitry Degtyarev
2021-07-09 13:52:22 +04:00
*
* 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"
2021-11-09 16:35:31 +04:00
#include "attribute_edits/expiry_edit.h"
#include "attribute_edits/expiry_widget.h"
#include "attribute_edits/ui_expiry_widget.h"
2021-07-09 13:52:22 +04:00
#include "globals.h"
#include <QDateEdit>
2021-11-02 15:54:13 +04:00
#include <QFormLayout>
#include <QRadioButton>
2021-07-09 13:52:22 +04:00
2021-07-16 17:35:44 +04:00
void ADMCTestExpiryEdit::initTestCase_data() {
QTest::addColumn<QString>("button_name");
2021-07-16 17:35:44 +04:00
QTest::addColumn<QDate>("date");
QTest::addColumn<QString>("value");
QTest::newRow("end of") << "end_of_check" << QDate(2011, 11, 11) << "129655295400000000";
QTest::newRow("never") << "never_check" << QDate() << AD_LARGE_INTEGER_DATETIME_NEVER_2;
;
}
2021-07-09 13:52:22 +04:00
void ADMCTestExpiryEdit::init() {
ADMCTest::init();
auto widget = new ExpiryWidget(parent_widget);
2021-12-22 16:26:03 +04:00
edit = new ExpiryEdit(widget, parent_widget);
2021-07-09 13:52:22 +04:00
date_edit = widget->ui->date_edit;
2021-07-09 13:52:22 +04:00
QFETCH_GLOBAL(QString, button_name);
const QHash<QString, QRadioButton *> button_map = {
{"end_of_check", widget->ui->end_of_check},
{"never_check", widget->ui->never_check},
};
button = button_map[button_name];
2021-07-16 17:35:44 +04:00
2021-07-09 13:52:22 +04:00
// 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);
}
2021-07-16 17:35:44 +04:00
void ADMCTestExpiryEdit::edited_signal() {
2021-07-09 13:52:22 +04:00
bool edited_signal_emitted = false;
connect(
edit, &AttributeEdit::edited,
this,
2021-07-09 13:52:22 +04:00
[&edited_signal_emitted]() {
edited_signal_emitted = true;
});
button->setChecked(true);
2021-07-09 13:52:22 +04:00
QVERIFY(edited_signal_emitted);
}
void ADMCTestExpiryEdit::load() {
2021-07-16 17:35:44 +04:00
QFETCH_GLOBAL(QDate, date);
QFETCH_GLOBAL(QString, value);
ad.attribute_replace_string(dn, ATTRIBUTE_ACCOUNT_EXPIRES, value);
2021-07-09 13:52:22 +04:00
const AdObject object = ad.search_object(dn);
edit->load(ad, object);
QVERIFY(button->isChecked());
2021-07-16 17:35:44 +04:00
if (date_edit->isEnabled()) {
QCOMPARE(date_edit->date(), date);
}
2021-07-09 13:52:22 +04:00
}
void ADMCTestExpiryEdit::apply_unmodified() {
test_edit_apply_unmodified(edit, dn);
}
2021-07-16 17:35:44 +04:00
void ADMCTestExpiryEdit::apply() {
QFETCH_GLOBAL(QDate, date);
QFETCH_GLOBAL(QString, value);
2021-07-09 13:52:22 +04:00
2021-07-16 17:35:44 +04:00
// Replace value into something different before testing
ad.attribute_replace_string(dn, ATTRIBUTE_ACCOUNT_EXPIRES, "129655295400000001");
2021-07-09 13:52:22 +04:00
button->setChecked(true);
2021-07-16 17:35:44 +04:00
date_edit->setDate(date);
2021-07-09 13:52:22 +04:00
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);
2021-07-16 17:35:44 +04:00
QCOMPARE(expiry_string, value);
2021-07-09 13:52:22 +04:00
}
QTEST_MAIN(ADMCTestExpiryEdit)