testing: minor refactoring so better error messages are shown
This commit is contained in:
parent
e968b42c38
commit
bbd21613f7
|
@ -77,9 +77,25 @@ bool TestFixture::runTest(const char testname[])
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestFixture::assertFail(const char *filename, int linenr)
|
void TestFixture::assertEquals(const char *filename, int linenr, const std::string &expected, const std::string &actual)
|
||||||
{
|
{
|
||||||
errmsg << "Assertion failed in " << filename << " at line " << linenr << std::endl;
|
if ( expected != actual )
|
||||||
|
{
|
||||||
|
errmsg << "Assertion failed in " << filename << " at line " << linenr << std::endl
|
||||||
|
<< "Expected:" << std::endl
|
||||||
|
<< expected << std::endl
|
||||||
|
<< "Actual:" << std::endl
|
||||||
|
<< actual << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestFixture::assertEquals(const char *filename, int linenr, unsigned int expected, unsigned int actual)
|
||||||
|
{
|
||||||
|
std::ostringstream ostr1;
|
||||||
|
ostr1 << expected;
|
||||||
|
std::ostringstream ostr2;
|
||||||
|
ostr2 << actual;
|
||||||
|
assertEquals( filename, linenr, ostr1.str(), ostr2.str() );
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestFixture::printTests()
|
void TestFixture::printTests()
|
||||||
|
|
|
@ -37,7 +37,8 @@ protected:
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
bool runTest(const char testname[]);
|
bool runTest(const char testname[]);
|
||||||
void assertFail(const char *filename, int linenr);
|
void assertEquals(const char *filename, int linenr, const std::string &expected, const std::string &actual);
|
||||||
|
void assertEquals(const char *filename, int linenr, unsigned int expected, unsigned int actual);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual void reportErr( const std::string &errmsg);
|
virtual void reportErr( const std::string &errmsg);
|
||||||
|
@ -53,6 +54,6 @@ public:
|
||||||
|
|
||||||
|
|
||||||
#define TEST_CASE( NAME ) if ( runTest(#NAME) ) NAME ();
|
#define TEST_CASE( NAME ) if ( runTest(#NAME) ) NAME ();
|
||||||
#define ASSERT_EQUALS( EXPECTED , ACTUAL ) if (EXPECTED!=ACTUAL) assertFail(__FILE__, __LINE__);
|
#define ASSERT_EQUALS( EXPECTED , ACTUAL ) assertEquals(__FILE__, __LINE__, EXPECTED, ACTUAL);
|
||||||
#define REGISTER_TEST( CLASSNAME ) namespace { CLASSNAME instance; }
|
#define REGISTER_TEST( CLASSNAME ) namespace { CLASSNAME instance; }
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue