corelib/tests/srd-preproc-cmd-compare.cc

340 lines
9.6 KiB
C++

#include "srd-preproc-cmd-common.hh"
class SRDPreprocCmdCompareTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE( SRDPreprocCmdCompareTest );
CPPUNIT_TEST( testCmpMissingArgs );
CPPUNIT_TEST( testCmpExtraArgs );
CPPUNIT_TEST( testCmp );
CPPUNIT_TEST( testEqMissingArgs );
CPPUNIT_TEST( testEqExtraArgs );
CPPUNIT_TEST( testEq );
CPPUNIT_TEST( testNeMissingArgs );
CPPUNIT_TEST( testNeExtraArgs );
CPPUNIT_TEST( testNe );
CPPUNIT_TEST( testLtMissingArgs );
CPPUNIT_TEST( testLtExtraArgs );
CPPUNIT_TEST( testLt );
CPPUNIT_TEST( testGtMissingArgs );
CPPUNIT_TEST( testGtExtraArgs );
CPPUNIT_TEST( testGt );
CPPUNIT_TEST( testLeMissingArgs );
CPPUNIT_TEST( testLeExtraArgs );
CPPUNIT_TEST( testLe );
CPPUNIT_TEST( testGeMissingArgs );
CPPUNIT_TEST( testGeExtraArgs );
CPPUNIT_TEST( testGe );
CPPUNIT_TEST_SUITE_END( );
public:
void testCmpMissingArgs( );
void testCmpExtraArgs( );
void testCmp( );
void testEqMissingArgs( );
void testEqExtraArgs( );
void testEq( );
void testNeMissingArgs( );
void testNeExtraArgs( );
void testNe( );
void testLtMissingArgs( );
void testLtExtraArgs( );
void testLt( );
void testGtMissingArgs( );
void testGtExtraArgs( );
void testGt( );
void testLeMissingArgs( );
void testLeExtraArgs( );
void testLe( );
void testGeMissingArgs( );
void testGeExtraArgs( );
void testGe( );
};
CPPUNIT_TEST_SUITE_REGISTRATION( SRDPreprocCmdCompareTest );
/*----------------------------------------------------------------------------*/
void SRDPreprocCmdCompareTest::testCmpMissingArgs( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -cmp )\n( -cmp a )" , errors ) );
CPPUNIT_ASSERT_EQUAL( 4u , errors.size( ) );
M_CKERR_( 0 , "not enough arguments" , 1 , 3 );
M_CKERR_( 1 , "previous error cause" , 1 , 8 );
M_CKERR_( 2 , "not enough arguments" , 2 , 3 );
M_CKERR_( 3 , "previous error cause" , 2 , 10 );
CPPUNIT_ASSERT( check( "0 0" , output ) );
}
void SRDPreprocCmdCompareTest::testCmpExtraArgs( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -cmp a b c )" , errors ) );
CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) );
M_CKERR_( 0 , "too many arguments" , 1 , 3 );
M_CKERR_( 1 , "previous error cause" , 1 , 12 );
CPPUNIT_ASSERT( check( "-1" , output ) );
}
void SRDPreprocCmdCompareTest::testCmp( )
{
T_SRDErrors errors;
T_SRDList output( process(
"( -cmp a a )\n"
"( -cmp a b )\n"
"( -cmp ((a)) b )\n"
"( -cmp a ((b)) )\n"
"( -cmp ((a)) ((b)) )\n"
"( -cmp ((a)) ((a)) )\n"
, errors ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) );
CPPUNIT_ASSERT( check( "0 -1 -1 1 -1 0" , output ) );
}
/*----------------------------------------------------------------------------*/
void SRDPreprocCmdCompareTest::testEqMissingArgs( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -eq )\n( -eq a )" , errors ) );
CPPUNIT_ASSERT_EQUAL( 4u , errors.size( ) );
M_CKERR_( 0 , "not enough arguments" , 1 , 3 );
M_CKERR_( 1 , "previous error cause" , 1 , 7 );
M_CKERR_( 2 , "not enough arguments" , 2 , 3 );
M_CKERR_( 3 , "previous error cause" , 2 , 9 );
CPPUNIT_ASSERT( check( "1 1" , output ) );
}
void SRDPreprocCmdCompareTest::testEqExtraArgs( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -eq a b c )" , errors ) );
CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) );
M_CKERR_( 0 , "too many arguments" , 1 , 3 );
M_CKERR_( 1 , "previous error cause" , 1 , 11 );
CPPUNIT_ASSERT( check( "0" , output ) );
}
void SRDPreprocCmdCompareTest::testEq( )
{
T_SRDErrors errors;
T_SRDList output( process(
"( -eq a a )\n"
"( -eq a b )\n"
"( -eq ((a)) b )\n"
"( -eq a ((b)) )\n"
"( -eq ((a)) ((b)) )\n"
"( -eq ((a)) ((a)) )\n"
, errors ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) );
CPPUNIT_ASSERT( check( "1 0 0 0 0 1" , output ) );
}
/*----------------------------------------------------------------------------*/
void SRDPreprocCmdCompareTest::testNeMissingArgs( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -ne )\n( -ne a )" , errors ) );
CPPUNIT_ASSERT_EQUAL( 4u , errors.size( ) );
M_CKERR_( 0 , "not enough arguments" , 1 , 3 );
M_CKERR_( 1 , "previous error cause" , 1 , 7 );
M_CKERR_( 2 , "not enough arguments" , 2 , 3 );
M_CKERR_( 3 , "previous error cause" , 2 , 9 );
CPPUNIT_ASSERT( check( "0 0" , output ) );
}
void SRDPreprocCmdCompareTest::testNeExtraArgs( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -ne a b c )" , errors ) );
CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) );
M_CKERR_( 0 , "too many arguments" , 1 , 3 );
M_CKERR_( 1 , "previous error cause" , 1 , 11 );
CPPUNIT_ASSERT( check( "1" , output ) );
}
void SRDPreprocCmdCompareTest::testNe( )
{
T_SRDErrors errors;
T_SRDList output( process(
"( -ne a a )\n"
"( -ne a b )\n"
"( -ne ((a)) b )\n"
"( -ne a ((b)) )\n"
"( -ne ((a)) ((b)) )\n"
"( -ne ((a)) ((a)) )\n"
, errors ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) );
CPPUNIT_ASSERT( check( "0 1 1 1 1 0" , output ) );
}
/*----------------------------------------------------------------------------*/
void SRDPreprocCmdCompareTest::testLtMissingArgs( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -lt )\n( -lt a )" , errors ) );
CPPUNIT_ASSERT_EQUAL( 4u , errors.size( ) );
M_CKERR_( 0 , "not enough arguments" , 1 , 3 );
M_CKERR_( 1 , "previous error cause" , 1 , 7 );
M_CKERR_( 2 , "not enough arguments" , 2 , 3 );
M_CKERR_( 3 , "previous error cause" , 2 , 9 );
CPPUNIT_ASSERT( check( "0 0" , output ) );
}
void SRDPreprocCmdCompareTest::testLtExtraArgs( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -lt a b c )" , errors ) );
CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) );
M_CKERR_( 0 , "too many arguments" , 1 , 3 );
M_CKERR_( 1 , "previous error cause" , 1 , 11 );
CPPUNIT_ASSERT( check( "1" , output ) );
}
void SRDPreprocCmdCompareTest::testLt( )
{
T_SRDErrors errors;
T_SRDList output( process(
"( -lt a a )\n"
"( -lt a b )\n"
"( -lt ((a)) b )\n"
"( -lt a ((b)) )\n"
"( -lt ((a)) ((b)) )\n"
"( -lt ((a)) ((a)) )\n"
, errors ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) );
CPPUNIT_ASSERT( check( "0 1 1 0 1 0" , output ) );
}
/*----------------------------------------------------------------------------*/
void SRDPreprocCmdCompareTest::testGtMissingArgs( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -gt )\n( -gt a )" , errors ) );
CPPUNIT_ASSERT_EQUAL( 4u , errors.size( ) );
M_CKERR_( 0 , "not enough arguments" , 1 , 3 );
M_CKERR_( 1 , "previous error cause" , 1 , 7 );
M_CKERR_( 2 , "not enough arguments" , 2 , 3 );
M_CKERR_( 3 , "previous error cause" , 2 , 9 );
CPPUNIT_ASSERT( check( "0 0" , output ) );
}
void SRDPreprocCmdCompareTest::testGtExtraArgs( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -gt a b c )" , errors ) );
CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) );
M_CKERR_( 0 , "too many arguments" , 1 , 3 );
M_CKERR_( 1 , "previous error cause" , 1 , 11 );
CPPUNIT_ASSERT( check( "0" , output ) );
}
void SRDPreprocCmdCompareTest::testGt( )
{
T_SRDErrors errors;
T_SRDList output( process(
"( -gt a a )\n"
"( -gt a b )\n"
"( -gt ((a)) b )\n"
"( -gt a ((b)) )\n"
"( -gt ((a)) ((b)) )\n"
"( -gt ((a)) ((a)) )\n"
, errors ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) );
CPPUNIT_ASSERT( check( "0 0 0 1 0 0" , output ) );
}
/*----------------------------------------------------------------------------*/
void SRDPreprocCmdCompareTest::testLeMissingArgs( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -le )\n( -le a )" , errors ) );
CPPUNIT_ASSERT_EQUAL( 4u , errors.size( ) );
M_CKERR_( 0 , "not enough arguments" , 1 , 3 );
M_CKERR_( 1 , "previous error cause" , 1 , 7 );
M_CKERR_( 2 , "not enough arguments" , 2 , 3 );
M_CKERR_( 3 , "previous error cause" , 2 , 9 );
CPPUNIT_ASSERT( check( "1 1" , output ) );
}
void SRDPreprocCmdCompareTest::testLeExtraArgs( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -le a b c )" , errors ) );
CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) );
M_CKERR_( 0 , "too many arguments" , 1 , 3 );
M_CKERR_( 1 , "previous error cause" , 1 , 11 );
CPPUNIT_ASSERT( check( "1" , output ) );
}
void SRDPreprocCmdCompareTest::testLe( )
{
T_SRDErrors errors;
T_SRDList output( process(
"( -le a a )\n"
"( -le a b )\n"
"( -le ((a)) b )\n"
"( -le a ((b)) )\n"
"( -le ((a)) ((b)) )\n"
"( -le ((a)) ((a)) )\n"
, errors ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) );
CPPUNIT_ASSERT( check( "1 1 1 0 1 1" , output ) );
}
/*----------------------------------------------------------------------------*/
void SRDPreprocCmdCompareTest::testGeMissingArgs( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -ge )\n( -ge a )" , errors ) );
CPPUNIT_ASSERT_EQUAL( 4u , errors.size( ) );
M_CKERR_( 0 , "not enough arguments" , 1 , 3 );
M_CKERR_( 1 , "previous error cause" , 1 , 7 );
M_CKERR_( 2 , "not enough arguments" , 2 , 3 );
M_CKERR_( 3 , "previous error cause" , 2 , 9 );
CPPUNIT_ASSERT( check( "1 1" , output ) );
}
void SRDPreprocCmdCompareTest::testGeExtraArgs( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -ge a b c )" , errors ) );
CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) );
M_CKERR_( 0 , "too many arguments" , 1 , 3 );
M_CKERR_( 1 , "previous error cause" , 1 , 11 );
CPPUNIT_ASSERT( check( "0" , output ) );
}
void SRDPreprocCmdCompareTest::testGe( )
{
T_SRDErrors errors;
T_SRDList output( process(
"( -ge a a )\n"
"( -ge a b )\n"
"( -ge ((a)) b )\n"
"( -ge a ((b)) )\n"
"( -ge ((a)) ((b)) )\n"
"( -ge ((a)) ((a)) )\n"
, errors ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) );
CPPUNIT_ASSERT( check( "1 0 0 1 0 1" , output ) );
}