+ wxVERIFY_FILECONFIG( _T("[foot]\n")
+ _T("entry=value\n")
+ _T("[foot/group1]\n")
+ _T("[foot/group1/subgroup]\n")
+ _T("subentry=subvalue\n")
+ _T("subentry2=subvalue2\n")
+ _T("[foot/group2]\n"),
+ fc );
+
+ // renaming a path doesn't work, it must be the immediate group
+ CPPUNIT_ASSERT( !fc.RenameGroup(_T("foot/group1"), _T("group2")) );
+
+
+ fc.SetPath(_T("foot"));
+
+ // renaming to a name of existing group doesn't work
+ CPPUNIT_ASSERT( !fc.RenameGroup(_T("group1"), _T("group2")) );
+
+ // try exchanging the groups names and then restore them back
+ CPPUNIT_ASSERT( fc.RenameGroup(_T("group1"), _T("groupTmp")) );
+ wxVERIFY_FILECONFIG( _T("[foot]\n")
+ _T("entry=value\n")
+ _T("[foot/groupTmp]\n")
+ _T("[foot/groupTmp/subgroup]\n")
+ _T("subentry=subvalue\n")
+ _T("subentry2=subvalue2\n")
+ _T("[foot/group2]\n"),
+ fc );
+
+ CPPUNIT_ASSERT( fc.RenameGroup(_T("group2"), _T("group1")) );
+ wxVERIFY_FILECONFIG( _T("[foot]\n")
+ _T("entry=value\n")
+ _T("[foot/groupTmp]\n")
+ _T("[foot/groupTmp/subgroup]\n")
+ _T("subentry=subvalue\n")
+ _T("subentry2=subvalue2\n")
+ _T("[foot/group1]\n"),
+ fc );
+
+ CPPUNIT_ASSERT( fc.RenameGroup(_T("groupTmp"), _T("group2")) );
+ wxVERIFY_FILECONFIG( _T("[foot]\n")
+ _T("entry=value\n")
+ _T("[foot/group2]\n")
+ _T("[foot/group2/subgroup]\n")
+ _T("subentry=subvalue\n")
+ _T("subentry2=subvalue2\n")
+ _T("[foot/group1]\n"),
+ fc );
+
+ CPPUNIT_ASSERT( fc.RenameGroup(_T("group1"), _T("groupTmp")) );
+ wxVERIFY_FILECONFIG( _T("[foot]\n")
+ _T("entry=value\n")
+ _T("[foot/group2]\n")
+ _T("[foot/group2/subgroup]\n")
+ _T("subentry=subvalue\n")
+ _T("subentry2=subvalue2\n")
+ _T("[foot/groupTmp]\n"),
+ fc );
+
+ CPPUNIT_ASSERT( fc.RenameGroup(_T("group2"), _T("group1")) );
+ wxVERIFY_FILECONFIG( _T("[foot]\n")
+ _T("entry=value\n")
+ _T("[foot/group1]\n")
+ _T("[foot/group1/subgroup]\n")
+ _T("subentry=subvalue\n")
+ _T("subentry2=subvalue2\n")
+ _T("[foot/groupTmp]\n"),
+ fc );
+
+ CPPUNIT_ASSERT( fc.RenameGroup(_T("groupTmp"), _T("group2")) );
+ wxVERIFY_FILECONFIG( _T("[foot]\n")
+ _T("entry=value\n")
+ _T("[foot/group1]\n")
+ _T("[foot/group1/subgroup]\n")
+ _T("subentry=subvalue\n")
+ _T("subentry2=subvalue2\n")
+ _T("[foot/group2]\n"),
+ fc );
+}
+
+void FileConfigTestCase::CreateSubgroupAndEntries()
+{
+ wxFileConfig fc;
+ fc.Write(_T("sub/sub_first"), _T("sub_one"));
+ fc.Write(_T("first"), _T("one"));
+
+ wxVERIFY_FILECONFIG( _T("first=one\n")
+ _T("[sub]\n")
+ _T("sub_first=sub_one\n"),
+ fc );
+}
+
+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"));
+
+ wxVERIFY_FILECONFIG( _T("first=one\n")
+ _T("second=two\n")
+ _T("[sub]\n")
+ _T("sub_first=sub_one\n"),
+ fc );
+}
+
+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")));