File indexing completed on 2024-05-19 05:42:27

0001 // ct_lvtqtw_statusbar.t.cpp                                                                                   -*-C++-*-
0002 
0003 /*
0004 // Copyright 2023 Codethink Ltd <codethink@codethink.co.uk>
0005 // SPDX-License-Identifier: Apache-2.0
0006 //
0007 // Licensed under the Apache License, Version 2.0 (the "License");
0008 // you may not use this file except in compliance with the License.
0009 // You may obtain a copy of the License at
0010 //
0011 //     http://www.apache.org/licenses/LICENSE-2.0
0012 //
0013 // Unless required by applicable law or agreed to in writing, software
0014 // distributed under the License is distributed on an "AS IS" BASIS,
0015 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0016 // See the License for the specific language governing permissions and
0017 // limitations under the License.
0018 */
0019 
0020 #include <ct_lvtqtw_statusbar.h>
0021 
0022 #include <ct_lvttst_fixture_qt.h>
0023 #include <preferences.h>
0024 
0025 #include <catch2-local-includes.h>
0026 
0027 using namespace Codethink::lvtqtw;
0028 
0029 class FakeParseCodebaseDialog : public ParseCodebaseDialog {
0030   public:
0031     void fakeParseStartedSignal(ParseCodebaseDialog::State s)
0032     {
0033         Q_EMIT parseStarted(s);
0034     }
0035 
0036     void fakeParseStepSignal(ParseCodebaseDialog::State s, int value, int max)
0037     {
0038         Q_EMIT parseStep(s, value, max);
0039     }
0040 
0041     void fakeParseFinished()
0042     {
0043         Q_EMIT parseFinished(Codethink::lvtqtw::ParseCodebaseDialog::State::Idle);
0044     }
0045 };
0046 
0047 class CodeVisStatusBarForTesting : public CodeVisStatusBar {
0048   public:
0049     [[nodiscard]] QString currentPanText() const
0050     {
0051         return m_labelPan->text();
0052     }
0053 
0054     [[nodiscard]] QString currentZoomText() const
0055     {
0056         return m_labelZoom->text();
0057     }
0058 
0059     void clickParseCodebaseStatus()
0060     {
0061         m_labelParseCodebaseWindowStatus->click();
0062     }
0063 
0064     QString parseCodebaseStatusText()
0065     {
0066         return m_labelParseCodebaseWindowStatus->text();
0067     }
0068 };
0069 
0070 TEST_CASE_METHOD(QTApplicationFixture, "Basic status bar workflow")
0071 {
0072     Preferences::setPanModifier(Qt::ALT);
0073     Preferences::setZoomModifier(Qt::CTRL);
0074 
0075     auto statusBar = CodeVisStatusBarForTesting{};
0076     statusBar.show();
0077 
0078 #ifdef __APPLE__
0079     REQUIRE(statusBar.currentPanText() == "Pan Graph: OPTION + Click");
0080     REQUIRE(statusBar.currentZoomText() == "Zoom: COMMAND + Wheel");
0081 #else
0082     REQUIRE(statusBar.currentPanText() == "Pan Graph: ALT + Click");
0083     REQUIRE(statusBar.currentZoomText() == "Zoom: CONTROL + Wheel");
0084 #endif
0085 
0086     Preferences::setPanModifier(Qt::SHIFT);
0087     Preferences::setZoomModifier(Qt::ALT);
0088 
0089 #ifdef __APPLE__
0090     REQUIRE(statusBar.currentPanText() == "Pan Graph: Click + SHIFT");
0091     REQUIRE(statusBar.currentZoomText() == "Zoom: Wheel + OPTION");
0092 #else
0093     REQUIRE(statusBar.currentPanText() == "Pan Graph: SHIFT + Click");
0094     REQUIRE(statusBar.currentZoomText() == "Zoom: ALT + Wheel");
0095 #endif
0096 }
0097 
0098 TEST_CASE_METHOD(QTApplicationFixture, "Logical parse on status bar")
0099 {
0100     auto fakeParseDialog = FakeParseCodebaseDialog{};
0101     fakeParseDialog.hide();
0102 
0103     auto statusBar = CodeVisStatusBarForTesting{};
0104     statusBar.show();
0105 
0106     // Must do nothing if there's no parseCodebaseWindow set.
0107     statusBar.clickParseCodebaseStatus();
0108     REQUIRE(fakeParseDialog.isHidden());
0109 
0110     statusBar.setParseCodebaseWindow(fakeParseDialog);
0111     statusBar.clickParseCodebaseStatus();
0112     REQUIRE(fakeParseDialog.isVisible());
0113 
0114     // Nothing is shown for the physical analysis
0115     REQUIRE(statusBar.parseCodebaseStatusText().isEmpty());
0116     fakeParseDialog.fakeParseStartedSignal(ParseCodebaseDialog::State::Idle);
0117     REQUIRE(statusBar.parseCodebaseStatusText().isEmpty());
0118     fakeParseDialog.fakeParseStartedSignal(ParseCodebaseDialog::State::RunAllPhysical);
0119     REQUIRE(statusBar.parseCodebaseStatusText().isEmpty());
0120     fakeParseDialog.fakeParseStepSignal(ParseCodebaseDialog::State::RunAllPhysical, 0, 1);
0121     REQUIRE(statusBar.parseCodebaseStatusText() == "Running physical parse [0/1].");
0122 
0123     // Text is updated for logical analysis
0124     fakeParseDialog.fakeParseStartedSignal(ParseCodebaseDialog::State::RunAllLogical);
0125     fakeParseDialog.fakeParseStepSignal(ParseCodebaseDialog::State::RunAllLogical, 0, 1);
0126     REQUIRE(statusBar.parseCodebaseStatusText() == "Running logical parse [0/1]. Some diagrams may be incomplete.");
0127     fakeParseDialog.fakeParseStepSignal(ParseCodebaseDialog::State::RunAllLogical, 1, 1);
0128     REQUIRE(statusBar.parseCodebaseStatusText() == "Running logical parse [1/1]. Some diagrams may be incomplete.");
0129     fakeParseDialog.fakeParseFinished();
0130     REQUIRE(statusBar.parseCodebaseStatusText() == "View last parse run");
0131 }