From 9a7b7798282622e445efc3318b6c85ff0bed9af8 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 26 Oct 2007 22:50:26 +0000 Subject: [PATCH] fix bug with adding entries to a root group containing only subgroups (as shown by new AddToExistingRoot() unit test) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@49476 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/fileconf.cpp | 13 +++---------- tests/config/fileconf.cpp | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/common/fileconf.cpp b/src/common/fileconf.cpp index 00ab5bf924..a09919e726 100644 --- a/src/common/fileconf.cpp +++ b/src/common/fileconf.cpp @@ -245,6 +245,7 @@ public: // get the last line belonging to an entry/subgroup of this group wxFileConfigLineList *GetGroupLine(); // line which contains [group] + // may be NULL for "/" only wxFileConfigLineList *GetLastEntryLine(); // after which our subgroups start wxFileConfigLineList *GetLastGroupLine(); // after which the next group starts @@ -550,16 +551,8 @@ void wxFileConfig::Parse(const wxTextBuffer& buffer, bool bLocal) // add the line to linked list if ( bLocal ) - { LineListAppend(strLine); - // let the root group have its start line as well - if ( !n ) - { - m_pCurrentGroup->SetLine(m_linesTail); - } - } - // skip leading spaces for ( pStart = buf; wxIsspace(*pStart); pStart++ ) @@ -958,8 +951,8 @@ bool wxFileConfig::DoWriteString(const wxString& key, const wxString& szValue) SetDirty(); - // this will add a line for this group if it didn't have it before - + // this will add a line for this group if it didn't have it before (or + // do nothing for the root but it's ok as it always exists anyhow) (void)m_pCurrentGroup->GetGroupLine(); } else diff --git a/tests/config/fileconf.cpp b/tests/config/fileconf.cpp index fe41fa8d26..a7f67216a3 100644 --- a/tests/config/fileconf.cpp +++ b/tests/config/fileconf.cpp @@ -79,6 +79,7 @@ private: CPPUNIT_TEST( CreateSubgroupAndEntries ); CPPUNIT_TEST( DeleteLastGroup ); CPPUNIT_TEST( DeleteAndRecreateGroup ); + CPPUNIT_TEST( AddToExistingRoot ); CPPUNIT_TEST_SUITE_END(); void Path(); @@ -99,6 +100,8 @@ private: void CreateSubgroupAndEntries(); void DeleteLastGroup(); void DeleteAndRecreateGroup(); + void AddToExistingRoot(); + static wxString ChangePath(wxFileConfig& fc, const wxChar *path) { @@ -607,5 +610,23 @@ void FileConfigTestCase::DeleteAndRecreateGroup() fc ); } +void FileConfigTestCase::AddToExistingRoot() +{ + static const wxChar *confInitial = + _T("[Group]\n") + _T("value1=foo\n"); + + wxStringInputStream sis(confInitial); + wxFileConfig fc(sis); + + fc.Write(_T("/value1"), _T("bar")); + wxVERIFY_FILECONFIG( + _T("value1=bar\n") + _T("[Group]\n") + _T("value1=foo\n"), + fc + ); +} + #endif // wxUSE_FILECONFIG -- 2.47.2