]> git.saurik.com Git - wxWidgets.git/blobdiff - tests/fileconf/fileconftest.cpp
added support for user-defined types to wxConfig (patch 1753875)
[wxWidgets.git] / tests / fileconf / fileconftest.cpp
index fa10884e15adc5063f428c2ff12e0ab608cd5c69..d3694190478543c84f83da72e89a9f74d1f357da 100644 (file)
@@ -67,6 +67,7 @@ private:
         CPPUNIT_TEST( GetGroups );
         CPPUNIT_TEST( HasEntry );
         CPPUNIT_TEST( HasGroup );
+        CPPUNIT_TEST( Binary );
         CPPUNIT_TEST( Save );
         CPPUNIT_TEST( DeleteEntry );
         CPPUNIT_TEST( DeleteGroup );
@@ -76,6 +77,7 @@ private:
         CPPUNIT_TEST( CreateEntriesAndSubgroup );
         CPPUNIT_TEST( CreateSubgroupAndEntries );
         CPPUNIT_TEST( DeleteLastGroup );
+        CPPUNIT_TEST( DeleteAndRecreateGroup );
     CPPUNIT_TEST_SUITE_END();
 
     void Path();
@@ -84,6 +86,7 @@ private:
     void GetGroups();
     void HasEntry();
     void HasGroup();
+    void Binary();
     void Save();
     void DeleteEntry();
     void DeleteGroup();
@@ -93,6 +96,7 @@ private:
     void CreateEntriesAndSubgroup();
     void CreateSubgroupAndEntries();
     void DeleteLastGroup();
+    void DeleteAndRecreateGroup();
 
     static wxString ChangePath(wxFileConfig& fc, const wxChar *path)
     {
@@ -263,6 +267,30 @@ void FileConfigTestCase::HasGroup()
     CPPUNIT_ASSERT( !fc.HasGroup(_T("foot")) );
 }
 
+void FileConfigTestCase::Binary()
+{
+    wxStringInputStream sis(
+        "[root]\n"
+        "binary=Zm9vCg==\n"
+    );
+    wxFileConfig fc(sis);
+
+    wxMemoryBuffer buf;
+    fc.Read("/root/binary", &buf);
+
+    CPPUNIT_ASSERT( memcmp("foo\n", buf.GetData(), buf.GetDataLen()) == 0 );
+
+    buf.SetDataLen(0);
+    buf.AppendData("\0\1\2", 3);
+    fc.Write("/root/012", buf);
+    wxVERIFY_FILECONFIG(
+        "[root]\n"
+        "binary=Zm9vCg==\n"
+        "012=AAEC\n",
+        fc
+    );
+}
+
 void FileConfigTestCase::Save()
 {
     wxStringInputStream sis(testconfig);
@@ -512,5 +540,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