diff --git a/gui/manualtest/projectfiledialog.md b/gui/manualtest/projectfiledialog.md index e8ce09cc96e..eb76109e53e 100644 --- a/gui/manualtest/projectfiledialog.md +++ b/gui/manualtest/projectfiledialog.md @@ -4,8 +4,21 @@ Some manual testing in the project file dialog interface + +## Test: Platform files + +Ticket: #14489 + +EXPECTED: In the project file dialog it should be possible to select xml files i.e. pic8.xml + +TODO: can this test be automated + + + ## Test: Misra C checkbox +Ticket: #14488 + Matrix: Use both open source and premium 1. Load project file in trac ticket 14488 diff --git a/gui/projectfile.cpp b/gui/projectfile.cpp index 3e4e783d7a8..d2913fbfd65 100644 --- a/gui/projectfile.cpp +++ b/gui/projectfile.cpp @@ -26,6 +26,7 @@ #include +#include #include #include #include @@ -1176,3 +1177,23 @@ QString ProjectFile::getAddonFilePath(QString filesDir, const QString &addon) return QString(); } + +QStringList ProjectFile::getSearchPaths(const QString& projectPath, const QString& appPath, const QString& datadir, const QString& dir) { + QStringList ret; + ret << appPath << (appPath + "/" + dir) << projectPath; +#ifdef FILESDIR + if (FILESDIR[0]) + ret << FILESDIR << (FILESDIR "/" + dir); +#endif + if (!datadir.isEmpty()) + ret << datadir << (datadir + "/" + dir); + return ret; +} + +QStringList ProjectFile::getSearchPaths(const QString& dir) const { + const QFileInfo inf(mFilename); + const QString applicationFilePath = QCoreApplication::applicationFilePath(); + const QString appPath = QFileInfo(applicationFilePath).canonicalPath(); + const QString datadir = getDataDir(); + return getSearchPaths(inf.canonicalFilePath(), appPath, datadir, dir); +} diff --git a/gui/projectfile.h b/gui/projectfile.h index 18503e8d6e1..01abe0643a5 100644 --- a/gui/projectfile.h +++ b/gui/projectfile.h @@ -446,6 +446,10 @@ class ProjectFile : public QObject { /** Use Clang parser */ bool clangParser; + /** Get paths where we should glob for certain files (dir="cfg"/"platforms"/etc */ + QStringList getSearchPaths(const QString& dir) const; + static QStringList getSearchPaths(const QString& projectPath, const QString& appPath, const QString& datadir, const QString& dir); + protected: /** diff --git a/gui/projectfiledialog.cpp b/gui/projectfiledialog.cpp index eeee66231b7..76fe51d2274 100644 --- a/gui/projectfiledialog.cpp +++ b/gui/projectfiledialog.cpp @@ -40,7 +40,6 @@ #include #include #include -#include #include #include #include @@ -142,22 +141,10 @@ ProjectFileDialog::ProjectFileDialog(ProjectFile *projectFile, bool premium, QWi mUI->premiumLicense->setVisible(false); - // Checkboxes for the libraries.. - const QString applicationFilePath = QCoreApplication::applicationFilePath(); - const QString appPath = QFileInfo(applicationFilePath).canonicalPath(); - const QString datadir = getDataDir(); - QStringList searchPaths; - searchPaths << appPath << appPath + "/cfg" << inf.canonicalPath(); -#ifdef FILESDIR - if (FILESDIR[0]) - searchPaths << FILESDIR << FILESDIR "/cfg"; -#endif - if (!datadir.isEmpty()) - searchPaths << datadir << datadir + "/cfg"; QStringList libs; // Search the std.cfg first since other libraries could depend on it QString stdLibraryFilename; - for (const QString &sp : searchPaths) { + for (const QString &sp : projectFile->getSearchPaths("cfg")) { QDir dir(sp); dir.setSorting(QDir::Name); dir.setNameFilters(QStringList("*.cfg")); @@ -179,7 +166,7 @@ ProjectFileDialog::ProjectFileDialog(ProjectFile *projectFile, bool premium, QWi break; } // Search other libraries - for (const QString &sp : searchPaths) { + for (const QString &sp : projectFile->getSearchPaths("cfg")) { QDir dir(sp); dir.setSorting(QDir::Name); dir.setNameFilters(QStringList("*.cfg")); @@ -218,22 +205,15 @@ ProjectFileDialog::ProjectFileDialog(ProjectFile *projectFile, bool premium, QWi for (const Platform::Type builtinPlatform : builtinPlatforms) mUI->mComboBoxPlatform->addItem(platforms.get(builtinPlatform).mTitle); QStringList platformFiles; - for (QString sp : searchPaths) { - if (sp.endsWith("/cfg")) - sp = sp.mid(0,sp.length()-3) + "platforms"; + for (const QString& sp : projectFile->getSearchPaths("platforms")) { QDir dir(sp); dir.setSorting(QDir::Name); dir.setNameFilters(QStringList("*.xml")); dir.setFilter(QDir::Files | QDir::NoDotAndDotDot); for (const QFileInfo& item : dir.entryInfoList()) { const QString platformFile = item.fileName(); - - const std::vector paths = { - Path::getCurrentPath(), // TODO: do we want to look in CWD? - applicationFilePath.toStdString(), - }; Platform plat2; - if (!plat2.loadFromFile(paths, platformFile.toStdString())) + if (!plat2.loadFromFile({sp.toStdString()}, platformFile.toStdString())) continue; if (platformFiles.indexOf(platformFile) == -1) diff --git a/gui/test/projectfile/CMakeLists.txt b/gui/test/projectfile/CMakeLists.txt index 2d9c254ec5f..f9bab8ba0c7 100644 --- a/gui/test/projectfile/CMakeLists.txt +++ b/gui/test/projectfile/CMakeLists.txt @@ -4,6 +4,7 @@ add_dependencies(gui-build-deps build-projectfile-deps) add_executable(test-projectfile ${test-projectfile_SRC} testprojectfile.cpp + ${CMAKE_SOURCE_DIR}/gui/common.cpp ${CMAKE_SOURCE_DIR}/gui/projectfile.cpp ) target_include_directories(test-projectfile PRIVATE ${CMAKE_SOURCE_DIR}/gui ${CMAKE_SOURCE_DIR}/lib) diff --git a/gui/test/projectfile/testprojectfile.cpp b/gui/test/projectfile/testprojectfile.cpp index 988d62e8bce..b38de056ec3 100644 --- a/gui/test/projectfile/testprojectfile.cpp +++ b/gui/test/projectfile/testprojectfile.cpp @@ -136,6 +136,24 @@ void TestProjectFile::getAddonFilePath() const QCOMPARE(ProjectFile::getAddonFilePath(tempdir.path(), filepath), filepath); } +void TestProjectFile::getSearchPaths() const +{ +#ifdef FILESDIR + const QString f(FILESDIR "\n" // example: "/usr/local/share/cppcheck\n" + FILESDIR "/dir\n"); // example: "/usr/local/share/cppcheck/dir\n" +#else + const QString f; +#endif + + QCOMPARE(ProjectFile::getSearchPaths("projectPath", "appPath", "datadir", "dir").join("\n"), + "appPath\n" + "appPath/dir\n" + "projectPath\n" + + f + + "datadir\n" + "datadir/dir"); +} + void TestProjectFile::getInlineSuppressionDefaultValue() const { ProjectFile projectFile; diff --git a/gui/test/projectfile/testprojectfile.h b/gui/test/projectfile/testprojectfile.h index 8f3e54c3008..027c7069706 100644 --- a/gui/test/projectfile/testprojectfile.h +++ b/gui/test/projectfile/testprojectfile.h @@ -28,6 +28,7 @@ private slots: void loadSimpleNoroot() const; void getAddonFilePath() const; + void getSearchPaths() const; void getInlineSuppressionDefaultValue() const; void getInlineSuppression() const; diff --git a/gui/test/resultstree/CMakeLists.txt b/gui/test/resultstree/CMakeLists.txt index 1bf8a02ffb1..a48b137e349 100644 --- a/gui/test/resultstree/CMakeLists.txt +++ b/gui/test/resultstree/CMakeLists.txt @@ -3,6 +3,7 @@ qt_wrap_cpp(test-resultstree_SRC ${CMAKE_SOURCE_DIR}/gui/resultstree.h ${CMAKE_SOURCE_DIR}/gui/resultitem.h ${CMAKE_SOURCE_DIR}/gui/applicationlist.h + ${CMAKE_SOURCE_DIR}/gui/common.h ${CMAKE_SOURCE_DIR}/gui/projectfile.h ${CMAKE_SOURCE_DIR}/gui/threadhandler.h ${CMAKE_SOURCE_DIR}/gui/threadresult.h @@ -14,6 +15,7 @@ add_executable(test-resultstree testresultstree.cpp ${CMAKE_SOURCE_DIR}/gui/resultstree.cpp ${CMAKE_SOURCE_DIR}/gui/resultitem.cpp + ${CMAKE_SOURCE_DIR}/gui/common.cpp ${CMAKE_SOURCE_DIR}/gui/erroritem.cpp ${CMAKE_SOURCE_DIR}/gui/showtypes.cpp ${CMAKE_SOURCE_DIR}/gui/report.cpp diff --git a/gui/test/resultstree/testresultstree.cpp b/gui/test/resultstree/testresultstree.cpp index ac3ba4ff78c..732ee0715d0 100644 --- a/gui/test/resultstree/testresultstree.cpp +++ b/gui/test/resultstree/testresultstree.cpp @@ -99,10 +99,6 @@ Application& ApplicationList::getApplication(const int /*unused*/) { const Application& ApplicationList::getApplication(const int index) const { return mApplications.at(index); } -QString getPath(const QString &type) { - return "/" + type; -} -void setPath(const QString & /*unused*/, const QString & /*unused*/) {} QString XmlReport::quoteMessage(const QString &message) { return message; }