fix bug with deleting and recreating entries in wxFileConfig (patch 1796866)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@48776 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2007-09-19 00:41:55 +00:00
parent 8a2a5a449e
commit e86882e38d
3 changed files with 61 additions and 19 deletions

View File

@@ -228,6 +228,13 @@ wxX11:
- Make Enter key activate the default button (David Hart).
2.8.6
-----
All:
- Fixed another bug in wxFileConfig when deleting entries (Axel Gembe)
2.8.5
-----

View File

@@ -1810,29 +1810,21 @@ bool wxFileConfigGroup::DeleteEntry(const wxString& name)
// our last entry is being deleted - find the last one which stays
wxASSERT( m_pLine != NULL ); // if we have an entry with !NULL pLine...
// go back until we find another entry or reach the group's line
// find the previous entry (if any)
wxFileConfigEntry *pNewLast = NULL;
size_t n, nEntries = m_aEntries.GetCount();
wxFileConfigLineList *pl;
for ( pl = pLine->Prev(); pl != m_pLine; pl = pl->Prev() ) {
// is it our subgroup?
for ( n = 0; (pNewLast == NULL) && (n < nEntries); n++ ) {
if ( m_aEntries[n]->GetLine() == m_pLine )
pNewLast = m_aEntries[n];
}
if ( pNewLast != NULL ) // found?
const wxFileConfigLineList * const
pNewLastLine = m_pLastEntry->GetLine()->Prev();
const size_t nEntries = m_aEntries.GetCount();
for ( size_t n = 0; n < nEntries; n++ ) {
if ( m_aEntries[n]->GetLine() == pNewLastLine ) {
pNewLast = m_aEntries[n];
break;
}
}
if ( pl == m_pLine ) {
wxASSERT( !pNewLast ); // how comes it has the same line as we?
// we've reached the group line without finding any subgroups
m_pLastEntry = NULL;
}
else
m_pLastEntry = pNewLast;
// pNewLast can be NULL here -- it's ok and can happen if we have no
// entries left
m_pLastEntry = pNewLast;
}
m_pConfig->LineListRemove(pLine);

View File

@@ -70,6 +70,7 @@ private:
CPPUNIT_TEST( Binary );
CPPUNIT_TEST( Save );
CPPUNIT_TEST( DeleteEntry );
CPPUNIT_TEST( DeleteAndWriteEntry );
CPPUNIT_TEST( DeleteGroup );
CPPUNIT_TEST( DeleteAll );
CPPUNIT_TEST( RenameEntry );
@@ -89,6 +90,7 @@ private:
void Binary();
void Save();
void DeleteEntry();
void DeleteAndWriteEntry();
void DeleteGroup();
void DeleteAll();
void RenameEntry();
@@ -324,6 +326,47 @@ void FileConfigTestCase::DeleteEntry()
fc );
}
void FileConfigTestCase::DeleteAndWriteEntry()
{
wxStringInputStream sis(
"[root/group1]\n"
"subentry=subvalue\n"
"subentry2=subvalue2\n"
"subentry3=subvalue3\n"
);
wxFileConfig fc(sis);
fc.DeleteEntry("/root/group1/subentry2");
fc.Write("/root/group1/subentry2", "testvalue");
fc.DeleteEntry("/root/group2/subentry2");
fc.Write("/root/group2/subentry2", "testvalue2");
fc.DeleteEntry("/root/group1/subentry2");
fc.Write("/root/group1/subentry2", "testvalue");
fc.DeleteEntry("/root/group2/subentry2");
fc.Write("/root/group2/subentry2", "testvalue2");
wxVERIFY_FILECONFIG( "[root/group1]\n"
"subentry=subvalue\n"
"subentry3=subvalue3\n"
"subentry2=testvalue\n"
"[root/group2]\n"
"subentry2=testvalue2\n",
fc );
fc.DeleteEntry("/root/group2/subentry2");
wxVERIFY_FILECONFIG( "[root/group1]\n"
"subentry=subvalue\n"
"subentry3=subvalue3\n"
"subentry2=testvalue\n",
fc );
fc.DeleteEntry("/root/group1/subentry2");
fc.DeleteEntry("/root/group1/subentry");
fc.DeleteEntry("/root/group1/subentry3");
wxVERIFY_FILECONFIG( "", fc );
}
void FileConfigTestCase::DeleteGroup()
{
wxStringInputStream sis(testconfig);