Fix failing TextFileTestCase::ReadMixedWithFuzzing().
The test failed with 33% probability because it didn't account for trailing non-newline character. Fixed and also changed the test to repeat itself a hundred times, to increase the probability of catching problems like this. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_3_0_BRANCH@75824 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -219,29 +219,34 @@ void TextFileTestCase::ReadMixed()
|
|||||||
|
|
||||||
void TextFileTestCase::ReadMixedWithFuzzing()
|
void TextFileTestCase::ReadMixedWithFuzzing()
|
||||||
{
|
{
|
||||||
// Create a random buffer with lots of newlines. This is intended to catch
|
for ( int iteration = 0; iteration < 100; iteration++)
|
||||||
// bad parsing in unexpected situations such as the one from ReadCRCRLF()
|
|
||||||
// (which is so common it deserves a test of its own).
|
|
||||||
static const char CHOICES[] = {'\r', '\n', 'X'};
|
|
||||||
|
|
||||||
unsigned linesCnt = 0;
|
|
||||||
const size_t BUF_LEN = 20000;
|
|
||||||
char data[BUF_LEN + 1];
|
|
||||||
data[0] = 'X';
|
|
||||||
data[BUF_LEN] = '\0';
|
|
||||||
for ( size_t i = 1; i < BUF_LEN; i++ )
|
|
||||||
{
|
{
|
||||||
char ch = CHOICES[rand() % WXSIZEOF(CHOICES)];
|
// Create a random buffer with lots of newlines. This is intended to catch
|
||||||
data[i] = ch;
|
// bad parsing in unexpected situations such as the one from ReadCRCRLF()
|
||||||
if ( ch == '\r' || (ch == '\n' && data[i-1] != '\r') )
|
// (which is so common it deserves a test of its own).
|
||||||
linesCnt++;
|
static const char CHOICES[] = {'\r', '\n', 'X'};
|
||||||
|
|
||||||
|
const size_t BUF_LEN = 100;
|
||||||
|
char data[BUF_LEN + 1];
|
||||||
|
data[0] = 'X';
|
||||||
|
data[BUF_LEN] = '\0';
|
||||||
|
unsigned linesCnt = 0;
|
||||||
|
for ( size_t i = 1; i < BUF_LEN; i++ )
|
||||||
|
{
|
||||||
|
char ch = CHOICES[rand() % WXSIZEOF(CHOICES)];
|
||||||
|
data[i] = ch;
|
||||||
|
if ( ch == '\r' || (ch == '\n' && data[i-1] != '\r') )
|
||||||
|
linesCnt++;
|
||||||
|
}
|
||||||
|
if (data[BUF_LEN-1] != '\r' && data[BUF_LEN-1] != '\n')
|
||||||
|
linesCnt++; // last line was unterminated
|
||||||
|
|
||||||
|
CreateTestFile(data);
|
||||||
|
|
||||||
|
wxTextFile f;
|
||||||
|
CPPUNIT_ASSERT( f.Open(wxString::FromAscii(GetTestFileName())) );
|
||||||
|
CPPUNIT_ASSERT_EQUAL( (size_t)linesCnt, f.GetLineCount() );
|
||||||
}
|
}
|
||||||
|
|
||||||
CreateTestFile(data);
|
|
||||||
|
|
||||||
wxTextFile f;
|
|
||||||
CPPUNIT_ASSERT( f.Open(wxString::FromAscii(GetTestFileName())) );
|
|
||||||
CPPUNIT_ASSERT_EQUAL( (size_t)linesCnt, f.GetLineCount() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextFileTestCase::ReadCRCRLF()
|
void TextFileTestCase::ReadCRCRLF()
|
||||||
|
Reference in New Issue
Block a user