X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a9e994615409e36d441135e4fa0761cf0398a2aa..aead8a4eabecca466070be6a1ff0e911602d75d9:/tests/fileconf/fileconftest.cpp diff --git a/tests/fileconf/fileconftest.cpp b/tests/fileconf/fileconftest.cpp index 7b8216b75e..c26cf1428f 100644 --- a/tests/fileconf/fileconftest.cpp +++ b/tests/fileconf/fileconftest.cpp @@ -11,7 +11,7 @@ // headers // ---------------------------------------------------------------------------- -#include "wx/wxprec.h" +#include "testprec.h" #ifdef __BORLANDC__ #pragma hdrstop @@ -24,8 +24,7 @@ #include "wx/fileconf.h" #include "wx/sstream.h" - -#include "wx/cppunit.h" +#include "wx/log.h" static const wxChar *testconfig = _T("[root]\n") @@ -60,6 +59,7 @@ private: CPPUNIT_TEST( DeleteAll ); CPPUNIT_TEST( RenameEntry ); CPPUNIT_TEST( RenameGroup ); + CPPUNIT_TEST( DeleteLastGroup ); CPPUNIT_TEST_SUITE_END(); void Path(); @@ -74,6 +74,7 @@ private: void DeleteAll(); void RenameEntry(); void RenameGroup(); + void DeleteLastGroup(); static wxString ChangePath(wxFileConfig& fc, const wxChar *path) { @@ -352,5 +353,48 @@ void FileConfigTestCase::RenameGroup() _T("[foot/group2]\n") ); } + +static void EmptyConfigAndWriteKey() +{ + wxFileConfig fc(_T("deleteconftest")); + + const wxString groupPath = _T("/root"); + + if (fc.Exists(groupPath)) + { + // using DeleteGroup exposes the problem, using DeleteAll doesn't + CPPUNIT_ASSERT( fc.DeleteGroup(groupPath) ); + } + + // the config must be empty for the problem to arise + CPPUNIT_ASSERT( !fc.GetNumberOfEntries(true) ); + CPPUNIT_ASSERT( !fc.GetNumberOfGroups(true) ); + + + // this crashes on second call of this function + CPPUNIT_ASSERT( fc.Write(groupPath + _T("/entry"), _T("value")) ); +} + +void FileConfigTestCase::DeleteLastGroup() +{ + /* + We make 2 of the same calls, first to create a file config with a single + group and key... + */ + ::EmptyConfigAndWriteKey(); + + /* + ... then the same but this time the key's group is deleted before the + key is written again. This causes a crash. + */ + ::EmptyConfigAndWriteKey(); + + + // clean up + wxLogNull noLogging; + (void) ::wxRemoveFile( + wxFileConfig::GetLocalFileName(_T("deleteconftest")) ); +} + #endif // wxUSE_FILECONFIG