utils: improve assert_equal macro

make it a macro so we get line numbers etc
This commit is contained in:
Dirk-Jan C. Binnema
2022-02-21 23:21:04 +02:00
parent ec826cd838
commit 0e117fd6ab
2 changed files with 11 additions and 17 deletions

View File

@ -502,21 +502,6 @@ Mu::canonicalize_filename(const std::string& path, const std::string& relative_t
return rv; return rv;
} }
void
Mu::assert_equal(const std::string& s1, const std::string& s2)
{
g_assert_cmpstr(s1.c_str(), ==, s2.c_str());
}
void
Mu::assert_equal(const Mu::StringVec& v1, const Mu::StringVec& v2)
{
g_assert_cmpuint(v1.size(), ==, v2.size());
for (auto i = 0U; i != v1.size(); ++i)
assert_equal(v1[i], v2[i]);
}
void void
Mu::allow_warnings() Mu::allow_warnings()
{ {

View File

@ -313,14 +313,23 @@ private:
* @param s1 string1 * @param s1 string1
* @param s2 string2 * @param s2 string2
*/ */
void assert_equal(const std::string& s1, const std::string& s2); #define assert_equal(s1__,s2__) do { \
std::string s1s__(s1__), s2s__(s2__); \
g_assert_cmpstr(s1s__.c_str(), ==, s2s__.c_str()); \
} while(0)
/** /**
* For unit tests, assert that to containers are the same. * For unit tests, assert that to containers are the same.
* *
* @param c1 container1 * @param c1 container1
* @param c2 container2 * @param c2 container2
*/ */
void assert_equal(const StringVec& v1, const StringVec& v2); #define assert_equal_svec(svec1__,svec2__) do { \
g_assert_cmpuint((svec1__).size(), ==, (svec2__).size()); \
for (auto i = 0U; i != (svec1__).size(); ++i) \
g_assert_cmpstr((svec1__)[i].c_str(), ==, (svec2__)[i].c_str()); \
} while (0)
/** /**
* For unit-tests, allow warnings in the current function. * For unit-tests, allow warnings in the current function.