1
0
mirror of https://github.com/altlinux/admc.git synced 2025-02-01 13:47:06 +03:00
admc/tests/admc_test_logon_hours_dialog.cpp

177 lines
4.7 KiB
C++
Raw Normal View History

2021-07-01 16:08:19 +04:00
/*
* ADMC - AD Management Center
*
2022-04-06 15:59:32 +04:00
* Copyright (C) 2020-2022 BaseALT Ltd.
* Copyright (C) 2020-2022 Dmitry Degtyarev
2021-07-01 16:08:19 +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_logon_hours_dialog.h"
2021-11-09 16:35:31 +04:00
#include "attribute_edits/logon_hours_dialog.h"
#include "attribute_edits/ui_logon_hours_dialog.h"
2021-07-01 16:08:19 +04:00
2021-07-02 15:15:56 +04:00
#include <QRadioButton>
2021-11-02 15:54:13 +04:00
#include <QStandardItemModel>
#include <QTableView>
2021-07-01 16:08:19 +04:00
2021-11-16 16:29:34 +04:00
void ADMCTestLogonHoursDialog::open_dialog(const QByteArray &value) {
dialog = new LogonHoursDialog(value, parent_widget);
2021-07-01 16:08:19 +04:00
dialog->open();
QVERIFY(QTest::qWaitForWindowExposed(dialog, 1000));
local_time_button = dialog->ui->local_time_button;
utc_time_button = dialog->ui->utc_time_button;
view = dialog->ui->view;
2021-07-01 16:08:19 +04:00
model = dialog->findChild<QStandardItemModel *>();
QVERIFY(model);
2021-07-01 16:08:19 +04:00
selection_model = view->selectionModel();
}
auto empty_day = []() {
QList<bool> out;
2021-07-02 16:53:32 +04:00
for (int i = 0; i < HOURS_IN_DAY; i++) {
2021-07-01 16:08:19 +04:00
out.append(false);
}
return out;
};
2021-07-08 17:04:59 +04:00
auto empty_week = []() {
2021-07-01 16:08:19 +04:00
QList<QList<bool>> out;
2021-07-02 16:53:32 +04:00
for (int day = 0; day < DAYS_IN_WEEK; day++) {
2021-07-01 16:08:19 +04:00
out.append(empty_day());
}
return out;
};
2021-07-02 11:57:55 +04:00
const QByteArray empty_bytes = QByteArray(LOGON_HOURS_SIZE, '\0');
2021-07-08 17:04:59 +04:00
const QByteArray test_bytes = []() {
2021-07-02 11:57:55 +04:00
QByteArray out = empty_bytes;
2021-07-01 16:08:19 +04:00
out[Weekday_Tuesday * 3] = 'a';
return out;
}();
2021-07-08 17:04:59 +04:00
const QList<QList<bool>> test_bools = []() {
2021-07-01 16:08:19 +04:00
QList<QList<bool>> out = empty_week();
out[Weekday_Tuesday][0] = true;
out[Weekday_Tuesday][5] = true;
out[Weekday_Tuesday][6] = true;
return out;
}();
void ADMCTestLogonHoursDialog::conversion_funs() {
const QList<QList<bool>> converted_bools = logon_hours_to_bools(test_bytes);
QCOMPARE(converted_bools, test_bools);
2021-07-01 16:08:19 +04:00
const QByteArray converted_bytes = logon_hours_to_bytes(test_bools);
QCOMPARE(converted_bytes, test_bytes);
2021-07-01 16:08:19 +04:00
}
2021-11-16 16:29:34 +04:00
void ADMCTestLogonHoursDialog::load_data() {
QTest::addColumn<QByteArray>("value");
QTest::newRow("empty") << empty_bytes;
QTest::newRow("non-empty") << test_bytes;
}
2021-07-01 16:08:19 +04:00
void ADMCTestLogonHoursDialog::load() {
2021-11-16 16:29:34 +04:00
QFETCH(QByteArray, value);
open_dialog(value);
2021-07-02 15:15:56 +04:00
utc_time_button->setChecked(true);
2021-11-02 15:54:13 +04:00
2021-11-16 16:29:34 +04:00
const QByteArray actual_value = dialog->get();
QCOMPARE(actual_value, value);
}
void ADMCTestLogonHoursDialog::select() {
open_dialog(test_bytes);
2021-11-16 16:29:34 +04:00
utc_time_button->setChecked(true);
2021-07-01 16:08:19 +04:00
const QList<QModelIndex> selected = selection_model->selectedIndexes();
const QSet<QModelIndex> selected_set = QSet<QModelIndex>(selected.begin(), selected.end());
2021-07-01 16:08:19 +04:00
const QSet<QModelIndex> correct_selected_set = {
model->index(2, 0),
model->index(2, 5),
model->index(2, 6),
};
QCOMPARE(selected_set, correct_selected_set);
2021-07-01 16:08:19 +04:00
}
void ADMCTestLogonHoursDialog::load_empty() {
2021-11-16 16:29:34 +04:00
open_dialog(QByteArray());
2021-11-16 16:29:34 +04:00
const QByteArray actual_value = dialog->get();
const QByteArray expected_value = QByteArray();
QCOMPARE(actual_value, expected_value);
2021-07-01 16:08:19 +04:00
}
void ADMCTestLogonHoursDialog::handle_timezone() {
const QByteArray bytes = [&]() {
QByteArray out = empty_bytes;
out[Weekday_Tuesday * 3] = 0x01;
return out;
}();
2021-11-16 16:29:34 +04:00
open_dialog(bytes);
// First do UTC
utc_time_button->setChecked(true);
const QList<QModelIndex> correct_utc_selected = {
model->index(Weekday_Tuesday, 0),
};
const QList<QModelIndex> utc_selected = selection_model->selectedIndexes();
QCOMPARE(utc_selected, correct_utc_selected);
// Then local time
local_time_button->setChecked(true);
const QList<QModelIndex> correct_local_selected = [&]() {
// UTC rows
int row = Weekday_Tuesday;
int col = 0;
// Apply timezone offset
const int offset = get_current_utc_offset();
col += offset;
if (col < 0) {
2021-07-02 16:53:32 +04:00
col += HOURS_IN_DAY;
row--;
2021-07-02 16:53:32 +04:00
} else if (col >= HOURS_IN_DAY) {
col -= HOURS_IN_DAY;
row++;
}
2021-11-02 15:54:13 +04:00
return QList<QModelIndex>({model->index(row, col)});
}();
const QList<QModelIndex> local_selected = selection_model->selectedIndexes();
QCOMPARE(local_selected, correct_local_selected);
}
2021-07-01 16:08:19 +04:00
QTEST_MAIN(ADMCTestLogonHoursDialog)