#include "srd-preproc-cmd-common.hh" class SRDPreprocCmdStringsTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE( SRDPreprocCmdStringsTest ); CPPUNIT_TEST( testConcatNoArgs ); CPPUNIT_TEST( testConcatBadArgs ); CPPUNIT_TEST( testConcatOneString ); CPPUNIT_TEST( testConcatStrings ); CPPUNIT_TEST( testConcatStringWord ); CPPUNIT_TEST( testConcatStringNumeric ); CPPUNIT_TEST( testConcatStringBinary ); CPPUNIT_TEST( testConcatOneBinary ); CPPUNIT_TEST( testConcatBinary ); CPPUNIT_TEST( testSubstrNotEnoughArgs ); CPPUNIT_TEST( testSubstrStringNotEnoughArgs ); CPPUNIT_TEST( testSubstrBinaryNotEnoughArgs ); CPPUNIT_TEST( testSubstrStringTooManyArgs ); CPPUNIT_TEST( testSubstrBinaryTooManyArgs ); CPPUNIT_TEST( testSubstrBadTooManyArgs ); CPPUNIT_TEST( testSubstrStringOffset ); CPPUNIT_TEST( testSubstrBinaryOffset ); CPPUNIT_TEST( testSubstrBadOffset ); CPPUNIT_TEST( testSubstrStringBad ); CPPUNIT_TEST( testSubstrStringInvalid ); CPPUNIT_TEST( testSubstrStringHigh ); CPPUNIT_TEST( testSubstrStringOffsetLength ); CPPUNIT_TEST( testSubstrBinaryOffsetLength ); CPPUNIT_TEST( testSubstrStringOffsetBad ); CPPUNIT_TEST( testSubstrStringOffsetToOffset ); CPPUNIT_TEST( testSubstrBinaryOffsetToOffset ); CPPUNIT_TEST( testSubstrStringRangeInverted ); CPPUNIT_TEST( testSubstrBinaryRangeInverted ); CPPUNIT_TEST( testSubstrStringOffsetBadOffset ); CPPUNIT_TEST( testSubstrStringOffsetToBad ); CPPUNIT_TEST( testSubstrRangeInvalidStart ); CPPUNIT_TEST( testSubstrRangeInvalidEnd ); CPPUNIT_TEST( testSplitNotEnoughArgs ); CPPUNIT_TEST( testSplitTooManyArgs ); CPPUNIT_TEST( testSplitBadString ); CPPUNIT_TEST( testSplitStringBad ); CPPUNIT_TEST( testSplitStringEmpty ); CPPUNIT_TEST( testSplitStringStringBad ); CPPUNIT_TEST( testSplitStringStringNegative ); CPPUNIT_TEST( testSplitSingleNormal ); CPPUNIT_TEST( testSplitSingleStart ); CPPUNIT_TEST( testSplitSingleEnd ); CPPUNIT_TEST( testSplitSingleNowhere ); CPPUNIT_TEST( testSplitMultiNormal ); CPPUNIT_TEST( testSplitMultiStart ); CPPUNIT_TEST( testSplitMultiEnd ); CPPUNIT_TEST( testSplitMultiNowhere ); CPPUNIT_TEST( testSplitMultiLonger ); CPPUNIT_TEST( testSplitLimitZero ); CPPUNIT_TEST( testSplitLimit ); CPPUNIT_TEST( testSplitLimitGreater ); CPPUNIT_TEST( testSWNotEnoughArgs ); CPPUNIT_TEST( testSWTooManyArgs ); CPPUNIT_TEST( testSWStringYes ); CPPUNIT_TEST( testSWStringYesEqual ); CPPUNIT_TEST( testSWStringYesEmpty ); CPPUNIT_TEST( testSWStringNoShorter ); CPPUNIT_TEST( testSWStringNoLonger ); CPPUNIT_TEST( testSWBinaryYes ); CPPUNIT_TEST( testSWBinaryYesEqual ); CPPUNIT_TEST( testSWBinaryYesEmpty ); CPPUNIT_TEST( testSWBinaryNoShorter ); CPPUNIT_TEST( testSWBinaryNoLonger ); CPPUNIT_TEST( testSWWordString ); CPPUNIT_TEST( testSWStringWord ); CPPUNIT_TEST( testSWStringBad ); CPPUNIT_TEST( testSWBadString ); CPPUNIT_TEST( testEWNotEnoughArgs ); CPPUNIT_TEST( testEWTooManyArgs ); CPPUNIT_TEST( testEWStringYes ); CPPUNIT_TEST( testEWStringYesEqual ); CPPUNIT_TEST( testEWStringYesEmpty ); CPPUNIT_TEST( testEWStringNoShorter ); CPPUNIT_TEST( testEWStringNoLonger ); CPPUNIT_TEST( testEWBinaryYes ); CPPUNIT_TEST( testEWBinaryYesEqual ); CPPUNIT_TEST( testEWBinaryYesEmpty ); CPPUNIT_TEST( testEWBinaryNoShorter ); CPPUNIT_TEST( testEWBinaryNoLonger ); CPPUNIT_TEST( testEWWordString ); CPPUNIT_TEST( testEWStringWord ); CPPUNIT_TEST( testEWStringBad ); CPPUNIT_TEST( testEWBadString ); CPPUNIT_TEST_SUITE_END( ); public: // -concat void testConcatNoArgs( ); void testConcatBadArgs( ); void testConcatOneString( ); void testConcatStrings( ); void testConcatStringWord( ); void testConcatStringNumeric( ); void testConcatStringBinary( ); void testConcatOneBinary( ); void testConcatBinary( ); // -substr void testSubstrNotEnoughArgs( ); // Not enough arguments void testSubstrStringNotEnoughArgs( ); // String void testSubstrBinaryNotEnoughArgs( ); // Binary void testSubstrStringTooManyArgs( ); // String + too many arguments void testSubstrBinaryTooManyArgs( ); // Binary + too many arguments void testSubstrBadTooManyArgs( ); // Invalid argument + too many arguments void testSubstrStringOffset( ); // String and offset arguments void testSubstrBinaryOffset( ); // Binary data and offset arguments void testSubstrBadOffset( ); // Invalid argument + offset void testSubstrStringBad( ); // String + invalid argument void testSubstrStringInvalid( ); // String, offset < 0 void testSubstrStringHigh( ); // String, offset > length void testSubstrStringOffsetLength( ); // String, offset and length arguments void testSubstrBinaryOffsetLength( ); // Binary, offset and length arguments void testSubstrStringOffsetBad( ); // String and offset followed by invalid argument void testSubstrStringOffsetToOffset( ); // String, range mode void testSubstrBinaryOffsetToOffset( ); // Binary, range mode void testSubstrStringRangeInverted( ); // String, range mode, end < start void testSubstrBinaryRangeInverted( ); // Binary, range mode, end < start void testSubstrStringOffsetBadOffset( ); // String, range mode, wrong "to" argument void testSubstrStringOffsetToBad( ); // String, range mode, wrong end argument void testSubstrRangeInvalidStart( ); // String, range mode, start < 0 void testSubstrRangeInvalidEnd( ); // String, range mode, end < 0 // -str-split void testSplitNotEnoughArgs( ); // Not enough arguments void testSplitTooManyArgs( ); // Too many arguments void testSplitBadString( ); // Invalid argument, string void testSplitStringBad( ); // String, invalid argument void testSplitStringEmpty( ); // String, empty string void testSplitStringStringBad( ); // String, string, invalid argument void testSplitStringStringNegative( ); // String, string, negative integer void testSplitSingleNormal( ); // Single-character delimiter, inside string void testSplitSingleStart( ); // Single-character delimiter, start of string void testSplitSingleEnd( ); // Single-character delimiter, end of string void testSplitSingleNowhere( ); // Single-character delimiter, not in string void testSplitMultiNormal( ); // Multi-character delimiter, inside string void testSplitMultiStart( ); // Multi-character delimiter, start of string void testSplitMultiEnd( ); // Multi-character delimiter, end of string void testSplitMultiNowhere( ); // Multi-character delimiter, not in string void testSplitMultiLonger( ); // Multi-character delimiter, longer than string void testSplitLimitZero( ); // With limit set to 0 void testSplitLimit( ); // With a non-zero limit void testSplitLimitGreater( ); // With a limit higher than the result count // -starts-with void testSWNotEnoughArgs( ); void testSWTooManyArgs( ); void testSWStringYes( ); void testSWStringYesEqual( ); void testSWStringYesEmpty( ); void testSWStringNoShorter( ); void testSWStringNoLonger( ); void testSWBinaryYes( ); void testSWBinaryYesEqual( ); void testSWBinaryYesEmpty( ); void testSWBinaryNoShorter( ); void testSWBinaryNoLonger( ); void testSWWordString( ); void testSWStringWord( ); void testSWStringBad( ); void testSWBadString( ); // -ends-with void testEWNotEnoughArgs( ); void testEWTooManyArgs( ); void testEWStringYes( ); void testEWStringYesEqual( ); void testEWStringYesEmpty( ); void testEWStringNoShorter( ); void testEWStringNoLonger( ); void testEWBinaryYes( ); void testEWBinaryYesEqual( ); void testEWBinaryYesEmpty( ); void testEWBinaryNoShorter( ); void testEWBinaryNoLonger( ); void testEWWordString( ); void testEWStringWord( ); void testEWStringBad( ); void testEWBadString( ); }; CPPUNIT_TEST_SUITE_REGISTRATION( SRDPreprocCmdStringsTest ); /*----------------------------------------------------------------------------*/ void SRDPreprocCmdStringsTest::testConcatNoArgs( ) { T_SRDErrors errors; T_SRDList output( process( "( -concat )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) ); M_CKERR_( 0 , "not enough arguments" , 1 , 3 ); M_CKERR_( 1 , "previous error cause" , 1 , 11 ); CPPUNIT_ASSERT( check( "\"\"" , output ) ); } void SRDPreprocCmdStringsTest::testConcatBadArgs( ) { T_SRDErrors errors; T_SRDList output( process( "( -concat ( nope ) [ 01 ] )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) ); M_CKERR_( 0 , "binary array, text or numeric argument expected" , 1 , 3 ); M_CKERR_( 1 , "previous error cause" , 1 , 11 ); CPPUNIT_ASSERT( check( "[ 01 ]" , output ) ); } void SRDPreprocCmdStringsTest::testConcatOneString( ) { T_SRDErrors errors; T_SRDList output( process( "( -concat \"string\" )" , errors ) ); CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) ); CPPUNIT_ASSERT( check( "\"string\"" , output ) ); } void SRDPreprocCmdStringsTest::testConcatStrings( ) { T_SRDErrors errors; T_SRDList output( process( "( -concat \"str\" \"ing\" )" , errors ) ); CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) ); CPPUNIT_ASSERT( check( "\"string\"" , output ) ); } void SRDPreprocCmdStringsTest::testConcatStringWord( ) { T_SRDErrors errors; T_SRDList output( process( "( -concat \"str\" ing )" , errors ) ); CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) ); CPPUNIT_ASSERT( check( "\"string\"" , output ) ); } void SRDPreprocCmdStringsTest::testConcatStringNumeric( ) { T_SRDErrors errors; T_SRDList output( process( "( -concat \"i\" 2 \"l\" ( -to-long 2 ) \"f\" 1.2 )" , errors ) ); CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) ); CPPUNIT_ASSERT( check( "\"i2l2f1.2\"" , output ) ); } void SRDPreprocCmdStringsTest::testConcatStringBinary( ) { T_SRDErrors errors; T_SRDList output( process( "( -concat \"string\"\n[ 01 ] )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) ); M_CKERR_( 0 , "text or numeric argument expected" , 1 , 3 ); M_CKERR_( 1 , "previous error cause" , 2 , 1 ); CPPUNIT_ASSERT( check( "\"string\"" , output ) ); } void SRDPreprocCmdStringsTest::testConcatOneBinary( ) { T_SRDErrors errors; T_SRDList output( process( "( -concat [ ] )" , errors ) ); CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) ); CPPUNIT_ASSERT( check( "[ ]" , output ) ); } void SRDPreprocCmdStringsTest::testConcatBinary( ) { T_SRDErrors errors; T_SRDList output( process( "( -concat [ 01 ] [] [ 02 ] )" , errors ) ); CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , errors.size( ) ); CPPUNIT_ASSERT( check( "[ 01 02 ]" , output ) ); } /*----------------------------------------------------------------------------*/ void SRDPreprocCmdStringsTest::testSubstrNotEnoughArgs( ) { T_SRDErrors errors; T_SRDList output( process( "( -substr )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) ); M_CKERR_( 0 , "not enough arguments" , 1 , 3 ); M_CKERR_( 1 , "previous error cause" , 1 , 11 ); CPPUNIT_ASSERT( check( "\"\"" , output ) ); } void SRDPreprocCmdStringsTest::testSubstrStringNotEnoughArgs( ) { T_SRDErrors errors; T_SRDList output( process( "( -substr \"abcdef\" )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) ); M_CKERR_( 0 , "not enough arguments" , 1 , 3 ); M_CKERR_( 1 , "previous error cause" , 1 , 20 ); CPPUNIT_ASSERT( check( "\"\"" , output ) ); } void SRDPreprocCmdStringsTest::testSubstrBinaryNotEnoughArgs( ) { T_SRDErrors errors; T_SRDList output( process( "( -substr [ 01 02 03 04 05 06 ] )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) ); M_CKERR_( 0 , "not enough arguments" , 1 , 3 ); M_CKERR_( 1 , "previous error cause" , 1 , 33 ); CPPUNIT_ASSERT( check( "[]" , output ) ); } void SRDPreprocCmdStringsTest::testSubstrStringTooManyArgs( ) { T_SRDErrors errors; T_SRDList output( process( "( -substr \"abcdef\" 1 to 2 blah )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) ); M_CKERR_( 0 , "too many arguments" , 1 , 3 ); M_CKERR_( 1 , "previous error cause" , 1 , 27 ); CPPUNIT_ASSERT( check( "\"bc\"" , output ) ); } void SRDPreprocCmdStringsTest::testSubstrBinaryTooManyArgs( ) { T_SRDErrors errors; T_SRDList output( process( "( -substr [ 01 02 03 04 05 06 ] 1 to 2 blah )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) ); M_CKERR_( 0 , "too many arguments" , 1 , 3 ); M_CKERR_( 1 , "previous error cause" , 1 , 40 ); CPPUNIT_ASSERT( check( "[]" , output ) ); } void SRDPreprocCmdStringsTest::testSubstrBadTooManyArgs( ) { T_SRDErrors errors; T_SRDList output( process( "( -substr -12 1 to 2 blah )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) ); M_CKERR_( 0 , "binary array or text argument expected" , 1 , 3 ); M_CKERR_( 1 , "previous error cause" , 1 , 11 ); CPPUNIT_ASSERT( check( "\"\"" , output ) ); } void SRDPreprocCmdStringsTest::testSubstrStringOffset( ) { T_SRDErrors errors; T_SRDList output( process( "( -substr \"abcdef\" 3 )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 0u , errors.size( ) ); CPPUNIT_ASSERT( check( "\"def\"" , output ) ); } void SRDPreprocCmdStringsTest::testSubstrBinaryOffset( ) { T_SRDErrors errors; T_SRDList output( process( "( -substr [ 01 02 03 04 05 06 ] 3 )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 0u , errors.size( ) ); CPPUNIT_ASSERT( check( "[ 04 05 06 ]" , output ) ); } void SRDPreprocCmdStringsTest::testSubstrBadOffset( ) { T_SRDErrors errors; T_SRDList output( process( "( -substr 12 3 )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) ); M_CKERR_( 0 , "binary array or text argument expected" , 1 , 3 ); M_CKERR_( 1 , "previous error cause" , 1 , 11 ); CPPUNIT_ASSERT( check( "\"\"" , output ) ); } void SRDPreprocCmdStringsTest::testSubstrStringBad( ) { T_SRDErrors errors; T_SRDList output( process( "( -substr \"\" \"\" )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) ); M_CKERR_( 0 , "integer argument expected" , 1 , 3 ); M_CKERR_( 1 , "previous error cause" , 1 , 14 ); CPPUNIT_ASSERT( check( "\"\"" , output ) ); } void SRDPreprocCmdStringsTest::testSubstrStringInvalid( ) { T_SRDErrors errors; T_SRDList output( process( "( -substr \"abcdef\" -1 )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) ); M_CKERR_( 0 , "invalid argument value" , 1 , 3 ); M_CKERR_( 1 , "previous error cause" , 1 , 20 ); CPPUNIT_ASSERT( check( "\"\"" , output ) ); } void SRDPreprocCmdStringsTest::testSubstrStringHigh( ) { T_SRDErrors errors; T_SRDList output( process( "( -substr \"abcdef\" 7 )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 0u , errors.size( ) ); CPPUNIT_ASSERT( check( "\"\"" , output ) ); } void SRDPreprocCmdStringsTest::testSubstrStringOffsetLength( ) { T_SRDErrors errors; T_SRDList output( process( "( -substr \"abcdef\" 2 3 )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 0u , errors.size( ) ); CPPUNIT_ASSERT( check( "\"cde\"" , output ) ); } void SRDPreprocCmdStringsTest::testSubstrBinaryOffsetLength( ) { T_SRDErrors errors; T_SRDList output( process( "( -substr [ 01 02 03 04 05 06 ] 2 3 )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 0u , errors.size( ) ); CPPUNIT_ASSERT( check( "[ 03 04 05 ]" , output ) ); } void SRDPreprocCmdStringsTest::testSubstrStringOffsetBad( ) { T_SRDErrors errors; T_SRDList output( process( "( -substr \"abcdef\" 2 nope )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) ); M_CKERR_( 0 , "'to' or integer argument expected" , 1 , 3 ); M_CKERR_( 1 , "previous error cause" , 1 , 22 ); CPPUNIT_ASSERT( check( "\"\"" , output ) ); } void SRDPreprocCmdStringsTest::testSubstrStringOffsetToOffset( ) { T_SRDErrors errors; T_SRDList output( process( "( -substr \"abcdef\" 2 to 3 )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 0u , errors.size( ) ); CPPUNIT_ASSERT( check( "\"cd\"" , output ) ); } void SRDPreprocCmdStringsTest::testSubstrBinaryOffsetToOffset( ) { T_SRDErrors errors; T_SRDList output( process( "( -substr [ 01 02 03 04 05 06 ] 2 to 3 )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 0u , errors.size( ) ); CPPUNIT_ASSERT( check( "[ 03 04 ]" , output ) ); } void SRDPreprocCmdStringsTest::testSubstrStringRangeInverted( ) { T_SRDErrors errors; T_SRDList output( process( "( -substr \"abcdef\" 3 to 2 )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 0u , errors.size( ) ); CPPUNIT_ASSERT( check( "\"\"" , output ) ); } void SRDPreprocCmdStringsTest::testSubstrBinaryRangeInverted( ) { T_SRDErrors errors; T_SRDList output( process( "( -substr [ 01 02 03 04 05 06 ] 3 to 2 )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 0u , errors.size( ) ); CPPUNIT_ASSERT( check( "[ ]" , output ) ); } void SRDPreprocCmdStringsTest::testSubstrStringOffsetBadOffset( ) { T_SRDErrors errors; T_SRDList output( process( "( -substr \"abcdef\" 2 ot 3 )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) ); M_CKERR_( 0 , "'to' or integer argument expected" , 1 , 3 ); M_CKERR_( 1 , "previous error cause" , 1 , 22 ); CPPUNIT_ASSERT( check( "\"\"" , output ) ); } void SRDPreprocCmdStringsTest::testSubstrStringOffsetToBad( ) { T_SRDErrors errors; T_SRDList output( process( "( -substr \"abcdef\" 2 to meh )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) ); M_CKERR_( 0 , "integer argument expected" , 1 , 3 ); M_CKERR_( 1 , "previous error cause" , 1 , 25 ); CPPUNIT_ASSERT( check( "\"\"" , output ) ); } void SRDPreprocCmdStringsTest::testSubstrRangeInvalidStart( ) { T_SRDErrors errors; T_SRDList output( process( "( -substr \"abcdef\" -2 to 12 )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) ); M_CKERR_( 0 , "invalid argument value" , 1 , 3 ); M_CKERR_( 1 , "previous error cause" , 1 , 20 ); CPPUNIT_ASSERT( check( "\"\"" , output ) ); } void SRDPreprocCmdStringsTest::testSubstrRangeInvalidEnd( ) { T_SRDErrors errors; T_SRDList output( process( "( -substr \"abcdef\" 2 to -2 )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) ); M_CKERR_( 0 , "invalid argument value" , 1 , 3 ); M_CKERR_( 1 , "previous error cause" , 1 , 25 ); CPPUNIT_ASSERT( check( "\"\"" , output ) ); } /*----------------------------------------------------------------------------*/ void SRDPreprocCmdStringsTest::testSplitNotEnoughArgs( ) { T_SRDErrors errors; T_SRDList output( process( "( -str-split \"x\" )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) ); M_CKERR_( 0 , "not enough arguments" , 1 , 3 ); M_CKERR_( 1 , "previous error cause" , 1 , 18 ); CPPUNIT_ASSERT( check( "\"\"" , output ) ); } void SRDPreprocCmdStringsTest::testSplitTooManyArgs( ) { T_SRDErrors errors; T_SRDList output( process( "( -str-split \"a\" \"b\" 12 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 , 25 ); CPPUNIT_ASSERT( check( "\"b\"" , output ) ); } void SRDPreprocCmdStringsTest::testSplitBadString( ) { T_SRDErrors errors; T_SRDList output( process( "( -str-split 12 \"x\" )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) ); M_CKERR_( 0 , "text argument expected" , 1 , 3 ); M_CKERR_( 1 , "previous error cause" , 1 , 14 ); CPPUNIT_ASSERT( check( "\"\"" , output ) ); } void SRDPreprocCmdStringsTest::testSplitStringBad( ) { T_SRDErrors errors; T_SRDList output( process( "( -str-split \"x\" 12 )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) ); M_CKERR_( 0 , "text argument expected" , 1 , 3 ); M_CKERR_( 1 , "previous error cause" , 1 , 18 ); CPPUNIT_ASSERT( check( "\"\"" , output ) ); } void SRDPreprocCmdStringsTest::testSplitStringEmpty( ) { T_SRDErrors errors; T_SRDList output( process( "( -str-split \"\" \"...\" )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) ); M_CKERR_( 0 , "invalid argument value" , 1 , 3 ); M_CKERR_( 1 , "previous error cause" , 1 , 14 ); CPPUNIT_ASSERT( check( "\"\"" , output ) ); } void SRDPreprocCmdStringsTest::testSplitStringStringBad( ) { T_SRDErrors errors; T_SRDList output( process( "( -str-split \"a\" \"...\" x )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) ); M_CKERR_( 0 , "integer argument or end of list expected" , 1 , 3 ); M_CKERR_( 1 , "previous error cause" , 1 , 24 ); CPPUNIT_ASSERT( check( "\"...\"" , output ) ); } void SRDPreprocCmdStringsTest::testSplitStringStringNegative( ) { T_SRDErrors errors; T_SRDList output( process( "( -str-split \"a\" \"bab\" -1 )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) ); M_CKERR_( 0 , "invalid argument value" , 1 , 3 ); M_CKERR_( 1 , "previous error cause" , 1 , 24 ); CPPUNIT_ASSERT( check( "\"b\" \"b\"" , output ) ); } void SRDPreprocCmdStringsTest::testSplitSingleNormal( ) { T_SRDErrors errors; T_SRDList output( process( "( -str-split \"a\" \"babaab\" )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 0u , errors.size( ) ); CPPUNIT_ASSERT( check( "\"b\" \"b\" \"\" \"b\"" , output ) ); } void SRDPreprocCmdStringsTest::testSplitSingleStart( ) { T_SRDErrors errors; T_SRDList output( process( "( -str-split \"a\" \"ab\" )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 0u , errors.size( ) ); CPPUNIT_ASSERT( check( "\"\" \"b\"" , output ) ); } void SRDPreprocCmdStringsTest::testSplitSingleEnd( ) { T_SRDErrors errors; T_SRDList output( process( "( -str-split \"a\" \"ba\" )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 0u , errors.size( ) ); CPPUNIT_ASSERT( check( "\"b\" \"\"" , output ) ); } void SRDPreprocCmdStringsTest::testSplitSingleNowhere( ) { T_SRDErrors errors; T_SRDList output( process( "( -str-split \"a\" \"nope\" )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 0u , errors.size( ) ); CPPUNIT_ASSERT( check( "\"nope\"" , output ) ); } void SRDPreprocCmdStringsTest::testSplitMultiNormal( ) { T_SRDErrors errors; T_SRDList output( process( "( -str-split \"aba\" \"babaxabaababa\" )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 0u , errors.size( ) ); CPPUNIT_ASSERT( check( "\"b\" \"x\" \"\" \"ba\"" , output ) ); } void SRDPreprocCmdStringsTest::testSplitMultiStart( ) { T_SRDErrors errors; T_SRDList output( process( "( -str-split \"aba\" \"abab\" )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 0u , errors.size( ) ); CPPUNIT_ASSERT( check( "\"\" \"b\"" , output ) ); } void SRDPreprocCmdStringsTest::testSplitMultiEnd( ) { T_SRDErrors errors; T_SRDList output( process( "( -str-split \"aba\" \"baba\" )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 0u , errors.size( ) ); CPPUNIT_ASSERT( check( "\"b\" \"\"" , output ) ); } void SRDPreprocCmdStringsTest::testSplitMultiNowhere( ) { T_SRDErrors errors; T_SRDList output( process( "( -str-split \"aba\" \"nope\" )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 0u , errors.size( ) ); CPPUNIT_ASSERT( check( "\"nope\"" , output ) ); } void SRDPreprocCmdStringsTest::testSplitMultiLonger( ) { T_SRDErrors errors; T_SRDList output( process( "( -str-split \"moomoo\" \"nope\" )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 0u , errors.size( ) ); CPPUNIT_ASSERT( check( "\"nope\"" , output ) ); } void SRDPreprocCmdStringsTest::testSplitLimitZero( ) { T_SRDErrors errors; T_SRDList output( process( "( -str-split \"x\" \"abababa\" 0 )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 0u , errors.size( ) ); CPPUNIT_ASSERT( check( "\"abababa\"" , output ) ); } void SRDPreprocCmdStringsTest::testSplitLimit( ) { T_SRDErrors errors; T_SRDList output( process( "( -str-split \"b\" \"abababa\" 2 )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 0u , errors.size( ) ); CPPUNIT_ASSERT( check( "\"a\" \"a\" \"aba\"" , output ) ); } void SRDPreprocCmdStringsTest::testSplitLimitGreater( ) { T_SRDErrors errors; T_SRDList output( process( "( -str-split \"b\" \"abababa\" 12 )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 0u , errors.size( ) ); CPPUNIT_ASSERT( check( "\"a\" \"a\" \"a\" \"a\"" , output ) ); } /*----------------------------------------------------------------------------*/ void SRDPreprocCmdStringsTest::testSWNotEnoughArgs( ) { T_SRDErrors errors; T_SRDList output( process( "( -starts-with \"x\" )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) ); M_CKERR_( 0 , "not enough arguments" , 1 , 3 ); M_CKERR_( 1 , "previous error cause" , 1 , 20 ); CPPUNIT_ASSERT( check( "0" , output ) ); } void SRDPreprocCmdStringsTest::testSWTooManyArgs( ) { T_SRDErrors errors; T_SRDList output( process( "( -starts-with x y z )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) ); M_CKERR_( 0 , "too many arguments" , 1 , 3 ); M_CKERR_( 1 , "previous error cause" , 1 , 20 ); CPPUNIT_ASSERT( check( "0" , output ) ); } void SRDPreprocCmdStringsTest::testSWStringYes( ) { T_SRDErrors errors; T_SRDList output( process( "( -starts-with \"abc\" \"abcdef\" )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 0u , errors.size( ) ); CPPUNIT_ASSERT( check( "1" , output ) ); } void SRDPreprocCmdStringsTest::testSWStringYesEqual( ) { T_SRDErrors errors; T_SRDList output( process( "( -starts-with \"abc\" \"abc\" )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 0u , errors.size( ) ); CPPUNIT_ASSERT( check( "1" , output ) ); } void SRDPreprocCmdStringsTest::testSWStringYesEmpty( ) { T_SRDErrors errors; T_SRDList output( process( "( -starts-with \"\" \"abc\" )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 0u , errors.size( ) ); CPPUNIT_ASSERT( check( "1" , output ) ); } void SRDPreprocCmdStringsTest::testSWStringNoShorter( ) { T_SRDErrors errors; T_SRDList output( process( "( -starts-with \"abc\" \"defg\" )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 0u , errors.size( ) ); CPPUNIT_ASSERT( check( "0" , output ) ); } void SRDPreprocCmdStringsTest::testSWStringNoLonger( ) { T_SRDErrors errors; T_SRDList output( process( "( -starts-with \"defg\" \"abc\" )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 0u , errors.size( ) ); CPPUNIT_ASSERT( check( "0" , output ) ); } void SRDPreprocCmdStringsTest::testSWBinaryYes( ) { T_SRDErrors errors; T_SRDList output( process( "( -starts-with [ 00 ] [ 00 01 02 ] )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 0u , errors.size( ) ); CPPUNIT_ASSERT( check( "1" , output ) ); } void SRDPreprocCmdStringsTest::testSWBinaryYesEqual( ) { T_SRDErrors errors; T_SRDList output( process( "( -starts-with [ 00 01 02 ] [ 00 01 02 ] )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 0u , errors.size( ) ); CPPUNIT_ASSERT( check( "1" , output ) ); } void SRDPreprocCmdStringsTest::testSWBinaryYesEmpty( ) { T_SRDErrors errors; T_SRDList output( process( "( -starts-with [ ] [ 00 01 02 ] )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 0u , errors.size( ) ); CPPUNIT_ASSERT( check( "1" , output ) ); } void SRDPreprocCmdStringsTest::testSWBinaryNoShorter( ) { T_SRDErrors errors; T_SRDList output( process( "( -starts-with [ 01 ] [ 00 01 02 ] )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 0u , errors.size( ) ); CPPUNIT_ASSERT( check( "0" , output ) ); } void SRDPreprocCmdStringsTest::testSWBinaryNoLonger( ) { T_SRDErrors errors; T_SRDList output( process( "( -starts-with [ 00 01 02 ] [ 00 ] )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 0u , errors.size( ) ); CPPUNIT_ASSERT( check( "0" , output ) ); } void SRDPreprocCmdStringsTest::testSWWordString( ) { T_SRDErrors errors; T_SRDList output( process( "( -starts-with abc \"abc d\" )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 0u , errors.size( ) ); CPPUNIT_ASSERT( check( "1" , output ) ); } void SRDPreprocCmdStringsTest::testSWStringWord( ) { T_SRDErrors errors; T_SRDList output( process( "( -starts-with \"abc\" abc-d )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 0u , errors.size( ) ); CPPUNIT_ASSERT( check( "1" , output ) ); } void SRDPreprocCmdStringsTest::testSWStringBad( ) { T_SRDErrors errors; T_SRDList output( process( "( -starts-with \"abc\" 12 )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) ); M_CKERR_( 0 , "text argument expected" , 1 , 3 ); M_CKERR_( 1 , "previous error cause" , 1 , 22 ); CPPUNIT_ASSERT( check( "0" , output ) ); } void SRDPreprocCmdStringsTest::testSWBadString( ) { T_SRDErrors errors; T_SRDList output( process( "( -starts-with 12 \"abc\" )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) ); M_CKERR_( 0 , "binary array or text argument expected" , 1 , 3 ); M_CKERR_( 1 , "previous error cause" , 1 , 16 ); CPPUNIT_ASSERT( check( "0" , output ) ); } /*----------------------------------------------------------------------------*/ void SRDPreprocCmdStringsTest::testEWNotEnoughArgs( ) { T_SRDErrors errors; T_SRDList output( process( "( -ends-with \"x\" )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) ); M_CKERR_( 0 , "not enough arguments" , 1 , 3 ); M_CKERR_( 1 , "previous error cause" , 1 , 18 ); CPPUNIT_ASSERT( check( "0" , output ) ); } void SRDPreprocCmdStringsTest::testEWTooManyArgs( ) { T_SRDErrors errors; T_SRDList output( process( "( -ends-with x y z )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) ); M_CKERR_( 0 , "too many arguments" , 1 , 3 ); M_CKERR_( 1 , "previous error cause" , 1 , 18 ); CPPUNIT_ASSERT( check( "0" , output ) ); } void SRDPreprocCmdStringsTest::testEWStringYes( ) { T_SRDErrors errors; T_SRDList output( process( "( -ends-with \"def\" \"abcdef\" )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 0u , errors.size( ) ); CPPUNIT_ASSERT( check( "1" , output ) ); } void SRDPreprocCmdStringsTest::testEWStringYesEqual( ) { T_SRDErrors errors; T_SRDList output( process( "( -ends-with \"abc\" \"abc\" )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 0u , errors.size( ) ); CPPUNIT_ASSERT( check( "1" , output ) ); } void SRDPreprocCmdStringsTest::testEWStringYesEmpty( ) { T_SRDErrors errors; T_SRDList output( process( "( -ends-with \"\" \"abc\" )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 0u , errors.size( ) ); CPPUNIT_ASSERT( check( "1" , output ) ); } void SRDPreprocCmdStringsTest::testEWStringNoShorter( ) { T_SRDErrors errors; T_SRDList output( process( "( -ends-with \"abc\" \"defg\" )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 0u , errors.size( ) ); CPPUNIT_ASSERT( check( "0" , output ) ); } void SRDPreprocCmdStringsTest::testEWStringNoLonger( ) { T_SRDErrors errors; T_SRDList output( process( "( -ends-with \"defg\" \"abc\" )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 0u , errors.size( ) ); CPPUNIT_ASSERT( check( "0" , output ) ); } void SRDPreprocCmdStringsTest::testEWBinaryYes( ) { T_SRDErrors errors; T_SRDList output( process( "( -ends-with [ 02 ] [ 00 01 02 ] )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 0u , errors.size( ) ); CPPUNIT_ASSERT( check( "1" , output ) ); } void SRDPreprocCmdStringsTest::testEWBinaryYesEqual( ) { T_SRDErrors errors; T_SRDList output( process( "( -ends-with [ 00 01 02 ] [ 00 01 02 ] )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 0u , errors.size( ) ); CPPUNIT_ASSERT( check( "1" , output ) ); } void SRDPreprocCmdStringsTest::testEWBinaryYesEmpty( ) { T_SRDErrors errors; T_SRDList output( process( "( -ends-with [ ] [ 00 01 02 ] )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 0u , errors.size( ) ); CPPUNIT_ASSERT( check( "1" , output ) ); } void SRDPreprocCmdStringsTest::testEWBinaryNoShorter( ) { T_SRDErrors errors; T_SRDList output( process( "( -ends-with [ 01 ] [ 00 01 02 ] )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 0u , errors.size( ) ); CPPUNIT_ASSERT( check( "0" , output ) ); } void SRDPreprocCmdStringsTest::testEWBinaryNoLonger( ) { T_SRDErrors errors; T_SRDList output( process( "( -ends-with [ 00 01 02 ] [ 00 ] )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 0u , errors.size( ) ); CPPUNIT_ASSERT( check( "0" , output ) ); } void SRDPreprocCmdStringsTest::testEWWordString( ) { T_SRDErrors errors; T_SRDList output( process( "( -ends-with d \"abc d\" )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 0u , errors.size( ) ); CPPUNIT_ASSERT( check( "1" , output ) ); } void SRDPreprocCmdStringsTest::testEWStringWord( ) { T_SRDErrors errors; T_SRDList output( process( "( -ends-with \"c-d\" abc-d )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 0u , errors.size( ) ); CPPUNIT_ASSERT( check( "1" , output ) ); } void SRDPreprocCmdStringsTest::testEWStringBad( ) { T_SRDErrors errors; T_SRDList output( process( "( -ends-with \"abc\" 12 )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) ); M_CKERR_( 0 , "text argument expected" , 1 , 3 ); M_CKERR_( 1 , "previous error cause" , 1 , 20 ); CPPUNIT_ASSERT( check( "0" , output ) ); } void SRDPreprocCmdStringsTest::testEWBadString( ) { T_SRDErrors errors; T_SRDList output( process( "( -ends-with 12 \"abc\" )" , errors ) ); CPPUNIT_ASSERT_EQUAL( 2u , errors.size( ) ); M_CKERR_( 0 , "binary array or text argument expected" , 1 , 3 ); M_CKERR_( 1 , "previous error cause" , 1 , 14 ); CPPUNIT_ASSERT( check( "0" , output ) ); }