Unit tests update

This commit is contained in:
Markus Gans 2018-03-01 01:05:32 +01:00
parent f42175c8da
commit b51d7a399c
2 changed files with 122 additions and 27 deletions

View File

@ -285,10 +285,9 @@ const FString& FString::operator = (const wchar_t s[])
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FString& FString::operator = (const std::string& s) FString& FString::operator = (const std::string& s)
{ {
const wchar_t* wc_string = c_to_wc_str(s.c_str()); if ( ! s.empty() )
if ( wc_string )
{ {
const wchar_t* wc_string = c_to_wc_str(s.c_str());
_assign( wc_string ); _assign( wc_string );
delete[] wc_string; delete[] wc_string;
} }
@ -301,10 +300,9 @@ FString& FString::operator = (const std::string& s)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
const FString& FString::operator = (const char s[]) const FString& FString::operator = (const char s[])
{ {
const wchar_t* wc_string = c_to_wc_str(s); if ( s )
if ( wc_string )
{ {
const wchar_t* wc_string = c_to_wc_str(s);
_assign( wc_string ); _assign( wc_string );
delete[] wc_string; delete[] wc_string;
} }
@ -317,20 +315,32 @@ const FString& FString::operator = (const char s[])
//---------------------------------------------------------------------- //----------------------------------------------------------------------
const FString& FString::operator = (const wchar_t c) const FString& FString::operator = (const wchar_t c)
{ {
wchar_t s[2]; if ( c )
s[0] = c; {
s[1] = L'\0'; wchar_t s[2];
_assign (s); s[0] = c;
s[1] = L'\0';
_assign (s);
}
else
clear();
return *this; return *this;
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
const FString& FString::operator = (const char c) const FString& FString::operator = (const char c)
{ {
wchar_t s[2]; if ( c )
s[0] = wchar_t(c & 0xff); {
s[1] = L'\0'; wchar_t s[2];
_assign (s); s[0] = wchar_t(c & 0xff);
s[1] = L'\0';
_assign (s);
}
else
clear();
return *this; return *this;
} }

View File

@ -58,6 +58,7 @@ class FStringTest : public CPPUNIT_NS::TestFixture
void NoArgumentTest(); void NoArgumentTest();
void initLengthTest(); void initLengthTest();
void copyConstructorTest(); void copyConstructorTest();
void assignmentTest();
void caseTest(); void caseTest();
void equalTest(); void equalTest();
void lessEqualTest(); void lessEqualTest();
@ -76,6 +77,7 @@ class FStringTest : public CPPUNIT_NS::TestFixture
CPPUNIT_TEST (NoArgumentTest); CPPUNIT_TEST (NoArgumentTest);
CPPUNIT_TEST (initLengthTest); CPPUNIT_TEST (initLengthTest);
CPPUNIT_TEST (copyConstructorTest); CPPUNIT_TEST (copyConstructorTest);
CPPUNIT_TEST (assignmentTest);
CPPUNIT_TEST (caseTest); CPPUNIT_TEST (caseTest);
CPPUNIT_TEST (equalTest); CPPUNIT_TEST (equalTest);
CPPUNIT_TEST (notEqualTest); CPPUNIT_TEST (notEqualTest);
@ -173,36 +175,119 @@ void FStringTest::initLengthTest()
CPPUNIT_ASSERT ( ! s2.isNull() ); CPPUNIT_ASSERT ( ! s2.isNull() );
CPPUNIT_ASSERT ( s2.isEmpty() ); CPPUNIT_ASSERT ( s2.isEmpty() );
FString s4(x1, '-'); FString s4(0, '-');
CPPUNIT_ASSERT ( s4.getLength() == 10 ); CPPUNIT_ASSERT ( s4.getLength() == 0 );
CPPUNIT_ASSERT ( ! s4.isNull() ); CPPUNIT_ASSERT ( s4.isNull() );
CPPUNIT_ASSERT ( ! s4.isEmpty() ); CPPUNIT_ASSERT ( s4.isEmpty() );
FString s5(x2, '-'); FString s5(0, char(0));
CPPUNIT_ASSERT ( s5.getLength() == 10 ); CPPUNIT_ASSERT ( s5.getLength() == 0 );
CPPUNIT_ASSERT ( ! s5.isNull() ); CPPUNIT_ASSERT ( s5.isNull() );
CPPUNIT_ASSERT ( ! s5.isEmpty() ); CPPUNIT_ASSERT ( s5.isEmpty() );
FString s6(x1, L'-'); FString s6(x1, '-');
CPPUNIT_ASSERT ( s6.getLength() == 10 ); CPPUNIT_ASSERT ( s6.getLength() == 10 );
CPPUNIT_ASSERT ( ! s6.isNull() ); CPPUNIT_ASSERT ( ! s6.isNull() );
CPPUNIT_ASSERT ( ! s6.isEmpty() ); CPPUNIT_ASSERT ( ! s6.isEmpty() );
FString s7(x2, L'-'); FString s7(x2, '-');
CPPUNIT_ASSERT ( s7.getLength() == 10 ); CPPUNIT_ASSERT ( s7.getLength() == 10 );
CPPUNIT_ASSERT ( ! s7.isNull() ); CPPUNIT_ASSERT ( ! s7.isNull() );
CPPUNIT_ASSERT ( ! s7.isEmpty() ); CPPUNIT_ASSERT ( ! s7.isEmpty() );
FString s8(x1, L'-');
CPPUNIT_ASSERT ( s8.getLength() == 10 );
CPPUNIT_ASSERT ( ! s8.isNull() );
CPPUNIT_ASSERT ( ! s8.isEmpty() );
FString s9(x2, L'-');
CPPUNIT_ASSERT ( s9.getLength() == 10 );
CPPUNIT_ASSERT ( ! s9.isNull() );
CPPUNIT_ASSERT ( ! s9.isEmpty() );
FString s10(x2, wchar_t(0));
CPPUNIT_ASSERT ( s10.getLength() == 10 );
CPPUNIT_ASSERT ( ! s10.isNull() );
CPPUNIT_ASSERT ( s10.isEmpty() );
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FStringTest::copyConstructorTest() void FStringTest::copyConstructorTest()
{ {
FString s1("abc"); const FString s1("abc");
FString s2(s1); FString s2(s1);
CPPUNIT_ASSERT ( s2 == L"abc" ); CPPUNIT_ASSERT ( s2 == L"abc" );
CPPUNIT_ASSERT ( s2.getLength() == 3 ); CPPUNIT_ASSERT ( s2.getLength() == 3 );
} }
//----------------------------------------------------------------------
void FStringTest::assignmentTest()
{
FString s1;
s1 = static_cast<FString>(0);
CPPUNIT_ASSERT ( s1.isNull() );
CPPUNIT_ASSERT ( s1.isEmpty() );
s1 = std::wstring();
CPPUNIT_ASSERT ( s1.isNull() );
CPPUNIT_ASSERT ( s1.isEmpty() );
s1 = std::string();
CPPUNIT_ASSERT ( s1.isNull() );
CPPUNIT_ASSERT ( s1.isEmpty() );
s1 = static_cast<wchar_t*>(0);
CPPUNIT_ASSERT ( s1.isNull() );
CPPUNIT_ASSERT ( s1.isEmpty() );
s1 = static_cast<char*>(0);
CPPUNIT_ASSERT ( s1.isNull() );
CPPUNIT_ASSERT ( s1.isEmpty() );
s1 = wchar_t(0);
CPPUNIT_ASSERT ( s1.isNull() );
CPPUNIT_ASSERT ( s1.isEmpty() );
s1 = char(0);
CPPUNIT_ASSERT ( s1.isNull() );
CPPUNIT_ASSERT ( s1.isEmpty() );
const FString s2("abc");
s1 = s2;
CPPUNIT_ASSERT ( s1 == L"abc" );
CPPUNIT_ASSERT ( s1.getLength() == 3 );
const std::wstring s3(L"def");
s1 = s3;
CPPUNIT_ASSERT ( s1 == L"def" );
CPPUNIT_ASSERT ( s1.getLength() == 3 );
const std::string s4("ghi");
s1 = s4;
CPPUNIT_ASSERT ( s1 == L"ghi" );
CPPUNIT_ASSERT ( s1.getLength() == 3 );
const wchar_t s5[] = L"abc";
s1 = s5;
CPPUNIT_ASSERT ( s1 == L"abc" );
CPPUNIT_ASSERT ( s1.getLength() == 3 );
const char s6[] = "def";
s1 = s6;
CPPUNIT_ASSERT ( s1 == L"def" );
CPPUNIT_ASSERT ( s1.getLength() == 3 );
const wchar_t s7 = L'#';
s1 = s7;
CPPUNIT_ASSERT ( s1 == L"#" );
CPPUNIT_ASSERT ( s1.getLength() == 1 );
const char s8 = '%';
s1 = s8;
CPPUNIT_ASSERT ( s1 == L"%" );
CPPUNIT_ASSERT ( s1.getLength() == 1 );
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FStringTest::caseTest() void FStringTest::caseTest()
{ {