#include "srd-preproc-cmd-common.hh" class SRDPreprocCmdVariablesTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE( SRDPreprocCmdVariablesTest ); CPPUNIT_TEST( testSetVarNoArgs ); CPPUNIT_TEST( testSetVarBadName ); CPPUNIT_TEST( testSetVarEmpty ); CPPUNIT_TEST( testSetVarBasic ); CPPUNIT_TEST( testSetVarList ); CPPUNIT_TEST( testSetVarExisting ); CPPUNIT_TEST( testSetVarsNoNames ); CPPUNIT_TEST( testSetVarsBadName ); CPPUNIT_TEST( testSetVarsEmpty ); CPPUNIT_TEST( testSetVarsMissing ); CPPUNIT_TEST( testSetVarsMultiple ); CPPUNIT_TEST( testSetVarsRest ); CPPUNIT_TEST( testSetVarsRepeatName ); CPPUNIT_TEST( testSetVarsExisting ); CPPUNIT_TEST( testSetVarsExistingAndRepeated ); CPPUNIT_TEST( testUnsetNoArgs ); CPPUNIT_TEST( testUnset ); CPPUNIT_TEST( testUnsetMissing ); CPPUNIT_TEST( testUnsetMultiple ); CPPUNIT_TEST( testUnsetFromVarBeingUnset ); CPPUNIT_TEST( testGetEmpty ); CPPUNIT_TEST( testGetBadArg ); CPPUNIT_TEST( testGetMissing ); CPPUNIT_TEST( testGetVar ); CPPUNIT_TEST( testGetVars ); CPPUNIT_TEST( testGetVarsWithErrors ); CPPUNIT_TEST( testListVariables ); CPPUNIT_TEST( testListVariablesArgs ); CPPUNIT_TEST_SUITE_END( ); public: void testSetVarNoArgs( ); void testSetVarBadName( ); void testSetVarEmpty( ); void testSetVarBasic( ); void testSetVarList( ); void testSetVarExisting( ); void testSetVarsNoNames( ); void testSetVarsBadName( ); void testSetVarsEmpty( ); void testSetVarsMissing( ); void testSetVarsMultiple( ); void testSetVarsRest( ); void testSetVarsRepeatName( ); void testSetVarsExisting( ); void testSetVarsExistingAndRepeated( ); void testUnsetNoArgs( ); void testUnset( ); void testUnsetMissing( ); void testUnsetMultiple( ); void testUnsetFromVarBeingUnset( ); void testGetEmpty( ); void testGetBadArg( ); void testGetMissing( ); void testGetVar( ); void testGetVars( ); void testGetVarsWithErrors( ); void testListVariables( ); void testListVariablesArgs( ); }; CPPUNIT_TEST_SUITE_REGISTRATION( SRDPreprocCmdVariablesTest ); /*----------------------------------------------------------------------------*/ void SRDPreprocCmdVariablesTest::testSetVarNoArgs( ) { T_SRDErrors errors; T_SRDList output( process( "( -set )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) ); M_CKERR_( 0 , "not enough arguments" , 1 , 3 ); M_CKERR_( 1 , "previous error cause" , 1 , 8 ); CPPUNIT_ASSERT( check( "" , output ) ); } void SRDPreprocCmdVariablesTest::testSetVarBadName( ) { T_SRDErrors errors; T_SRDList output( process( "( -set 1 )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) ); M_CKERR_( 0 , "word or list expected" , 1 , 3 ); M_CKERR_( 1 , "previous error cause" , 1 , 8 ); CPPUNIT_ASSERT( check( "" , output ) ); } void SRDPreprocCmdVariablesTest::testSetVarEmpty( ) { T_SRDErrors errors; T_SRDList output( process( "( -set x )\n$x" , errors ) ); CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) ); CPPUNIT_ASSERT( check( "" , output ) ); } void SRDPreprocCmdVariablesTest::testSetVarBasic( ) { T_SRDErrors errors; T_SRDList output( process( "( -set x y )\n$x" , errors ) ); CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) ); CPPUNIT_ASSERT( check( "y" , output ) ); } void SRDPreprocCmdVariablesTest::testSetVarList( ) { T_SRDErrors errors; T_SRDList output( process( "( -set x y z )\n$x" , errors ) ); CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) ); CPPUNIT_ASSERT( check( "y z" , output ) ); } void SRDPreprocCmdVariablesTest::testSetVarExisting( ) { T_SRDErrors errors; T_SRDList output( process( "( -set x a )\n$x\n( -set x b )\n$x" , errors ) ); CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) ); M_CKERR_( 0 , "duplicate variable name" , 3 , 3 ); M_CKERR_( 1 , "previous error cause" , 3 , 8 ); CPPUNIT_ASSERT( check( "a a" , output ) ); } /*----------------------------------------------------------------------------*/ void SRDPreprocCmdVariablesTest::testSetVarsNoNames( ) { T_SRDErrors errors; T_SRDList output( process( "( -set ( ) )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) ); M_CKERR_( 0 , "no variable names" , 1 , 3 ); M_CKERR_( 1 , "previous error cause" , 1 , 10 ); CPPUNIT_ASSERT( check( "" , output ) ); } void SRDPreprocCmdVariablesTest::testSetVarsBadName( ) { T_SRDErrors errors; T_SRDList output( process( "( -set ( 1 ( ) ) )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 4u , errors.size( ) ); M_CKERR_( 0 , "word expected" , 1 , 3 ); M_CKERR_( 1 , "previous error cause" , 1 , 10 ); M_CKERR_( 2 , "word expected" , 1 , 3 ); M_CKERR_( 3 , "previous error cause" , 1 , 12 ); CPPUNIT_ASSERT( check( "" , output ) ); } void SRDPreprocCmdVariablesTest::testSetVarsEmpty( ) { T_SRDErrors errors; T_SRDList output( process( "( -set ( a b ) )\n( $b ) ( $a )" , errors ) ); CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) ); CPPUNIT_ASSERT( check( "()()" , output ) ); } void SRDPreprocCmdVariablesTest::testSetVarsMissing( ) { T_SRDErrors errors; T_SRDList output( process( "( -set ( a b ) a )\n( $b ) ( $a )" , errors ) ); CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) ); CPPUNIT_ASSERT( check( "( ) ( a )" , output ) ); } void SRDPreprocCmdVariablesTest::testSetVarsMultiple( ) { T_SRDErrors errors; T_SRDList output( process( "( -set ( a b ) a b )\n( $b ) ( $a )" , errors ) ); CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) ); CPPUNIT_ASSERT( check( "( b ) ( a )" , output ) ); } void SRDPreprocCmdVariablesTest::testSetVarsRest( ) { T_SRDErrors errors; T_SRDList output( process( "( -set ( a b ) a b c )\n( $b ) ( $a )" , errors ) ); CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) ); CPPUNIT_ASSERT( check( "( b c ) ( a )" , output ) ); } void SRDPreprocCmdVariablesTest::testSetVarsRepeatName( ) { T_SRDErrors errors; T_SRDList output( process( "( -set ( a a ) a b c )\n( $a )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 3u , errors.size( ) ); M_CKERR_( 0 , "duplicate variable name" , 1 , 3 ); M_CKERR_( 1 , "previous error cause" , 1 , 10 ); M_CKERR_( 2 , "unknown variable" , 2 , 3 ); CPPUNIT_ASSERT( check( "( )" , output ) ); } void SRDPreprocCmdVariablesTest::testSetVarsExisting( ) { T_SRDErrors errors; T_SRDList output( process( "( -set b x )\n( -set ( a b ) u v )\n( $a )( $b )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 3u , errors.size( ) ); M_CKERR_( 0 , "duplicate variable name" , 2 , 3 ); M_CKERR_( 1 , "previous error cause" , 2 , 12 ); M_CKERR_( 2 , "unknown variable" , 3 , 3 ); CPPUNIT_ASSERT( check( "( )( x )" , output ) ); } void SRDPreprocCmdVariablesTest::testSetVarsExistingAndRepeated( ) { T_SRDErrors errors; T_SRDList output( process( "( -set b x )\n( -set ( a b b a ) u v )\n( $a )( $b )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 5u , errors.size( ) ); M_CKERR_( 0 , "duplicate variable name" , 2 , 3 ); M_CKERR_( 1 , "previous error cause" , 2 , 10 ); M_CKERR_( 2 , "duplicate variable name" , 2 , 3 ); M_CKERR_( 3 , "previous error cause" , 2 , 12 ); M_CKERR_( 4 , "unknown variable" , 3 , 3 ); CPPUNIT_ASSERT( check( "( )( x )" , output ) ); } /*----------------------------------------------------------------------------*/ void SRDPreprocCmdVariablesTest::testUnsetNoArgs( ) { T_SRDErrors errors; T_SRDList output( process( "( -unset ) " , errors ) ); CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) ); CPPUNIT_ASSERT( check( "" , output ) ); } void SRDPreprocCmdVariablesTest::testUnset( ) { T_SRDErrors errors; T_SRDList output( process( "( -set a 1 )\n$a\n( -unset a )\n$a" , errors ) ); CPPUNIT_ASSERT_EQUAL( uint32_t( 1 ) , errors.size( ) ); M_CKERR_( 0 , "unknown variable" , 4 , 1 ); CPPUNIT_ASSERT( check( "1" , output ) ); } void SRDPreprocCmdVariablesTest::testUnsetMissing( ) { T_SRDErrors errors; T_SRDList output( process( "( -unset a )" , errors ) ); CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) ); CPPUNIT_ASSERT( check( "" , output ) ); } void SRDPreprocCmdVariablesTest::testUnsetMultiple( ) { T_SRDErrors errors; T_SRDList output( process( "( -set ( a b c ) 1 2 3)\n" "( -unset a c )\n" "( $a $b $c )" , errors ) ); CPPUNIT_ASSERT_EQUAL( uint32_t( 2 ) , errors.size( ) ); M_CKERR_( 0 , "unknown variable" , 3 , 3 ); M_CKERR_( 1 , "unknown variable" , 3 , 9 ); CPPUNIT_ASSERT( check( "( 2 )" , output ) ); } void SRDPreprocCmdVariablesTest::testUnsetFromVarBeingUnset( ) { T_SRDErrors errors; T_SRDList output( process( "( -set ( c b a ) d c a b)\n" "( -unset $a $b )\n" "( $a $b $c )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 3u , errors.size( ) ); M_CKERR_( 0 , "unknown variable" , 2 , 13 ); M_CKERR_( 1 , "unknown variable" , 3 , 3 ); M_CKERR_( 2 , "unknown variable" , 3 , 6 ); CPPUNIT_ASSERT( check( "( d )" , output ) ); } /*----------------------------------------------------------------------------*/ void SRDPreprocCmdVariablesTest::testGetEmpty( ) { T_SRDErrors errors; T_SRDList output( process( "( -get )" , errors ) ); CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) ); CPPUNIT_ASSERT( check( "" , output ) ); } void SRDPreprocCmdVariablesTest::testGetBadArg( ) { T_SRDErrors errors; T_SRDList output( process( "( -get 1 ( ) )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 4u , errors.size( ) ); M_CKERR_( 0 , "word expected" , 1 , 3 ); M_CKERR_( 1 , "previous error cause" , 1 , 8 ); M_CKERR_( 2 , "word expected" , 1 , 3 ); M_CKERR_( 3 , "previous error cause" , 1 , 10 ); CPPUNIT_ASSERT( check( "" , output ) ); } void SRDPreprocCmdVariablesTest::testGetMissing( ) { T_SRDErrors errors; T_SRDList output( process( "( -get a )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) ); M_CKERR_( 0 , "unknown variable" , 1 , 3 ); M_CKERR_( 1 , "previous error cause" , 1 , 8 ); CPPUNIT_ASSERT( check( "" , output ) ); } void SRDPreprocCmdVariablesTest::testGetVar( ) { T_SRDErrors errors; T_SRDList output( process( "(-set a x)\n( -get a )" , errors ) ); CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) ); CPPUNIT_ASSERT( check( "x" , output ) ); } void SRDPreprocCmdVariablesTest::testGetVars( ) { T_SRDErrors errors; T_SRDList output( process( "(-set ( a b c ) x y z w )\n( -get c b a )" , errors ) ); CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) ); CPPUNIT_ASSERT( check( "z w y x" , output ) ); } void SRDPreprocCmdVariablesTest::testGetVarsWithErrors( ) { T_SRDErrors errors; T_SRDList output( process( "(-set ( a b ) x y )\n( -get b c a )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) ); M_CKERR_( 0 , "unknown variable" , 2 , 3 ); M_CKERR_( 1 , "previous error cause" , 2 , 10 ); CPPUNIT_ASSERT( check( "y x" , output ) ); } /*----------------------------------------------------------------------------*/ void SRDPreprocCmdVariablesTest::testListVariables( ) { T_SRDErrors errors; T_SRDList output( process( "( -set x )\n" "( -set-macro y ( ( ) ) )\n" "( -set f (-raw (() ((-ls-variables))) ))\n" "( -bless f )\n" "( ( -ls-variables ) )\n" "( -scope\n" "( -unset x )\n" "( ( -ls-variables ) )\n" ")\n" "($f)\n" , errors ) ); CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) ); CPPUNIT_ASSERT( check( "( x f ) ( f ) ( f )" , output ) ); } void SRDPreprocCmdVariablesTest::testListVariablesArgs( ) { T_SRDErrors errors; T_SRDList output( process( "( -set x )\n" "( -ls-variables blah )\n" , errors ) ); CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) ); M_CKERR_( 0 , "too many arguments" , 2 , 3 ); M_CKERR_( 1 , "previous error cause" , 2 , 17 ); CPPUNIT_ASSERT( check( "x" , output ) ); }