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:
@@ -228,6 +228,13 @@ wxX11:
|
|||||||
- Make Enter key activate the default button (David Hart).
|
- 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
|
2.8.5
|
||||||
-----
|
-----
|
||||||
|
|
||||||
|
@@ -1810,29 +1810,21 @@ bool wxFileConfigGroup::DeleteEntry(const wxString& name)
|
|||||||
// our last entry is being deleted - find the last one which stays
|
// our last entry is being deleted - find the last one which stays
|
||||||
wxASSERT( m_pLine != NULL ); // if we have an entry with !NULL pLine...
|
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;
|
wxFileConfigEntry *pNewLast = NULL;
|
||||||
size_t n, nEntries = m_aEntries.GetCount();
|
const wxFileConfigLineList * const
|
||||||
wxFileConfigLineList *pl;
|
pNewLastLine = m_pLastEntry->GetLine()->Prev();
|
||||||
for ( pl = pLine->Prev(); pl != m_pLine; pl = pl->Prev() ) {
|
const size_t nEntries = m_aEntries.GetCount();
|
||||||
// is it our subgroup?
|
for ( size_t n = 0; n < nEntries; n++ ) {
|
||||||
for ( n = 0; (pNewLast == NULL) && (n < nEntries); n++ ) {
|
if ( m_aEntries[n]->GetLine() == pNewLastLine ) {
|
||||||
if ( m_aEntries[n]->GetLine() == m_pLine )
|
pNewLast = m_aEntries[n];
|
||||||
pNewLast = m_aEntries[n];
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( pNewLast != NULL ) // found?
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( pl == m_pLine ) {
|
// pNewLast can be NULL here -- it's ok and can happen if we have no
|
||||||
wxASSERT( !pNewLast ); // how comes it has the same line as we?
|
// entries left
|
||||||
|
m_pLastEntry = pNewLast;
|
||||||
// we've reached the group line without finding any subgroups
|
|
||||||
m_pLastEntry = NULL;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
m_pLastEntry = pNewLast;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_pConfig->LineListRemove(pLine);
|
m_pConfig->LineListRemove(pLine);
|
||||||
|
@@ -70,6 +70,7 @@ private:
|
|||||||
CPPUNIT_TEST( Binary );
|
CPPUNIT_TEST( Binary );
|
||||||
CPPUNIT_TEST( Save );
|
CPPUNIT_TEST( Save );
|
||||||
CPPUNIT_TEST( DeleteEntry );
|
CPPUNIT_TEST( DeleteEntry );
|
||||||
|
CPPUNIT_TEST( DeleteAndWriteEntry );
|
||||||
CPPUNIT_TEST( DeleteGroup );
|
CPPUNIT_TEST( DeleteGroup );
|
||||||
CPPUNIT_TEST( DeleteAll );
|
CPPUNIT_TEST( DeleteAll );
|
||||||
CPPUNIT_TEST( RenameEntry );
|
CPPUNIT_TEST( RenameEntry );
|
||||||
@@ -89,6 +90,7 @@ private:
|
|||||||
void Binary();
|
void Binary();
|
||||||
void Save();
|
void Save();
|
||||||
void DeleteEntry();
|
void DeleteEntry();
|
||||||
|
void DeleteAndWriteEntry();
|
||||||
void DeleteGroup();
|
void DeleteGroup();
|
||||||
void DeleteAll();
|
void DeleteAll();
|
||||||
void RenameEntry();
|
void RenameEntry();
|
||||||
@@ -324,6 +326,47 @@ void FileConfigTestCase::DeleteEntry()
|
|||||||
fc );
|
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()
|
void FileConfigTestCase::DeleteGroup()
|
||||||
{
|
{
|
||||||
wxStringInputStream sis(testconfig);
|
wxStringInputStream sis(testconfig);
|
||||||
|
Reference in New Issue
Block a user