#include <Common.hpp>
using namespace corelinux;
#include <FooBarClassAdapter.hpp>
#include <FooBarObjectAdapter.hpp>
#include <iostream>
#include <exception>
int main( void );
void addOneToFoo( FooRef );
void displayFoo( FooRef );
void testFooConstraints( FooRef );
void handleAssertion( AssertionCref );
void handleException( ExceptionCref );
int main( void )
{
cout << endl;
try
{
FooBarClassAdapter aFooClassAdapter;
addOneToFoo( aFooClassAdapter );
cout << "Displaying Foo Bar Class Adapter coordinates" << endl;
displayFoo( aFooClassAdapter );
Bar aBarObject(3,1);
FooBarObjectAdapter aFooObjectAdapter( &aBarObject );
addOneToFoo( aFooObjectAdapter );
cout << endl;
cout << "Displaying Foo Bar Object Adapter coordinates" << endl;
displayFoo( aFooObjectAdapter );
}
catch( AssertionRef aAssert )
{
handleAssertion(aAssert);
}
catch( ExceptionRef aException )
{
handleException(aException);
}
catch( std::exception & e )
{
cerr << e.what() << endl;
}
catch( ... )
{
cerr << "Unknown exception." << endl;
}
return 0;
}
void addOneToFoo( FooRef aRef )
{
aRef.setVerticalPosition( aRef.getVerticalPosition() + 1 );
aRef.setHorizontalPosition( aRef.getHorizontalPosition() + 1 );
}
void displayFoo( FooRef aRef )
{
cout << "X [" << aRef.getHorizontalPosition() <<
"] : Y [" << aRef.getVerticalPosition() << "]" << endl;
}
void testFooConstraints( FooRef aRef )
{
cout << endl;
cout << "Stressing coordinate system" << endl;
cout << endl;
while( 1 )
{
addOneToFoo( aRef );
displayFoo( aRef );
}
}
void handleAssertion( AssertionCref aAssert )
{
cerr << aAssert.getFile() << ":" << aAssert.getLine() << ":" <<
"Assertion: ";
if( aAssert.getType() == Assertion::NEVERGETHERE )
{
cerr << "NEVER_GET_HERE";
}
else
{
if( aAssert.getType() == Assertion::REQUIRE )
{
cerr << "REQUIRE";
}
else if( aAssert.getType() == Assertion::ENSURE )
{
cerr << "ENSURE";
}
else if( aAssert.getType() == Assertion::CHECK )
{
cerr << "CHECK";
}
else
{
cerr << "ASSERT";
}
cerr << "( " << aAssert.getWhy() << " )";
}
cerr << endl;
}
void handleException( ExceptionCref aExcp )
{
cerr << aExcp.getFile() << ":" << aExcp.getLine() << ":" <<
"Exception: " << aExcp.getWhy() << endl;
}