mirror of
https://github.com/altlinux/admc.git
synced 2025-03-13 04:58:22 +03:00
add string edit tests
This commit is contained in:
parent
b6f0d0d63f
commit
b2aea97dd8
@ -79,6 +79,7 @@ cd BUILD
|
||||
%_bindir/admc_test_object_menu
|
||||
%_bindir/admc_test_unlock_edit
|
||||
%_bindir/admc_test_upn_edit
|
||||
%_bindir/admc_test_string_edit
|
||||
%_bindir/admc_test_gplink
|
||||
%_bindir/admc_test_ad_interface
|
||||
|
||||
|
@ -115,6 +115,7 @@ set(TEST_TARGETS
|
||||
admc_test_object_menu
|
||||
admc_test_unlock_edit
|
||||
admc_test_upn_edit
|
||||
admc_test_string_edit
|
||||
admc_test_gplink
|
||||
)
|
||||
|
||||
|
108
tests/admc_test_string_edit.cpp
Normal file
108
tests/admc_test_string_edit.cpp
Normal file
@ -0,0 +1,108 @@
|
||||
/*
|
||||
* ADMC - AD Management Center
|
||||
*
|
||||
* Copyright (C) 2020 BaseALT Ltd.
|
||||
*
|
||||
* 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_string_edit.h"
|
||||
|
||||
#include "adldap.h"
|
||||
#include "edits/string_edit.h"
|
||||
|
||||
#include <QFormLayout>
|
||||
#include <QLineEdit>
|
||||
|
||||
#define TEST_ATTRIBUTE ATTRIBUTE_FIRST_NAME
|
||||
|
||||
void ADMCTestStringEdit::init() {
|
||||
ADMCTest::init();
|
||||
|
||||
// Embed unlock edit in parent widget
|
||||
QList<AttributeEdit *> edits;
|
||||
edit = new StringEdit(TEST_ATTRIBUTE, CLASS_USER, &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));
|
||||
|
||||
tab();
|
||||
line_edit = qobject_cast<QLineEdit *>(QApplication::focusWidget());
|
||||
QVERIFY(line_edit != nullptr);
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
// edited() signal should be emitted when lineedit is edited
|
||||
void ADMCTestStringEdit::test_emit_edited_signal() {
|
||||
bool edited_signal_emitted = false;
|
||||
connect(
|
||||
edit, &AttributeEdit::edited,
|
||||
[&edited_signal_emitted]() {
|
||||
edited_signal_emitted = true;
|
||||
});
|
||||
|
||||
line_edit->setText("test");
|
||||
QVERIFY(edited_signal_emitted);
|
||||
}
|
||||
|
||||
// Edit should contain current attribute value after load()
|
||||
// call
|
||||
void ADMCTestStringEdit::load() {
|
||||
const QString test_value = "test value";
|
||||
// Set attribute value
|
||||
ad.attribute_replace_string(dn, TEST_ATTRIBUTE, test_value);
|
||||
|
||||
// Load user into edit
|
||||
const AdObject object = ad.search_object(dn);
|
||||
edit->load(ad, object);
|
||||
|
||||
const QString edit_value = line_edit->text();;
|
||||
QVERIFY(edit_value == test_value);
|
||||
}
|
||||
|
||||
// Edit should do nothing if value wasn't modified
|
||||
void ADMCTestStringEdit::apply_unmodified() {
|
||||
const AdObject object_before_apply = ad.search_object(dn);
|
||||
|
||||
const bool apply_success = edit->apply(ad, dn);
|
||||
QVERIFY(apply_success);
|
||||
|
||||
const AdObject object_after_apply = ad.search_object(dn);
|
||||
|
||||
QVERIFY(object_before_apply.get_attributes_data() == object_after_apply.get_attributes_data());
|
||||
}
|
||||
|
||||
// Edit should do change attribute to value
|
||||
void ADMCTestStringEdit::apply_modified() {
|
||||
const QString new_value = "new value";
|
||||
line_edit->setText(new_value);
|
||||
|
||||
const bool apply_success = edit->apply(ad, dn);
|
||||
QVERIFY(apply_success);
|
||||
|
||||
const AdObject object = ad.search_object(dn);
|
||||
const QString current_value = object.get_string(TEST_ATTRIBUTE);
|
||||
|
||||
QVERIFY(current_value == new_value);
|
||||
}
|
||||
|
||||
QTEST_MAIN(ADMCTestStringEdit)
|
45
tests/admc_test_string_edit.h
Normal file
45
tests/admc_test_string_edit.h
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* ADMC - AD Management Center
|
||||
*
|
||||
* Copyright (C) 2020 BaseALT Ltd.
|
||||
*
|
||||
* 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_STRING_EDIT_H
|
||||
#define ADMC_TEST_STRING_EDIT_H
|
||||
|
||||
#include "admc_test.h"
|
||||
|
||||
class StringEdit;
|
||||
class QLineEdit;
|
||||
|
||||
class ADMCTestStringEdit : public ADMCTest {
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void init() override;
|
||||
|
||||
void test_emit_edited_signal();
|
||||
void load();
|
||||
void apply_unmodified();
|
||||
void apply_modified();
|
||||
|
||||
private:
|
||||
StringEdit *edit;
|
||||
QLineEdit *line_edit;
|
||||
QString dn;
|
||||
};
|
||||
|
||||
#endif /* ADMC_TEST_STRING_EDIT_H */
|
Loading…
x
Reference in New Issue
Block a user