File indexing completed on 2024-05-12 05:13:46
0001 /* 0002 SPDX-FileCopyrightText: 2018-2021 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef TESTHELPER_H 0008 #define TESTHELPER_H 0009 0010 #include "applicationcontroller.h" 0011 #include "documentmanager.h" 0012 #include "passmanager.h" 0013 #include "pkpassmanager.h" 0014 #include "reservationmanager.h" 0015 0016 #include <QFile> 0017 0018 namespace Test 0019 { 0020 0021 /** Read the entire file content. */ 0022 inline QByteArray readFile(const QString &fn) 0023 { 0024 QFile f(fn); 0025 f.open(QFile::ReadOnly); 0026 return f.readAll(); 0027 } 0028 0029 /** Delete all reservations. */ 0030 inline void clearAll(ReservationManager *mgr) 0031 { 0032 const auto batches = mgr->batches(); // copy, as this is getting modified in the process 0033 for (const auto &id : batches) { 0034 mgr->removeBatch(id); 0035 } 0036 Q_ASSERT(mgr->batches().empty()); 0037 } 0038 0039 /** Delete all passes. */ 0040 inline void clearAll(PkPassManager *mgr) 0041 { 0042 for (const auto &id : mgr->passes()) { 0043 mgr->removePass(id); 0044 } 0045 Q_ASSERT(mgr->passes().isEmpty()); 0046 } 0047 0048 /** Delete all documents. */ 0049 inline void clearAll(DocumentManager *docMgr) 0050 { 0051 for (const auto &id : docMgr->documents()) { 0052 docMgr->removeDocument(id); 0053 } 0054 Q_ASSERT(docMgr->documents().isEmpty()); 0055 0056 } 0057 0058 inline void clearAll(PassManager *passMgr) 0059 { 0060 while (passMgr->rowCount()) { 0061 passMgr->removeRow(0); 0062 } 0063 Q_ASSERT(passMgr->rowCount() == 0); 0064 } 0065 0066 /** Fully set up application controller. */ 0067 inline std::unique_ptr<ApplicationController> makeAppController() 0068 { 0069 std::unique_ptr<ApplicationController> ctrl(new ApplicationController); 0070 0071 auto passMgr = new PassManager(ctrl.get()); 0072 clearAll(passMgr); 0073 ctrl->setPassManager(passMgr); 0074 return ctrl; 0075 } 0076 0077 } 0078 0079 #endif