1185 lines
31 KiB
C++
1185 lines
31 KiB
C++
|
#include <lw/lib/Strings.hh>
|
||
|
#include <cppunit/extensions/HelperMacros.h>
|
||
|
using namespace lw;
|
||
|
|
||
|
|
||
|
class StringsTest : public CppUnit::TestFixture
|
||
|
{
|
||
|
CPPUNIT_TEST_SUITE( StringsTest );
|
||
|
CPPUNIT_TEST( testEmpty );
|
||
|
CPPUNIT_TEST( testValidASCII );
|
||
|
CPPUNIT_TEST( testValidUTF8 );
|
||
|
CPPUNIT_TEST( testInvalid );
|
||
|
|
||
|
CPPUNIT_TEST( testCopyCons );
|
||
|
CPPUNIT_TEST( testCopyAss );
|
||
|
CPPUNIT_TEST( testMoveCons );
|
||
|
CPPUNIT_TEST( testMoveAss );
|
||
|
CPPUNIT_TEST( testSwap );
|
||
|
|
||
|
CPPUNIT_TEST( testCharAccess );
|
||
|
|
||
|
CPPUNIT_TEST( testEquals );
|
||
|
CPPUNIT_TEST( testEqualsEmpty );
|
||
|
CPPUNIT_TEST( testEqualsCString );
|
||
|
|
||
|
CPPUNIT_TEST( testCompareEmpty );
|
||
|
CPPUNIT_TEST( testCompareSame );
|
||
|
CPPUNIT_TEST( testCompareShorter );
|
||
|
CPPUNIT_TEST( testCompareLonger );
|
||
|
CPPUNIT_TEST( testCompareInf );
|
||
|
CPPUNIT_TEST( testCompareSup );
|
||
|
CPPUNIT_TEST( testCompareInvalid );
|
||
|
|
||
|
CPPUNIT_TEST( testCompareICEmpty );
|
||
|
CPPUNIT_TEST( testCompareICSame );
|
||
|
CPPUNIT_TEST( testCompareICShorter );
|
||
|
CPPUNIT_TEST( testCompareICLonger );
|
||
|
CPPUNIT_TEST( testCompareICInf );
|
||
|
CPPUNIT_TEST( testCompareICSup );
|
||
|
CPPUNIT_TEST( testCompareICInvalid );
|
||
|
|
||
|
CPPUNIT_TEST( testStartsWithEmpty );
|
||
|
CPPUNIT_TEST( testStartsWithLonger );
|
||
|
CPPUNIT_TEST( testStartsWithYes );
|
||
|
CPPUNIT_TEST( testStartsWithNope );
|
||
|
CPPUNIT_TEST( testStartsWithInvalid );
|
||
|
|
||
|
CPPUNIT_TEST( testEndsWithEmpty );
|
||
|
CPPUNIT_TEST( testEndsWithLonger );
|
||
|
CPPUNIT_TEST( testEndsWithYes );
|
||
|
CPPUNIT_TEST( testEndsWithNope );
|
||
|
CPPUNIT_TEST( testEndsWithInvalid );
|
||
|
|
||
|
CPPUNIT_TEST( testCmpOpEq );
|
||
|
CPPUNIT_TEST( testCmpOpNe );
|
||
|
CPPUNIT_TEST( testCmpOpLt );
|
||
|
CPPUNIT_TEST( testCmpOpLe );
|
||
|
CPPUNIT_TEST( testCmpOpGt );
|
||
|
CPPUNIT_TEST( testCmpOpGe );
|
||
|
CPPUNIT_TEST( testCmpOpEqCString );
|
||
|
CPPUNIT_TEST( testCmpOpNeCString );
|
||
|
|
||
|
CPPUNIT_TEST( testFindEmpty );
|
||
|
CPPUNIT_TEST( testFindLonger );
|
||
|
CPPUNIT_TEST( testFindYes );
|
||
|
CPPUNIT_TEST( testFindNope );
|
||
|
CPPUNIT_TEST( testFindInvalidStrings );
|
||
|
CPPUNIT_TEST( testFindOffsetEmpty );
|
||
|
CPPUNIT_TEST( testFindOffsetLonger );
|
||
|
CPPUNIT_TEST( testFindOffsetBad );
|
||
|
CPPUNIT_TEST( testFindOffsetYes );
|
||
|
CPPUNIT_TEST( testFindOffsetNo );
|
||
|
|
||
|
CPPUNIT_TEST( testFindCharEmpty );
|
||
|
CPPUNIT_TEST( testFindCharYes );
|
||
|
CPPUNIT_TEST( testFindCharNo );
|
||
|
CPPUNIT_TEST( testFindCharInvalidString );
|
||
|
CPPUNIT_TEST( testFindCharInvalidChar );
|
||
|
CPPUNIT_TEST( testFindCharOffsetBad );
|
||
|
CPPUNIT_TEST( testFindCharOffsetYes );
|
||
|
CPPUNIT_TEST( testFindCharOffsetNo );
|
||
|
|
||
|
CPPUNIT_TEST( testToUnsignedBasic );
|
||
|
CPPUNIT_TEST( testToUnsignedOkValue );
|
||
|
CPPUNIT_TEST( testToUnsignedInvalid );
|
||
|
CPPUNIT_TEST( testToUnsignedTooLarge );
|
||
|
CPPUNIT_TEST( testToUnsignedBaseOk );
|
||
|
CPPUNIT_TEST( testToUnsignedBaseInvalid );
|
||
|
CPPUNIT_TEST( testToUnsignedBaseAutoBinary );
|
||
|
CPPUNIT_TEST( testToUnsignedBaseAutoOctal );
|
||
|
CPPUNIT_TEST( testToUnsignedBaseAutoDecimal );
|
||
|
CPPUNIT_TEST( testToUnsignedBaseAutoHexa );
|
||
|
CPPUNIT_TEST( testToUnsignedBaseAutoZero );
|
||
|
CPPUNIT_TEST( testToUnsignedBaseAutoInvalid );
|
||
|
CPPUNIT_TEST( testToUnsignedBaseAutoCut );
|
||
|
CPPUNIT_TEST( testToUnsignedSeparator );
|
||
|
CPPUNIT_TEST( testToUnsignedSeparatorCustom );
|
||
|
CPPUNIT_TEST( testToUnsignedSeparatorCustomUTF8 );
|
||
|
CPPUNIT_TEST( testToUnsignedLeadingWhitespace );
|
||
|
CPPUNIT_TEST( testToUnsignedLeadingWhitespaceOnly );
|
||
|
|
||
|
CPPUNIT_TEST( testToSignedBasic );
|
||
|
CPPUNIT_TEST( testToSignedOkValue );
|
||
|
CPPUNIT_TEST( testToSignedPlus );
|
||
|
CPPUNIT_TEST( testToSignedPlusMultiple );
|
||
|
CPPUNIT_TEST( testToSignedMinus );
|
||
|
CPPUNIT_TEST( testToSignedMinusMultiple );
|
||
|
CPPUNIT_TEST( testToSignedInvalid );
|
||
|
CPPUNIT_TEST( testToSignedTooLarge );
|
||
|
CPPUNIT_TEST( testToSignedTooSmall );
|
||
|
CPPUNIT_TEST( testToSignedBaseOk );
|
||
|
CPPUNIT_TEST( testToSignedBaseInvalid );
|
||
|
CPPUNIT_TEST( testToSignedBaseAutoBinary );
|
||
|
CPPUNIT_TEST( testToSignedBaseAutoOctal );
|
||
|
CPPUNIT_TEST( testToSignedBaseAutoDecimal );
|
||
|
CPPUNIT_TEST( testToSignedBaseAutoHexa );
|
||
|
CPPUNIT_TEST( testToSignedBaseAutoZero );
|
||
|
CPPUNIT_TEST( testToSignedBaseAutoInvalid );
|
||
|
CPPUNIT_TEST( testToSignedBaseAutoCut );
|
||
|
CPPUNIT_TEST( testToSignedBaseAutoPlus );
|
||
|
CPPUNIT_TEST( testToSignedBaseAutoMinus );
|
||
|
CPPUNIT_TEST( testToSignedSeparator );
|
||
|
CPPUNIT_TEST( testToSignedSeparatorCustom );
|
||
|
CPPUNIT_TEST( testToSignedSeparatorCustomUTF8 );
|
||
|
CPPUNIT_TEST( testToSignedLeadingWhitespace );
|
||
|
CPPUNIT_TEST( testToSignedLeadingWhitespaceOnly );
|
||
|
|
||
|
CPPUNIT_TEST( testToDouble );
|
||
|
CPPUNIT_TEST_SUITE_END( );
|
||
|
|
||
|
public:
|
||
|
void testEmpty( );
|
||
|
void testValidASCII( );
|
||
|
void testValidUTF8( );
|
||
|
void testInvalid( );
|
||
|
|
||
|
void testCopyCons( );
|
||
|
void testCopyAss( );
|
||
|
void testMoveCons( );
|
||
|
void testMoveAss( );
|
||
|
void testSwap( );
|
||
|
|
||
|
void testCharAccess( );
|
||
|
|
||
|
void testEquals( );
|
||
|
void testEqualsEmpty( );
|
||
|
void testEqualsCString( );
|
||
|
|
||
|
void testCompareEmpty( );
|
||
|
void testCompareSame( );
|
||
|
void testCompareShorter( );
|
||
|
void testCompareLonger( );
|
||
|
void testCompareInf( );
|
||
|
void testCompareSup( );
|
||
|
void testCompareInvalid( );
|
||
|
|
||
|
void testCompareICEmpty( );
|
||
|
void testCompareICSame( );
|
||
|
void testCompareICShorter( );
|
||
|
void testCompareICLonger( );
|
||
|
void testCompareICInf( );
|
||
|
void testCompareICSup( );
|
||
|
void testCompareICInvalid( );
|
||
|
|
||
|
void testStartsWithEmpty( );
|
||
|
void testStartsWithLonger( );
|
||
|
void testStartsWithYes( );
|
||
|
void testStartsWithNope( );
|
||
|
void testStartsWithInvalid( );
|
||
|
|
||
|
void testEndsWithEmpty( );
|
||
|
void testEndsWithLonger( );
|
||
|
void testEndsWithYes( );
|
||
|
void testEndsWithNope( );
|
||
|
void testEndsWithInvalid( );
|
||
|
|
||
|
void testCmpOpEq( );
|
||
|
void testCmpOpNe( );
|
||
|
void testCmpOpLt( );
|
||
|
void testCmpOpLe( );
|
||
|
void testCmpOpGt( );
|
||
|
void testCmpOpGe( );
|
||
|
void testCmpOpEqCString( );
|
||
|
void testCmpOpNeCString( );
|
||
|
|
||
|
void testFindEmpty( );
|
||
|
void testFindLonger( );
|
||
|
void testFindYes( );
|
||
|
void testFindNope( );
|
||
|
void testFindInvalidStrings( );
|
||
|
void testFindOffsetEmpty( );
|
||
|
void testFindOffsetLonger( );
|
||
|
void testFindOffsetBad( );
|
||
|
void testFindOffsetYes( );
|
||
|
void testFindOffsetNo( );
|
||
|
|
||
|
void testFindCharEmpty( );
|
||
|
void testFindCharYes( );
|
||
|
void testFindCharNo( );
|
||
|
void testFindCharInvalidString( );
|
||
|
void testFindCharInvalidChar( );
|
||
|
void testFindCharOffsetBad( );
|
||
|
void testFindCharOffsetYes( );
|
||
|
void testFindCharOffsetNo( );
|
||
|
|
||
|
void testToUnsignedBasic( );
|
||
|
void testToUnsignedOkValue( );
|
||
|
void testToUnsignedInvalid( );
|
||
|
void testToUnsignedTooLarge( );
|
||
|
void testToUnsignedBaseOk( );
|
||
|
void testToUnsignedBaseInvalid( );
|
||
|
void testToUnsignedBaseAutoBinary( );
|
||
|
void testToUnsignedBaseAutoOctal( );
|
||
|
void testToUnsignedBaseAutoDecimal( );
|
||
|
void testToUnsignedBaseAutoHexa( );
|
||
|
void testToUnsignedBaseAutoZero( );
|
||
|
void testToUnsignedBaseAutoInvalid( );
|
||
|
void testToUnsignedBaseAutoCut( );
|
||
|
void testToUnsignedSeparator( );
|
||
|
void testToUnsignedSeparatorCustom( );
|
||
|
void testToUnsignedSeparatorCustomUTF8( );
|
||
|
void testToUnsignedLeadingWhitespace( );
|
||
|
void testToUnsignedLeadingWhitespaceOnly( );
|
||
|
|
||
|
void testToSignedBasic( );
|
||
|
void testToSignedOkValue( );
|
||
|
void testToSignedPlus( );
|
||
|
void testToSignedPlusMultiple( );
|
||
|
void testToSignedMinus( );
|
||
|
void testToSignedMinusMultiple( );
|
||
|
void testToSignedInvalid( );
|
||
|
void testToSignedTooLarge( );
|
||
|
void testToSignedTooSmall( );
|
||
|
void testToSignedBaseOk( );
|
||
|
void testToSignedBaseInvalid( );
|
||
|
void testToSignedBaseAutoBinary( );
|
||
|
void testToSignedBaseAutoOctal( );
|
||
|
void testToSignedBaseAutoDecimal( );
|
||
|
void testToSignedBaseAutoHexa( );
|
||
|
void testToSignedBaseAutoZero( );
|
||
|
void testToSignedBaseAutoInvalid( );
|
||
|
void testToSignedBaseAutoCut( );
|
||
|
void testToSignedBaseAutoPlus( );
|
||
|
void testToSignedBaseAutoMinus( );
|
||
|
void testToSignedSeparator( );
|
||
|
void testToSignedSeparatorCustom( );
|
||
|
void testToSignedSeparatorCustomUTF8( );
|
||
|
void testToSignedLeadingWhitespace( );
|
||
|
void testToSignedLeadingWhitespaceOnly( );
|
||
|
|
||
|
void testToDouble( );
|
||
|
};
|
||
|
CPPUNIT_TEST_SUITE_REGISTRATION( StringsTest );
|
||
|
|
||
|
/*----------------------------------------------------------------------------*/
|
||
|
|
||
|
void StringsTest::testEmpty( )
|
||
|
{
|
||
|
T_String empty;
|
||
|
CPPUNIT_ASSERT( empty.valid( ) );
|
||
|
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , empty.size( ) );
|
||
|
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , empty.length( ) );
|
||
|
CPPUNIT_ASSERT( empty.data( ) == nullptr );
|
||
|
CPPUNIT_ASSERT( !bool( empty ) );
|
||
|
CPPUNIT_ASSERT( !empty );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testValidASCII( )
|
||
|
{
|
||
|
char const* const s = "le saut ASCII";
|
||
|
const uint32_t sl( strlen( s ) );
|
||
|
T_String ascii( s );
|
||
|
CPPUNIT_ASSERT( ascii.valid( ) );
|
||
|
CPPUNIT_ASSERT_EQUAL( sl , ascii.size( ) );
|
||
|
CPPUNIT_ASSERT_EQUAL( sl , ascii.length( ) );
|
||
|
CPPUNIT_ASSERT( ascii.data( ) != nullptr );
|
||
|
CPPUNIT_ASSERT( !memcmp( ascii.data( ) , s , sl ) );
|
||
|
CPPUNIT_ASSERT( bool( ascii ) );
|
||
|
CPPUNIT_ASSERT( !!ascii );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testValidUTF8( )
|
||
|
{
|
||
|
char const* const s = "euro sign: \xe2\x82\xac";
|
||
|
const uint32_t ss( strlen( s ) );
|
||
|
const uint32_t sl( ss - 2 );
|
||
|
T_String utf8( s );
|
||
|
CPPUNIT_ASSERT( utf8.valid( ) );
|
||
|
CPPUNIT_ASSERT_EQUAL( ss , utf8.size( ) );
|
||
|
CPPUNIT_ASSERT_EQUAL( sl , utf8.length( ) );
|
||
|
CPPUNIT_ASSERT( utf8.data( ) != nullptr );
|
||
|
CPPUNIT_ASSERT( !memcmp( utf8.data( ) , s , ss ) );
|
||
|
CPPUNIT_ASSERT( bool( utf8 ) );
|
||
|
CPPUNIT_ASSERT( !!utf8 );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testInvalid( )
|
||
|
{
|
||
|
char const* const s = "much \x80 fail";
|
||
|
const uint32_t ss( strlen( s ) );
|
||
|
T_String bad( s );
|
||
|
CPPUNIT_ASSERT( !bad.valid( ) );
|
||
|
CPPUNIT_ASSERT_EQUAL( ss , bad.size( ) );
|
||
|
CPPUNIT_ASSERT_EQUAL( ss , bad.length( ) );
|
||
|
CPPUNIT_ASSERT( bad.data( ) != nullptr );
|
||
|
CPPUNIT_ASSERT( !memcmp( bad.data( ) , s , ss ) );
|
||
|
CPPUNIT_ASSERT( bool( bad ) );
|
||
|
CPPUNIT_ASSERT( !!bad );
|
||
|
}
|
||
|
|
||
|
/*----------------------------------------------------------------------------*/
|
||
|
|
||
|
void StringsTest::testCopyCons( )
|
||
|
{
|
||
|
char const* const s = "wargl gargl";
|
||
|
const uint32_t sl( strlen( s ) );
|
||
|
T_String s1( s );
|
||
|
T_String s2( s1 );
|
||
|
CPPUNIT_ASSERT( s1 );
|
||
|
CPPUNIT_ASSERT( s2 );
|
||
|
CPPUNIT_ASSERT( s2.data( ) != nullptr );
|
||
|
CPPUNIT_ASSERT_EQUAL( sl , s2.size( ) );
|
||
|
CPPUNIT_ASSERT( !memcmp( s1.data( ) , s2.data( ) , sl ) );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testCopyAss( )
|
||
|
{
|
||
|
char const* const s = "wargl gargl";
|
||
|
const uint32_t sl( strlen( s ) );
|
||
|
T_String s1( s );
|
||
|
T_String s2;
|
||
|
s2 = s1;
|
||
|
CPPUNIT_ASSERT( s1 );
|
||
|
CPPUNIT_ASSERT( s2 );
|
||
|
CPPUNIT_ASSERT( s2.data( ) != nullptr );
|
||
|
CPPUNIT_ASSERT_EQUAL( sl , s2.size( ) );
|
||
|
CPPUNIT_ASSERT( !memcmp( s , s2.data( ) , sl ) );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testMoveCons( )
|
||
|
{
|
||
|
char const* const s = "wargl gargl";
|
||
|
const uint32_t sl( strlen( s ) );
|
||
|
T_String s1( s );
|
||
|
T_String s2( std::move( s1 ) );
|
||
|
CPPUNIT_ASSERT( !s1 );
|
||
|
CPPUNIT_ASSERT( s2 );
|
||
|
CPPUNIT_ASSERT( s2.data( ) != nullptr );
|
||
|
CPPUNIT_ASSERT_EQUAL( sl , s2.size( ) );
|
||
|
CPPUNIT_ASSERT( !memcmp( s , s2.data( ) , sl ) );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testMoveAss( )
|
||
|
{
|
||
|
char const* const s = "wargl gargl";
|
||
|
const uint32_t sl( strlen( s ) );
|
||
|
T_String s1( s );
|
||
|
T_String s2( "woot" );
|
||
|
s2 = std::move( s1 );
|
||
|
CPPUNIT_ASSERT( !s1 );
|
||
|
CPPUNIT_ASSERT( s2 );
|
||
|
CPPUNIT_ASSERT( s2.data( ) != nullptr );
|
||
|
CPPUNIT_ASSERT_EQUAL( sl , s2.size( ) );
|
||
|
CPPUNIT_ASSERT( !memcmp( s , s2.data( ) , sl ) );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testSwap( )
|
||
|
{
|
||
|
char const* const str1 = "wargl gargl";
|
||
|
const uint32_t sl1( strlen( str1 ) );
|
||
|
char const* const str2 = "bite my shiny metal ass";
|
||
|
const uint32_t sl2( strlen( str2 ) );
|
||
|
|
||
|
T_String s1( str1 );
|
||
|
T_String s2( str2 );
|
||
|
swap( s1 , s2 );
|
||
|
|
||
|
CPPUNIT_ASSERT( s1 );
|
||
|
CPPUNIT_ASSERT( s1.data( ) != nullptr );
|
||
|
CPPUNIT_ASSERT_EQUAL( sl2 , s1.size( ) );
|
||
|
CPPUNIT_ASSERT( !memcmp( str2 , s1.data( ) , sl2 ) );
|
||
|
|
||
|
CPPUNIT_ASSERT( s2 );
|
||
|
CPPUNIT_ASSERT( s2.data( ) != nullptr );
|
||
|
CPPUNIT_ASSERT_EQUAL( sl1 , s2.size( ) );
|
||
|
CPPUNIT_ASSERT( !memcmp( str1 , s2.data( ) , sl1 ) );
|
||
|
}
|
||
|
|
||
|
/*----------------------------------------------------------------------------*/
|
||
|
|
||
|
void StringsTest::testCharAccess( )
|
||
|
{
|
||
|
char const* const s = "a\xe2\x82\xac\nb\0c";
|
||
|
const T_Character chars[] = {
|
||
|
'a' , 0x20ac , '\n' , 'b' , 0 , 'c'
|
||
|
};
|
||
|
|
||
|
T_String test( s , 8 );
|
||
|
CPPUNIT_ASSERT_EQUAL( uint32_t( 8 ) , test.size( ) );
|
||
|
CPPUNIT_ASSERT_EQUAL( uint32_t( 6 ) , test.length( ) );
|
||
|
CPPUNIT_ASSERT_EQUAL( chars[ 0 ] , test[ 0 ] );
|
||
|
CPPUNIT_ASSERT_EQUAL( chars[ 1 ] , test[ 1 ] );
|
||
|
CPPUNIT_ASSERT_EQUAL( chars[ 2 ] , test[ 2 ] );
|
||
|
CPPUNIT_ASSERT_EQUAL( chars[ 3 ] , test[ 3 ] );
|
||
|
CPPUNIT_ASSERT_EQUAL( chars[ 4 ] , test[ 4 ] );
|
||
|
CPPUNIT_ASSERT_EQUAL( chars[ 5 ] , test[ 5 ] );
|
||
|
}
|
||
|
|
||
|
/*----------------------------------------------------------------------------*/
|
||
|
|
||
|
void StringsTest::testEquals( )
|
||
|
{
|
||
|
T_String s1( "wargl" ) , s2( "wargl" ) , s3( "gargl" );
|
||
|
CPPUNIT_ASSERT( s1.equals( s1 ) );
|
||
|
CPPUNIT_ASSERT( s1.equals( s2 ) );
|
||
|
CPPUNIT_ASSERT( !s1.equals( s3 ) );
|
||
|
CPPUNIT_ASSERT( s2.equals( s2 ) );
|
||
|
CPPUNIT_ASSERT( s2.equals( s1 ) );
|
||
|
CPPUNIT_ASSERT( !s2.equals( s3 ) );
|
||
|
CPPUNIT_ASSERT( s3.equals( s3 ) );
|
||
|
CPPUNIT_ASSERT( !s3.equals( s1 ) );
|
||
|
CPPUNIT_ASSERT( !s3.equals( s2 ) );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testEqualsEmpty( )
|
||
|
{
|
||
|
T_String s1 , s2 , s3( "gargl" );
|
||
|
CPPUNIT_ASSERT( s1.equals( s1 ) );
|
||
|
CPPUNIT_ASSERT( s1.equals( s2 ) );
|
||
|
CPPUNIT_ASSERT( !s1.equals( s3 ) );
|
||
|
CPPUNIT_ASSERT( s2.equals( s2 ) );
|
||
|
CPPUNIT_ASSERT( s2.equals( s1 ) );
|
||
|
CPPUNIT_ASSERT( !s2.equals( s3 ) );
|
||
|
CPPUNIT_ASSERT( s3.equals( s3 ) );
|
||
|
CPPUNIT_ASSERT( !s3.equals( s1 ) );
|
||
|
CPPUNIT_ASSERT( !s3.equals( s2 ) );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testEqualsCString( )
|
||
|
{
|
||
|
T_String s1( "wargl" ) , s2;
|
||
|
CPPUNIT_ASSERT( s1.equals( "wargl" ) );
|
||
|
CPPUNIT_ASSERT( !s1.equals( "gargl" ) );
|
||
|
CPPUNIT_ASSERT( s2.equals( "" ) );
|
||
|
CPPUNIT_ASSERT( !s2.equals( "wargl" ) );
|
||
|
}
|
||
|
|
||
|
/*----------------------------------------------------------------------------*/
|
||
|
|
||
|
void StringsTest::testCompareEmpty( )
|
||
|
{
|
||
|
T_String s1 , s2 , s3( "wargl" );
|
||
|
CPPUNIT_ASSERT_EQUAL( int32_t( 0 ) , s1.compare( s2 ) );
|
||
|
CPPUNIT_ASSERT( s1.compare( s3 ) != 0 );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testCompareSame( )
|
||
|
{
|
||
|
T_String s1( "wargl" ) , s2( "wargl" );
|
||
|
CPPUNIT_ASSERT_EQUAL( int32_t( 0 ) , s1.compare( s2 ) );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testCompareShorter( )
|
||
|
{
|
||
|
T_String s1( "wargl gargl" ) , s2( "wargl" );
|
||
|
CPPUNIT_ASSERT_EQUAL( int32_t( 1 ) , s1.compare( s2 ) );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testCompareLonger( )
|
||
|
{
|
||
|
T_String s1( "wargl" ) , s2( "wargl gargl" );
|
||
|
CPPUNIT_ASSERT_EQUAL( int32_t( -1 ) , s1.compare( s2 ) );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testCompareInf( )
|
||
|
{
|
||
|
T_String s1( "wargl" ) , s2( "gargl" );
|
||
|
CPPUNIT_ASSERT_EQUAL( int32_t( 1 ) , s1.compare( s2 ) );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testCompareSup( )
|
||
|
{
|
||
|
T_String s1( "gargl" ) , s2( "wargl" );
|
||
|
CPPUNIT_ASSERT_EQUAL( int32_t( -1 ) , s1.compare( s2 ) );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testCompareInvalid( )
|
||
|
{
|
||
|
T_String s1( "gargl\x80" ) , s2( "wargl\x80" );
|
||
|
CPPUNIT_ASSERT_EQUAL( int32_t( 0 ) , s1.compare( s2 ) );
|
||
|
}
|
||
|
|
||
|
/*----------------------------------------------------------------------------*/
|
||
|
|
||
|
void StringsTest::testCompareICEmpty( )
|
||
|
{
|
||
|
T_String s1 , s2 , s3( "wargl" );
|
||
|
CPPUNIT_ASSERT_EQUAL( int32_t( 0 ) , s1.compareIgnoreCase( s2 ) );
|
||
|
CPPUNIT_ASSERT( s1.compareIgnoreCase( s3 ) != 0 );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testCompareICSame( )
|
||
|
{
|
||
|
T_String s1( "wArgl" ) , s2( "waRgl" );
|
||
|
CPPUNIT_ASSERT_EQUAL( int32_t( 0 ) , s1.compareIgnoreCase( s2 ) );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testCompareICShorter( )
|
||
|
{
|
||
|
T_String s1( "waRgl gargl" ) , s2( "wargl" );
|
||
|
CPPUNIT_ASSERT_EQUAL( int32_t( 1 ) , s1.compareIgnoreCase( s2 ) );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testCompareICLonger( )
|
||
|
{
|
||
|
T_String s1( "wargl" ) , s2( "WArgl gargl" );
|
||
|
CPPUNIT_ASSERT_EQUAL( int32_t( -1 ) , s1.compareIgnoreCase( s2 ) );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testCompareICInf( )
|
||
|
{
|
||
|
T_String s1( "wArgl" ) , s2( "wargh" );
|
||
|
CPPUNIT_ASSERT_EQUAL( int32_t( 1 ) , s1.compareIgnoreCase( s2 ) );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testCompareICSup( )
|
||
|
{
|
||
|
T_String s1( "wargh" ) , s2( "wArgl" );
|
||
|
CPPUNIT_ASSERT_EQUAL( int32_t( -1 ) , s1.compareIgnoreCase( s2 ) );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testCompareICInvalid( )
|
||
|
{
|
||
|
T_String s1( "gargl\x80" ) , s2( "wargl\x80" );
|
||
|
CPPUNIT_ASSERT_EQUAL( int32_t( 0 ) , s1.compareIgnoreCase( s2 ) );
|
||
|
}
|
||
|
|
||
|
/*----------------------------------------------------------------------------*/
|
||
|
|
||
|
void StringsTest::testStartsWithEmpty( )
|
||
|
{
|
||
|
T_String str( "wargl gargl" );
|
||
|
CPPUNIT_ASSERT( str.startsWith( T_String( ) ) );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testStartsWithLonger( )
|
||
|
{
|
||
|
T_String str( "wargl" );
|
||
|
CPPUNIT_ASSERT( !str.startsWith( T_String( "wargl gargl" ) ) );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testStartsWithYes( )
|
||
|
{
|
||
|
T_String str( "wargl gargl" );
|
||
|
CPPUNIT_ASSERT( str.startsWith( T_String( "wargl" ) ) );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testStartsWithNope( )
|
||
|
{
|
||
|
T_String str( "wargl gargl" );
|
||
|
CPPUNIT_ASSERT( !str.startsWith( T_String( "gargl" ) ) );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testStartsWithInvalid( )
|
||
|
{
|
||
|
T_String str( "\x80 wargl" );
|
||
|
CPPUNIT_ASSERT( !str.startsWith( T_String( "\x80" ) ) );
|
||
|
}
|
||
|
|
||
|
/*----------------------------------------------------------------------------*/
|
||
|
|
||
|
void StringsTest::testEndsWithEmpty( )
|
||
|
{
|
||
|
T_String str( "wargl gargl" );
|
||
|
CPPUNIT_ASSERT( str.endsWith( T_String( ) ) );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testEndsWithLonger( )
|
||
|
{
|
||
|
T_String str( "wargl" );
|
||
|
CPPUNIT_ASSERT( !str.endsWith( T_String( "wargl gargl" ) ) );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testEndsWithYes( )
|
||
|
{
|
||
|
T_String str( "wargl gargl" );
|
||
|
CPPUNIT_ASSERT( str.endsWith( T_String( "gargl" ) ) );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testEndsWithNope( )
|
||
|
{
|
||
|
T_String str( "wargl gargl" );
|
||
|
CPPUNIT_ASSERT( !str.endsWith( T_String( "wargl" ) ) );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testEndsWithInvalid( )
|
||
|
{
|
||
|
T_String str( "wargl \x80" );
|
||
|
CPPUNIT_ASSERT( !str.endsWith( T_String( "\x80" ) ) );
|
||
|
}
|
||
|
|
||
|
/*----------------------------------------------------------------------------*/
|
||
|
|
||
|
void StringsTest::testCmpOpEq( )
|
||
|
{
|
||
|
T_String s1( "wargl" ) , s2( "wargl" ) , s3( "gargl" );
|
||
|
CPPUNIT_ASSERT( s1 == s2 );
|
||
|
CPPUNIT_ASSERT( s2 == s1 );
|
||
|
CPPUNIT_ASSERT( !( s1 == s3 ) );
|
||
|
CPPUNIT_ASSERT( !( s3 == s1 ) );
|
||
|
CPPUNIT_ASSERT( !( s2 == s3 ) );
|
||
|
CPPUNIT_ASSERT( !( s3 == s2 ) );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testCmpOpNe( )
|
||
|
{
|
||
|
T_String s1( "wargl" ) , s2( "wargl" ) , s3( "gargl" );
|
||
|
CPPUNIT_ASSERT( !( s1 != s2 ) );
|
||
|
CPPUNIT_ASSERT( !( s2 != s1 ) );
|
||
|
CPPUNIT_ASSERT( s1 != s3 );
|
||
|
CPPUNIT_ASSERT( s3 != s1 );
|
||
|
CPPUNIT_ASSERT( s2 != s3 );
|
||
|
CPPUNIT_ASSERT( s3 != s2 );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testCmpOpLt( )
|
||
|
{
|
||
|
T_String s1( "wargl" ) , s2( "wargl" ) , s3( "gargl" );
|
||
|
CPPUNIT_ASSERT( !( s1 < s2 ) );
|
||
|
CPPUNIT_ASSERT( !( s1 < s3 ) );
|
||
|
CPPUNIT_ASSERT( !( s2 < s1 ) );
|
||
|
CPPUNIT_ASSERT( !( s2 < s3 ) );
|
||
|
CPPUNIT_ASSERT( s3 < s1 );
|
||
|
CPPUNIT_ASSERT( s3 < s2 );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testCmpOpLe( )
|
||
|
{
|
||
|
T_String s1( "wargl" ) , s2( "wargl" ) , s3( "gargl" );
|
||
|
CPPUNIT_ASSERT( s1 <= s2 );
|
||
|
CPPUNIT_ASSERT( !( s1 < s3 ) );
|
||
|
CPPUNIT_ASSERT( s2 <= s1 );
|
||
|
CPPUNIT_ASSERT( !( s2 < s3 ) );
|
||
|
CPPUNIT_ASSERT( s3 <= s1 );
|
||
|
CPPUNIT_ASSERT( s3 <= s2 );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testCmpOpGt( )
|
||
|
{
|
||
|
T_String s1( "wargl" ) , s2( "wargl" ) , s3( "gargl" );
|
||
|
CPPUNIT_ASSERT( !( s1 > s2 ) );
|
||
|
CPPUNIT_ASSERT( s1 > s3 );
|
||
|
CPPUNIT_ASSERT( !( s2 > s1 ) );
|
||
|
CPPUNIT_ASSERT( s2 > s3 );
|
||
|
CPPUNIT_ASSERT( !( s3 > s1 ) );
|
||
|
CPPUNIT_ASSERT( !( s3 > s2 ) );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testCmpOpGe( )
|
||
|
{
|
||
|
T_String s1( "wargl" ) , s2( "wargl" ) , s3( "gargl" );
|
||
|
CPPUNIT_ASSERT( s1 >= s2 );
|
||
|
CPPUNIT_ASSERT( s1 >= s3 );
|
||
|
CPPUNIT_ASSERT( s2 >= s1 );
|
||
|
CPPUNIT_ASSERT( s2 >= s3 );
|
||
|
CPPUNIT_ASSERT( !( s3 >= s1 ) );
|
||
|
CPPUNIT_ASSERT( !( s3 >= s2 ) );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testCmpOpEqCString( )
|
||
|
{
|
||
|
T_String s1( "wargl" );
|
||
|
CPPUNIT_ASSERT( s1 == "wargl" );
|
||
|
CPPUNIT_ASSERT( !( s1 == "gargl" ) );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testCmpOpNeCString( )
|
||
|
{
|
||
|
T_String s1( "wargl" );
|
||
|
CPPUNIT_ASSERT( s1 != "gargl" );
|
||
|
CPPUNIT_ASSERT( !( s1 != "wargl" ) );
|
||
|
}
|
||
|
|
||
|
/*----------------------------------------------------------------------------*/
|
||
|
|
||
|
void StringsTest::testFindEmpty( )
|
||
|
{
|
||
|
T_String str( "wargl" );
|
||
|
CPPUNIT_ASSERT_EQUAL( int32_t( 0 ) , str.find( T_String( ) ) );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testFindLonger( )
|
||
|
{
|
||
|
T_String str( "wargl" );
|
||
|
CPPUNIT_ASSERT_EQUAL( int32_t( -1 ) , str.find( T_String( "wargl gargl" ) ) );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testFindYes( )
|
||
|
{
|
||
|
T_String str( "wargl" );
|
||
|
CPPUNIT_ASSERT_EQUAL( int32_t( 1 ) , str.find( T_String( "arg" ) ) );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testFindNope( )
|
||
|
{
|
||
|
T_String str( "wargl" );
|
||
|
CPPUNIT_ASSERT_EQUAL( int32_t( -1 ) , str.find( T_String( "gar" ) ) );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testFindInvalidStrings( )
|
||
|
{
|
||
|
T_String str( "lol\x80" );
|
||
|
CPPUNIT_ASSERT_EQUAL( int32_t( -1 ) , str.find( T_String( "\x80" ) ) );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testFindOffsetEmpty( )
|
||
|
{
|
||
|
T_String str( "wargl" );
|
||
|
CPPUNIT_ASSERT_EQUAL( int32_t( 1 ) , str.find( T_String( ) , 1 ) );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testFindOffsetLonger( )
|
||
|
{
|
||
|
T_String str( "wargl" );
|
||
|
CPPUNIT_ASSERT_EQUAL( int32_t( -1 ) , str.find( T_String( "wargl" ) , 1 ) );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testFindOffsetBad( )
|
||
|
{
|
||
|
T_String str( "wargl" );
|
||
|
CPPUNIT_ASSERT_EQUAL( int32_t( -1 ) , str.find( T_String( "arg" ) , UINT32_MAX ) );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testFindOffsetYes( )
|
||
|
{
|
||
|
T_String str( "wargl" );
|
||
|
CPPUNIT_ASSERT_EQUAL( int32_t( 2 ) , str.find( T_String( "rg" ) , 1 ) );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testFindOffsetNo( )
|
||
|
{
|
||
|
T_String str( "wargl" );
|
||
|
CPPUNIT_ASSERT_EQUAL( int32_t( -1 ) , str.find( T_String( "wa" ) , 1 ) );
|
||
|
}
|
||
|
|
||
|
/*----------------------------------------------------------------------------*/
|
||
|
|
||
|
void StringsTest::testFindCharEmpty( )
|
||
|
{
|
||
|
T_String str;
|
||
|
CPPUNIT_ASSERT_EQUAL( int32_t( -1 ) , str.find( 'c' ) );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testFindCharYes( )
|
||
|
{
|
||
|
T_String str( "wargl" );
|
||
|
CPPUNIT_ASSERT_EQUAL( int32_t( 2 ) , str.find( 'r' ) );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testFindCharNo( )
|
||
|
{
|
||
|
T_String str( "wargl" );
|
||
|
CPPUNIT_ASSERT_EQUAL( int32_t( -1 ) , str.find( 'c' ) );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testFindCharInvalidString( )
|
||
|
{
|
||
|
T_String str( "wa\x80rgl" );
|
||
|
CPPUNIT_ASSERT_EQUAL( int32_t( -1 ) , str.find( 'w' ) );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testFindCharInvalidChar( )
|
||
|
{
|
||
|
T_String str( "wargl" );
|
||
|
CPPUNIT_ASSERT_EQUAL( int32_t( -1 ) , str.find( T_Character( 0x10000000 ) ) );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testFindCharOffsetBad( )
|
||
|
{
|
||
|
T_String str( "wargl" );
|
||
|
CPPUNIT_ASSERT_EQUAL( int32_t( -1 ) , str.find( 'l' , UINT32_MAX ) );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testFindCharOffsetYes( )
|
||
|
{
|
||
|
T_String str( "wargl" );
|
||
|
CPPUNIT_ASSERT_EQUAL( int32_t( 4 ) , str.find( 'l' , 1 ) );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testFindCharOffsetNo( )
|
||
|
{
|
||
|
T_String str( "wargl" );
|
||
|
CPPUNIT_ASSERT_EQUAL( int32_t( -1 ) , str.find( 'w' , 1 ) );
|
||
|
}
|
||
|
|
||
|
/*----------------------------------------------------------------------------*/
|
||
|
|
||
|
void StringsTest::testToUnsignedBasic( )
|
||
|
{
|
||
|
T_String str( "123" );
|
||
|
CPPUNIT_ASSERT_EQUAL( uint64_t( 123 ) , str.toUnsignedInteger( ) );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testToUnsignedOkValue( )
|
||
|
{
|
||
|
bool ok;
|
||
|
T_String str( "123" );
|
||
|
CPPUNIT_ASSERT_EQUAL( uint64_t( 123 ) , str.toUnsignedInteger( &ok ) );
|
||
|
CPPUNIT_ASSERT( ok );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testToUnsignedInvalid( )
|
||
|
{
|
||
|
bool ok;
|
||
|
T_String str( "123lol" );
|
||
|
CPPUNIT_ASSERT_EQUAL( uint64_t( 123 ) , str.toUnsignedInteger( &ok ) );
|
||
|
CPPUNIT_ASSERT( !ok );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testToUnsignedTooLarge( )
|
||
|
{
|
||
|
bool ok;
|
||
|
T_String str( "18446744073709551616" );
|
||
|
CPPUNIT_ASSERT_EQUAL( uint64_t( UINT64_MAX ) , str.toUnsignedInteger( &ok ) );
|
||
|
CPPUNIT_ASSERT( !ok );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testToUnsignedBaseOk( )
|
||
|
{
|
||
|
bool ok;
|
||
|
T_String str( "1a23" );
|
||
|
CPPUNIT_ASSERT_EQUAL( uint64_t( 6691 ) , str.toUnsignedInteger( &ok , 16 ) );
|
||
|
CPPUNIT_ASSERT( ok );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testToUnsignedBaseInvalid( )
|
||
|
{
|
||
|
bool ok;
|
||
|
T_String str( "12g3" );
|
||
|
CPPUNIT_ASSERT_EQUAL( uint64_t( 18 ) , str.toUnsignedInteger( &ok , 16 ) );
|
||
|
CPPUNIT_ASSERT( !ok );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testToUnsignedBaseAutoBinary( )
|
||
|
{
|
||
|
bool ok;
|
||
|
T_String str( "0b1111" );
|
||
|
CPPUNIT_ASSERT_EQUAL( uint64_t( 15 ) , str.toUnsignedInteger( &ok , 0 ) );
|
||
|
CPPUNIT_ASSERT( ok );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testToUnsignedBaseAutoOctal( )
|
||
|
{
|
||
|
bool ok;
|
||
|
T_String str( "0123" );
|
||
|
CPPUNIT_ASSERT_EQUAL( uint64_t( 83 ) , str.toUnsignedInteger( &ok , 0 ) );
|
||
|
CPPUNIT_ASSERT( ok );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testToUnsignedBaseAutoDecimal( )
|
||
|
{
|
||
|
bool ok;
|
||
|
T_String str( "123" );
|
||
|
CPPUNIT_ASSERT_EQUAL( uint64_t( 123 ) , str.toUnsignedInteger( &ok , 0 ) );
|
||
|
CPPUNIT_ASSERT( ok );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testToUnsignedBaseAutoHexa( )
|
||
|
{
|
||
|
bool ok;
|
||
|
T_String str( "0x123" );
|
||
|
CPPUNIT_ASSERT_EQUAL( uint64_t( 291 ) , str.toUnsignedInteger( &ok , 0 ) );
|
||
|
CPPUNIT_ASSERT( ok );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testToUnsignedBaseAutoZero( )
|
||
|
{
|
||
|
bool ok;
|
||
|
T_String str( "0" );
|
||
|
CPPUNIT_ASSERT_EQUAL( uint64_t( 0 ) , str.toUnsignedInteger( &ok , 0 ) );
|
||
|
CPPUNIT_ASSERT( ok );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testToUnsignedBaseAutoInvalid( )
|
||
|
{
|
||
|
bool ok;
|
||
|
T_String str( "0z123" );
|
||
|
CPPUNIT_ASSERT_EQUAL( uint64_t( 0 ) , str.toUnsignedInteger( &ok , 0 ) );
|
||
|
CPPUNIT_ASSERT( !ok );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testToUnsignedBaseAutoCut( )
|
||
|
{
|
||
|
bool ok;
|
||
|
T_String str( "0x" );
|
||
|
CPPUNIT_ASSERT_EQUAL( uint64_t( 0 ) , str.toUnsignedInteger( &ok , 0 ) );
|
||
|
CPPUNIT_ASSERT( !ok );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testToUnsignedSeparator( )
|
||
|
{
|
||
|
bool ok;
|
||
|
T_String str( "1 2 3" );
|
||
|
CPPUNIT_ASSERT_EQUAL( uint64_t( 123 ) , str.toUnsignedInteger( &ok , 10 , true ) );
|
||
|
CPPUNIT_ASSERT( ok );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testToUnsignedSeparatorCustom( )
|
||
|
{
|
||
|
bool ok;
|
||
|
T_String str( "1.2.3" );
|
||
|
CPPUNIT_ASSERT_EQUAL( uint64_t( 123 ) , str.toUnsignedInteger( &ok , 10 , true , '.' ) );
|
||
|
CPPUNIT_ASSERT( ok );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testToUnsignedSeparatorCustomUTF8( )
|
||
|
{
|
||
|
bool ok;
|
||
|
T_String str( "1""\xe2\x82\xac""23" );
|
||
|
CPPUNIT_ASSERT_EQUAL( uint64_t( 123 ) , str.toUnsignedInteger( &ok , 10 , true , T_Character( 0x20ac ) ) );
|
||
|
CPPUNIT_ASSERT( ok );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testToUnsignedLeadingWhitespace( )
|
||
|
{
|
||
|
bool ok;
|
||
|
T_String str( " 123" );
|
||
|
CPPUNIT_ASSERT_EQUAL( uint64_t( 123 ) , str.toUnsignedInteger( &ok ) );
|
||
|
CPPUNIT_ASSERT( ok );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testToUnsignedLeadingWhitespaceOnly( )
|
||
|
{
|
||
|
bool ok;
|
||
|
T_String str( " " );
|
||
|
CPPUNIT_ASSERT_EQUAL( uint64_t( 0 ) , str.toUnsignedInteger( &ok ) );
|
||
|
CPPUNIT_ASSERT( !ok );
|
||
|
}
|
||
|
|
||
|
/*----------------------------------------------------------------------------*/
|
||
|
|
||
|
void StringsTest::testToSignedBasic( )
|
||
|
{
|
||
|
T_String str( "123" );
|
||
|
CPPUNIT_ASSERT_EQUAL( int64_t( 123 ) , str.toInteger( ) );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testToSignedOkValue( )
|
||
|
{
|
||
|
bool ok;
|
||
|
T_String str( "123" );
|
||
|
CPPUNIT_ASSERT_EQUAL( int64_t( 123 ) , str.toInteger( &ok ) );
|
||
|
CPPUNIT_ASSERT( ok );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testToSignedPlus( )
|
||
|
{
|
||
|
bool ok;
|
||
|
T_String str( "+123" );
|
||
|
CPPUNIT_ASSERT_EQUAL( int64_t( 123 ) , str.toInteger( &ok ) );
|
||
|
CPPUNIT_ASSERT( ok );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testToSignedPlusMultiple( )
|
||
|
{
|
||
|
bool ok;
|
||
|
T_String str( "++123" );
|
||
|
CPPUNIT_ASSERT_EQUAL( int64_t( 0 ) , str.toInteger( &ok ) );
|
||
|
CPPUNIT_ASSERT( !ok );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testToSignedMinus( )
|
||
|
{
|
||
|
bool ok;
|
||
|
T_String str( "-123" );
|
||
|
CPPUNIT_ASSERT_EQUAL( int64_t( -123 ) , str.toInteger( &ok ) );
|
||
|
CPPUNIT_ASSERT( ok );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testToSignedMinusMultiple( )
|
||
|
{
|
||
|
bool ok;
|
||
|
T_String str( "--123" );
|
||
|
CPPUNIT_ASSERT_EQUAL( int64_t( 0 ) , str.toInteger( &ok ) );
|
||
|
CPPUNIT_ASSERT( !ok );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testToSignedInvalid( )
|
||
|
{
|
||
|
bool ok;
|
||
|
T_String str( "1lol23wut" );
|
||
|
CPPUNIT_ASSERT_EQUAL( int64_t( 1 ) , str.toInteger( &ok ) );
|
||
|
CPPUNIT_ASSERT( !ok );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testToSignedTooLarge( )
|
||
|
{
|
||
|
bool ok;
|
||
|
T_String str( "18446744073709551616" );
|
||
|
CPPUNIT_ASSERT_EQUAL( INT64_MAX , str.toInteger( &ok ) );
|
||
|
CPPUNIT_ASSERT( !ok );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testToSignedTooSmall( )
|
||
|
{
|
||
|
bool ok;
|
||
|
T_String str( "-18446744073709551616" );
|
||
|
CPPUNIT_ASSERT_EQUAL( INT64_MIN , str.toInteger( &ok ) );
|
||
|
CPPUNIT_ASSERT( !ok );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testToSignedBaseOk( )
|
||
|
{
|
||
|
bool ok;
|
||
|
T_String str( "1a2" );
|
||
|
CPPUNIT_ASSERT_EQUAL( int64_t( 418 ) , str.toInteger( &ok , 16 ) );
|
||
|
CPPUNIT_ASSERT( ok );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testToSignedBaseInvalid( )
|
||
|
{
|
||
|
bool ok;
|
||
|
T_String str( "g12" );
|
||
|
CPPUNIT_ASSERT_EQUAL( int64_t( 0 ) , str.toInteger( &ok , 16 ) );
|
||
|
CPPUNIT_ASSERT( !ok );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testToSignedBaseAutoBinary( )
|
||
|
{
|
||
|
bool ok;
|
||
|
T_String str( "0b11" );
|
||
|
CPPUNIT_ASSERT_EQUAL( int64_t( 3 ) , str.toInteger( &ok , 0 ) );
|
||
|
CPPUNIT_ASSERT( ok );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testToSignedBaseAutoOctal( )
|
||
|
{
|
||
|
bool ok;
|
||
|
T_String str( "011" );
|
||
|
CPPUNIT_ASSERT_EQUAL( int64_t( 9 ) , str.toInteger( &ok , 0 ) );
|
||
|
CPPUNIT_ASSERT( ok );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testToSignedBaseAutoDecimal( )
|
||
|
{
|
||
|
bool ok;
|
||
|
T_String str( "11" );
|
||
|
CPPUNIT_ASSERT_EQUAL( int64_t( 11 ) , str.toInteger( &ok , 0 ) );
|
||
|
CPPUNIT_ASSERT( ok );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testToSignedBaseAutoHexa( )
|
||
|
{
|
||
|
bool ok;
|
||
|
T_String str( "0x12" );
|
||
|
CPPUNIT_ASSERT_EQUAL( int64_t( 18 ) , str.toInteger( &ok , 0 ) );
|
||
|
CPPUNIT_ASSERT( ok );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testToSignedBaseAutoZero( )
|
||
|
{
|
||
|
bool ok;
|
||
|
T_String str( "0" );
|
||
|
CPPUNIT_ASSERT_EQUAL( int64_t( 0 ) , str.toInteger( &ok , 0 ) );
|
||
|
CPPUNIT_ASSERT( ok );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testToSignedBaseAutoInvalid( )
|
||
|
{
|
||
|
bool ok;
|
||
|
T_String str( "0z12" );
|
||
|
CPPUNIT_ASSERT_EQUAL( int64_t( 0 ) , str.toInteger( &ok , 0 ) );
|
||
|
CPPUNIT_ASSERT( !ok );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testToSignedBaseAutoCut( )
|
||
|
{
|
||
|
bool ok;
|
||
|
T_String str( "0x" );
|
||
|
CPPUNIT_ASSERT_EQUAL( int64_t( 0 ) , str.toInteger( &ok , 0 ) );
|
||
|
CPPUNIT_ASSERT( !ok );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testToSignedBaseAutoPlus( )
|
||
|
{
|
||
|
bool ok;
|
||
|
T_String str( "+0b11" );
|
||
|
CPPUNIT_ASSERT_EQUAL( int64_t( 3 ) , str.toInteger( &ok , 0 ) );
|
||
|
CPPUNIT_ASSERT( ok );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testToSignedBaseAutoMinus( )
|
||
|
{
|
||
|
bool ok;
|
||
|
T_String str( "-0b11" );
|
||
|
CPPUNIT_ASSERT_EQUAL( int64_t( -3 ) , str.toInteger( &ok , 0 ) );
|
||
|
CPPUNIT_ASSERT( ok );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testToSignedSeparator( )
|
||
|
{
|
||
|
bool ok;
|
||
|
T_String str( "-1 1" );
|
||
|
CPPUNIT_ASSERT_EQUAL( int64_t( -11 ) , str.toInteger( &ok , 10 , true ) );
|
||
|
CPPUNIT_ASSERT( ok );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testToSignedSeparatorCustom( )
|
||
|
{
|
||
|
bool ok;
|
||
|
T_String str( "-1x1" );
|
||
|
CPPUNIT_ASSERT_EQUAL( int64_t( -11 ) , str.toInteger( &ok , 10 , true , 'x' ) );
|
||
|
CPPUNIT_ASSERT( ok );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testToSignedSeparatorCustomUTF8( )
|
||
|
{
|
||
|
bool ok;
|
||
|
T_String str( "1""\xe2\x82\xac""23" );
|
||
|
CPPUNIT_ASSERT_EQUAL( int64_t( 123 ) , str.toInteger( &ok , 10 , true , T_Character( 0x20ac ) ) );
|
||
|
CPPUNIT_ASSERT( ok );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testToSignedLeadingWhitespace( )
|
||
|
{
|
||
|
bool ok;
|
||
|
T_String str( " - 123" );
|
||
|
CPPUNIT_ASSERT_EQUAL( int64_t( -123 ) , str.toInteger( &ok ) );
|
||
|
CPPUNIT_ASSERT( ok );
|
||
|
}
|
||
|
|
||
|
void StringsTest::testToSignedLeadingWhitespaceOnly( )
|
||
|
{
|
||
|
bool ok;
|
||
|
T_String str( " " );
|
||
|
CPPUNIT_ASSERT_EQUAL( int64_t( 0 ) , str.toInteger( &ok ) );
|
||
|
CPPUNIT_ASSERT( !ok );
|
||
|
}
|
||
|
|
||
|
/*----------------------------------------------------------------------------*/
|
||
|
|
||
|
#define M_CHECK_( STR , VAL , OK ) \
|
||
|
do { \
|
||
|
bool ok; \
|
||
|
double v( T_String( STR ).toDouble( &ok , '.' , true , ',' ) ); \
|
||
|
CPPUNIT_ASSERT_EQUAL( double( VAL ) , v ); \
|
||
|
CPPUNIT_ASSERT_EQUAL( bool( OK ) , ok ); \
|
||
|
} while ( 0 )
|
||
|
|
||
|
void StringsTest::testToDouble( )
|
||
|
{
|
||
|
M_CHECK_( " " , 0 , false );
|
||
|
M_CHECK_( " 0" , 0 , true );
|
||
|
M_CHECK_( " ,,0" , 0 , false );
|
||
|
M_CHECK_( "+" , 0 , false );
|
||
|
M_CHECK_( "-" , 0 , false );
|
||
|
M_CHECK_( "123" , 123 , true );
|
||
|
M_CHECK_( ",123" , 0 , false );
|
||
|
M_CHECK_( "1,2,3" , 123 , true );
|
||
|
M_CHECK_( "1,2," , 0 , false );
|
||
|
M_CHECK_( ",-123" , 0 , false );
|
||
|
M_CHECK_( "-123" , -123 , true );
|
||
|
M_CHECK_( "+123" , +123 , true );
|
||
|
M_CHECK_( "+,123" , 0 , false );
|
||
|
M_CHECK_( ".12" , .12 , true );
|
||
|
M_CHECK_( "-.12" , -.12 , true );
|
||
|
M_CHECK_( "+.12" , .12 , true );
|
||
|
M_CHECK_( "." , 0 , true );
|
||
|
M_CHECK_( "12." , 12 , true );
|
||
|
M_CHECK_( "12e" , 0 , false );
|
||
|
M_CHECK_( "12e2" , 12e2 , true );
|
||
|
M_CHECK_( "12e+" , 0 , false );
|
||
|
M_CHECK_( "12e-" , 0 , false );
|
||
|
M_CHECK_( "12e+2" , 12e2 , true );
|
||
|
M_CHECK_( "12e-2" , 12e-2 , true );
|
||
|
M_CHECK_( "1.2e2" , 120 , true );
|
||
|
M_CHECK_( "1.2e+2" , 120 , true );
|
||
|
M_CHECK_( "1.2e-2" , 1.2e-2 , true );
|
||
|
M_CHECK_( "1e3000" , std::numeric_limits< double >::infinity( ) , false );
|
||
|
M_CHECK_( "-1e3000" , -std::numeric_limits< double >::infinity( ) , false );
|
||
|
M_CHECK_( "1e-3000" , 0 , false );
|
||
|
}
|
||
|
|
||
|
#undef M_CHECK_
|