File indexing completed on 2024-05-12 16:45:19

0001 /***************************************************************************
0002  * SPDX-FileCopyrightText: 2022 S. MANKOWSKI stephane@mankowski.fr
0003  * SPDX-FileCopyrightText: 2022 G. DE BURE support@mankowski.fr
0004  * SPDX-License-Identifier: GPL-3.0-or-later
0005  ***************************************************************************/
0006 /** @file
0007  * This file is a test for SKGMainPanel component.
0008  *
0009  * @author Stephane MANKOWSKI / Guillaume DE BURE
0010  */
0011 #include "skgtestmainpanel.h"
0012 #include "skgboardwidget.h"
0013 #include "skgdocumentbank.h"
0014 #include "skgmainpanel.h"
0015 #include "skgtestmacro.h"
0016 #include "skgtraces.h"
0017 
0018 void SKGTESTMainPanel::Test()
0019 {
0020     KLocalizedString::setApplicationDomain("skrooge");
0021 
0022     // Initialize document
0023     SKGDocumentBank doc;
0024 
0025     // Create main panel
0026     SKGMainPanel mainpanel(nullptr, &doc);
0027 
0028     QVERIFY2(!doc.load(SKGTest::getTestPath(QStringLiteral("IN")) % "/advice.skg"), "Load document failed");
0029     SKGError err;
0030     {
0031         // Scope of the transaction
0032         SKGBEGINTRANSACTION(doc, QStringLiteral("PROP"), err)
0033         doc.setParameter(QStringLiteral("SKG_LAST_BUDGET_PROCESSING"), QLatin1String(""));
0034     }
0035 
0036     // Check plugins
0037     {
0038         SKGBEGINTRANSACTION(doc, QStringLiteral("PLUGINS"), err)
0039         int i = 0;
0040         SKGInterfacePlugin* plugin = nullptr;
0041         do {
0042             plugin = mainpanel.getPluginByIndex(i);
0043             if (plugin != nullptr) {
0044                 SKGTRACE << i << ": " << plugin->title() << "(" << plugin->icon() << ")" << SKGENDL;
0045                 plugin->statusTip();
0046                 plugin->toolTip();
0047                 plugin->tips();
0048                 plugin->getOrder();
0049                 plugin->isInPagesChooser();
0050                 plugin->isEnabled();
0051 
0052                 SKGTabPage* tab = plugin->getWidget();
0053                 if (tab != nullptr) {
0054                     tab->printableWidgets();
0055                     tab->activateEditor();
0056                     tab->getBookmarkID();
0057                     tab->setState(tab->getState());
0058 
0059                     if (tab->isZoomable()) {
0060                         tab->zoomableWidget();
0061                         tab->setZoomPosition(5);
0062                         QCOMPARE(tab->zoomPosition(), 5);
0063                     }
0064                 }
0065 
0066                 int nbd = plugin->getNbDashboardWidgets();
0067                 for (int j = 0; j < nbd + 1; ++j) {
0068                     SKGTRACE << "    Dashboard " << j << "/" << nbd + 1 << ": " << plugin->getDashboardWidgetTitle(j) << SKGENDL;
0069                     SKGBoardWidget* bw = plugin->getDashboardWidget(j);
0070                     if (bw != nullptr) {
0071                         bw->setState(bw->getState());
0072                         bw->getDefaultStateAttribute();
0073                         bw->getFirstSelectedObject();
0074                     }
0075                 }
0076 
0077                 plugin->getDockWidget();
0078                 plugin->getPreferenceWidget();
0079                 plugin->getPreferenceSkeleton();
0080                 plugin->savePreferences();
0081 
0082                 SKGAdviceList adviceList = plugin->advice(QStringList());
0083                 for (const auto& advice : qAsConst(adviceList)) {
0084                     SKGTRACE << "    Advice: " << advice.getUUID() << SKGENDL;
0085                     for (int k = 0; k < 5; ++k) {
0086                         plugin->executeAdviceCorrection(advice.getUUID(), k);
0087                     }
0088                 }
0089             }
0090             ++i;
0091         } while (plugin != nullptr);
0092 
0093         // Compute advices
0094         SKGTRACE << "getAdvice" << SKGENDL;
0095         mainpanel.getAdvice();
0096     }
0097 
0098     // Functions
0099     SKGTRACE << "processArguments" << SKGENDL;
0100     mainpanel.processArguments(QStringList());
0101 
0102     mainpanel.openPage(QStringLiteral("skg://skrooge_operation_plugin"));
0103     SKGTabPage* page = mainpanel.currentPage();
0104     mainpanel.switchPinPage(page);
0105     mainpanel.currentPageHistoryItem();
0106 
0107     mainpanel.openPage(0, true);
0108     mainpanel.openPage(0, false);
0109     mainpanel.setCurrentPage(0);
0110 
0111     mainpanel.getNbSelectedObjects();
0112 
0113     mainpanel.countPages();
0114     mainpanel.page(0);
0115     mainpanel.currentPageIndex();
0116 
0117     mainpanel.closeAllOtherPages(page);
0118     mainpanel.closeAllPages(true);
0119 
0120     mainpanel.splashScreen();
0121 
0122     mainpanel.getTabWidget();
0123 
0124     mainpanel.setContextVisibility(1, true);
0125     mainpanel.setContextVisibility(1, false);
0126 }
0127 
0128 QTEST_MAIN(SKGTESTMainPanel)
0129