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

1101 lines
35 KiB
C++
Raw Normal View History

#include "srd-preproc-cmd-common.hh"
class SRDPreprocCmdCastsTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE( SRDPreprocCmdCastsTest );
CPPUNIT_TEST( testToStringEmpty );
CPPUNIT_TEST( testToStringString );
CPPUNIT_TEST( testToStringWord );
CPPUNIT_TEST( testToStringInt );
CPPUNIT_TEST( testToStringLong );
CPPUNIT_TEST( testToStringReal );
CPPUNIT_TEST( testToStringVar );
CPPUNIT_TEST( testToStringList );
CPPUNIT_TEST( testToStringBinary );
CPPUNIT_TEST( testToStringBinaryInvalid );
CPPUNIT_TEST( testToStringMultiple );
CPPUNIT_TEST( testToWordEmpty );
CPPUNIT_TEST( testToWordStringOk );
CPPUNIT_TEST( testToWordStringBad );
CPPUNIT_TEST( testToWordWord );
CPPUNIT_TEST( testToWordInt );
CPPUNIT_TEST( testToWordLong );
CPPUNIT_TEST( testToWordReal );
CPPUNIT_TEST( testToWordVar );
CPPUNIT_TEST( testToWordList );
CPPUNIT_TEST( testToWordMultiple );
CPPUNIT_TEST( testToIntEmpty );
CPPUNIT_TEST( testToIntStringOk );
CPPUNIT_TEST( testToIntStringBad );
CPPUNIT_TEST( testToIntWord );
CPPUNIT_TEST( testToIntInt );
CPPUNIT_TEST( testToIntLongOk );
CPPUNIT_TEST( testToIntLongBad );
CPPUNIT_TEST( testToIntReal );
CPPUNIT_TEST( testToIntVar );
CPPUNIT_TEST( testToIntList );
CPPUNIT_TEST( testToIntMultiple );
CPPUNIT_TEST( testToLongEmpty );
CPPUNIT_TEST( testToLongStringOk );
CPPUNIT_TEST( testToLongStringBad );
CPPUNIT_TEST( testToLongWord );
CPPUNIT_TEST( testToLongInt );
CPPUNIT_TEST( testToLongLong );
CPPUNIT_TEST( testToLongReal );
CPPUNIT_TEST( testToLongVar );
CPPUNIT_TEST( testToLongList );
CPPUNIT_TEST( testToLongMultiple );
CPPUNIT_TEST( testToBestIntEmpty );
CPPUNIT_TEST( testToBestIntString32 );
CPPUNIT_TEST( testToBestIntString64 );
CPPUNIT_TEST( testToBestIntStringBad );
CPPUNIT_TEST( testToBestIntWord );
CPPUNIT_TEST( testToBestIntInt );
CPPUNIT_TEST( testToBestIntLong32 );
CPPUNIT_TEST( testToBestIntLong64 );
CPPUNIT_TEST( testToBestIntReal32 );
CPPUNIT_TEST( testToBestIntReal64 );
CPPUNIT_TEST( testToBestIntVar );
CPPUNIT_TEST( testToBestIntList );
CPPUNIT_TEST( testToBestIntMultiple );
CPPUNIT_TEST( testToRealEmpty );
CPPUNIT_TEST( testToRealStringOk );
CPPUNIT_TEST( testToRealStringBad );
CPPUNIT_TEST( testToRealWord );
CPPUNIT_TEST( testToRealInt );
CPPUNIT_TEST( testToRealLong );
CPPUNIT_TEST( testToRealReal );
CPPUNIT_TEST( testToRealVar );
CPPUNIT_TEST( testToRealList );
CPPUNIT_TEST( testToRealMultiple );
CPPUNIT_TEST( testToVarEmpty );
CPPUNIT_TEST( testToVarStringOk );
CPPUNIT_TEST( testToVarStringOkWithDollar );
CPPUNIT_TEST( testToVarStringBadWord );
CPPUNIT_TEST( testToVarStringBadVarName );
CPPUNIT_TEST( testToVarWordOk );
CPPUNIT_TEST( testToVarWordBad );
CPPUNIT_TEST( testToVarInt );
CPPUNIT_TEST( testToVarLong );
CPPUNIT_TEST( testToVarReal );
CPPUNIT_TEST( testToVarVar );
CPPUNIT_TEST( testToVarList );
CPPUNIT_TEST( testToVarMultiple );
CPPUNIT_TEST( testToListEmpty );
CPPUNIT_TEST( testToListString );
CPPUNIT_TEST( testToListStringEmpty );
CPPUNIT_TEST( testToListWord );
CPPUNIT_TEST( testToListBinary );
CPPUNIT_TEST( testToListBinaryEmpty );
CPPUNIT_TEST( testToListList );
CPPUNIT_TEST( testToListListEmpty );
CPPUNIT_TEST( testToListOtherTypes );
CPPUNIT_TEST( testToSourceEmpty );
CPPUNIT_TEST( testToSourceWord );
CPPUNIT_TEST( testToSourceString );
CPPUNIT_TEST( testToSourceInt );
CPPUNIT_TEST( testToSourceLong );
CPPUNIT_TEST( testToSourceReal );
CPPUNIT_TEST( testToSourceVar );
CPPUNIT_TEST( testToSourceList );
CPPUNIT_TEST( testToSourceMultiple );
CPPUNIT_TEST_SUITE_END( );
public:
void testToStringEmpty( );
void testToStringString( );
void testToStringWord( );
void testToStringInt( );
void testToStringLong( );
void testToStringReal( );
void testToStringVar( );
void testToStringList( );
void testToStringBinary( );
void testToStringBinaryInvalid( );
void testToStringMultiple( );
void testToWordEmpty( );
void testToWordStringOk( );
void testToWordStringBad( );
void testToWordWord( );
void testToWordInt( );
void testToWordLong( );
void testToWordReal( );
void testToWordVar( );
void testToWordList( );
void testToWordMultiple( );
void testToIntEmpty( );
void testToIntStringOk( );
void testToIntStringBad( );
void testToIntWord( );
void testToIntInt( );
void testToIntLongOk( );
void testToIntLongBad( );
void testToIntReal( );
void testToIntVar( );
void testToIntList( );
void testToIntMultiple( );
void testToLongEmpty( );
void testToLongStringOk( );
void testToLongStringBad( );
void testToLongWord( );
void testToLongInt( );
void testToLongLong( );
void testToLongReal( );
void testToLongVar( );
void testToLongList( );
void testToLongMultiple( );
void testToBestIntEmpty( );
void testToBestIntString32( );
void testToBestIntString64( );
void testToBestIntStringBad( );
void testToBestIntWord( );
void testToBestIntInt( );
void testToBestIntLong32( );
void testToBestIntLong64( );
void testToBestIntReal32( );
void testToBestIntReal64( );
void testToBestIntVar( );
void testToBestIntList( );
void testToBestIntMultiple( );
void testToRealEmpty( );
void testToRealStringOk( );
void testToRealStringBad( );
void testToRealWord( );
void testToRealInt( );
void testToRealLong( );
void testToRealReal( );
void testToRealVar( );
void testToRealList( );
void testToRealMultiple( );
void testToVarEmpty( );
void testToVarStringOk( );
void testToVarStringOkWithDollar( );
void testToVarStringBadWord( );
void testToVarStringBadVarName( );
void testToVarWordOk( );
void testToVarWordBad( );
void testToVarInt( );
void testToVarLong( );
void testToVarReal( );
void testToVarVar( );
void testToVarList( );
void testToVarMultiple( );
void testToListEmpty( );
void testToListString( );
void testToListStringEmpty( );
void testToListWord( );
void testToListBinary( );
void testToListBinaryEmpty( );
void testToListList( );
void testToListListEmpty( );
void testToListOtherTypes( );
void testToSourceEmpty( );
void testToSourceWord( );
void testToSourceString( );
void testToSourceInt( );
void testToSourceLong( );
void testToSourceReal( );
void testToSourceVar( );
void testToSourceList( );
void testToSourceMultiple( );
};
CPPUNIT_TEST_SUITE_REGISTRATION( SRDPreprocCmdCastsTest );
/*----------------------------------------------------------------------------*/
void SRDPreprocCmdCastsTest::testToStringEmpty( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-string )" , errors ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) );
CPPUNIT_ASSERT( check( "" , output ) );
}
void SRDPreprocCmdCastsTest::testToStringString( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-string \"a string\" )" , errors ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) );
CPPUNIT_ASSERT( check( "\"a string\"" , output ) );
}
void SRDPreprocCmdCastsTest::testToStringWord( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-string word )" , errors ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) );
CPPUNIT_ASSERT( check( "\"word\"" , output ) );
}
void SRDPreprocCmdCastsTest::testToStringInt( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-string 1 )" , errors ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) );
CPPUNIT_ASSERT( check( "\"1\"" , output ) );
}
void SRDPreprocCmdCastsTest::testToStringLong( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-string 12123456789 )" , errors ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) );
CPPUNIT_ASSERT( check( "\"12123456789\"" , output ) );
}
void SRDPreprocCmdCastsTest::testToStringReal( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-string 0.5 )" , errors ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) );
CPPUNIT_ASSERT( check( "\"0.5\"" , output ) );
}
void SRDPreprocCmdCastsTest::testToStringVar( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-string ( -raw $a ) )" , errors ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) );
CPPUNIT_ASSERT( check( "\"$a\"" , output ) );
}
void SRDPreprocCmdCastsTest::testToStringList( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-string ( ) )" , errors ) );
CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) );
M_CKERR_( 0 , "unsupported type conversion" , 1 , 3 );
M_CKERR_( 1 , "previous error cause" , 1 , 14 );
CPPUNIT_ASSERT( check( "" , output ) );
}
void SRDPreprocCmdCastsTest::testToStringBinary( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-string [ 4c 4f 4c ] )" , errors ) );
CPPUNIT_ASSERT_EQUAL( 0u , errors.size( ) );
CPPUNIT_ASSERT( check( "\"LOL\"" , output ) );
}
void SRDPreprocCmdCastsTest::testToStringBinaryInvalid( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-string [ 80 4c 4f 4c e5 ] )" , errors ) );
CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) );
M_CKERR_( 0 , "invalid UTF-8 data" , 1 , 3 );
M_CKERR_( 1 , "previous error cause" , 1 , 14 );
CPPUNIT_ASSERT( check( "\"\"" , output ) );
}
void SRDPreprocCmdCastsTest::testToStringMultiple( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-string \"a\" b ( ) ( -raw $c ) )" , errors ) );
CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) );
M_CKERR_( 0 , "unsupported type conversion" , 1 , 3 );
M_CKERR_( 1 , "previous error cause" , 1 , 20 );
CPPUNIT_ASSERT( check( "\"a\" \"b\" \"$c\"" , output ) );
}
/*----------------------------------------------------------------------------*/
void SRDPreprocCmdCastsTest::testToWordEmpty( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-word )" , errors ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) );
CPPUNIT_ASSERT( check( "" , output ) );
}
void SRDPreprocCmdCastsTest::testToWordStringOk( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-word \"a-word\" )" , errors ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) );
CPPUNIT_ASSERT( check( "a-word" , output ) );
}
void SRDPreprocCmdCastsTest::testToWordStringBad( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-word \"not a word, lol\" )" , errors ) );
CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) );
M_CKERR_( 0 , "invalid word" , 1 , 3 );
M_CKERR_( 1 , "previous error cause" , 1 , 12 );
CPPUNIT_ASSERT( check( "invalid" , output ) );
}
void SRDPreprocCmdCastsTest::testToWordWord( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-word word )" , errors ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) );
CPPUNIT_ASSERT( check( "word" , output ) );
}
void SRDPreprocCmdCastsTest::testToWordInt( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-word 1 )" , errors ) );
CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) );
M_CKERR_( 0 , "unsupported type conversion" , 1 , 3 );
M_CKERR_( 1 , "previous error cause" , 1 , 12 );
CPPUNIT_ASSERT( check( "invalid" , output ) );
}
void SRDPreprocCmdCastsTest::testToWordLong( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-word 12123456789 )" , errors ) );
CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) );
M_CKERR_( 0 , "unsupported type conversion" , 1 , 3 );
M_CKERR_( 1 , "previous error cause" , 1 , 12 );
CPPUNIT_ASSERT( check( "invalid" , output ) );
}
void SRDPreprocCmdCastsTest::testToWordReal( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-word 0.5 )" , errors ) );
CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) );
M_CKERR_( 0 , "unsupported type conversion" , 1 , 3 );
M_CKERR_( 1 , "previous error cause" , 1 , 12 );
CPPUNIT_ASSERT( check( "invalid" , output ) );
}
void SRDPreprocCmdCastsTest::testToWordVar( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-word ( -raw $x ) )" , errors ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) );
CPPUNIT_ASSERT( check( "x" , output ) );
}
void SRDPreprocCmdCastsTest::testToWordList( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-word ( ) )" , errors ) );
CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) );
M_CKERR_( 0 , "unsupported type conversion" , 1 , 3 );
M_CKERR_( 1 , "previous error cause" , 1 , 12 );
CPPUNIT_ASSERT( check( "invalid" , output ) );
}
void SRDPreprocCmdCastsTest::testToWordMultiple( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-word ( ) \"a\" ( -raw $b ) )" , errors ) );
CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) );
M_CKERR_( 0 , "unsupported type conversion" , 1 , 3 );
M_CKERR_( 1 , "previous error cause" , 1 , 12 );
CPPUNIT_ASSERT( check( "invalid a b" , output ) );
}
/*----------------------------------------------------------------------------*/
void SRDPreprocCmdCastsTest::testToIntEmpty( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-integer )" , errors ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) );
CPPUNIT_ASSERT( check( "" , output ) );
}
void SRDPreprocCmdCastsTest::testToIntStringOk( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-integer \"123\" )" , errors ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) );
CPPUNIT_ASSERT( check( "123" , output ) );
}
void SRDPreprocCmdCastsTest::testToIntStringBad( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-integer \"123nope\" )" , errors ) );
CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) );
M_CKERR_( 0 , "invalid integer value" , 1 , 3 );
M_CKERR_( 1 , "previous error cause" , 1 , 15 );
CPPUNIT_ASSERT( check( "0" , output ) );
}
void SRDPreprocCmdCastsTest::testToIntWord( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-integer word )" , errors ) );
CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) );
M_CKERR_( 0 , "unsupported type conversion" , 1 , 3 );
M_CKERR_( 1 , "previous error cause" , 1 , 15 );
CPPUNIT_ASSERT( check( "0" , output ) );
}
void SRDPreprocCmdCastsTest::testToIntInt( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-integer 123 )" , errors ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) );
CPPUNIT_ASSERT( check( "123" , output ) );
}
void SRDPreprocCmdCastsTest::testToIntLongOk( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-integer ( -to-long 123 ) )" , errors ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) );
CPPUNIT_ASSERT( check( "123" , output ) );
}
void SRDPreprocCmdCastsTest::testToIntLongBad( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-integer 12345678912 )" , errors ) );
CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) );
M_CKERR_( 0 , "value out of range" , 1 , 3 );
M_CKERR_( 1 , "previous error cause" , 1 , 15 );
CPPUNIT_ASSERT( check( "2147483647" , output ) );
}
void SRDPreprocCmdCastsTest::testToIntReal( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-integer 0.5 )" , errors ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) );
CPPUNIT_ASSERT( check( "0" , output ) );
}
void SRDPreprocCmdCastsTest::testToIntVar( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-integer ( -raw $x ) )" , errors ) );
CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) );
M_CKERR_( 0 , "unsupported type conversion" , 1 , 3 );
M_CKERR_( 1 , "previous error cause" , 1 , 22 );
CPPUNIT_ASSERT( check( "0" , output ) );
}
void SRDPreprocCmdCastsTest::testToIntList( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-integer ( ) )" , errors ) );
CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) );
M_CKERR_( 0 , "unsupported type conversion" , 1 , 3 );
M_CKERR_( 1 , "previous error cause" , 1 , 15 );
CPPUNIT_ASSERT( check( "0" , output ) );
}
void SRDPreprocCmdCastsTest::testToIntMultiple( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-integer ( ) 1 \"2\" )" , errors ) );
CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) );
M_CKERR_( 0 , "unsupported type conversion" , 1 , 3 );
M_CKERR_( 1 , "previous error cause" , 1 , 15 );
CPPUNIT_ASSERT( check( "0 1 2" , output ) );
}
/*----------------------------------------------------------------------------*/
void SRDPreprocCmdCastsTest::testToLongEmpty( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-long )" , errors ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) );
CPPUNIT_ASSERT( check( "" , output ) );
}
void SRDPreprocCmdCastsTest::testToLongStringOk( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-long \"12345678912\" )" , errors ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) );
CPPUNIT_ASSERT( check( "12345678912" , output ) );
}
void SRDPreprocCmdCastsTest::testToLongStringBad( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-long \"123nope\" )" , errors ) );
CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) );
M_CKERR_( 0 , "invalid integer value" , 1 , 3 );
M_CKERR_( 1 , "previous error cause" , 1 , 12 );
CPPUNIT_ASSERT_EQUAL( uint32_t( 1 ) , output.size( ) );
CPPUNIT_ASSERT( output[ 0 ].type( ) == E_SRDTokenType::LONG );
CPPUNIT_ASSERT_EQUAL( int64_t( 0 ) , output[ 0 ].longValue( ) );
}
void SRDPreprocCmdCastsTest::testToLongWord( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-long word )" , errors ) );
CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) );
M_CKERR_( 0 , "unsupported type conversion" , 1 , 3 );
M_CKERR_( 1 , "previous error cause" , 1 , 12 );
CPPUNIT_ASSERT_EQUAL( uint32_t( 1 ) , output.size( ) );
CPPUNIT_ASSERT( output[ 0 ].type( ) == E_SRDTokenType::LONG );
CPPUNIT_ASSERT_EQUAL( int64_t( 0 ) , output[ 0 ].longValue( ) );
}
void SRDPreprocCmdCastsTest::testToLongInt( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-long 123 )" , errors ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 1 ) , output.size( ) );
CPPUNIT_ASSERT( output[ 0 ].type( ) == E_SRDTokenType::LONG );
CPPUNIT_ASSERT_EQUAL( int64_t( 123 ) , output[ 0 ].longValue( ) );
}
void SRDPreprocCmdCastsTest::testToLongLong( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-long 12345678912 )" , errors ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) );
CPPUNIT_ASSERT( check( "12345678912" , output ) );
}
void SRDPreprocCmdCastsTest::testToLongReal( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-long 1e10 )" , errors ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) );
CPPUNIT_ASSERT( check( "10000000000" , output ) );
}
void SRDPreprocCmdCastsTest::testToLongVar( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-long ( -raw $x ) )" , errors ) );
CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) );
M_CKERR_( 0 , "unsupported type conversion" , 1 , 3 );
M_CKERR_( 1 , "previous error cause" , 1 , 19 );
CPPUNIT_ASSERT_EQUAL( uint32_t( 1 ) , output.size( ) );
CPPUNIT_ASSERT( output[ 0 ].type( ) == E_SRDTokenType::LONG );
CPPUNIT_ASSERT_EQUAL( int64_t( 0 ) , output[ 0 ].longValue( ) );
}
void SRDPreprocCmdCastsTest::testToLongList( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-long ( ) )" , errors ) );
CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) );
M_CKERR_( 0 , "unsupported type conversion" , 1 , 3 );
M_CKERR_( 1 , "previous error cause" , 1 , 12 );
CPPUNIT_ASSERT_EQUAL( uint32_t( 1 ) , output.size( ) );
CPPUNIT_ASSERT( output[ 0 ].type( ) == E_SRDTokenType::LONG );
CPPUNIT_ASSERT_EQUAL( int64_t( 0 ) , output[ 0 ].longValue( ) );
}
void SRDPreprocCmdCastsTest::testToLongMultiple( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-long ( ) 12345678912 \"12123456789\" )" , errors ) );
CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) );
M_CKERR_( 0 , "unsupported type conversion" , 1 , 3 );
M_CKERR_( 1 , "previous error cause" , 1 , 12 );
CPPUNIT_ASSERT_EQUAL( 3u , output.size( ) );
CPPUNIT_ASSERT( output[ 0 ].type( ) == E_SRDTokenType::LONG );
CPPUNIT_ASSERT_EQUAL( int64_t( 0 ) , output[ 0 ].longValue( ) );
CPPUNIT_ASSERT( output[ 1 ].type( ) == E_SRDTokenType::LONG );
CPPUNIT_ASSERT_EQUAL( int64_t( 12345678912L ) , output[ 1 ].longValue( ) );
CPPUNIT_ASSERT( output[ 2 ].type( ) == E_SRDTokenType::LONG );
CPPUNIT_ASSERT_EQUAL( int64_t( 12123456789L ) , output[ 2 ].longValue( ) );
}
/*----------------------------------------------------------------------------*/
void SRDPreprocCmdCastsTest::testToBestIntEmpty( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-best-integer )" , errors ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) );
CPPUNIT_ASSERT( check( "" , output ) );
}
void SRDPreprocCmdCastsTest::testToBestIntString32( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-best-integer \"123456\" )" , errors ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) );
CPPUNIT_ASSERT( check( "123456" , output ) );
}
void SRDPreprocCmdCastsTest::testToBestIntString64( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-best-integer \"12345678912\" )" , errors ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) );
CPPUNIT_ASSERT( check( "12345678912" , output ) );
}
void SRDPreprocCmdCastsTest::testToBestIntStringBad( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-best-integer \"123nope\" )" , errors ) );
CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) );
M_CKERR_( 0 , "invalid integer value" , 1 , 3 );
M_CKERR_( 1 , "previous error cause" , 1 , 20 );
CPPUNIT_ASSERT( check( "0" , output ) );
}
void SRDPreprocCmdCastsTest::testToBestIntWord( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-best-integer nope )" , errors ) );
CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) );
M_CKERR_( 0 , "unsupported type conversion" , 1 , 3 );
M_CKERR_( 1 , "previous error cause" , 1 , 20 );
CPPUNIT_ASSERT( check( "0" , output ) );
}
void SRDPreprocCmdCastsTest::testToBestIntInt( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-best-integer 123 )" , errors ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) );
CPPUNIT_ASSERT( check( "123" , output ) );
}
void SRDPreprocCmdCastsTest::testToBestIntLong32( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-best-integer ( -to-long 123 ) )" , errors ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) );
CPPUNIT_ASSERT( check( "123" , output ) );
}
void SRDPreprocCmdCastsTest::testToBestIntLong64( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-best-integer 12345678912 )" , errors ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) );
CPPUNIT_ASSERT( check( "12345678912" , output ) );
}
void SRDPreprocCmdCastsTest::testToBestIntReal32( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-best-integer 12.3 )" , errors ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) );
CPPUNIT_ASSERT( check( "12" , output ) );
}
void SRDPreprocCmdCastsTest::testToBestIntReal64( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-best-integer 1e10 )" , errors ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) );
CPPUNIT_ASSERT( check( "10000000000" , output ) );
}
void SRDPreprocCmdCastsTest::testToBestIntVar( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-best-integer ( -raw $x ) )" , errors ) );
CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) );
M_CKERR_( 0 , "unsupported type conversion" , 1 , 3 );
M_CKERR_( 1 , "previous error cause" , 1 , 27 );
CPPUNIT_ASSERT( check( "0" , output ) );
}
void SRDPreprocCmdCastsTest::testToBestIntList( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-best-integer ( ) )" , errors ) );
CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) );
M_CKERR_( 0 , "unsupported type conversion" , 1 , 3 );
M_CKERR_( 1 , "previous error cause" , 1 , 20 );
CPPUNIT_ASSERT( check( "0" , output ) );
}
void SRDPreprocCmdCastsTest::testToBestIntMultiple( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-best-integer ( ) \"123\" 456 78912345678 )" , errors ) );
CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) );
M_CKERR_( 0 , "unsupported type conversion" , 1 , 3 );
M_CKERR_( 1 , "previous error cause" , 1 , 20 );
CPPUNIT_ASSERT( check( "0 123 456 78912345678" , output ) );
}
/*----------------------------------------------------------------------------*/
void SRDPreprocCmdCastsTest::testToRealEmpty( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-real )" , errors ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) );
CPPUNIT_ASSERT( check( "" , output ) );
}
void SRDPreprocCmdCastsTest::testToRealStringOk( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-real \"-12e-3\" )" , errors ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) );
CPPUNIT_ASSERT( check( "-0.012" , output ) );
}
void SRDPreprocCmdCastsTest::testToRealStringBad( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-real \"nope\" )" , errors ) );
CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) );
M_CKERR_( 0 , "invalid real value" , 1 , 3 );
M_CKERR_( 1 , "previous error cause" , 1 , 12 );
CPPUNIT_ASSERT( check( "0." , output ) );
}
void SRDPreprocCmdCastsTest::testToRealWord( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-real nope )" , errors ) );
CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) );
M_CKERR_( 0 , "unsupported type conversion" , 1 , 3 );
M_CKERR_( 1 , "previous error cause" , 1 , 12 );
CPPUNIT_ASSERT( check( "0." , output ) );
}
void SRDPreprocCmdCastsTest::testToRealInt( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-real 12 )" , errors ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) );
CPPUNIT_ASSERT( check( "12.0" , output ) );
}
void SRDPreprocCmdCastsTest::testToRealLong( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-real 12345678912 )" , errors ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) );
CPPUNIT_ASSERT( check( "12345678912.0" , output ) );
}
void SRDPreprocCmdCastsTest::testToRealReal( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-real 1234567891.2 )" , errors ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) );
CPPUNIT_ASSERT( check( "1234567891.2" , output ) );
}
void SRDPreprocCmdCastsTest::testToRealVar( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-real ( -raw $x ) )" , errors ) );
CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) );
M_CKERR_( 0 , "unsupported type conversion" , 1 , 3 );
M_CKERR_( 1 , "previous error cause" , 1 , 19 );
CPPUNIT_ASSERT( check( "0." , output ) );
}
void SRDPreprocCmdCastsTest::testToRealList( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-real ( ) )" , errors ) );
CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) );
M_CKERR_( 0 , "unsupported type conversion" , 1 , 3 );
M_CKERR_( 1 , "previous error cause" , 1 , 12 );
CPPUNIT_ASSERT( check( "0." , output ) );
}
void SRDPreprocCmdCastsTest::testToRealMultiple( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-real ( ) 123 456.5 )" , errors ) );
CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) );
M_CKERR_( 0 , "unsupported type conversion" , 1 , 3 );
M_CKERR_( 1 , "previous error cause" , 1 , 12 );
CPPUNIT_ASSERT( check( "0. 123.0 456.5" , output ) );
}
/*----------------------------------------------------------------------------*/
void SRDPreprocCmdCastsTest::testToVarEmpty( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-variable )" , errors ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) );
CPPUNIT_ASSERT( check( "" , output ) );
}
void SRDPreprocCmdCastsTest::testToVarStringOk( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-variable \"name\" )" , errors ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) );
CPPUNIT_ASSERT( check( "$name" , output ) );
}
void SRDPreprocCmdCastsTest::testToVarStringOkWithDollar( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-variable \"$name\" )" , errors ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) );
CPPUNIT_ASSERT( check( "$name" , output ) );
}
void SRDPreprocCmdCastsTest::testToVarStringBadWord( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-variable \"not a word\" )" , errors ) );
CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) );
M_CKERR_( 0 , "invalid variable name" , 1 , 3 );
M_CKERR_( 1 , "previous error cause" , 1 , 16 );
CPPUNIT_ASSERT( check( "$invalid" , output ) );
}
void SRDPreprocCmdCastsTest::testToVarStringBadVarName( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-variable \"-bad\" )" , errors ) );
CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) );
M_CKERR_( 0 , "invalid variable name" , 1 , 3 );
M_CKERR_( 1 , "previous error cause" , 1 , 16 );
CPPUNIT_ASSERT( check( "$invalid" , output ) );
}
void SRDPreprocCmdCastsTest::testToVarWordOk( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-variable name )" , errors ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) );
CPPUNIT_ASSERT( check( "$name" , output ) );
}
void SRDPreprocCmdCastsTest::testToVarWordBad( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-variable -bad )" , errors ) );
CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) );
M_CKERR_( 0 , "invalid variable name" , 1 , 3 );
M_CKERR_( 1 , "previous error cause" , 1 , 16 );
CPPUNIT_ASSERT( check( "$invalid" , output ) );
}
void SRDPreprocCmdCastsTest::testToVarInt( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-variable 1 )" , errors ) );
CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) );
M_CKERR_( 0 , "unsupported type conversion" , 1 , 3 );
M_CKERR_( 1 , "previous error cause" , 1 , 16 );
CPPUNIT_ASSERT( check( "$invalid" , output ) );
}
void SRDPreprocCmdCastsTest::testToVarLong( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-variable 12345678912 )" , errors ) );
CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) );
M_CKERR_( 0 , "unsupported type conversion" , 1 , 3 );
M_CKERR_( 1 , "previous error cause" , 1 , 16 );
CPPUNIT_ASSERT( check( "$invalid" , output ) );
}
void SRDPreprocCmdCastsTest::testToVarReal( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-variable 1.5 )" , errors ) );
CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) );
M_CKERR_( 0 , "unsupported type conversion" , 1 , 3 );
M_CKERR_( 1 , "previous error cause" , 1 , 16 );
CPPUNIT_ASSERT( check( "$invalid" , output ) );
}
void SRDPreprocCmdCastsTest::testToVarVar( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-variable ( -raw $x ) )" , errors ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) );
CPPUNIT_ASSERT( check( "$x" , output ) );
}
void SRDPreprocCmdCastsTest::testToVarList( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-variable ( ) )" , errors ) );
CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) );
M_CKERR_( 0 , "unsupported type conversion" , 1 , 3 );
M_CKERR_( 1 , "previous error cause" , 1 , 16 );
CPPUNIT_ASSERT( check( "$invalid" , output ) );
}
void SRDPreprocCmdCastsTest::testToVarMultiple( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-variable ( ) \"$x\" y )" , errors ) );
CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) );
M_CKERR_( 0 , "unsupported type conversion" , 1 , 3 );
M_CKERR_( 1 , "previous error cause" , 1 , 16 );
CPPUNIT_ASSERT( check( "$invalid $x $y" , output ) );
}
/*----------------------------------------------------------------------------*/
void SRDPreprocCmdCastsTest::testToListEmpty( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-list )" , errors ) );
CPPUNIT_ASSERT_EQUAL( 0u , errors.size( ) );
CPPUNIT_ASSERT( check( "" , output ) );
}
void SRDPreprocCmdCastsTest::testToListString( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-list \"abc\" )" , errors ) );
CPPUNIT_ASSERT_EQUAL( 0u , errors.size( ) );
CPPUNIT_ASSERT( check( "\"a\" \"b\" \"c\"" , output ) );
}
void SRDPreprocCmdCastsTest::testToListStringEmpty( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-list \"\" )" , errors ) );
CPPUNIT_ASSERT_EQUAL( 0u , errors.size( ) );
CPPUNIT_ASSERT( check( "" , output ) );
}
void SRDPreprocCmdCastsTest::testToListWord( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-list abc )" , errors ) );
CPPUNIT_ASSERT_EQUAL( 0u , errors.size( ) );
CPPUNIT_ASSERT( check( "\"a\" \"b\" \"c\"" , output ) );
}
void SRDPreprocCmdCastsTest::testToListBinary( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-list [ deadbeef ] )" , errors ) );
CPPUNIT_ASSERT_EQUAL( 0u , errors.size( ) );
CPPUNIT_ASSERT( check( "222 173 190 239" , output ) );
}
void SRDPreprocCmdCastsTest::testToListBinaryEmpty( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-list [ ] )" , errors ) );
CPPUNIT_ASSERT_EQUAL( 0u , errors.size( ) );
CPPUNIT_ASSERT( check( "" , output ) );
}
void SRDPreprocCmdCastsTest::testToListList( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-list ( ab c ) )" , errors ) );
CPPUNIT_ASSERT_EQUAL( 0u , errors.size( ) );
CPPUNIT_ASSERT( check( "ab c" , output ) );
}
void SRDPreprocCmdCastsTest::testToListListEmpty( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-list ( ) )" , errors ) );
CPPUNIT_ASSERT_EQUAL( 0u , errors.size( ) );
CPPUNIT_ASSERT( check( "" , output ) );
}
void SRDPreprocCmdCastsTest::testToListOtherTypes( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-list 10 1.2 (-raw $x) )" , errors ) );
CPPUNIT_ASSERT_EQUAL( 0u , errors.size( ) );
CPPUNIT_ASSERT( check( "10 1.2 $x" , output ) );
}
/*----------------------------------------------------------------------------*/
void SRDPreprocCmdCastsTest::testToSourceEmpty( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-source )" , errors ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) );
CPPUNIT_ASSERT( check( "\"\"" , output ) );
}
void SRDPreprocCmdCastsTest::testToSourceWord( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-source word )" , errors ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) );
CPPUNIT_ASSERT( check( "\"word\"" , output ) );
}
void SRDPreprocCmdCastsTest::testToSourceString( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-source \"some\\nstring\" )" , errors ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) );
CPPUNIT_ASSERT( check( "\"\\\"some\\\\nstring\\\"\"" , output ) );
}
void SRDPreprocCmdCastsTest::testToSourceInt( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-source 123 )" , errors ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) );
CPPUNIT_ASSERT( check( "\"123\"" , output ) );
}
void SRDPreprocCmdCastsTest::testToSourceLong( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-source 5000000000 )" , errors ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) );
CPPUNIT_ASSERT( check( "\"5000000000\"" , output ) );
}
void SRDPreprocCmdCastsTest::testToSourceReal( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-source 1.2 )" , errors ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) );
CPPUNIT_ASSERT( check( "\"1.2\"" , output ) );
}
void SRDPreprocCmdCastsTest::testToSourceVar( )
{
T_SRDErrors errors;
T_SRDList output( process( "( -to-source (-raw $x) )" , errors ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) );
CPPUNIT_ASSERT( check( "\"$x\"" , output ) );
}
void SRDPreprocCmdCastsTest::testToSourceList( )
{
T_SRDErrors errors;
T_SRDList output( process( "(-to-source ( word \"string\" 123 5000000000 1.2 (-raw $x) ))" , errors ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) );
CPPUNIT_ASSERT( check( "\"( word \\\"string\\\" 123 5000000000 1.2 $x )\"" , output ) );
}
void SRDPreprocCmdCastsTest::testToSourceMultiple( )
{
T_SRDErrors errors;
T_SRDList output( process( "(-to-source word \"string\" 123 5000000000 1.2 (-raw $x) ( some list ))" , errors ) );
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) );
CPPUNIT_ASSERT( check( "\"word \\\"string\\\" 123 5000000000 1.2 $x ( some list )\"" , output ) );
}