From 04c2be33a68d8a76b207e39dfb53cdad7e526475 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 24 Sep 2017 22:57:24 +0200 Subject: [PATCH] Unit testing visual studio import --- lib/importproject.h | 24 ++++++++++++------------ test/testimportproject.cpp | 16 ++++++++++++++-- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/lib/importproject.h b/lib/importproject.h index a881fb23c..1a994b445 100644 --- a/lib/importproject.h +++ b/lib/importproject.h @@ -35,19 +35,19 @@ /// @{ namespace cppcheck { -struct stricmp { - bool operator()(const std::string &lhs, const std::string &rhs) const { - if (lhs.size() != rhs.size()) - return lhs.size() < rhs.size(); - for (unsigned int i = 0; i < lhs.size(); ++i) { - char c1 = std::toupper((unsigned char)lhs[i]); - char c2 = std::toupper((unsigned char)rhs[i]); - if (c1 != c2) - return c1 < c2; + struct stricmp { + bool operator()(const std::string &lhs, const std::string &rhs) const { + if (lhs.size() != rhs.size()) + return lhs.size() < rhs.size(); + for (unsigned int i = 0; i < lhs.size(); ++i) { + char c1 = std::toupper((unsigned char)lhs[i]); + char c2 = std::toupper((unsigned char)rhs[i]); + if (c1 != c2) + return c1 < c2; + } + return false; } - return false; - } -}; + }; } /** diff --git a/test/testimportproject.cpp b/test/testimportproject.cpp index a89025528..08812b82d 100644 --- a/test/testimportproject.cpp +++ b/test/testimportproject.cpp @@ -34,6 +34,7 @@ private: TEST_CASE(setDefines); TEST_CASE(setIncludePaths1); TEST_CASE(setIncludePaths2); + TEST_CASE(setIncludePaths3); // macro names are case insensitive } void setDefines() const { @@ -56,7 +57,7 @@ private: ImportProject::FileSettings fs; std::list in; in.push_back("../include"); - std::map variables; + std::map variables; fs.setIncludePaths("abc/def/", in, variables); ASSERT_EQUALS(1U, fs.includePaths.size()); ASSERT_EQUALS("abc/include/", fs.includePaths.front()); @@ -66,7 +67,18 @@ private: ImportProject::FileSettings fs; std::list in; in.push_back("$(SolutionDir)other"); - std::map variables; + std::map variables; + variables["SolutionDir"] = "c:/abc/"; + fs.setIncludePaths("/home/fred", in, variables); + ASSERT_EQUALS(1U, fs.includePaths.size()); + ASSERT_EQUALS("c:/abc/other/", fs.includePaths.front()); + } + + void setIncludePaths3() const { // macro names are case insensitive + ImportProject::FileSettings fs; + std::list in; + in.push_back("$(SOLUTIONDIR)other"); + std::map variables; variables["SolutionDir"] = "c:/abc/"; fs.setIncludePaths("/home/fred", in, variables); ASSERT_EQUALS(1U, fs.includePaths.size());