]> git.saurik.com Git - wxWidgets.git/blobdiff - tests/fileconf/fileconftest.cpp
non-PCH build fix (according to Tinderbox).
[wxWidgets.git] / tests / fileconf / fileconftest.cpp
index 587b980f5dad68d32cec9e8335ff4fff102b2d67..82a983500b2c358074df54e4633c84d779f76152 100644 (file)
@@ -24,6 +24,7 @@
 
 #include "wx/fileconf.h"
 #include "wx/sstream.h"
 
 #include "wx/fileconf.h"
 #include "wx/sstream.h"
+#include "wx/log.h"
 
 static const wxChar *testconfig =
 _T("[root]\n")
 
 static const wxChar *testconfig =
 _T("[root]\n")
@@ -58,6 +59,8 @@ private:
         CPPUNIT_TEST( DeleteAll );
         CPPUNIT_TEST( RenameEntry );
         CPPUNIT_TEST( RenameGroup );
         CPPUNIT_TEST( DeleteAll );
         CPPUNIT_TEST( RenameEntry );
         CPPUNIT_TEST( RenameGroup );
+        CPPUNIT_TEST( CreateEntriesAndSubgroup );
+        CPPUNIT_TEST( CreateSubgroupAndEntries );
         CPPUNIT_TEST( DeleteLastGroup );
     CPPUNIT_TEST_SUITE_END();
 
         CPPUNIT_TEST( DeleteLastGroup );
     CPPUNIT_TEST_SUITE_END();
 
@@ -73,6 +76,8 @@ private:
     void DeleteAll();
     void RenameEntry();
     void RenameGroup();
     void DeleteAll();
     void RenameEntry();
     void RenameGroup();
+    void CreateEntriesAndSubgroup();
+    void CreateSubgroupAndEntries();
     void DeleteLastGroup();
 
     static wxString ChangePath(wxFileConfig& fc, const wxChar *path)
     void DeleteLastGroup();
 
     static wxString ChangePath(wxFileConfig& fc, const wxChar *path)
@@ -231,6 +236,8 @@ void FileConfigTestCase::HasEntry()
     CPPUNIT_ASSERT( !fc.HasEntry(_T("")) );
     CPPUNIT_ASSERT( !fc.HasEntry(_T("root/group1")) );
     CPPUNIT_ASSERT( !fc.HasEntry(_T("subgroup/subentry")) );
     CPPUNIT_ASSERT( !fc.HasEntry(_T("")) );
     CPPUNIT_ASSERT( !fc.HasEntry(_T("root/group1")) );
     CPPUNIT_ASSERT( !fc.HasEntry(_T("subgroup/subentry")) );
+    CPPUNIT_ASSERT( !fc.HasEntry(_T("/root/no_such_group/entry")) );
+    CPPUNIT_ASSERT( !fc.HasGroup(_T("/root/no_such_group")) );
 }
 
 void FileConfigTestCase::HasGroup()
 }
 
 void FileConfigTestCase::HasGroup()
@@ -242,10 +249,11 @@ void FileConfigTestCase::HasGroup()
     CPPUNIT_ASSERT( fc.HasGroup(_T("root/group1")) );
     CPPUNIT_ASSERT( fc.HasGroup(_T("root/group1/subgroup")) );
     CPPUNIT_ASSERT( fc.HasGroup(_T("root/group2")) );
     CPPUNIT_ASSERT( fc.HasGroup(_T("root/group1")) );
     CPPUNIT_ASSERT( fc.HasGroup(_T("root/group1/subgroup")) );
     CPPUNIT_ASSERT( fc.HasGroup(_T("root/group2")) );
-    CPPUNIT_ASSERT( !fc.HasGroup(_T("foot")) );
     CPPUNIT_ASSERT( !fc.HasGroup(_T("")) );
     CPPUNIT_ASSERT( !fc.HasGroup(_T("root/group")) );
     CPPUNIT_ASSERT( !fc.HasGroup(_T("root//subgroup")) );
     CPPUNIT_ASSERT( !fc.HasGroup(_T("")) );
     CPPUNIT_ASSERT( !fc.HasGroup(_T("root/group")) );
     CPPUNIT_ASSERT( !fc.HasGroup(_T("root//subgroup")) );
+    CPPUNIT_ASSERT( !fc.HasGroup(_T("foot/subgroup")) );
+    CPPUNIT_ASSERT( !fc.HasGroup(_T("foot")) );
 }
 
 void FileConfigTestCase::Save()
 }
 
 void FileConfigTestCase::Save()
@@ -352,6 +360,29 @@ void FileConfigTestCase::RenameGroup()
                                 _T("[foot/group2]\n") );
 }
 
                                 _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()
 {
 
 static void EmptyConfigAndWriteKey()
 {
@@ -359,7 +390,7 @@ static void EmptyConfigAndWriteKey()
 
     const wxString groupPath = _T("/root");
 
 
     const wxString groupPath = _T("/root");
 
-    if (fc.Exists(groupPath))
+    if ( fc.Exists(groupPath) )
     {
         // using DeleteGroup exposes the problem, using DeleteAll doesn't
         CPPUNIT_ASSERT( fc.DeleteGroup(groupPath) );
     {
         // using DeleteGroup exposes the problem, using DeleteAll doesn't
         CPPUNIT_ASSERT( fc.DeleteGroup(groupPath) );
@@ -391,8 +422,7 @@ void FileConfigTestCase::DeleteLastGroup()
 
     // clean up
     wxLogNull noLogging;
 
     // clean up
     wxLogNull noLogging;
-    (void) ::wxRemoveFile(
-        wxFileConfig::GetLocalFileName(_T("deleteconftest")) );
+    (void) ::wxRemoveFile(wxFileConfig::GetLocalFileName(_T("deleteconftest")));
 }
 
 #endif // wxUSE_FILECONFIG
 }
 
 #endif // wxUSE_FILECONFIG