2021-02-05 17:56:49 +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-02-05 17:56:49 +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/>.
*/
2021-02-11 14:54:40 +04:00
# ifndef ADMC_TEST_H
# define ADMC_TEST_H
2021-02-05 17:56:49 +04:00
2021-02-19 15:23:43 +04:00
/**
* Base test class for testing ADMC . Implements init and
* cleanup f - ns that create a fresh testing environment for
* each test .
2021-02-05 17:56:49 +04:00
*/
# include <QTest>
2021-03-25 15:08:39 +04:00
# include "adldap.h"
2021-02-20 13:42:27 +04:00
2021-02-09 15:22:46 +04:00
class QTreeView ;
2021-06-25 15:32:23 +04:00
class SelectObjectDialog ;
2021-06-30 13:29:43 +04:00
class SelectBaseWidget ;
2021-07-09 15:44:23 +04:00
class QFormLayout ;
class AttributeEdit ;
2021-02-19 15:23:43 +04:00
2021-10-01 13:34:32 +04:00
# define TEST_USER "ADMCTEST-test-user"
# define TEST_USER_LOGON "ADMCTEST-test-user-logon"
# define TEST_PASSWORD "ADMCTEST-pass123!"
# define TEST_OU "ADMCTEST-test-ou"
# define TEST_GROUP "ADMCTEST-test-group"
2022-03-11 16:32:36 +04:00
// NOTE: use shorter length for computer to fit within
// 16 char length limit for sam account name
# define TEST_COMPUTER "ADMCTEST-pc"
2022-03-16 13:51:24 +04:00
# define TEST_OBJECT "ADMCTEST-object"
2021-02-05 17:56:49 +04:00
2021-02-11 14:54:40 +04:00
class ADMCTest : public QObject {
2021-02-05 17:56:49 +04:00
Q_OBJECT
2021-02-19 15:23:43 +04:00
public slots :
2021-02-08 12:38:23 +04:00
// NOTE: initTestCase(), cleanupTestCase(), init() and
// cleanup() are special slots called by QTest.
2021-02-05 17:56:49 +04:00
// Called before first test
2021-05-28 13:18:19 +04:00
virtual void initTestCase ( ) ;
2021-02-05 17:56:49 +04:00
// Called after last test
2021-08-05 16:58:33 +04:00
virtual void cleanupTestCase ( ) ;
2021-02-05 17:56:49 +04:00
2021-02-19 15:23:43 +04:00
// Called before and after each test
virtual void init ( ) ;
2021-08-05 16:58:33 +04:00
virtual void cleanup ( ) ;
2021-02-05 17:56:49 +04:00
2021-02-19 14:51:11 +04:00
protected :
AdInterface ad ;
2021-02-05 17:56:49 +04:00
// Use this as parents for widgets used inside tests.
// For every test a new parent will be created and after
// test completes, parent is deleted which deletes all
// child widgets as well.
QWidget * parent_widget = nullptr ;
2021-07-09 15:44:23 +04:00
// This list is just for passing to edit ctors
QList < AttributeEdit * > edits ;
2021-02-05 17:56:49 +04:00
// For easy setup and cleanup of each test, we use an
// object named "test-arena" which is an OU. It is
// created before every test and deleted after every
// test. All test activity should happen inside this
// object.
QString test_arena_dn ( ) ;
// Creates dn for object with given name whose parent is
// test arena. Class is used to determine suffix.
QString test_object_dn ( const QString & name , const QString & object_class ) ;
2021-02-05 18:04:07 +04:00
// Tests object's existance on the server.
2021-02-05 17:56:49 +04:00
bool object_exists ( const QString & dn ) ;
2021-02-05 18:04:07 +04:00
2021-03-01 13:53:29 +04:00
// Call this after pressing "Find" button. Needed
// because find results are loaded in separate thread.
void wait_for_find_results_to_load ( QTreeView * view ) ;
2021-06-28 13:13:51 +04:00
void select_in_select_dialog ( SelectObjectDialog * select_dialog , const QString & dn ) ;
2021-06-25 15:32:23 +04:00
2021-06-30 13:09:27 +04:00
// This is for closing message boxes opened using
2021-06-30 15:13:32 +04:00
// open(). Won't work for QMessageBox static f-ns
2021-06-30 13:09:27 +04:00
void close_message_box ( ) ;
2022-03-29 11:12:36 +04:00
bool message_box_is_open ( ) const ;
2021-06-30 13:58:28 +04:00
// Selects an object via an already open select object
// dialog. Object must be inside test arena
void select_object_dialog_select ( const QString & dn ) ;
2021-07-09 15:44:23 +04:00
// Adds a widget to layout in parent widget
void add_widget ( QWidget * widget ) ;
2021-07-14 12:35:00 +04:00
void test_edit_apply_unmodified ( AttributeEdit * edit , const QString & dn ) ;
2021-10-18 12:29:43 +04:00
// Add a base to the base combo. Note that it is also
// automatically selected.
void select_base_widget_add ( SelectBaseWidget * widget , const QString & dn ) ;
2021-07-09 15:44:23 +04:00
private :
QFormLayout * layout ;
2021-02-05 17:56:49 +04:00
} ;
2021-03-26 17:38:38 +04:00
void navigate_until_object ( QTreeView * view , const QString & target_dn , const int dn_role ) ;
2022-03-29 12:27:40 +04:00
void test_lineedit_autofill ( QLineEdit * src_edit , QLineEdit * dest_edit ) ;
2021-02-19 15:23:43 +04:00
2021-02-11 14:54:40 +04:00
# endif /* ADMC_TEST_H */