2021-04-12 14:40:32 +04:00
/*
* ADMC - AD Management Center
*
2021-06-07 11:51:19 +04:00
* Copyright ( C ) 2020 - 2021 BaseALT Ltd .
* Copyright ( C ) 2020 - 2021 Dmitry Degtyarev
2021-04-12 14:40:32 +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_edit.h"
2021-11-09 16:35:31 +04:00
# include "attribute_edits/string_edit.h"
2021-04-12 14:40:32 +04:00
# include <QFormLayout>
# include <QLineEdit>
# define TEST_ATTRIBUTE ATTRIBUTE_FIRST_NAME
void ADMCTestStringEdit : : init ( ) {
ADMCTest : : init ( ) ;
2021-10-05 17:01:33 +04:00
line_edit = new QLineEdit ( parent_widget ) ;
2021-04-12 14:40:32 +04:00
2021-10-05 17:15:31 +04:00
edit = new StringEdit ( line_edit , TEST_ATTRIBUTE , & edits , parent_widget ) ;
2021-04-12 14:40:32 +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 ) ;
}
// 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 ) ;
2021-06-10 16:34:06 +04:00
const QString edit_value = line_edit - > text ( ) ;
;
2021-10-01 14:23:56 +04:00
QCOMPARE ( edit_value , test_value ) ;
2021-04-12 14:40:32 +04:00
}
void ADMCTestStringEdit : : apply_unmodified ( ) {
2021-07-14 12:35:00 +04:00
test_edit_apply_unmodified ( edit , dn ) ;
2021-04-12 14:40:32 +04:00
}
// 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 ) ;
2021-10-01 14:23:56 +04:00
QCOMPARE ( current_value , new_value ) ;
2021-04-12 14:40:32 +04:00
}
QTEST_MAIN ( ADMCTestStringEdit )