Skip to content
Open
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
14 changes: 8 additions & 6 deletions lib/importproject.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ namespace cppcheck {
* @brief Importing project settings.
*/
class CPPCHECKLIB WARN_UNUSED ImportProject {
friend class TestImporter;
public:
enum class Type : std::uint8_t {
NONE,
Expand All @@ -69,9 +68,11 @@ class CPPCHECKLIB WARN_UNUSED ImportProject {
CPPCHECK_GUI
};

protected:
static void fsSetDefines(FileSettings& fs, std::string defs);
static void fsSetIncludePaths(FileSettings& fs, const std::string &basepath, const std::list<std::string> &in, std::map<std::string, std::string, cppcheck::stricmp> &variables);

public:
std::list<FileSettings> fileSettings;
std::vector<std::string> errors;

Expand Down Expand Up @@ -103,24 +104,25 @@ class CPPCHECKLIB WARN_UNUSED ImportProject {
bool importCompileCommands(std::istream &istr);
bool importCppcheckGuiProject(std::istream &istr, Settings &settings, Suppressions &supprs);
static std::string collectArgs(const std::string &cmd, std::vector<std::string> &args);
static void parseArgs(FileSettings &fs, const std::vector<std::string> &args);

private:
struct SharedItemsProject {
bool successful = false;
std::string pathToProjectFile;
std::vector<std::string> includePaths;
std::vector<std::string> sourceFiles;
};

bool importSln(std::istream &istr, const std::string &path, const std::vector<std::string> &fileFilters);
SharedItemsProject importVcxitems(const std::string &filename, const std::vector<std::string> &fileFilters, std::vector<SharedItemsProject> &cache);
bool importVcxproj(const std::string &filename, std::map<std::string, std::string, cppcheck::stricmp> &variables, const std::string &additionalIncludeDirectories, const std::vector<std::string> &fileFilters, std::vector<SharedItemsProject> &cache);
bool importVcxproj(const std::string &filename, const tinyxml2::XMLDocument &doc, std::map<std::string, std::string, cppcheck::stricmp> &variables, const std::string &additionalIncludeDirectories, const std::vector<std::string> &fileFilters, std::vector<SharedItemsProject> &cache);
bool importBcb6Prj(const std::string &projectFilename);

private:
static void parseArgs(FileSettings &fs, const std::vector<std::string> &args);
void setRelativePaths(const std::string &filename);

bool importSln(std::istream &istr, const std::string &path, const std::vector<std::string> &fileFilters);
SharedItemsProject importVcxitems(const std::string &filename, const std::vector<std::string> &fileFilters, std::vector<SharedItemsProject> &cache);
bool importBcb6Prj(const std::string &projectFilename);

std::string mPath;
std::set<std::string> mAllVSConfigs;
};
Expand Down
18 changes: 10 additions & 8 deletions test/testimportproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@
#include <utility>
#include <vector>

class TestImporter : public ImportProject {
class TestImporter final : public ImportProject {
public:
using ImportProject::importCompileCommands;
using ImportProject::importCppcheckGuiProject;
using ImportProject::importVcxproj;
using ImportProject::SharedItemsProject;
using ImportProject::collectArgs;
using ImportProject::fsSetDefines;
Comment on lines -35 to +42
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks better than the friend approach I used in all the other cases. I will look into adjusting the others. I will not do it to the existing open PRs but do it in a batch later on since I still have others sitting locally.

using ImportProject::fsSetIncludePaths;
};


Expand Down Expand Up @@ -88,24 +90,24 @@ class TestImportProject : public TestFixture {
void setDefines() const {
FileSettings fs{"test.cpp", Standards::Language::CPP, 0};

ImportProject::fsSetDefines(fs, "A");
TestImporter::fsSetDefines(fs, "A");
ASSERT_EQUALS("A=1", fs.defines);

ImportProject::fsSetDefines(fs, "A;B;");
TestImporter::fsSetDefines(fs, "A;B;");
ASSERT_EQUALS("A=1;B=1", fs.defines);

ImportProject::fsSetDefines(fs, "A;;B;");
TestImporter::fsSetDefines(fs, "A;;B;");
ASSERT_EQUALS("A=1;B=1", fs.defines);

ImportProject::fsSetDefines(fs, "A;;B");
TestImporter::fsSetDefines(fs, "A;;B");
ASSERT_EQUALS("A=1;B=1", fs.defines);
}

void setIncludePaths1() const {
FileSettings fs{"test.cpp", Standards::Language::CPP, 0};
std::list<std::string> in(1, "../include");
std::map<std::string, std::string, cppcheck::stricmp> variables;
ImportProject::fsSetIncludePaths(fs, "abc/def/", in, variables);
TestImporter::fsSetIncludePaths(fs, "abc/def/", in, variables);
ASSERT_EQUALS(1U, fs.includePaths.size());
ASSERT_EQUALS("abc/include/", fs.includePaths.front());
}
Expand All @@ -115,7 +117,7 @@ class TestImportProject : public TestFixture {
std::list<std::string> in(1, "$(SolutionDir)other");
std::map<std::string, std::string, cppcheck::stricmp> variables;
variables["SolutionDir"] = "c:/abc/";
ImportProject::fsSetIncludePaths(fs, "/home/fred", in, variables);
TestImporter::fsSetIncludePaths(fs, "/home/fred", in, variables);
ASSERT_EQUALS(1U, fs.includePaths.size());
ASSERT_EQUALS("c:/abc/other/", fs.includePaths.front());
}
Expand All @@ -125,7 +127,7 @@ class TestImportProject : public TestFixture {
std::list<std::string> in(1, "$(SOLUTIONDIR)other");
std::map<std::string, std::string, cppcheck::stricmp> variables;
variables["SolutionDir"] = "c:/abc/";
ImportProject::fsSetIncludePaths(fs, "/home/fred", in, variables);
TestImporter::fsSetIncludePaths(fs, "/home/fred", in, variables);
ASSERT_EQUALS(1U, fs.includePaths.size());
ASSERT_EQUALS("c:/abc/other/", fs.includePaths.front());
}
Expand Down
Loading