From e6c77b4ab6422c264027637843b7fc0156d27574 Mon Sep 17 00:00:00 2001 From: Dmitry Degtyarev Date: Fri, 9 Jul 2021 13:52:22 +0400 Subject: [PATCH] add expiry edit tests --- .gear/admc.spec | 1 + src/admc/edits/expiry_widget.cpp | 4 + tests/CMakeLists.txt | 1 + tests/admc_test_expiry_edit.cpp | 121 +++++++++++++++++++++++++++++++ tests/admc_test_expiry_edit.h | 50 +++++++++++++ 5 files changed, 177 insertions(+) create mode 100644 tests/admc_test_expiry_edit.cpp create mode 100644 tests/admc_test_expiry_edit.h diff --git a/.gear/admc.spec b/.gear/admc.spec index de2eff2b..d19b4baf 100644 --- a/.gear/admc.spec +++ b/.gear/admc.spec @@ -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 0.6.0-alt1 diff --git a/src/admc/edits/expiry_widget.cpp b/src/admc/edits/expiry_widget.cpp index d3ccfcf2..52debd1b 100644 --- a/src/admc/edits/expiry_widget.cpp +++ b/src/admc/edits/expiry_widget.cpp @@ -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); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 1cc07da1..735f25ea 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -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}) diff --git a/tests/admc_test_expiry_edit.cpp b/tests/admc_test_expiry_edit.cpp new file mode 100644 index 00000000..1bcbb877 --- /dev/null +++ b/tests/admc_test_expiry_edit.cpp @@ -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 . + */ + +#include "admc_test_expiry_edit.h" + +#include "edits/expiry_edit.h" +#include "globals.h" + +#include +#include +#include + +void ADMCTestExpiryEdit::init() { + ADMCTest::init(); + + // Embed unlock edit in parent widget + QList 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("never_check"); + end_of_check = parent_widget->findChild("end_of_check"); + date_edit = parent_widget->findChild("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) diff --git a/tests/admc_test_expiry_edit.h b/tests/admc_test_expiry_edit.h new file mode 100644 index 00000000..b8c49acd --- /dev/null +++ b/tests/admc_test_expiry_edit.h @@ -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 . + */ + +#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 */