Fix wxStringTokenizer copy ctor and assignment operator.
Implement copying of wxStringTokenizer correctly: compiler-generated versions didn't work as the position of the tokenizer didn't point into the correct string after making the copy. Fix this by adjusting the position iterator to use the copy of the string. Closes #16339. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@78050 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -38,6 +38,8 @@ private:
|
||||
CPPUNIT_TEST( GetString );
|
||||
CPPUNIT_TEST( LastDelimiter );
|
||||
CPPUNIT_TEST( StrtokCompat );
|
||||
CPPUNIT_TEST( CopyObj );
|
||||
CPPUNIT_TEST( AssignObj );
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
void GetCount();
|
||||
@@ -45,6 +47,8 @@ private:
|
||||
void GetString();
|
||||
void LastDelimiter();
|
||||
void StrtokCompat();
|
||||
void CopyObj();
|
||||
void AssignObj();
|
||||
|
||||
DECLARE_NO_COPY_CLASS(TokenizerTestCase)
|
||||
};
|
||||
@@ -268,4 +272,45 @@ void TokenizerTestCase::StrtokCompat()
|
||||
}
|
||||
}
|
||||
|
||||
void TokenizerTestCase::CopyObj()
|
||||
{
|
||||
// Test copy ctor
|
||||
wxStringTokenizer tkzSrc(wxT("first:second:third:fourth"), wxT(":"));
|
||||
while ( tkzSrc.HasMoreTokens() )
|
||||
{
|
||||
wxString tokenSrc = tkzSrc.GetNextToken();
|
||||
wxStringTokenizer tkz = tkzSrc;
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( tkzSrc.GetPosition(), tkz.GetPosition() );
|
||||
CPPUNIT_ASSERT_EQUAL( tkzSrc.GetString(), tkz.GetString() );
|
||||
|
||||
// Change the state of both objects and compare again...
|
||||
tokenSrc = tkzSrc.GetNextToken();
|
||||
wxString token = tkz.GetNextToken();
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( tkzSrc.GetPosition(), tkz.GetPosition() );
|
||||
CPPUNIT_ASSERT_EQUAL( tkzSrc.GetString(), tkz.GetString() );
|
||||
}
|
||||
}
|
||||
|
||||
void TokenizerTestCase::AssignObj()
|
||||
{
|
||||
// Test assignment
|
||||
wxStringTokenizer tkzSrc(wxT("first:second:third:fourth"), wxT(":"));
|
||||
wxStringTokenizer tkz;
|
||||
while ( tkzSrc.HasMoreTokens() )
|
||||
{
|
||||
wxString tokenSrc = tkzSrc.GetNextToken();
|
||||
tkz = tkzSrc;
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( tkzSrc.GetPosition(), tkz.GetPosition() );
|
||||
CPPUNIT_ASSERT_EQUAL( tkzSrc.GetString(), tkz.GetString() );
|
||||
|
||||
// Change the state of both objects and compare again...
|
||||
tokenSrc = tkzSrc.GetNextToken();
|
||||
wxString token = tkz.GetNextToken();
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( tkzSrc.GetPosition(), tkz.GetPosition() );
|
||||
CPPUNIT_ASSERT_EQUAL( tkzSrc.GetString(), tkz.GetString() );
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user