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

0001 // projectsettingsdialog.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 #include <ct_lvtprj_projectfile.h>
0022 #include <ct_lvttst_fixture_qt.h>
0023 #include <projectsettingsdialog.h>
0024 #include <ui_projectsettingsdialog.h>
0025 
0026 using namespace Codethink::lvtprj;
0027 
0028 class ProjectSettingsDialogForTesting : public ProjectSettingsDialog {
0029   public:
0030     using ProjectSettingsDialog::ProjectSettingsDialog;
0031 
0032     std::string projectNameText()
0033     {
0034         return ui->projectNameValue->text().toStdString();
0035     }
0036 
0037     void setProjectNameText(std::string const& s)
0038     {
0039         return ui->projectNameValue->setText(QString::fromStdString(s));
0040     }
0041 
0042     std::string sourcePathText()
0043     {
0044         return ui->sourceCodePathValue->text().toStdString();
0045     }
0046 
0047     void setSourcePathText(std::string const& s)
0048     {
0049         return ui->sourceCodePathValue->setText(QString::fromStdString(s));
0050     }
0051 
0052     void clickApply()
0053     {
0054         ui->buttonBox->button(QDialogButtonBox::StandardButton::Apply)->click();
0055     }
0056 };
0057 
0058 TEST_CASE_METHOD(QTApplicationFixture, "Basic workflow")
0059 {
0060     auto projectModel = ProjectFile{};
0061 
0062     projectModel.setProjectName("MyProject");
0063     projectModel.setSourceCodePath("/a/b/c/");
0064 
0065     auto dialog = ProjectSettingsDialogForTesting{projectModel};
0066     dialog.show();
0067 
0068     REQUIRE(dialog.projectNameText() == "MyProject");
0069     REQUIRE(dialog.sourcePathText() == "/a/b/c/");
0070     dialog.setProjectNameText("OtherName");
0071     dialog.setSourcePathText("/d/e/f/");
0072 
0073     // Changes are not applied while the button "apply" is not clicked
0074     REQUIRE(projectModel.projectName() == "MyProject");
0075     REQUIRE(projectModel.sourceCodePath() == "/a/b/c/");
0076     dialog.clickApply();
0077     REQUIRE(projectModel.projectName() == "OtherName");
0078     REQUIRE(projectModel.sourceCodePath() == "/d/e/f/");
0079 }