File indexing completed on 2024-05-19 05:41:56

0001 // mainwindow_auto_add_edges_from_classes.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_lvtqtc_graphicsscene.h>
0021 #include <ct_lvtqtc_graphicsview.h>
0022 #include <ct_lvtqtc_lakosrelation.h>
0023 #include <ct_lvttst_fixture_qt.h>
0024 
0025 #include <apptesting_fixture.h>
0026 #include <catch2-local-includes.h>
0027 #include <variant>
0028 
0029 #include <preferences.h>
0030 
0031 // in a header
0032 Q_DECLARE_LOGGING_CATEGORY(LogTest)
0033 
0034 // in one source file
0035 Q_LOGGING_CATEGORY(LogTest, "log.test")
0036 
0037 using namespace Codethink::lvtldr;
0038 
0039 TEST_CASE_METHOD(CodeVisApplicationTestFixture, "Auto Add Edge From Classes")
0040 {
0041     clickOn(Menubar::File::NewProject{});
0042 
0043     clickOn(Sidebar::ManipulationTool::NewPackage{"abc"});
0044     clickOn(CurrentGraph{0, 0});
0045     QTest::qWait(100);
0046 
0047     auto point = findElementTopLeftPosition("abc");
0048     clickOn(Sidebar::ManipulationTool::NewPackage{"abcxyz"});
0049     clickOn(CurrentGraph{point});
0050     QTest::qWait(100);
0051 
0052     point = findElementTopLeftPosition("abc/abcxyz");
0053 
0054     clickOn(Sidebar::ManipulationTool::NewComponent{"abcxyz_comp1"});
0055     clickOn(CurrentGraph{point});
0056     QTest::qWait(100);
0057 
0058     point = findElementTopLeftPosition("abc/abcxyz/abcxyz_comp1");
0059 
0060     clickOn(Sidebar::ManipulationTool::NewLogicalEntity{"first_class", "ClassA"});
0061     clickOn(CurrentGraph{point});
0062     QTest::qWait(100);
0063 
0064     clickOn(Sidebar::ManipulationTool::NewPackage{"def"});
0065     clickOn(CurrentGraph{500, 400});
0066     QTest::qWait(100);
0067 
0068     point = findElementTopLeftPosition("def");
0069 
0070     clickOn(Sidebar::ManipulationTool::NewPackage{"defg"});
0071     clickOn(CurrentGraph{point});
0072     QTest::qWait(100);
0073 
0074     point = findElementTopLeftPosition("def/defg");
0075 
0076     clickOn(Sidebar::ManipulationTool::NewComponent{"defg_comp1"});
0077     clickOn(CurrentGraph{point});
0078     QTest::qWait(1000);
0079 
0080     point = findElementTopLeftPosition("def/defg/defg_comp1");
0081 
0082     clickOn(Sidebar::ManipulationTool::NewLogicalEntity{"second_class", "ClassB"});
0083     clickOn(CurrentGraph{point});
0084     QTest::qWait(100);
0085 
0086     clickOn(Sidebar::ManipulationTool::AddIsA{});
0087 
0088     auto element1 = findElementTopLeftPosition("abcxyz_comp1::first_class");
0089     clickOn(CurrentGraph{element1});
0090     QTest::qWait(100);
0091 
0092     auto element2 = findElementTopLeftPosition("defg_comp1::second_class");
0093     clickOn(CurrentGraph{element2});
0094     QTest::qWait(100);
0095 
0096     LakosEntity *abc = findElement("abc");
0097     LakosEntity *def = findElement("def");
0098     LakosEntity *abcd = findElement("abc/abcxyz");
0099     LakosEntity *defg = findElement("def/defg");
0100     LakosEntity *abc_comp1 = findElement("abc/abcxyz/abcxyz_comp1");
0101     LakosEntity *def_comp1 = findElement("def/defg/defg_comp1");
0102 
0103     REQUIRE(abc->internalNode()->hasProvider(def->internalNode()));
0104     REQUIRE(abcd->internalNode()->hasProvider(defg->internalNode()));
0105     REQUIRE(abc_comp1->internalNode()->hasProvider(def_comp1->internalNode()));
0106     QTest::qWait(100);
0107 
0108     ctrlZ();
0109     QTest::qWait(100);
0110 
0111     REQUIRE_FALSE(abc->internalNode()->hasProvider(def->internalNode()));
0112     REQUIRE_FALSE(abcd->internalNode()->hasProvider(defg->internalNode()));
0113     REQUIRE_FALSE(abc_comp1->internalNode()->hasProvider(def_comp1->internalNode()));
0114 
0115     ctrlShiftZ();
0116     QTest::qWait(100);
0117 
0118     REQUIRE(abc->internalNode()->hasProvider(def->internalNode()));
0119     REQUIRE(abcd->internalNode()->hasProvider(defg->internalNode()));
0120     REQUIRE(abc_comp1->internalNode()->hasProvider(def_comp1->internalNode()));
0121 }