@@ -68,39 +68,35 @@ class TestFixture : public ErrorLogger {
6868 virtual void teardownTestInternal () {}
6969 std::string getLocationStr (const char * filename, unsigned int linenr) const ;
7070
71- bool assert_ (const char * filename, unsigned int linenr, bool condition) const ;
71+ void assert_ (const char * filename, unsigned int linenr, bool condition) const ;
7272
7373 template <typename T>
74- bool assertEquals (const char * const filename, const unsigned int linenr, const T& expected, const T& actual, const std::string& msg = emptyString) const {
74+ void assertEquals (const char * const filename, const unsigned int linenr, const T& expected, const T& actual, const std::string& msg = emptyString) const {
7575 if (expected != actual) {
7676 std::ostringstream expectedStr;
7777 expectedStr << expected;
7878 std::ostringstream actualStr;
7979 actualStr << actual;
8080
81- assertEqualsFailed (filename, linenr, expectedStr.str (), actualStr.str (), msg);
81+ assertFailure (filename, linenr, expectedStr.str (), actualStr.str (), msg);
8282 }
83- return expected == actual;
8483 }
8584
8685 template <typename T>
87- bool assertEqualsEnum (const char * const filename, const unsigned int linenr, const T& expected, const T& actual, const std::string& msg = emptyString) const {
86+ void assertEqualsEnum (const char * const filename, const unsigned int linenr, const T& expected, const T& actual, const std::string& msg = emptyString) const {
8887 if (std::is_unsigned<T>())
89- return assertEquals (filename, linenr, static_cast <std::uint64_t >(expected), static_cast <std::uint64_t >(actual), msg);
90- return assertEquals (filename, linenr, static_cast <std::int64_t >(expected), static_cast <std::int64_t >(actual), msg);
88+ assertEquals (filename, linenr, static_cast <std::uint64_t >(expected), static_cast <std::uint64_t >(actual), msg);
89+ else
90+ assertEquals (filename, linenr, static_cast <std::int64_t >(expected), static_cast <std::int64_t >(actual), msg);
9191 }
9292
93- // Helper function to be called when an assertEquals assertion fails.
94- // Writes the appropriate failure message to errmsg and increments fails_counter
95- void assertEqualsFailed (const char * filename, unsigned int linenr, const std::string& expected, const std::string& actual, const std::string& msg) const ;
96-
97- bool assertEquals (const char * filename, unsigned int linenr, const std::string &expected, const std::string &actual, const std::string &msg = emptyString) const ;
98- bool assertEqualsWithoutLineNumbers (const char * filename, unsigned int linenr, const std::string &expected, const std::string &actual, const std::string &msg = emptyString) const ;
99- bool assertEquals (const char * filename, unsigned int linenr, const char expected[], const std::string& actual, const std::string &msg = emptyString) const ;
100- bool assertEquals (const char * filename, unsigned int linenr, const char expected[], const char actual[], const std::string &msg = emptyString) const ;
101- bool assertEquals (const char * filename, unsigned int linenr, const std::string& expected, const char actual[], const std::string &msg = emptyString) const ;
102- bool assertEquals (const char * filename, unsigned int linenr, long long expected, long long actual, const std::string &msg = emptyString) const ;
103- bool assertEqualsDouble (const char * filename, unsigned int linenr, double expected, double actual, double tolerance, const std::string &msg = emptyString) const ;
93+ void assertEquals (const char * filename, unsigned int linenr, const std::string &expected, const std::string &actual, const std::string &msg = emptyString) const ;
94+ void assertEqualsWithoutLineNumbers (const char * filename, unsigned int linenr, const std::string &expected, const std::string &actual, const std::string &msg = emptyString) const ;
95+ void assertEquals (const char * filename, unsigned int linenr, const char expected[], const std::string& actual, const std::string &msg = emptyString) const ;
96+ void assertEquals (const char * filename, unsigned int linenr, const char expected[], const char actual[], const std::string &msg = emptyString) const ;
97+ void assertEquals (const char * filename, unsigned int linenr, const std::string& expected, const char actual[], const std::string &msg = emptyString) const ;
98+ void assertEquals (const char * filename, unsigned int linenr, long long expected, long long actual, const std::string &msg = emptyString) const ;
99+ void assertEqualsDouble (const char * filename, unsigned int linenr, double expected, double actual, double tolerance, const std::string &msg = emptyString) const ;
104100
105101 void todoAssertEquals (const char * filename, unsigned int linenr, const std::string &wanted,
106102 const std::string ¤t, const std::string &actual) const ;
@@ -267,6 +263,10 @@ class TestFixture : public ErrorLogger {
267263 const Settings settingsDefault;
268264
269265private:
266+ // Helper function to be called when an assertEquals assertion fails.
267+ // Writes the appropriate failure message to errmsg and increments fails_counter
268+ void assertFailure (const char * filename, unsigned int linenr, const std::string& expected, const std::string& actual, const std::string& msg) const ;
269+
270270 std::ostringstream mOutput ;
271271 std::ostringstream mErrout ;
272272
@@ -295,31 +295,31 @@ class TestInstance {
295295 std::unique_ptr<TestFixture> impl;
296296};
297297
298- // TODO: most asserts do not actually assert i.e. do not return
299298#define TEST_CASE ( NAME ) do { if (prepareTest (#NAME)) { setVerbose (false ); try { NAME (); teardownTest (); } catch (...) { assertNoThrowFail (__FILE__, __LINE__); } } } while (false )
300- #define ASSERT ( CONDITION ) if (!assert_(__FILE__, __LINE__, (CONDITION))) return
301- #define ASSERT_LOC ( CONDITION, FILE_, LINE_ ) (void )assert_(FILE_, LINE_, (CONDITION))
302- #define CHECK_EQUALS ( EXPECTED, ACTUAL ) (void )assertEquals(__FILE__, __LINE__, (EXPECTED), (ACTUAL))
299+
300+ // TODO: the asserts do not actually assert i.e. do stop executing the test
301+ #define ASSERT ( CONDITION ) assert_(__FILE__, __LINE__, (CONDITION))
302+ #define ASSERT_LOC ( CONDITION, FILE_, LINE_ ) assert_(FILE_, LINE_, (CONDITION))
303303// *INDENT-OFF*
304- #define ASSERT_EQUALS ( EXPECTED, ACTUAL ) do { try { if (! assertEquals (__FILE__, __LINE__, (EXPECTED), (ACTUAL))) return ; } catch (...) { assertNoThrowFail (__FILE__, __LINE__); } } while (false )
304+ #define ASSERT_EQUALS ( EXPECTED, ACTUAL ) do { try { assertEquals (__FILE__, __LINE__, (EXPECTED), (ACTUAL)); } catch (...) { assertNoThrowFail (__FILE__, __LINE__); } } while (false )
305305// *INDENT-ON*
306- #define ASSERT_EQUALS_WITHOUT_LINENUMBERS ( EXPECTED, ACTUAL ) ( void ) assertEqualsWithoutLineNumbers(__FILE__, __LINE__, EXPECTED, ACTUAL)
307- #define ASSERT_EQUALS_DOUBLE ( EXPECTED, ACTUAL, TOLERANCE ) ( void ) assertEqualsDouble(__FILE__, __LINE__, EXPECTED, ACTUAL, TOLERANCE)
308- #define ASSERT_EQUALS_LOC_MSG ( EXPECTED, ACTUAL, MSG, FILE_, LINE_ ) ( void ) assertEquals(FILE_, LINE_, EXPECTED, ACTUAL, MSG)
309- #define ASSERT_EQUALS_MSG ( EXPECTED, ACTUAL, MSG ) ( void ) assertEquals(__FILE__, __LINE__, EXPECTED, ACTUAL, MSG)
310- #define ASSERT_EQUALS_ENUM ( EXPECTED, ACTUAL ) if (! assertEqualsEnum(__FILE__, __LINE__, (EXPECTED), (ACTUAL))) return
306+ #define ASSERT_EQUALS_WITHOUT_LINENUMBERS ( EXPECTED, ACTUAL ) assertEqualsWithoutLineNumbers(__FILE__, __LINE__, EXPECTED, ACTUAL)
307+ #define ASSERT_EQUALS_DOUBLE ( EXPECTED, ACTUAL, TOLERANCE ) assertEqualsDouble(__FILE__, __LINE__, EXPECTED, ACTUAL, TOLERANCE)
308+ #define ASSERT_EQUALS_LOC_MSG ( EXPECTED, ACTUAL, MSG, FILE_, LINE_ ) assertEquals(FILE_, LINE_, EXPECTED, ACTUAL, MSG)
309+ #define ASSERT_EQUALS_MSG ( EXPECTED, ACTUAL, MSG ) assertEquals(__FILE__, __LINE__, EXPECTED, ACTUAL, MSG)
310+ #define ASSERT_EQUALS_ENUM ( EXPECTED, ACTUAL ) assertEqualsEnum(__FILE__, __LINE__, (EXPECTED), (ACTUAL))
311311#define ASSERT_THROW ( CMD, EXCEPTION ) do { try { (void )(CMD); assertThrowFail (__FILE__, __LINE__); } catch (const EXCEPTION&) {} catch (...) { assertThrowFail (__FILE__, __LINE__); } } while (false )
312- #define ASSERT_THROW_EQUALS ( CMD, EXCEPTION, EXPECTED ) do { try { (void )(CMD); assertThrowFail (__FILE__, __LINE__); } catch (const EXCEPTION&e) { ( void ) assertEquals (__FILE__, __LINE__, EXPECTED, e.errorMessage ); } catch (...) { assertThrowFail (__FILE__, __LINE__); } } while (false )
313- #define ASSERT_THROW_EQUALS_2 ( CMD, EXCEPTION, EXPECTED ) do { try { (void )(CMD); assertThrowFail (__FILE__, __LINE__); } catch (const EXCEPTION&e) { ( void ) assertEquals (__FILE__, __LINE__, EXPECTED, e.what ()); } catch (...) { assertThrowFail (__FILE__, __LINE__); } } while (false )
314- #define ASSERT_THROW_INTERNAL ( CMD, TYPE ) do { try { (void )(CMD); assertThrowFail (__FILE__, __LINE__); } catch (const InternalError& e) { ( void ) assertEqualsEnum (__FILE__, __LINE__, InternalError::TYPE, e.type ); } catch (...) { assertThrowFail (__FILE__, __LINE__); } } while (false )
315- #define ASSERT_THROW_INTERNAL_EQUALS ( CMD, TYPE, EXPECTED ) do { try { (void )(CMD); assertThrowFail (__FILE__, __LINE__); } catch (const InternalError& e) { ( void ) assertEqualsEnum (__FILE__, __LINE__, InternalError::TYPE, e.type ); ( void ) assertEquals (__FILE__, __LINE__, EXPECTED, e.errorMessage ); } catch (...) { assertThrowFail (__FILE__, __LINE__); } } while (false )
312+ #define ASSERT_THROW_EQUALS ( CMD, EXCEPTION, EXPECTED ) do { try { (void )(CMD); assertThrowFail (__FILE__, __LINE__); } catch (const EXCEPTION&e) { assertEquals (__FILE__, __LINE__, EXPECTED, e.errorMessage ); } catch (...) { assertThrowFail (__FILE__, __LINE__); } } while (false )
313+ #define ASSERT_THROW_EQUALS_2 ( CMD, EXCEPTION, EXPECTED ) do { try { (void )(CMD); assertThrowFail (__FILE__, __LINE__); } catch (const EXCEPTION&e) { assertEquals (__FILE__, __LINE__, EXPECTED, e.what ()); } catch (...) { assertThrowFail (__FILE__, __LINE__); } } while (false )
314+ #define ASSERT_THROW_INTERNAL ( CMD, TYPE ) do { try { (void )(CMD); assertThrowFail (__FILE__, __LINE__); } catch (const InternalError& e) { assertEqualsEnum (__FILE__, __LINE__, InternalError::TYPE, e.type ); } catch (...) { assertThrowFail (__FILE__, __LINE__); } } while (false )
315+ #define ASSERT_THROW_INTERNAL_EQUALS ( CMD, TYPE, EXPECTED ) do { try { (void )(CMD); assertThrowFail (__FILE__, __LINE__); } catch (const InternalError& e) { assertEqualsEnum (__FILE__, __LINE__, InternalError::TYPE, e.type ); assertEquals (__FILE__, __LINE__, EXPECTED, e.errorMessage ); } catch (...) { assertThrowFail (__FILE__, __LINE__); } } while (false )
316316#define ASSERT_NO_THROW ( CMD ) do { try { (void )(CMD); } catch (...) { assertNoThrowFail (__FILE__, __LINE__); } } while (false )
317317#define TODO_ASSERT_THROW ( CMD, EXCEPTION ) do { try { (void )(CMD); } catch (const EXCEPTION&) {} catch (...) { assertThrow (__FILE__, __LINE__); } } while (false )
318318#define TODO_ASSERT ( CONDITION ) do { const bool condition=(CONDITION); todoAssertEquals (__FILE__, __LINE__, true , false , condition); } while (false )
319319#define TODO_ASSERT_EQUALS ( WANTED, CURRENT, ACTUAL ) todoAssertEquals(__FILE__, __LINE__, WANTED, CURRENT, ACTUAL)
320- # define EXPECT_EQ ( EXPECTED, ACTUAL ) ( void )assertEquals(__FILE__, __LINE__, EXPECTED, ACTUAL)
320+
321321#define REGISTER_TEST ( CLASSNAME ) namespace { class CLASSNAME ## Instance : public TestInstance { public: CLASSNAME ## Instance() : TestInstance(#CLASSNAME) {} TestFixture* create () override { impl.reset (new CLASSNAME); return impl.get (); } }; CLASSNAME ## Instance instance_ ## CLASSNAME; }
322322
323- #define PLATFORM ( P, T ) do { std::string errstr; ( void ) assertEquals (__FILE__, __LINE__, true , P.set (Platform::toString (T), errstr, {exename}), errstr); } while (false )
323+ #define PLATFORM ( P, T ) do { std::string errstr; assertEquals (__FILE__, __LINE__, true , P.set (Platform::toString (T), errstr, {exename}), errstr); } while (false )
324324
325325#endif // fixtureH
0 commit comments