corelib/tests/console-text.cc

405 lines
10 KiB
C++

#include <lw/lib/Console.hh>
#include <cppunit/extensions/HelperMacros.h>
using namespace lw;
class ConsoleTextTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE( ConsoleTextTest );
CPPUNIT_TEST( testEmpty );
CPPUNIT_TEST( testSimpleString );
CPPUNIT_TEST( testChangeStyle );
CPPUNIT_TEST( testChangeStyleTwice );
CPPUNIT_TEST( testChangeStyleAtEnd );
CPPUNIT_TEST( testChangeColor );
CPPUNIT_TEST( testChangeColorTwice );
CPPUNIT_TEST( testChangeColorAtEnd );
CPPUNIT_TEST( testChangeColorAndStyle );
CPPUNIT_TEST( testTextCopyCons );
CPPUNIT_TEST( testTextCopyAss );
CPPUNIT_TEST( testTextMoveCons );
CPPUNIT_TEST( testTextMoveAss );
CPPUNIT_TEST( testTextSwap );
CPPUNIT_TEST( testBuilderCopyCons );
CPPUNIT_TEST( testBuilderCopyAss );
CPPUNIT_TEST( testBuilderMoveCons );
CPPUNIT_TEST( testBuilderMoveAss );
CPPUNIT_TEST( testBuilderSwap );
CPPUNIT_TEST_SUITE_END( );
public:
void testEmpty( );
void testSimpleString( );
void testChangeStyle( );
void testChangeStyleTwice( );
void testChangeStyleAtEnd( );
void testChangeColor( );
void testChangeColorTwice( );
void testChangeColorAtEnd( );
void testChangeColorAndStyle( );
void testTextCopyCons( );
void testTextCopyAss( );
void testTextMoveCons( );
void testTextMoveAss( );
void testTextSwap( );
void testBuilderCopyCons( );
void testBuilderCopyAss( );
void testBuilderMoveCons( );
void testBuilderMoveAss( );
void testBuilderSwap( );
};
CPPUNIT_TEST_SUITE_REGISTRATION( ConsoleTextTest );
/*----------------------------------------------------------------------------*/
void ConsoleTextTest::testEmpty( )
{
T_TextBuilder tb;
T_Text t( tb );
CPPUNIT_ASSERT( t.string( ) == "" );
}
void ConsoleTextTest::testSimpleString( )
{
T_TextBuilder tb;
tb << "test";
T_Text t( tb );
CPPUNIT_ASSERT( t.string( ) == "test" );
for ( int i = 0 ; i < 4 ; i ++ ) {
CPPUNIT_ASSERT_EQUAL( uint8_t( 0 ) , t.styleAt( i ) );
CPPUNIT_ASSERT( E_TextColor::WHITE == t.colorAt( i ).type );
}
}
/*----------------------------------------------------------------------------*/
void ConsoleTextTest::testChangeStyle( )
{
T_TextBuilder tb;
tb << "te";
tb.addStyle( E_TextStyle::BOLD );
tb << "st";
T_Text t( tb );
CPPUNIT_ASSERT( t.string( ) == "test" );
for ( int i = 0 ; i < 4 ; i ++ ) {
if ( i < 2 ) {
CPPUNIT_ASSERT_EQUAL( uint8_t( 0 ) , t.styleAt( i ) );
} else {
CPPUNIT_ASSERT_EQUAL( uint8_t( E_TextStyle::BOLD ) , t.styleAt( i ) );
}
CPPUNIT_ASSERT( E_TextColor::WHITE == t.colorAt( i ).type );
}
}
void ConsoleTextTest::testChangeStyleTwice( )
{
T_TextBuilder tb;
tb << "te";
tb.addStyle( E_TextStyle::BOLD );
tb.addStyle( E_TextStyle::ITALIC );
tb << "st";
T_Text t( tb );
CPPUNIT_ASSERT( t.string( ) == "test" );
for ( int i = 0 ; i < 4 ; i ++ ) {
if ( i < 2 ) {
CPPUNIT_ASSERT_EQUAL( uint8_t( 0 ) , t.styleAt( i ) );
} else {
CPPUNIT_ASSERT_EQUAL(
uint8_t( uint8_t( E_TextStyle::BOLD ) | uint8_t( E_TextStyle::ITALIC ) ) ,
t.styleAt( i ) );
}
CPPUNIT_ASSERT( E_TextColor::WHITE == t.colorAt( i ).type );
}
}
void ConsoleTextTest::testChangeStyleAtEnd( )
{
T_TextBuilder tb;
tb << "test";
tb.addStyle( E_TextStyle::BOLD );
T_Text t( tb );
CPPUNIT_ASSERT( t.string( ) == "test" );
for ( int i = 0 ; i < 4 ; i ++ ) {
CPPUNIT_ASSERT_EQUAL( uint8_t( 0 ) , t.styleAt( i ) );
CPPUNIT_ASSERT( E_TextColor::WHITE == t.colorAt( i ).type );
}
}
/*----------------------------------------------------------------------------*/
void ConsoleTextTest::testChangeColor( )
{
T_TextBuilder tb;
tb << "te";
tb.setColor( E_TextColor::RED );
tb << "st";
T_Text t( tb );
CPPUNIT_ASSERT( t.string( ) == "test" );
for ( int i = 0 ; i < 4 ; i ++ ) {
CPPUNIT_ASSERT_EQUAL( uint8_t( 0 ) , t.styleAt( i ) );
if ( i < 2 ) {
CPPUNIT_ASSERT( E_TextColor::WHITE == t.colorAt( i ).type );
} else {
CPPUNIT_ASSERT( E_TextColor::RED == t.colorAt( i ).type );
}
}
}
void ConsoleTextTest::testChangeColorTwice( )
{
T_TextBuilder tb;
tb << "te";
tb.setColor( E_TextColor::RED );
tb.setColor( E_TextColor::GREEN );
tb << "st";
T_Text t( tb );
CPPUNIT_ASSERT( t.string( ) == "test" );
for ( int i = 0 ; i < 4 ; i ++ ) {
CPPUNIT_ASSERT_EQUAL( uint8_t( 0 ) , t.styleAt( i ) );
if ( i < 2 ) {
CPPUNIT_ASSERT( E_TextColor::WHITE == t.colorAt( i ).type );
} else {
CPPUNIT_ASSERT( E_TextColor::GREEN == t.colorAt( i ).type );
}
}
}
void ConsoleTextTest::testChangeColorAtEnd( )
{
T_TextBuilder tb;
tb << "test";
tb.setColor( E_TextColor::GREEN );
T_Text t( tb );
CPPUNIT_ASSERT( t.string( ) == "test" );
for ( int i = 0 ; i < 4 ; i ++ ) {
CPPUNIT_ASSERT_EQUAL( uint8_t( 0 ) , t.styleAt( i ) );
CPPUNIT_ASSERT( E_TextColor::WHITE == t.colorAt( i ).type );
}
}
/*----------------------------------------------------------------------------*/
void ConsoleTextTest::testChangeColorAndStyle( )
{
T_TextBuilder tb;
tb.addStyle( E_TextStyle::BOLD );
tb << "te";
tb.removeStyle( E_TextStyle::BOLD );
tb.setColor( E_TextColor::GREEN );
tb << "st";
T_Text t( tb );
CPPUNIT_ASSERT( t.string( ) == "test" );
for ( int i = 0 ; i < 4 ; i ++ ) {
if ( i < 2 ) {
CPPUNIT_ASSERT_EQUAL( uint8_t( E_TextStyle::BOLD ) , t.styleAt( i ) );
CPPUNIT_ASSERT( E_TextColor::WHITE == t.colorAt( i ).type );
} else {
CPPUNIT_ASSERT_EQUAL( uint8_t( 0 ) , t.styleAt( i ) );
CPPUNIT_ASSERT( E_TextColor::GREEN == t.colorAt( i ).type );
}
}
}
/*----------------------------------------------------------------------------*/
void ConsoleTextTest::testTextCopyCons( )
{
T_TextBuilder tb;
tb << "test";
T_Text t( tb );
T_Text t2( t );
CPPUNIT_ASSERT( t.string( ) == "test" );
CPPUNIT_ASSERT( t2.string( ) == "test" );
for ( int i = 0 ; i < 4 ; i ++ ) {
CPPUNIT_ASSERT_EQUAL( uint8_t( 0 ) , t.styleAt( i ) );
CPPUNIT_ASSERT( E_TextColor::WHITE == t.colorAt( i ).type );
CPPUNIT_ASSERT_EQUAL( uint8_t( 0 ) , t2.styleAt( i ) );
CPPUNIT_ASSERT( E_TextColor::WHITE == t2.colorAt( i ).type );
}
}
void ConsoleTextTest::testTextCopyAss( )
{
T_TextBuilder tb;
tb << "test";
T_Text t( tb );
tb.clear( );
tb << "blargh";
T_Text t2( tb );
t2 = t;
CPPUNIT_ASSERT( t.string( ) == "test" );
CPPUNIT_ASSERT( t2.string( ) == "test" );
for ( int i = 0 ; i < 4 ; i ++ ) {
CPPUNIT_ASSERT_EQUAL( uint8_t( 0 ) , t.styleAt( i ) );
CPPUNIT_ASSERT( E_TextColor::WHITE == t.colorAt( i ).type );
CPPUNIT_ASSERT_EQUAL( uint8_t( 0 ) , t2.styleAt( i ) );
CPPUNIT_ASSERT( E_TextColor::WHITE == t2.colorAt( i ).type );
}
}
void ConsoleTextTest::testTextMoveCons( )
{
T_TextBuilder tb;
tb << "test";
T_Text t( tb );
T_Text t2( std::move( t ) );
CPPUNIT_ASSERT( t.string( ) == "" );
CPPUNIT_ASSERT( t2.string( ) == "test" );
for ( int i = 0 ; i < 4 ; i ++ ) {
CPPUNIT_ASSERT_EQUAL( uint8_t( 0 ) , t2.styleAt( i ) );
CPPUNIT_ASSERT( E_TextColor::WHITE == t2.colorAt( i ).type );
}
}
void ConsoleTextTest::testTextMoveAss( )
{
T_TextBuilder tb;
tb << "te";
T_Text t2( tb );
tb << "st";
T_Text t( tb );
t2 = std::move( t );
CPPUNIT_ASSERT( t.string( ) == "" );
CPPUNIT_ASSERT( t2.string( ) == "test" );
for ( int i = 0 ; i < 4 ; i ++ ) {
CPPUNIT_ASSERT_EQUAL( uint8_t( 0 ) , t2.styleAt( i ) );
CPPUNIT_ASSERT( E_TextColor::WHITE == t2.colorAt( i ).type );
}
}
void ConsoleTextTest::testTextSwap( )
{
T_TextBuilder tb;
tb << "test";
T_Text t( tb );
tb.clear( );
tb << E_TextStyle::BOLD << "blah";
T_Text t2( tb );
swap( t , t2 );
CPPUNIT_ASSERT( t.string( ) == "blah" );
CPPUNIT_ASSERT( t2.string( ) == "test" );
for ( int i = 0 ; i < 4 ; i ++ ) {
CPPUNIT_ASSERT_EQUAL( uint8_t( E_TextStyle::BOLD ) , t.styleAt( i ) );
CPPUNIT_ASSERT( E_TextColor::WHITE == t.colorAt( i ).type );
CPPUNIT_ASSERT_EQUAL( uint8_t( 0 ) , t2.styleAt( i ) );
CPPUNIT_ASSERT( E_TextColor::WHITE == t2.colorAt( i ).type );
}
}
/*----------------------------------------------------------------------------*/
void ConsoleTextTest::testBuilderCopyCons( )
{
T_TextBuilder tb;
tb << "test";
T_TextBuilder tb2( tb );
T_Text t( tb ) , t2( tb2 );
CPPUNIT_ASSERT( t.string( ) == "test" );
CPPUNIT_ASSERT( t2.string( ) == "test" );
for ( int i = 0 ; i < 4 ; i ++ ) {
CPPUNIT_ASSERT_EQUAL( uint8_t( 0 ) , t.styleAt( i ) );
CPPUNIT_ASSERT( E_TextColor::WHITE == t.colorAt( i ).type );
CPPUNIT_ASSERT_EQUAL( uint8_t( 0 ) , t2.styleAt( i ) );
CPPUNIT_ASSERT( E_TextColor::WHITE == t2.colorAt( i ).type );
}
}
void ConsoleTextTest::testBuilderCopyAss( )
{
T_TextBuilder tb , tb2;
tb << "test";
tb2 << "blah";
tb2 = tb;
T_Text t( tb ) , t2( tb2 );
CPPUNIT_ASSERT( t.string( ) == "test" );
CPPUNIT_ASSERT( t2.string( ) == "test" );
for ( int i = 0 ; i < 4 ; i ++ ) {
CPPUNIT_ASSERT_EQUAL( uint8_t( 0 ) , t.styleAt( i ) );
CPPUNIT_ASSERT( E_TextColor::WHITE == t.colorAt( i ).type );
CPPUNIT_ASSERT_EQUAL( uint8_t( 0 ) , t2.styleAt( i ) );
CPPUNIT_ASSERT( E_TextColor::WHITE == t2.colorAt( i ).type );
}
}
void ConsoleTextTest::testBuilderMoveCons( )
{
T_TextBuilder tb;
tb << "test";
T_TextBuilder tb2( std::move( tb ) );
T_Text t( tb ) , t2( tb2 );
CPPUNIT_ASSERT( t.string( ) == "" );
CPPUNIT_ASSERT( t2.string( ) == "test" );
for ( int i = 0 ; i < 4 ; i ++ ) {
CPPUNIT_ASSERT_EQUAL( uint8_t( 0 ) , t2.styleAt( i ) );
CPPUNIT_ASSERT( E_TextColor::WHITE == t2.colorAt( i ).type );
}
}
void ConsoleTextTest::testBuilderMoveAss( )
{
T_TextBuilder tb , tb2;
tb << "test";
tb2 << "blah";
tb2 = std::move( tb );
T_Text t( tb ) , t2( tb2 );
CPPUNIT_ASSERT( t.string( ) == "" );
CPPUNIT_ASSERT( t2.string( ) == "test" );
for ( int i = 0 ; i < 4 ; i ++ ) {
CPPUNIT_ASSERT_EQUAL( uint8_t( 0 ) , t2.styleAt( i ) );
CPPUNIT_ASSERT( E_TextColor::WHITE == t2.colorAt( i ).type );
}
}
void ConsoleTextTest::testBuilderSwap( )
{
T_TextBuilder tb , tb2;
tb << "test";
tb2 << E_TextStyle::BOLD << "blah";
swap( tb , tb2 );
T_Text t( tb ) , t2( tb2 );
CPPUNIT_ASSERT( t.string( ) == "blah" );
CPPUNIT_ASSERT( t2.string( ) == "test" );
for ( int i = 0 ; i < 4 ; i ++ ) {
CPPUNIT_ASSERT_EQUAL( uint8_t( E_TextStyle::BOLD ) , t.styleAt( i ) );
CPPUNIT_ASSERT( E_TextColor::WHITE == t.colorAt( i ).type );
CPPUNIT_ASSERT_EQUAL( uint8_t( 0 ) , t2.styleAt( i ) );
CPPUNIT_ASSERT( E_TextColor::WHITE == t2.colorAt( i ).type );
}
}