|
Packit |
8c9aa0 |
#include "CoreSuite.h"
|
|
Packit |
8c9aa0 |
#include "MessageTest.h"
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( MessageTest,
|
|
Packit |
8c9aa0 |
coreSuiteName() );
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
MessageTest::MessageTest()
|
|
Packit |
8c9aa0 |
{
|
|
Packit |
8c9aa0 |
}
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
MessageTest::~MessageTest()
|
|
Packit |
8c9aa0 |
{
|
|
Packit |
8c9aa0 |
}
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
void
|
|
Packit |
8c9aa0 |
MessageTest::setUp()
|
|
Packit |
8c9aa0 |
{
|
|
Packit |
8c9aa0 |
m_message = new CPPUNIT_NS::Message();
|
|
Packit |
8c9aa0 |
}
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
void
|
|
Packit |
8c9aa0 |
MessageTest::tearDown()
|
|
Packit |
8c9aa0 |
{
|
|
Packit |
8c9aa0 |
delete m_message;
|
|
Packit |
8c9aa0 |
}
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
void
|
|
Packit |
8c9aa0 |
MessageTest::testDefaultConstructor()
|
|
Packit |
8c9aa0 |
{
|
|
Packit |
8c9aa0 |
std::string empty;
|
|
Packit |
8c9aa0 |
CPPUNIT_ASSERT_EQUAL( empty, m_message->shortDescription() );
|
|
Packit |
8c9aa0 |
CPPUNIT_ASSERT_EQUAL( 0, m_message->detailCount() );
|
|
Packit |
8c9aa0 |
}
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
void
|
|
Packit |
8c9aa0 |
MessageTest::testDetailAtThrowIfBadIndex()
|
|
Packit |
8c9aa0 |
{
|
|
Packit |
8c9aa0 |
m_message->detailAt( -1 );
|
|
Packit |
8c9aa0 |
}
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
void
|
|
Packit |
8c9aa0 |
MessageTest::testDetailAtThrowIfBadIndex2()
|
|
Packit |
8c9aa0 |
{
|
|
Packit |
8c9aa0 |
m_message->detailAt( 0 );
|
|
Packit |
8c9aa0 |
}
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
void
|
|
Packit |
8c9aa0 |
MessageTest::testAddDetail()
|
|
Packit |
8c9aa0 |
{
|
|
Packit |
8c9aa0 |
std::string expected( "first" );
|
|
Packit |
8c9aa0 |
m_message->addDetail( expected );
|
|
Packit |
8c9aa0 |
CPPUNIT_ASSERT_EQUAL( 1, m_message->detailCount() );
|
|
Packit |
8c9aa0 |
CPPUNIT_ASSERT_EQUAL( expected, m_message->detailAt(0) );
|
|
Packit |
8c9aa0 |
}
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
void
|
|
Packit |
8c9aa0 |
MessageTest::testAddDetail2()
|
|
Packit |
8c9aa0 |
{
|
|
Packit |
8c9aa0 |
std::string expected1( "first" );
|
|
Packit |
8c9aa0 |
std::string expected2( "second" );
|
|
Packit |
8c9aa0 |
m_message->addDetail( expected1, expected2 );
|
|
Packit |
8c9aa0 |
CPPUNIT_ASSERT_EQUAL( 2, m_message->detailCount() );
|
|
Packit |
8c9aa0 |
CPPUNIT_ASSERT_EQUAL( expected1, m_message->detailAt(0) );
|
|
Packit |
8c9aa0 |
CPPUNIT_ASSERT_EQUAL( expected2, m_message->detailAt(1) );
|
|
Packit |
8c9aa0 |
}
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
void
|
|
Packit |
8c9aa0 |
MessageTest::testAddDetail3()
|
|
Packit |
8c9aa0 |
{
|
|
Packit |
8c9aa0 |
std::string expected1( "first" );
|
|
Packit |
8c9aa0 |
std::string expected2( "second" );
|
|
Packit |
8c9aa0 |
std::string expected3( "third" );
|
|
Packit |
8c9aa0 |
m_message->addDetail( expected1, expected2, expected3 );
|
|
Packit |
8c9aa0 |
CPPUNIT_ASSERT_EQUAL( 3, m_message->detailCount() );
|
|
Packit |
8c9aa0 |
CPPUNIT_ASSERT_EQUAL( expected1, m_message->detailAt(0) );
|
|
Packit |
8c9aa0 |
CPPUNIT_ASSERT_EQUAL( expected2, m_message->detailAt(1) );
|
|
Packit |
8c9aa0 |
CPPUNIT_ASSERT_EQUAL( expected3, m_message->detailAt(2) );
|
|
Packit |
8c9aa0 |
}
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
void
|
|
Packit |
8c9aa0 |
MessageTest::testAddDetailEmptyMessage()
|
|
Packit |
8c9aa0 |
{
|
|
Packit |
8c9aa0 |
m_message->addDetail( CPPUNIT_NS::Message() );
|
|
Packit |
8c9aa0 |
CPPUNIT_ASSERT_EQUAL( 0, m_message->detailCount() );
|
|
Packit |
8c9aa0 |
}
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
void
|
|
Packit |
8c9aa0 |
MessageTest::testAddDetailMessage()
|
|
Packit |
8c9aa0 |
{
|
|
Packit |
8c9aa0 |
std::string expected1( "first" );
|
|
Packit |
8c9aa0 |
std::string expected2( "second" );
|
|
Packit |
8c9aa0 |
m_message->addDetail( CPPUNIT_NS::Message( "shortDesc", expected1, expected2 ) );
|
|
Packit |
8c9aa0 |
CPPUNIT_ASSERT_EQUAL( 2, m_message->detailCount() );
|
|
Packit |
8c9aa0 |
CPPUNIT_ASSERT_EQUAL( expected1, m_message->detailAt(0) );
|
|
Packit |
8c9aa0 |
CPPUNIT_ASSERT_EQUAL( expected2, m_message->detailAt(1) );
|
|
Packit |
8c9aa0 |
}
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
void
|
|
Packit |
8c9aa0 |
MessageTest::testSetShortDescription()
|
|
Packit |
8c9aa0 |
{
|
|
Packit |
8c9aa0 |
std::string expected( "shortDesc" );
|
|
Packit |
8c9aa0 |
m_message->setShortDescription( expected );
|
|
Packit |
8c9aa0 |
CPPUNIT_ASSERT_EQUAL( expected, m_message->shortDescription() );
|
|
Packit |
8c9aa0 |
}
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
void
|
|
Packit |
8c9aa0 |
MessageTest::testClearDetails()
|
|
Packit |
8c9aa0 |
{
|
|
Packit |
8c9aa0 |
m_message->addDetail( "detail1" );
|
|
Packit |
8c9aa0 |
m_message->clearDetails();
|
|
Packit |
8c9aa0 |
CPPUNIT_ASSERT_EQUAL( 0, m_message->detailCount() );
|
|
Packit |
8c9aa0 |
}
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
void
|
|
Packit |
8c9aa0 |
MessageTest::testConstructor()
|
|
Packit |
8c9aa0 |
{
|
|
Packit |
8c9aa0 |
std::string expected( "short" );
|
|
Packit |
8c9aa0 |
CPPUNIT_NS::Message message( expected );
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
CPPUNIT_ASSERT_EQUAL( expected, message.shortDescription() );
|
|
Packit |
8c9aa0 |
CPPUNIT_ASSERT_EQUAL( 0, message.detailCount() );
|
|
Packit |
8c9aa0 |
}
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
void
|
|
Packit |
8c9aa0 |
MessageTest::testConstructorDetail1()
|
|
Packit |
8c9aa0 |
{
|
|
Packit |
8c9aa0 |
std::string expected( "short" );
|
|
Packit |
8c9aa0 |
std::string expected1( "detail-1" );
|
|
Packit |
8c9aa0 |
CPPUNIT_NS::Message message( expected, expected1 );
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
CPPUNIT_ASSERT_EQUAL( expected, message.shortDescription() );
|
|
Packit |
8c9aa0 |
CPPUNIT_ASSERT_EQUAL( 1, message.detailCount() );
|
|
Packit |
8c9aa0 |
CPPUNIT_ASSERT_EQUAL( expected1, message.detailAt(0) );
|
|
Packit |
8c9aa0 |
}
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
void
|
|
Packit |
8c9aa0 |
MessageTest::testConstructorDetail2()
|
|
Packit |
8c9aa0 |
{
|
|
Packit |
8c9aa0 |
std::string expected( "short" );
|
|
Packit |
8c9aa0 |
std::string expected1( "detail-1" );
|
|
Packit |
8c9aa0 |
std::string expected2( "detail-2" );
|
|
Packit |
8c9aa0 |
CPPUNIT_NS::Message message( expected, expected1, expected2 );
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
CPPUNIT_ASSERT_EQUAL( expected, message.shortDescription() );
|
|
Packit |
8c9aa0 |
CPPUNIT_ASSERT_EQUAL( 2, message.detailCount() );
|
|
Packit |
8c9aa0 |
CPPUNIT_ASSERT_EQUAL( expected1, message.detailAt(0) );
|
|
Packit |
8c9aa0 |
CPPUNIT_ASSERT_EQUAL( expected2, message.detailAt(1) );
|
|
Packit |
8c9aa0 |
}
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
void
|
|
Packit |
8c9aa0 |
MessageTest::testConstructorDetail3()
|
|
Packit |
8c9aa0 |
{
|
|
Packit |
8c9aa0 |
std::string expected( "short" );
|
|
Packit |
8c9aa0 |
std::string expected1( "detail-1" );
|
|
Packit |
8c9aa0 |
std::string expected2( "detail-2" );
|
|
Packit |
8c9aa0 |
std::string expected3( "detail-3" );
|
|
Packit |
8c9aa0 |
CPPUNIT_NS::Message message( expected, expected1, expected2, expected3 );
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
CPPUNIT_ASSERT_EQUAL( expected, message.shortDescription() );
|
|
Packit |
8c9aa0 |
CPPUNIT_ASSERT_EQUAL( 3, message.detailCount() );
|
|
Packit |
8c9aa0 |
CPPUNIT_ASSERT_EQUAL( expected1, message.detailAt(0) );
|
|
Packit |
8c9aa0 |
CPPUNIT_ASSERT_EQUAL( expected2, message.detailAt(1) );
|
|
Packit |
8c9aa0 |
CPPUNIT_ASSERT_EQUAL( expected3, message.detailAt(2) );
|
|
Packit |
8c9aa0 |
}
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
void
|
|
Packit |
8c9aa0 |
MessageTest::testDetailsNone()
|
|
Packit |
8c9aa0 |
{
|
|
Packit |
8c9aa0 |
CPPUNIT_ASSERT_MESSAGE("012345678901234",true);
|
|
Packit |
8c9aa0 |
std::string empty;
|
|
Packit |
8c9aa0 |
CPPUNIT_ASSERT_EQUAL( empty, m_message->details() );
|
|
Packit |
8c9aa0 |
}
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
void
|
|
Packit |
8c9aa0 |
MessageTest::testDetailsSome()
|
|
Packit |
8c9aa0 |
{
|
|
Packit |
8c9aa0 |
m_message->addDetail( "Expected: 1", "Actual: 7", "Info: number" );
|
|
Packit |
8c9aa0 |
std::string expected( "- Expected: 1\n- Actual: 7\n- Info: number\n" );
|
|
Packit |
8c9aa0 |
std::string actual = m_message->details();
|
|
Packit |
8c9aa0 |
CPPUNIT_ASSERT_EQUAL( expected, actual );
|
|
Packit |
8c9aa0 |
}
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
void
|
|
Packit |
8c9aa0 |
MessageTest::testEqual()
|
|
Packit |
8c9aa0 |
{
|
|
Packit |
8c9aa0 |
CPPUNIT_ASSERT( *m_message == CPPUNIT_NS::Message() );
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
CPPUNIT_NS::Message message1( "short", "det1", "det2", "det3" );
|
|
Packit |
8c9aa0 |
CPPUNIT_NS::Message message2( message1 );
|
|
Packit |
8c9aa0 |
CPPUNIT_ASSERT( message1 == message2 );
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
CPPUNIT_ASSERT( !(*m_message == message1) );
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
CPPUNIT_NS::Message message3( "short" );
|
|
Packit |
8c9aa0 |
CPPUNIT_ASSERT( !(message3 == message1) );
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
CPPUNIT_NS::Message message4( "long" );
|
|
Packit |
8c9aa0 |
CPPUNIT_ASSERT( !(message3 == message4) );
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
CPPUNIT_NS::Message message5( "short", "det1", "det-2", "det3" );
|
|
Packit |
8c9aa0 |
CPPUNIT_ASSERT( !(message1 == message5) );
|
|
Packit |
8c9aa0 |
}
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
void
|
|
Packit |
8c9aa0 |
MessageTest::testNotEqual()
|
|
Packit |
8c9aa0 |
{
|
|
Packit |
8c9aa0 |
CPPUNIT_NS::Message message1( "short", "det1", "det2", "det3" );
|
|
Packit |
8c9aa0 |
CPPUNIT_NS::Message message2( "short", "det1", "det-2", "det3" );
|
|
Packit |
8c9aa0 |
CPPUNIT_ASSERT( message1 != message2 );
|
|
Packit |
8c9aa0 |
CPPUNIT_ASSERT( !(message1 != message1) );
|
|
Packit |
8c9aa0 |
}
|