From 0e117fd6ab6bc1dcbe3a31ac4405af0966406fe2 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Mon, 21 Feb 2022 23:21:04 +0200 Subject: [PATCH] utils: improve assert_equal macro make it a macro so we get line numbers etc --- lib/utils/mu-utils.cc | 15 --------------- lib/utils/mu-utils.hh | 13 +++++++++++-- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/lib/utils/mu-utils.cc b/lib/utils/mu-utils.cc index e87fc020..287d26be 100644 --- a/lib/utils/mu-utils.cc +++ b/lib/utils/mu-utils.cc @@ -502,21 +502,6 @@ Mu::canonicalize_filename(const std::string& path, const std::string& relative_t 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 Mu::allow_warnings() { diff --git a/lib/utils/mu-utils.hh b/lib/utils/mu-utils.hh index 868ffe6a..5ff63131 100644 --- a/lib/utils/mu-utils.hh +++ b/lib/utils/mu-utils.hh @@ -313,14 +313,23 @@ private: * @param s1 string1 * @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. * * @param c1 container1 * @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.