File indexing completed on 2024-05-19 05:42:25
0001 // ct_lvtqtc_undo_rename_entity.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 <catch2-local-includes.h> 0021 0022 #include <ct_lvtqtc_undo_rename_entity.h> 0023 0024 #include <ct_lvtclr_colormanagement.h> 0025 #include <ct_lvtldr_lakosiannode.h> 0026 #include <ct_lvtldr_nodestoragetestutils.h> 0027 #include <ct_lvtqtc_graphicsscene.h> 0028 #include <ct_lvtqtc_testing_utils.h> 0029 #include <ct_lvttst_fixture_qt.h> 0030 #include <ct_lvttst_tmpdir.h> 0031 0032 #include <memory> 0033 0034 using namespace Codethink::lvtqtc; 0035 using namespace Codethink::lvtldr; 0036 using namespace Codethink::lvtclr; 0037 using namespace Codethink::lvtshr; 0038 0039 TEST_CASE_METHOD(QTApplicationFixture, "Undo/Redo rename entity") 0040 { 0041 auto tmpDir = TmpDir{"undo_redo_rename_entity"}; 0042 auto dbPath = tmpDir.path() / "codedb.db"; 0043 auto nodeStorage = NodeStorageTestUtils::createEmptyNodeStorage(dbPath); 0044 0045 auto *a = nodeStorage.addPackage("a", "a").value(); 0046 0047 auto gv = GraphicsViewWrapperForTesting{nodeStorage}; 0048 // TODO: Update this call. 0049 // gv.updatePackageGraph(QString::fromStdString(a->qualifiedName())); 0050 gv.show(); 0051 0052 auto oldQualifiedName = a->qualifiedName(); 0053 auto oldName = a->name(); 0054 auto type = a->type(); 0055 a->setName("b"); 0056 auto qualifiedName = a->qualifiedName(); 0057 auto newName = a->name(); 0058 0059 auto undoRedo = UndoManager{}; 0060 undoRedo.addUndoCommand(new UndoRenameEntity(qualifiedName, oldQualifiedName, type, oldName, newName, nodeStorage)); 0061 0062 REQUIRE(nodeStorage.findByQualifiedName(type, qualifiedName)->name() == newName); 0063 undoRedo.undo(); 0064 REQUIRE(nodeStorage.findByQualifiedName(type, oldQualifiedName)->name() == oldName); 0065 undoRedo.redo(); 0066 REQUIRE(nodeStorage.findByQualifiedName(type, qualifiedName)->name() == newName); 0067 }