diff --git a/lib/exprengine.h b/lib/exprengine.h index 305f0392d..9b5114345 100644 --- a/lib/exprengine.h +++ b/lib/exprengine.h @@ -294,7 +294,7 @@ namespace ExprEngine { ValuePtr op1; ValuePtr op2; private: - std::string getName(const std::string &binop, ValuePtr op1, ValuePtr op2) const { + static std::string getName(const std::string& binop, ValuePtr op1, ValuePtr op2) { std::string name1 = op1 ? op1->name : std::string("null"); std::string name2 = op2 ? op2->name : std::string("null"); return "(" + name1 + ")" + binop + "(" + name2 + ")"; diff --git a/lib/valueflow.h b/lib/valueflow.h index 76a8d0e6a..6af45da73 100644 --- a/lib/valueflow.h +++ b/lib/valueflow.h @@ -244,7 +244,7 @@ namespace ValueFlow { /** The value bound */ enum class Bound { Upper, Lower, Point } bound; - /** int value */ + /** int value (or sometimes bool value?) */ long long intvalue; /** token value - the token that has the value. this is used for pointer aliases, strings, etc. */ diff --git a/test/testsimplifytemplate.cpp b/test/testsimplifytemplate.cpp index 9e1631d5e..df5b55ab4 100644 --- a/test/testsimplifytemplate.cpp +++ b/test/testsimplifytemplate.cpp @@ -5297,7 +5297,7 @@ private: ASSERT_EQUALS(expected, tok(code)); } - unsigned int instantiateMatch(const char code[], const std::size_t numberOfArguments, const char patternAfter[]) { + bool instantiateMatch(const char code[], const std::size_t numberOfArguments, const char patternAfter[]) { Tokenizer tokenizer(&settings, this); std::istringstream istr(code); diff --git a/test/testsuite.cpp b/test/testsuite.cpp index 80dc4ca04..ef3f55b68 100644 --- a/test/testsuite.cpp +++ b/test/testsuite.cpp @@ -143,18 +143,23 @@ bool TestFixture::assert_(const char * const filename, const unsigned int linenr return condition; } +void TestFixture::assertEqualsFailed(const char* const filename, const unsigned int linenr, const std::string& expected, const std::string& actual, const std::string& msg) const +{ + ++fails_counter; + errmsg << getLocationStr(filename, linenr) << ": Assertion failed. " << std::endl + << "Expected: " << std::endl + << writestr(expected) << std::endl + << "Actual: " << std::endl + << writestr(actual) << std::endl; + if (!msg.empty()) + errmsg << "Hint:" << std::endl << msg << std::endl; + errmsg << "_____" << std::endl; +} + bool TestFixture::assertEquals(const char * const filename, const unsigned int linenr, const std::string &expected, const std::string &actual, const std::string &msg) const { if (expected != actual) { - ++fails_counter; - errmsg << getLocationStr(filename, linenr) << ": Assertion failed. " << std::endl - << "Expected: " << std::endl - << writestr(expected) << std::endl - << "Actual: " << std::endl - << writestr(actual) << std::endl; - if (!msg.empty()) - errmsg << "Hint:" << std::endl << msg << std::endl; - errmsg << "_____" << std::endl; + assertEqualsFailed(filename, linenr, expected, actual, msg); } return expected == actual; } diff --git a/test/testsuite.h b/test/testsuite.h index 10b8373b3..b69176468 100644 --- a/test/testsuite.h +++ b/test/testsuite.h @@ -53,6 +53,23 @@ protected: bool assert_(const char * const filename, const unsigned int linenr, const bool condition) const; + template + bool assertEquals(const char* const filename, const unsigned int linenr, const T& expected, const U& actual, const std::string& msg = emptyString) const { + if (expected != actual) { + std::ostringstream expectedStr; + expectedStr << expected; + std::ostringstream actualStr; + actualStr << actual; + + assertEqualsFailed(filename, linenr, expectedStr.str(), actualStr.str(), msg); + } + return expected == actual; + } + + //Helper function to be called when an assertEquals assertion fails. + //Writes the appropriate failure message to errmsg and increments fails_counter + void assertEqualsFailed(const char* const filename, const unsigned int linenr, const std::string& expected, const std::string& actual, const std::string& msg) const; + bool assertEquals(const char * const filename, const unsigned int linenr, const std::string &expected, const std::string &actual, const std::string &msg = emptyString) const; void assertEqualsWithoutLineNumbers(const char * const filename, const unsigned int linenr, const std::string &expected, const std::string &actual, const std::string &msg = emptyString) const; bool assertEquals(const char * const filename, const unsigned int linenr, const char expected[], const std::string& actual, const std::string &msg = emptyString) const; diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 8a7f76085..67d98eb2f 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -3103,7 +3103,7 @@ private: values = tokenValues(code, "<"); ASSERT_EQUALS(1, values.size()); ASSERT(values.front().isPossible()); - ASSERT_EQUALS(true, values.front().intvalue); + ASSERT_EQUALS(1, values.front().intvalue); code = "void f() {\n" " S s;\n" @@ -3143,7 +3143,7 @@ private: values = tokenValues(code, ">"); ASSERT_EQUALS(1, values.size()); ASSERT(values.front().isPossible()); - ASSERT_EQUALS(true, values.front().intvalue); + ASSERT_EQUALS(1, values.front().intvalue); code = "void foo() {\n" " struct ISO_PVD_s pvd;\n"