Simplified code in testerrorlogger by reusing constant object.
This commit is contained in:
parent
758d68519d
commit
a65e08b648
|
@ -23,10 +23,12 @@
|
||||||
|
|
||||||
class TestErrorLogger : public TestFixture {
|
class TestErrorLogger : public TestFixture {
|
||||||
public:
|
public:
|
||||||
TestErrorLogger() : TestFixture("TestErrorLogger") {
|
TestErrorLogger() : TestFixture("TestErrorLogger"), fooCpp5("foo.cpp", 5), barCpp8("bar.cpp", 8) {
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
const ErrorLogger::ErrorMessage::FileLocation fooCpp5;
|
||||||
|
const ErrorLogger::ErrorMessage::FileLocation barCpp8;
|
||||||
|
|
||||||
void run() {
|
void run() {
|
||||||
TEST_CASE(FileLocationDefaults);
|
TEST_CASE(FileLocationDefaults);
|
||||||
|
@ -68,11 +70,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void ErrorMessageConstruct() const {
|
void ErrorMessageConstruct() const {
|
||||||
ErrorLogger::ErrorMessage::FileLocation loc;
|
std::list<ErrorLogger::ErrorMessage::FileLocation> locs(1, fooCpp5);
|
||||||
loc.setfile("foo.cpp");
|
|
||||||
loc.line = 5;
|
|
||||||
std::list<ErrorLogger::ErrorMessage::FileLocation> locs;
|
|
||||||
locs.push_back(loc);
|
|
||||||
ErrorMessage msg(locs, Severity::error, "Programming error.", "errorId", false);
|
ErrorMessage msg(locs, Severity::error, "Programming error.", "errorId", false);
|
||||||
ASSERT_EQUALS(1, (int)msg._callStack.size());
|
ASSERT_EQUALS(1, (int)msg._callStack.size());
|
||||||
ASSERT_EQUALS("Programming error.", msg.shortMessage());
|
ASSERT_EQUALS("Programming error.", msg.shortMessage());
|
||||||
|
@ -82,15 +80,9 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void ErrorMessageConstructLocations() const {
|
void ErrorMessageConstructLocations() const {
|
||||||
ErrorLogger::ErrorMessage::FileLocation loc;
|
|
||||||
loc.setfile("foo.cpp");
|
|
||||||
loc.line = 5;
|
|
||||||
ErrorLogger::ErrorMessage::FileLocation loc2;
|
|
||||||
loc2.setfile("bar.cpp");
|
|
||||||
loc2.line = 8;
|
|
||||||
std::list<ErrorLogger::ErrorMessage::FileLocation> locs;
|
std::list<ErrorLogger::ErrorMessage::FileLocation> locs;
|
||||||
locs.push_back(loc);
|
locs.push_back(fooCpp5);
|
||||||
locs.push_back(loc2);
|
locs.push_back(barCpp8);
|
||||||
ErrorMessage msg(locs, Severity::error, "Programming error.", "errorId", false);
|
ErrorMessage msg(locs, Severity::error, "Programming error.", "errorId", false);
|
||||||
ASSERT_EQUALS(2, (int)msg._callStack.size());
|
ASSERT_EQUALS(2, (int)msg._callStack.size());
|
||||||
ASSERT_EQUALS("Programming error.", msg.shortMessage());
|
ASSERT_EQUALS("Programming error.", msg.shortMessage());
|
||||||
|
@ -100,11 +92,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void ErrorMessageVerbose() const {
|
void ErrorMessageVerbose() const {
|
||||||
ErrorLogger::ErrorMessage::FileLocation loc;
|
std::list<ErrorLogger::ErrorMessage::FileLocation> locs(1, fooCpp5);
|
||||||
loc.setfile("foo.cpp");
|
|
||||||
loc.line = 5;
|
|
||||||
std::list<ErrorLogger::ErrorMessage::FileLocation> locs;
|
|
||||||
locs.push_back(loc);
|
|
||||||
ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId", false);
|
ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId", false);
|
||||||
ASSERT_EQUALS(1, (int)msg._callStack.size());
|
ASSERT_EQUALS(1, (int)msg._callStack.size());
|
||||||
ASSERT_EQUALS("Programming error.", msg.shortMessage());
|
ASSERT_EQUALS("Programming error.", msg.shortMessage());
|
||||||
|
@ -114,15 +102,9 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void ErrorMessageVerboseLocations() const {
|
void ErrorMessageVerboseLocations() const {
|
||||||
ErrorLogger::ErrorMessage::FileLocation loc;
|
|
||||||
loc.setfile("foo.cpp");
|
|
||||||
loc.line = 5;
|
|
||||||
std::list<ErrorLogger::ErrorMessage::FileLocation> locs;
|
std::list<ErrorLogger::ErrorMessage::FileLocation> locs;
|
||||||
ErrorLogger::ErrorMessage::FileLocation loc2;
|
locs.push_back(fooCpp5);
|
||||||
loc2.setfile("bar.cpp");
|
locs.push_back(barCpp8);
|
||||||
loc2.line = 8;
|
|
||||||
locs.push_back(loc);
|
|
||||||
locs.push_back(loc2);
|
|
||||||
ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId", false);
|
ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId", false);
|
||||||
ASSERT_EQUALS(2, (int)msg._callStack.size());
|
ASSERT_EQUALS(2, (int)msg._callStack.size());
|
||||||
ASSERT_EQUALS("Programming error.", msg.shortMessage());
|
ASSERT_EQUALS("Programming error.", msg.shortMessage());
|
||||||
|
@ -132,11 +114,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void CustomFormat() const {
|
void CustomFormat() const {
|
||||||
ErrorLogger::ErrorMessage::FileLocation loc;
|
std::list<ErrorLogger::ErrorMessage::FileLocation> locs(1, fooCpp5);
|
||||||
loc.setfile("foo.cpp");
|
|
||||||
loc.line = 5;
|
|
||||||
std::list<ErrorLogger::ErrorMessage::FileLocation> locs;
|
|
||||||
locs.push_back(loc);
|
|
||||||
ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId", false);
|
ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId", false);
|
||||||
ASSERT_EQUALS(1, (int)msg._callStack.size());
|
ASSERT_EQUALS(1, (int)msg._callStack.size());
|
||||||
ASSERT_EQUALS("Programming error.", msg.shortMessage());
|
ASSERT_EQUALS("Programming error.", msg.shortMessage());
|
||||||
|
@ -146,11 +124,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void CustomFormat2() const {
|
void CustomFormat2() const {
|
||||||
ErrorLogger::ErrorMessage::FileLocation loc;
|
std::list<ErrorLogger::ErrorMessage::FileLocation> locs(1, fooCpp5);
|
||||||
loc.setfile("foo.cpp");
|
|
||||||
loc.line = 5;
|
|
||||||
std::list<ErrorLogger::ErrorMessage::FileLocation> locs;
|
|
||||||
locs.push_back(loc);
|
|
||||||
ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId", false);
|
ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId", false);
|
||||||
ASSERT_EQUALS(1, (int)msg._callStack.size());
|
ASSERT_EQUALS(1, (int)msg._callStack.size());
|
||||||
ASSERT_EQUALS("Programming error.", msg.shortMessage());
|
ASSERT_EQUALS("Programming error.", msg.shortMessage());
|
||||||
|
@ -161,15 +135,9 @@ private:
|
||||||
|
|
||||||
void CustomFormatLocations() const {
|
void CustomFormatLocations() const {
|
||||||
// Check that first location from location stack is used in template
|
// Check that first location from location stack is used in template
|
||||||
ErrorLogger::ErrorMessage::FileLocation loc;
|
|
||||||
loc.setfile("foo.cpp");
|
|
||||||
loc.line = 5;
|
|
||||||
ErrorLogger::ErrorMessage::FileLocation loc2;
|
|
||||||
loc2.setfile("bar.cpp");
|
|
||||||
loc2.line = 8;
|
|
||||||
std::list<ErrorLogger::ErrorMessage::FileLocation> locs;
|
std::list<ErrorLogger::ErrorMessage::FileLocation> locs;
|
||||||
locs.push_back(loc);
|
locs.push_back(fooCpp5);
|
||||||
locs.push_back(loc2);
|
locs.push_back(barCpp8);
|
||||||
ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId", false);
|
ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId", false);
|
||||||
ASSERT_EQUALS(2, (int)msg._callStack.size());
|
ASSERT_EQUALS(2, (int)msg._callStack.size());
|
||||||
ASSERT_EQUALS("Programming error.", msg.shortMessage());
|
ASSERT_EQUALS("Programming error.", msg.shortMessage());
|
||||||
|
@ -179,11 +147,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void ToXml() const {
|
void ToXml() const {
|
||||||
ErrorLogger::ErrorMessage::FileLocation loc;
|
std::list<ErrorLogger::ErrorMessage::FileLocation> locs(1, fooCpp5);
|
||||||
loc.setfile("foo.cpp");
|
|
||||||
loc.line = 5;
|
|
||||||
std::list<ErrorLogger::ErrorMessage::FileLocation> locs;
|
|
||||||
locs.push_back(loc);
|
|
||||||
ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId", false);
|
ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId", false);
|
||||||
ASSERT_EQUALS("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<results>", ErrorLogger::ErrorMessage::getXMLHeader(1));
|
ASSERT_EQUALS("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<results>", ErrorLogger::ErrorMessage::getXMLHeader(1));
|
||||||
ASSERT_EQUALS("</results>", ErrorLogger::ErrorMessage::getXMLFooter(1));
|
ASSERT_EQUALS("</results>", ErrorLogger::ErrorMessage::getXMLFooter(1));
|
||||||
|
@ -191,15 +155,9 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void ToXmlLocations() const {
|
void ToXmlLocations() const {
|
||||||
ErrorLogger::ErrorMessage::FileLocation loc;
|
|
||||||
loc.setfile("foo.cpp");
|
|
||||||
loc.line = 5;
|
|
||||||
ErrorLogger::ErrorMessage::FileLocation loc2;
|
|
||||||
loc2.setfile("bar.cpp");
|
|
||||||
loc2.line = 8;
|
|
||||||
std::list<ErrorLogger::ErrorMessage::FileLocation> locs;
|
std::list<ErrorLogger::ErrorMessage::FileLocation> locs;
|
||||||
locs.push_back(loc);
|
locs.push_back(fooCpp5);
|
||||||
locs.push_back(loc2);
|
locs.push_back(barCpp8);
|
||||||
ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId", false);
|
ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId", false);
|
||||||
ASSERT_EQUALS("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<results>", ErrorLogger::ErrorMessage::getXMLHeader(1));
|
ASSERT_EQUALS("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<results>", ErrorLogger::ErrorMessage::getXMLHeader(1));
|
||||||
ASSERT_EQUALS("</results>", ErrorLogger::ErrorMessage::getXMLFooter(1));
|
ASSERT_EQUALS("</results>", ErrorLogger::ErrorMessage::getXMLFooter(1));
|
||||||
|
@ -207,11 +165,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void ToVerboseXml() const {
|
void ToVerboseXml() const {
|
||||||
ErrorLogger::ErrorMessage::FileLocation loc;
|
std::list<ErrorLogger::ErrorMessage::FileLocation> locs(1, fooCpp5);
|
||||||
loc.setfile("foo.cpp");
|
|
||||||
loc.line = 5;
|
|
||||||
std::list<ErrorLogger::ErrorMessage::FileLocation> locs;
|
|
||||||
locs.push_back(loc);
|
|
||||||
ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId", false);
|
ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId", false);
|
||||||
ASSERT_EQUALS("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<results>", ErrorLogger::ErrorMessage::getXMLHeader(1));
|
ASSERT_EQUALS("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<results>", ErrorLogger::ErrorMessage::getXMLHeader(1));
|
||||||
ASSERT_EQUALS("</results>", ErrorLogger::ErrorMessage::getXMLFooter(1));
|
ASSERT_EQUALS("</results>", ErrorLogger::ErrorMessage::getXMLFooter(1));
|
||||||
|
@ -219,15 +173,9 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void ToVerboseXmlLocations() const {
|
void ToVerboseXmlLocations() const {
|
||||||
ErrorLogger::ErrorMessage::FileLocation loc;
|
|
||||||
loc.setfile("foo.cpp");
|
|
||||||
loc.line = 5;
|
|
||||||
ErrorLogger::ErrorMessage::FileLocation loc2;
|
|
||||||
loc2.setfile("bar.cpp");
|
|
||||||
loc2.line = 8;
|
|
||||||
std::list<ErrorLogger::ErrorMessage::FileLocation> locs;
|
std::list<ErrorLogger::ErrorMessage::FileLocation> locs;
|
||||||
locs.push_back(loc);
|
locs.push_back(fooCpp5);
|
||||||
locs.push_back(loc2);
|
locs.push_back(barCpp8);
|
||||||
ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId", false);
|
ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId", false);
|
||||||
ASSERT_EQUALS("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<results>", ErrorLogger::ErrorMessage::getXMLHeader(1));
|
ASSERT_EQUALS("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<results>", ErrorLogger::ErrorMessage::getXMLHeader(1));
|
||||||
ASSERT_EQUALS("</results>", ErrorLogger::ErrorMessage::getXMLFooter(1));
|
ASSERT_EQUALS("</results>", ErrorLogger::ErrorMessage::getXMLFooter(1));
|
||||||
|
@ -235,11 +183,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void ToXmlV2() const {
|
void ToXmlV2() const {
|
||||||
ErrorLogger::ErrorMessage::FileLocation loc;
|
std::list<ErrorLogger::ErrorMessage::FileLocation> locs(1, fooCpp5);
|
||||||
loc.setfile("foo.cpp");
|
|
||||||
loc.line = 5;
|
|
||||||
std::list<ErrorLogger::ErrorMessage::FileLocation> locs;
|
|
||||||
locs.push_back(loc);
|
|
||||||
ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId", false);
|
ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId", false);
|
||||||
std::string header("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<results version=\"2\">\n");
|
std::string header("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<results version=\"2\">\n");
|
||||||
header += " <cppcheck version=\"";
|
header += " <cppcheck version=\"";
|
||||||
|
@ -254,15 +198,9 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void ToXmlV2Locations() const {
|
void ToXmlV2Locations() const {
|
||||||
ErrorLogger::ErrorMessage::FileLocation loc;
|
|
||||||
loc.setfile("foo.cpp");
|
|
||||||
loc.line = 5;
|
|
||||||
ErrorLogger::ErrorMessage::FileLocation loc2;
|
|
||||||
loc2.setfile("bar.cpp");
|
|
||||||
loc2.line = 8;
|
|
||||||
std::list<ErrorLogger::ErrorMessage::FileLocation> locs;
|
std::list<ErrorLogger::ErrorMessage::FileLocation> locs;
|
||||||
locs.push_back(loc);
|
locs.push_back(fooCpp5);
|
||||||
locs.push_back(loc2);
|
locs.push_back(barCpp8);
|
||||||
ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId", false);
|
ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId", false);
|
||||||
std::string header("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<results version=\"2\">\n");
|
std::string header("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<results version=\"2\">\n");
|
||||||
header += " <cppcheck version=\"";
|
header += " <cppcheck version=\"";
|
||||||
|
@ -279,11 +217,7 @@ private:
|
||||||
|
|
||||||
void InconclusiveXml() const {
|
void InconclusiveXml() const {
|
||||||
// Location
|
// Location
|
||||||
ErrorLogger::ErrorMessage::FileLocation loc;
|
std::list<ErrorLogger::ErrorMessage::FileLocation> locs(1, fooCpp5);
|
||||||
loc.setfile("foo.cpp");
|
|
||||||
loc.line = 5;
|
|
||||||
std::list<ErrorLogger::ErrorMessage::FileLocation> locs;
|
|
||||||
locs.push_back(loc);
|
|
||||||
|
|
||||||
// Inconclusive error message
|
// Inconclusive error message
|
||||||
ErrorMessage msg(locs, Severity::error, "Programming error", "errorId", true);
|
ErrorMessage msg(locs, Severity::error, "Programming error", "errorId", true);
|
||||||
|
|
Loading…
Reference in New Issue