Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions gui/manualtest/projectfiledialog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions gui/projectfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include <utility>

#include <QCoreApplication>
#include <QFile>
#include <QDir>
#include <QIODevice>
Expand Down Expand Up @@ -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);
}
4 changes: 4 additions & 0 deletions gui/projectfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:

/**
Expand Down
28 changes: 4 additions & 24 deletions gui/projectfiledialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
#include <QByteArray>
#include <QCheckBox>
#include <QComboBox>
#include <QCoreApplication>
#include <QDialogButtonBox>
#include <QDir>
#include <QFileDialog>
Expand Down Expand Up @@ -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"));
Expand All @@ -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"));
Expand Down Expand Up @@ -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<std::string> 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)
Expand Down
1 change: 1 addition & 0 deletions gui/test/projectfile/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 18 additions & 0 deletions gui/test/projectfile/testprojectfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions gui/test/projectfile/testprojectfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ private slots:
void loadSimpleNoroot() const;

void getAddonFilePath() const;
void getSearchPaths() const;

void getInlineSuppressionDefaultValue() const;
void getInlineSuppression() const;
Expand Down
2 changes: 2 additions & 0 deletions gui/test/resultstree/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 0 additions & 4 deletions gui/test/resultstree/testresultstree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Loading