]> git.saurik.com Git - wxWidgets.git/commitdiff
added FileConfig test case exposing a problem with deleting the last group
authorDimitri Schoolwerth <dimitri.schoolwerth@gmail.com>
Wed, 22 Dec 2004 11:12:05 +0000 (11:12 +0000)
committerDimitri Schoolwerth <dimitri.schoolwerth@gmail.com>
Wed, 22 Dec 2004 11:12:05 +0000 (11:12 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@31117 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

tests/fileconf/fileconftest.cpp

index a2fb2e61bf375b26274c23519f11a668fe67aff6..587b980f5dad68d32cec9e8335ff4fff102b2d67 100644 (file)
@@ -58,6 +58,7 @@ private:
         CPPUNIT_TEST( DeleteAll );
         CPPUNIT_TEST( RenameEntry );
         CPPUNIT_TEST( RenameGroup );
+        CPPUNIT_TEST( DeleteLastGroup );
     CPPUNIT_TEST_SUITE_END();
 
     void Path();
@@ -72,6 +73,7 @@ private:
     void DeleteAll();
     void RenameEntry();
     void RenameGroup();
+    void DeleteLastGroup();
 
     static wxString ChangePath(wxFileConfig& fc, const wxChar *path)
     {
@@ -350,5 +352,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