mirror of
https://github.com/altlinux/admc.git
synced 2025-02-19 01:58:09 +03:00
add octet editor tests
This commit is contained in:
parent
629b8a5287
commit
d4274dec32
@ -91,6 +91,7 @@ Tests for ADMC
|
||||
%_bindir/admc_test_datetime_edit
|
||||
%_bindir/admc_test_manager_edit
|
||||
%_bindir/admc_test_delegation_edit
|
||||
%_bindir/admc_test_octet_editor
|
||||
|
||||
%changelog
|
||||
* Fri Jul 09 2021 Dmitry Degtyarev <kevl@altlinux.org> 0.6.0-alt1
|
||||
|
@ -57,9 +57,7 @@ OctetEditor::OctetEditor(const QString attribute, const QList<QByteArray> values
|
||||
const QFont fixed_font = QFontDatabase::systemFont(QFontDatabase::FixedFont);
|
||||
edit->setFont(fixed_font);
|
||||
|
||||
const QByteArray value = values.value(0, QByteArray());
|
||||
const QString value_string = octet_bytes_to_string(value, current_format(format_combo));
|
||||
edit->setPlainText(value_string);
|
||||
load(values);
|
||||
|
||||
if (g_adconfig->get_attribute_is_system_only(attribute)) {
|
||||
edit->setReadOnly(true);
|
||||
@ -95,9 +93,13 @@ void OctetEditor::accept() {
|
||||
}
|
||||
}
|
||||
|
||||
void OctetEditor::on_format_combo() {
|
||||
static int prev_index = 0;
|
||||
void OctetEditor::load(const QList<QByteArray> values) {
|
||||
const QByteArray value = values.value(0, QByteArray());
|
||||
const QString value_string = octet_bytes_to_string(value, current_format(format_combo));
|
||||
edit->setPlainText(value_string);
|
||||
}
|
||||
|
||||
void OctetEditor::on_format_combo() {
|
||||
// Check that input is ok for previous format, otherwise
|
||||
// won't be able to convert it to new format
|
||||
const bool input_ok_for_prev_format = check_input(prev_format);
|
||||
@ -116,7 +118,7 @@ void OctetEditor::on_format_combo() {
|
||||
// Revert to previous format if input is invalid for
|
||||
// current format
|
||||
format_combo->blockSignals(true);
|
||||
format_combo->setCurrentIndex(prev_index);
|
||||
format_combo->setCurrentIndex((int) prev_format);
|
||||
format_combo->blockSignals(false);
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ class QPlainTextEdit;
|
||||
class QComboBox;
|
||||
|
||||
enum OctetDisplayFormat {
|
||||
OctetDisplayFormat_Hexadecimal,
|
||||
OctetDisplayFormat_Hexadecimal = 0,
|
||||
OctetDisplayFormat_Binary,
|
||||
OctetDisplayFormat_Decimal,
|
||||
OctetDisplayFormat_Octal,
|
||||
@ -41,6 +41,7 @@ public:
|
||||
|
||||
QList<QByteArray> get_new_values() const override;
|
||||
void accept() override;
|
||||
void load(const QList<QByteArray> values);
|
||||
|
||||
private slots:
|
||||
void on_format_combo();
|
||||
|
@ -55,6 +55,7 @@ set(TEST_TARGETS
|
||||
admc_test_datetime_edit
|
||||
admc_test_manager_edit
|
||||
admc_test_delegation_edit
|
||||
admc_test_octet_editor
|
||||
)
|
||||
|
||||
foreach(target ${TEST_TARGETS})
|
||||
|
139
tests/admc_test_octet_editor.cpp
Normal file
139
tests/admc_test_octet_editor.cpp
Normal file
@ -0,0 +1,139 @@
|
||||
/*
|
||||
* 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_octet_editor.h"
|
||||
|
||||
#include "editors/octet_editor.h"
|
||||
|
||||
#include <QPlainTextEdit>
|
||||
#include <QComboBox>
|
||||
|
||||
enum FormatIndex {
|
||||
FormatIndex_Hex = 0,
|
||||
FormatIndex_Bin,
|
||||
FormatIndex_Dec,
|
||||
FormatIndex_Oct,
|
||||
};
|
||||
|
||||
const QList<FormatIndex> index_list = {
|
||||
FormatIndex_Hex,
|
||||
FormatIndex_Bin,
|
||||
FormatIndex_Dec,
|
||||
FormatIndex_Oct,
|
||||
};
|
||||
|
||||
const QHash<FormatIndex, QString> formatted_value_list = {
|
||||
{FormatIndex_Hex, "31 32 33 34 35"},
|
||||
{FormatIndex_Bin, "00110001 00110010 00110011 00110100 00110101"},
|
||||
{FormatIndex_Dec, "049 050 051 052 053"},
|
||||
{FormatIndex_Oct, "061 062 063 064 065"},
|
||||
};
|
||||
|
||||
const QList<QByteArray> value_bytes = {QByteArray("12345")};
|
||||
|
||||
FormatIndex next_format_index(const FormatIndex index);
|
||||
|
||||
void ADMCTestOctetEdit::init() {
|
||||
ADMCTest::init();
|
||||
|
||||
edit = new OctetEditor(ATTRIBUTE_DESCRIPTION, QList<QByteArray>(), parent_widget);
|
||||
edit->open();
|
||||
QVERIFY(QTest::qWaitForWindowExposed(edit, 1000));
|
||||
|
||||
format_combo = edit->findChild<QComboBox *>();
|
||||
QVERIFY(format_combo);
|
||||
|
||||
text_edit = edit->findChild<QPlainTextEdit *>();
|
||||
QVERIFY(text_edit);
|
||||
}
|
||||
|
||||
void ADMCTestOctetEdit::display() {
|
||||
edit->load(value_bytes);
|
||||
|
||||
for (const FormatIndex &index : index_list) {
|
||||
format_combo->setCurrentIndex(index);
|
||||
const QString correct_value = formatted_value_list[index];
|
||||
const QString value = text_edit->toPlainText();
|
||||
QVERIFY(value == correct_value);
|
||||
}
|
||||
}
|
||||
|
||||
// Check that edit correctly converts formatted strings back
|
||||
// to bytes for each format
|
||||
void ADMCTestOctetEdit::get_new_values() {
|
||||
edit->load({});
|
||||
|
||||
for (const FormatIndex &index : index_list) {
|
||||
format_combo->setCurrentIndex(index);
|
||||
const QString value = formatted_value_list[index];
|
||||
text_edit->setPlainText(value);
|
||||
|
||||
const QList<QByteArray> current_value_bytes = edit->get_new_values();
|
||||
QVERIFY(current_value_bytes == value_bytes);
|
||||
}
|
||||
}
|
||||
|
||||
void ADMCTestOctetEdit::handle_empty_value() {
|
||||
edit->load({});
|
||||
|
||||
for (const FormatIndex &index : index_list) {
|
||||
// Check that empty value correctly loads and is
|
||||
// displayed as empty string
|
||||
format_combo->setCurrentIndex(index);
|
||||
QVERIFY(text_edit->toPlainText().isEmpty());
|
||||
|
||||
// Check that edit correctly switches formats when
|
||||
// value is empty
|
||||
const FormatIndex next_index = next_format_index(index);
|
||||
format_combo->setCurrentIndex(next_index);
|
||||
QVERIFY(format_combo->currentIndex() == next_index);
|
||||
}
|
||||
}
|
||||
|
||||
// Check that when incorrectly formatted value is entered,
|
||||
// edit fails to switch to different format
|
||||
void ADMCTestOctetEdit::handle_incorrect_input() {
|
||||
edit->load({});
|
||||
|
||||
for (const FormatIndex &index : index_list) {
|
||||
text_edit->setPlainText("");
|
||||
|
||||
format_combo->setCurrentIndex(index);
|
||||
text_edit->setPlainText("incorrect format");
|
||||
|
||||
const FormatIndex next_index = next_format_index(index);
|
||||
format_combo->setCurrentIndex(next_index);
|
||||
close_message_box();
|
||||
|
||||
QVERIFY(format_combo->currentIndex() == index);
|
||||
}
|
||||
}
|
||||
|
||||
FormatIndex next_format_index(const FormatIndex index) {
|
||||
int out = index + 1;
|
||||
|
||||
if (!index_list.contains((FormatIndex) out)) {
|
||||
out = index_list[0];
|
||||
}
|
||||
|
||||
return (FormatIndex) out;
|
||||
}
|
||||
|
||||
QTEST_MAIN(ADMCTestOctetEdit)
|
47
tests/admc_test_octet_editor.h
Normal file
47
tests/admc_test_octet_editor.h
Normal file
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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_OCTET_EDIT_H
|
||||
#define ADMC_TEST_OCTET_EDIT_H
|
||||
|
||||
#include "admc_test.h"
|
||||
|
||||
class OctetEditor;
|
||||
class QComboBox;
|
||||
class QPlainTextEdit;
|
||||
|
||||
class ADMCTestOctetEdit : public ADMCTest {
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void init() override;
|
||||
|
||||
void display();
|
||||
void get_new_values();
|
||||
void handle_empty_value();
|
||||
void handle_incorrect_input();
|
||||
|
||||
private:
|
||||
OctetEditor *edit;
|
||||
QComboBox *format_combo;
|
||||
QPlainTextEdit *text_edit;
|
||||
};
|
||||
|
||||
#endif /* ADMC_TEST_OCTET_EDIT_H */
|
Loading…
x
Reference in New Issue
Block a user