]> git.saurik.com Git - wxWidgets.git/blobdiff - tests/fileconf/fileconftest.cpp
Finally fixed control scrolling
[wxWidgets.git] / tests / fileconf / fileconftest.cpp
index 942fdada9d72676cb0b063fd40534d1e45380f38..6f4aa5ff5357d1d215a02f01a6f8ef62a4730e44 100644 (file)
@@ -76,6 +76,7 @@ private:
         CPPUNIT_TEST( CreateEntriesAndSubgroup );
         CPPUNIT_TEST( CreateSubgroupAndEntries );
         CPPUNIT_TEST( DeleteLastGroup );
+        CPPUNIT_TEST( DeleteAndRecreateGroup );
     CPPUNIT_TEST_SUITE_END();
 
     void Path();
@@ -93,6 +94,7 @@ private:
     void CreateEntriesAndSubgroup();
     void CreateSubgroupAndEntries();
     void DeleteLastGroup();
+    void DeleteAndRecreateGroup();
 
     static wxString ChangePath(wxFileConfig& fc, const wxChar *path)
     {
@@ -309,7 +311,8 @@ void FileConfigTestCase::DeleteGroup()
                          _T("[root/group2]\n"),
                          fc );
 
-    CPPUNIT_ASSERT( fc.DeleteGroup(_T("root/group2")) );
+    // notice trailing slash: it should be ignored
+    CPPUNIT_ASSERT( fc.DeleteGroup(_T("root/group2/")) );
     wxVERIFY_FILECONFIG( _T("[root]\n")
                          _T("entry=value\n"),
                          fc );
@@ -372,6 +375,76 @@ void FileConfigTestCase::RenameGroup()
                          _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()
@@ -441,5 +514,29 @@ void FileConfigTestCase::DeleteLastGroup()
     (void) ::wxRemoveFile(wxFileConfig::GetLocalFileName(_T("deleteconftest")));
 }
 
+void FileConfigTestCase::DeleteAndRecreateGroup()
+{
+    static const wxChar *confInitial =
+        _T("[First]\n")
+        _T("Value1=Foo\n")
+        _T("[Second]\n")
+        _T("Value2=Bar\n");
+
+    wxStringInputStream sis(confInitial);
+    wxFileConfig fc(sis);
+
+    fc.DeleteGroup(_T("Second"));
+    wxVERIFY_FILECONFIG( _T("[First]\n")
+                         _T("Value1=Foo\n"),
+                         fc );
+
+    fc.Write(_T("Second/Value2"), _T("New"));
+    wxVERIFY_FILECONFIG( _T("[First]\n")
+                         _T("Value1=Foo\n")
+                         _T("[Second]\n")
+                         _T("Value2=New\n"),
+                         fc );
+}
+
 #endif // wxUSE_FILECONFIG