File indexing completed on 2024-05-19 05:41:55
0001 // apptesting_fixture.h -*-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 #ifndef DIAGRAM_SERVER_APPTESTING_FIXTURE_H 0020 #define DIAGRAM_SERVER_APPTESTING_FIXTURE_H 0021 0022 #include <QObject> 0023 #include <QToolButton> 0024 #include <QtTest/QTest> 0025 #include <algorithm> 0026 #include <ct_lvtldr_nodestorage.h> 0027 #include <ct_lvtqtc_graphicsview.h> 0028 #include <ct_lvtqtc_lakosentity.h> 0029 #include <ct_lvtqtc_tool_add_component.h> 0030 #include <ct_lvtqtc_tool_add_logical_entity.h> 0031 #include <ct_lvtqtc_tool_add_package.h> 0032 #include <ct_lvtqtc_tool_add_physical_dependency.h> 0033 #include <ct_lvtqtc_undo_manager.h> 0034 #include <ct_lvtqtw_graphtabelement.h> 0035 #include <ct_lvtqtw_toolbox.h> 0036 #include <ct_lvttst_fixture_qt.h> 0037 #include <mainwindow.h> 0038 #include <testmainwindow.h> 0039 #include <ui_ct_lvtqtw_graphtabelement.h> 0040 0041 #include <any> 0042 #include <variant> 0043 0044 using namespace Codethink::lvtldr; 0045 using namespace Codethink::lvtqtw; 0046 using namespace Codethink::lvtqtc; 0047 0048 // clang-format off 0049 namespace Sidebar { namespace ManipulationTool { struct NewPackage { QString name; }; } } 0050 namespace Sidebar { namespace ManipulationTool { struct NewComponent { QString name; }; } } 0051 namespace Sidebar { namespace ManipulationTool { struct NewLogicalEntity { QString name; QString kind; }; } } 0052 namespace Sidebar { namespace ManipulationTool { struct AddDependency {}; } } 0053 namespace Sidebar { namespace ManipulationTool { struct AddIsA {}; } } 0054 namespace Sidebar { namespace VisualizationTool { struct ResetZoom {}; } } 0055 namespace Sidebar { struct ToggleApplicationMode {}; } 0056 namespace Menubar { namespace File { struct NewProject {}; } } 0057 namespace Menubar { namespace File { struct CloseProject {}; } } 0058 namespace PackageTreeView { struct Package {std::string name; }; } 0059 0060 struct CurrentGraph { 0061 CurrentGraph(int x, int y) : x(x), y(y) {} 0062 explicit CurrentGraph(QPoint const& p) : x(p.x()), y(p.y()) {} 0063 0064 int x; 0065 int y; 0066 }; 0067 // clang-format on 0068 0069 using ClickableFeature = std::variant<Sidebar::ManipulationTool::NewPackage, 0070 Sidebar::ManipulationTool::NewComponent, 0071 Sidebar::ManipulationTool::NewLogicalEntity, 0072 Sidebar::ManipulationTool::AddDependency, 0073 Sidebar::ManipulationTool::AddIsA, 0074 Sidebar::VisualizationTool::ResetZoom, 0075 Menubar::File::NewProject, 0076 Menubar::File::CloseProject, 0077 PackageTreeView::Package, 0078 CurrentGraph>; 0079 0080 template<class... Ts> 0081 struct visitor : Ts... { 0082 using Ts::operator()...; 0083 }; 0084 template<class... Ts> 0085 visitor(Ts...) -> visitor<Ts...>; 0086 0087 auto constexpr DEFAULT_QT_DELAY = 50; // ms 0088 0089 // Those are hardcoded indexes, look at graphtabelement.cpp 0090 // for the positions of tools in the d->tools vector 0091 auto constexpr TOOL_ADD_DEPENDENCY_ID = 1; 0092 auto constexpr TOOL_ADD_PACKAGE_ID = 2; 0093 auto constexpr TOOL_ADD_COMPONENT_ID = 3; 0094 auto constexpr TOOL_ADD_LOGICAL_ENTITY_ID = 4; 0095 auto constexpr TOOL_ADD_ISA_RELATIONSHIP_ID = 5; 0096 0097 class CodeVisApplicationTestFixture : public QTApplicationFixture { 0098 public: 0099 CodeVisApplicationTestFixture(); 0100 [[nodiscard]] bool hasDefaultTabWidget() const; 0101 [[nodiscard]] bool isShowingWelcomePage() const; 0102 [[nodiscard]] bool isShowingGraphPage() const; 0103 void forceRelayout(); 0104 void clickOn(ClickableFeature const& feature); 0105 void graphPressMoveRelease(QPoint source, QPoint destiny); 0106 QPoint findElementTopLeftPosition(const std::string& qname); 0107 LakosEntity *findElement(const std::string& qualifiedName); 0108 void ctrlZ(); 0109 void ctrlShiftZ(); 0110 bool isAnyToolSelected(); 0111 TestMainWindow& window() 0112 { 0113 return *mainWindow; 0114 }; 0115 0116 private: 0117 Codethink::lvtqtc::UndoManager undoManager; 0118 NodeStorage sharedNodeStorage; 0119 TestMainWindow *mainWindow; 0120 }; 0121 0122 #endif // DIAGRAM_SERVER_APPTESTING_FIXTURE_H