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

0001 // ct_lvtqtc_inspect_dependency_window.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 #include <ct_lvtldr_nodestoragetestutils.h>
0020 #include <ct_lvtqtc_inspect_dependency_window.h>
0021 #include <ct_lvtqtc_nodestorage_testing_helpers.h>
0022 #include <ct_lvtqtc_testing_utils.h>
0023 
0024 #include <catch2-local-includes.h>
0025 
0026 #include <ct_lvttst_fixture_qt.h>
0027 #include <ct_lvttst_tmpdir.h>
0028 
0029 using namespace Codethink::lvtqtc;
0030 using namespace Codethink::lvtprj;
0031 using namespace Codethink::lvtldr;
0032 
0033 class InspectDependencyWindowForTesting : public InspectDependencyWindow {
0034   public:
0035     using InspectDependencyWindow::InspectDependencyWindow;
0036 
0037     [[nodiscard]] int nRows()
0038     {
0039         return d_contentsTable->rowCount();
0040     }
0041 
0042     void showFileNotFoundWarning(QString const& filepath) const override
0043     {
0044         if (onFileNotFound) {
0045             (*onFileNotFound)(filepath);
0046         }
0047     }
0048 
0049     std::optional<std::function<void(QString const&)>> onFileNotFound = std::nullopt;
0050 };
0051 
0052 TEST_CASE_METHOD(QTApplicationFixture, "Basic workflow")
0053 {
0054     auto tmpDir = TmpDir{"basic_workflow"};
0055     auto dbPath = tmpDir.path() / "codedb.db";
0056     auto ns = NodeStorageTestUtils::createEmptyNodeStorage(dbPath);
0057 
0058     auto projectFile = ProjectFileForTesting{};
0059 
0060     auto parent = ScopedPackageEntity(ns, "pkggrp");
0061     auto source = ScopedPackageEntity(ns, "pkgA", parent.value());
0062     auto componentA = ScopedComponentEntity(ns, "componentA", source.value());
0063     auto target = ScopedPackageEntity(ns, "pkgB", parent.value());
0064     auto componentB = ScopedComponentEntity(ns, "componentB", target.value());
0065     auto dep = ScopedPackageDependency(ns, source.value(), target.value());
0066     auto compDep = ScopedPackageDependency(ns, componentA.value(), componentB.value());
0067 
0068     //    auto window = InspectDependencyWindowForTesting{projectFile, dep.value()};
0069     //    window.show();
0070     //    REQUIRE(window.nRows() == 1);
0071     //    auto expectedFilepath = std::filesystem::path{};
0072     //    auto triggerCount = 0;
0073     //    window.onFileNotFound = [&triggerCount, &expectedFilepath](auto filepath) {
0074     //        REQUIRE(filepath.toStdString() == expectedFilepath.string());
0075     //        triggerCount += 1;
0076     //    };
0077 }