Fix reading of files with Mac EOLs in wxTextFile.

The last CR-terminated line wasn't handled correctly.

Fix this now and add unit tests to ensure that it stays fixed.

Closes #15583.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@75009 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2013-10-15 13:04:23 +00:00
parent 471111f1d7
commit b845aa636a
3 changed files with 61 additions and 2 deletions

View File

@@ -43,8 +43,11 @@ private:
CPPUNIT_TEST_SUITE( TextFileTestCase );
CPPUNIT_TEST( ReadEmpty );
CPPUNIT_TEST( ReadDOS );
CPPUNIT_TEST( ReadDOSLast );
CPPUNIT_TEST( ReadUnix );
CPPUNIT_TEST( ReadUnixLast );
CPPUNIT_TEST( ReadMac );
CPPUNIT_TEST( ReadMacLast );
CPPUNIT_TEST( ReadMixed );
#if wxUSE_UNICODE
CPPUNIT_TEST( ReadUTF8 );
@@ -55,8 +58,11 @@ private:
void ReadEmpty();
void ReadDOS();
void ReadDOSLast();
void ReadUnix();
void ReadUnixLast();
void ReadMac();
void ReadMacLast();
void ReadMixed();
#if wxUSE_UNICODE
void ReadUTF8();
@@ -120,6 +126,18 @@ void TextFileTestCase::ReadDOS()
CPPUNIT_ASSERT_EQUAL( wxString(wxT("baz")), f.GetLastLine() );
}
void TextFileTestCase::ReadDOSLast()
{
CreateTestFile("foo\r\n");
wxTextFile f;
CPPUNIT_ASSERT( f.Open(GetTestFileName()) );
CPPUNIT_ASSERT_EQUAL( 1, f.GetLineCount() );
CPPUNIT_ASSERT_EQUAL( wxTextFileType_Dos, f.GetLineType(0) );
CPPUNIT_ASSERT_EQUAL( "foo", f.GetFirstLine() );
}
void TextFileTestCase::ReadUnix()
{
CreateTestFile("foo\nbar\nbaz");
@@ -134,6 +152,18 @@ void TextFileTestCase::ReadUnix()
CPPUNIT_ASSERT_EQUAL( wxString(wxT("baz")), f.GetLastLine() );
}
void TextFileTestCase::ReadUnixLast()
{
CreateTestFile("foo\n");
wxTextFile f;
CPPUNIT_ASSERT( f.Open(GetTestFileName()) );
CPPUNIT_ASSERT_EQUAL( 1, f.GetLineCount() );
CPPUNIT_ASSERT_EQUAL( wxTextFileType_Unix, f.GetLineType(0) );
CPPUNIT_ASSERT_EQUAL( "foo", f.GetFirstLine() );
}
void TextFileTestCase::ReadMac()
{
CreateTestFile("foo\rbar\rbaz");
@@ -148,6 +178,18 @@ void TextFileTestCase::ReadMac()
CPPUNIT_ASSERT_EQUAL( wxString(wxT("baz")), f.GetLastLine() );
}
void TextFileTestCase::ReadMacLast()
{
CreateTestFile("foo\r");
wxTextFile f;
CPPUNIT_ASSERT( f.Open(GetTestFileName()) );
CPPUNIT_ASSERT_EQUAL( 1, f.GetLineCount() );
CPPUNIT_ASSERT_EQUAL( wxTextFileType_Mac, f.GetLineType(0) );
CPPUNIT_ASSERT_EQUAL( "foo", f.GetFirstLine() );
}
void TextFileTestCase::ReadMixed()
{
CreateTestFile("foo\rbar\r\nbaz\n");