2021-07-14 11:52:26 +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-14 11:52:26 +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_string_other_edit.h"
2021-11-09 16:25:26 +04:00
# include "attribute_dialogs/list_attribute_dialog.h"
# include "attribute_dialogs/string_attribute_dialog.h"
# include "attribute_dialogs/ui_list_attribute_dialog.h"
2021-11-09 16:35:31 +04:00
# include "attribute_edits/string_other_edit.h"
2021-07-14 11:52:26 +04:00
# include <QFormLayout>
# include <QLineEdit>
2022-06-10 16:32:52 +04:00
# include <QPlainTextEdit>
2021-07-14 11:52:26 +04:00
# include <QListWidget>
# include <QPushButton>
# define TEST_ATTRIBUTE_MAIN ATTRIBUTE_WWW_HOMEPAGE
# define TEST_ATTRIBUTE_OTHER ATTRIBUTE_WWW_HOMEPAGE_OTHER
const QString main_value = " main_value " ;
const QList < QByteArray > other_value_list = {
" first " ,
" second " ,
" third " ,
} ;
# define new_value "new_value"
void ADMCTestStringOtherEdit : : init ( ) {
ADMCTest : : init ( ) ;
2021-10-05 17:01:33 +04:00
line_edit = new QLineEdit ( parent_widget ) ;
other_button = new QPushButton ( parent_widget ) ;
2021-07-14 11:52:26 +04:00
2021-12-22 16:26:03 +04:00
edit = new StringOtherEdit ( line_edit , other_button , TEST_ATTRIBUTE_MAIN , ATTRIBUTE_WWW_HOMEPAGE_OTHER , parent_widget ) ;
2021-07-14 11:52:26 +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 ) ;
// Set values
ad . attribute_replace_string ( dn , TEST_ATTRIBUTE_MAIN , main_value ) ;
ad . attribute_replace_values ( dn , TEST_ATTRIBUTE_OTHER , other_value_list ) ;
// Load user into edit
const AdObject object = ad . search_object ( dn ) ;
edit - > load ( ad , object ) ;
}
// edited() signal should be emitted when lineedit is edited
// and when other values are added
void ADMCTestStringOtherEdit : : test_emit_edited_signal ( ) {
bool edited_signal_emitted = false ;
connect (
edit , & AttributeEdit : : edited ,
2021-11-17 12:22:24 +04:00
this ,
2021-07-14 11:52:26 +04:00
[ & edited_signal_emitted ] ( ) {
edited_signal_emitted = true ;
} ) ;
line_edit - > setText ( " test " ) ;
QVERIFY ( edited_signal_emitted ) ;
edited_signal_emitted = false ;
add_new_other_value ( ) ;
QVERIFY ( edited_signal_emitted ) ;
}
// Edit should contain current attribute value after load()
// call
void ADMCTestStringOtherEdit : : load ( ) {
2021-10-01 14:23:56 +04:00
QCOMPARE ( line_edit - > text ( ) , main_value ) ;
2021-07-14 11:52:26 +04:00
other_button - > click ( ) ;
2021-11-09 16:25:26 +04:00
auto list_attribute_dialog = parent_widget - > findChild < ListAttributeDialog * > ( ) ;
QVERIFY ( list_attribute_dialog ) ;
2021-07-14 11:52:26 +04:00
2021-11-09 16:25:26 +04:00
auto list_widget = list_attribute_dialog - > findChild < QListWidget * > ( ) ;
2021-10-01 14:23:56 +04:00
QVERIFY ( list_widget ) ;
2021-07-14 11:52:26 +04:00
2021-10-01 14:23:56 +04:00
QCOMPARE ( line_edit - > text ( ) , main_value ) ;
2021-07-14 11:52:26 +04:00
for ( int i = 0 ; i < 3 ; i + + ) {
2021-10-01 14:23:56 +04:00
QCOMPARE ( list_widget - > item ( i ) - > text ( ) , other_value_list [ i ] ) ;
2021-07-14 11:52:26 +04:00
}
}
void ADMCTestStringOtherEdit : : apply_unmodified ( ) {
2021-07-14 12:35:00 +04:00
test_edit_apply_unmodified ( edit , dn ) ;
2021-07-14 11:52:26 +04:00
}
void ADMCTestStringOtherEdit : : apply_modified_main_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_main = object . get_string ( TEST_ATTRIBUTE_MAIN ) ;
2021-10-01 14:23:56 +04:00
QCOMPARE ( current_value_main , new_value ) ;
2021-07-14 11:52:26 +04:00
const QList < QByteArray > current_value_other = object . get_values ( TEST_ATTRIBUTE_OTHER ) ;
2021-10-01 14:23:56 +04:00
QCOMPARE ( current_value_other , other_value_list ) ;
2021-07-14 11:52:26 +04:00
}
void ADMCTestStringOtherEdit : : apply_modified_other_value ( ) {
add_new_other_value ( ) ;
const bool apply_success = edit - > apply ( ad , dn ) ;
QVERIFY ( apply_success ) ;
const AdObject object = ad . search_object ( dn ) ;
const QString current_value_main = object . get_string ( TEST_ATTRIBUTE_MAIN ) ;
2021-10-01 14:23:56 +04:00
QCOMPARE ( current_value_main , main_value ) ;
2021-07-14 11:52:26 +04:00
const QList < QByteArray > current_value_other = object . get_values ( TEST_ATTRIBUTE_OTHER ) ;
2021-11-02 15:54:13 +04:00
QList < QByteArray > correct_value_other = other_value_list ;
2021-07-14 11:52:26 +04:00
correct_value_other . append ( new_value ) ;
2021-10-01 14:23:56 +04:00
QCOMPARE ( current_value_other , correct_value_other ) ;
2021-07-14 11:52:26 +04:00
}
void ADMCTestStringOtherEdit : : add_new_other_value ( ) {
other_button - > click ( ) ;
2021-11-09 16:25:26 +04:00
auto list_attribute_dialog = parent_widget - > findChild < ListAttributeDialog * > ( ) ;
QVERIFY ( list_attribute_dialog ) ;
2021-07-14 11:52:26 +04:00
2021-11-09 16:25:26 +04:00
QPushButton * add_button = list_attribute_dialog - > ui - > add_button ;
2021-07-14 11:52:26 +04:00
add_button - > click ( ) ;
2021-11-09 16:25:26 +04:00
auto string_attribute_dialog = list_attribute_dialog - > findChild < StringAttributeDialog * > ( ) ;
QVERIFY ( string_attribute_dialog ) ;
2021-07-14 11:52:26 +04:00
2022-06-10 16:32:52 +04:00
auto string_attribute_dialog_line_edit = string_attribute_dialog - > findChild < QPlainTextEdit * > ( ) ;
2021-11-09 16:25:26 +04:00
QVERIFY ( string_attribute_dialog_line_edit ) ;
2021-07-14 11:52:26 +04:00
2022-06-10 16:32:52 +04:00
string_attribute_dialog_line_edit - > setPlainText ( new_value ) ;
2021-07-14 11:52:26 +04:00
2021-11-09 16:25:26 +04:00
string_attribute_dialog - > accept ( ) ;
2021-07-14 11:52:26 +04:00
2021-11-09 16:25:26 +04:00
list_attribute_dialog - > accept ( ) ;
2021-07-14 11:52:26 +04:00
}
QTEST_MAIN ( ADMCTestStringOtherEdit )