X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/8899b155a1e4fa5f4b90e1f3bebe28088ea46bc9..c0b49f7fffbd1cecb9c67b578db62d84bd8c8ff8:/tests/fileconf/fileconftest.cpp diff --git a/tests/fileconf/fileconftest.cpp b/tests/fileconf/fileconftest.cpp index a2fb2e61bf..4d8234caf5 100644 --- a/tests/fileconf/fileconftest.cpp +++ b/tests/fileconf/fileconftest.cpp @@ -24,6 +24,7 @@ #include "wx/fileconf.h" #include "wx/sstream.h" +#include "wx/log.h" static const wxChar *testconfig = _T("[root]\n") @@ -58,6 +59,9 @@ private: CPPUNIT_TEST( DeleteAll ); CPPUNIT_TEST( RenameEntry ); CPPUNIT_TEST( RenameGroup ); + CPPUNIT_TEST( CreateEntriesAndSubgroup ); + CPPUNIT_TEST( CreateSubgroupAndEntries ); + CPPUNIT_TEST( DeleteLastGroup ); CPPUNIT_TEST_SUITE_END(); void Path(); @@ -72,6 +76,9 @@ private: void DeleteAll(); void RenameEntry(); void RenameGroup(); + void CreateEntriesAndSubgroup(); + void CreateSubgroupAndEntries(); + void DeleteLastGroup(); static wxString ChangePath(wxFileConfig& fc, const wxChar *path) { @@ -350,5 +357,70 @@ void FileConfigTestCase::RenameGroup() _T("[foot/group2]\n") ); } +void FileConfigTestCase::CreateSubgroupAndEntries() +{ + wxFileConfig fc; + fc.Write(_T("sub/sub_first"), _T("sub_one")); + fc.Write(_T("first"), _T("one")); + + CPPUNIT_ASSERT( Dump(fc) == _T("first=one\n") + _T("[sub]\n") + _T("sub_first=sub_one\n")); +} + +void FileConfigTestCase::CreateEntriesAndSubgroup() +{ + wxFileConfig fc; + fc.Write(_T("first"), _T("one")); + fc.Write(_T("second"), _T("two")); + fc.Write(_T("sub/sub_first"), _T("sub_one")); + + CPPUNIT_ASSERT( Dump(fc) == _T("first=one\n") + _T("second=two\n") + _T("[sub]\n") + _T("sub_first=sub_one\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