Skip to content

Commit 04c2be3

Browse files
committed
Unit testing visual studio import
1 parent 30e6a05 commit 04c2be3

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

lib/importproject.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,19 @@
3535
/// @{
3636

3737
namespace cppcheck {
38-
struct stricmp {
39-
bool operator()(const std::string &lhs, const std::string &rhs) const {
40-
if (lhs.size() != rhs.size())
41-
return lhs.size() < rhs.size();
42-
for (unsigned int i = 0; i < lhs.size(); ++i) {
43-
char c1 = std::toupper((unsigned char)lhs[i]);
44-
char c2 = std::toupper((unsigned char)rhs[i]);
45-
if (c1 != c2)
46-
return c1 < c2;
38+
struct stricmp {
39+
bool operator()(const std::string &lhs, const std::string &rhs) const {
40+
if (lhs.size() != rhs.size())
41+
return lhs.size() < rhs.size();
42+
for (unsigned int i = 0; i < lhs.size(); ++i) {
43+
char c1 = std::toupper((unsigned char)lhs[i]);
44+
char c2 = std::toupper((unsigned char)rhs[i]);
45+
if (c1 != c2)
46+
return c1 < c2;
47+
}
48+
return false;
4749
}
48-
return false;
49-
}
50-
};
50+
};
5151
}
5252

5353
/**

test/testimportproject.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class TestImportProject : public TestFixture {
3434
TEST_CASE(setDefines);
3535
TEST_CASE(setIncludePaths1);
3636
TEST_CASE(setIncludePaths2);
37+
TEST_CASE(setIncludePaths3); // macro names are case insensitive
3738
}
3839

3940
void setDefines() const {
@@ -56,7 +57,7 @@ class TestImportProject : public TestFixture {
5657
ImportProject::FileSettings fs;
5758
std::list<std::string> in;
5859
in.push_back("../include");
59-
std::map<std::string, std::string> variables;
60+
std::map<std::string, std::string, cppcheck::stricmp> variables;
6061
fs.setIncludePaths("abc/def/", in, variables);
6162
ASSERT_EQUALS(1U, fs.includePaths.size());
6263
ASSERT_EQUALS("abc/include/", fs.includePaths.front());
@@ -66,7 +67,18 @@ class TestImportProject : public TestFixture {
6667
ImportProject::FileSettings fs;
6768
std::list<std::string> in;
6869
in.push_back("$(SolutionDir)other");
69-
std::map<std::string, std::string> variables;
70+
std::map<std::string, std::string, cppcheck::stricmp> variables;
71+
variables["SolutionDir"] = "c:/abc/";
72+
fs.setIncludePaths("/home/fred", in, variables);
73+
ASSERT_EQUALS(1U, fs.includePaths.size());
74+
ASSERT_EQUALS("c:/abc/other/", fs.includePaths.front());
75+
}
76+
77+
void setIncludePaths3() const { // macro names are case insensitive
78+
ImportProject::FileSettings fs;
79+
std::list<std::string> in;
80+
in.push_back("$(SOLUTIONDIR)other");
81+
std::map<std::string, std::string, cppcheck::stricmp> variables;
7082
variables["SolutionDir"] = "c:/abc/";
7183
fs.setIncludePaths("/home/fred", in, variables);
7284
ASSERT_EQUALS(1U, fs.includePaths.size());

0 commit comments

Comments
 (0)