added tests for deleting and renaming entries and groups
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@29644 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -53,6 +53,12 @@ private:
|
||||
CPPUNIT_TEST( GetGroups );
|
||||
CPPUNIT_TEST( HasEntry );
|
||||
CPPUNIT_TEST( HasGroup );
|
||||
CPPUNIT_TEST( Save );
|
||||
CPPUNIT_TEST( DeleteEntry );
|
||||
CPPUNIT_TEST( DeleteGroup );
|
||||
CPPUNIT_TEST( DeleteAll );
|
||||
CPPUNIT_TEST( RenameEntry );
|
||||
CPPUNIT_TEST( RenameGroup );
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
void Path();
|
||||
@@ -60,6 +66,12 @@ private:
|
||||
void GetGroups();
|
||||
void HasEntry();
|
||||
void HasGroup();
|
||||
void Save();
|
||||
void DeleteEntry();
|
||||
void DeleteGroup();
|
||||
void DeleteAll();
|
||||
void RenameEntry();
|
||||
void RenameGroup();
|
||||
|
||||
static wxString ChangePath(wxFileConfig& fc, const wxChar *path)
|
||||
{
|
||||
@@ -68,6 +80,13 @@ private:
|
||||
return fc.GetPath();
|
||||
}
|
||||
|
||||
static wxString Dump(wxFileConfig& fc)
|
||||
{
|
||||
wxStringOutputStream sos;
|
||||
fc.Save(sos);
|
||||
return wxTextFile::Translate(sos.GetString(), wxTextFileType_Unix);
|
||||
}
|
||||
|
||||
void CheckGroupEntries(const wxFileConfig& fc,
|
||||
const wxChar *path,
|
||||
size_t nEntries,
|
||||
@@ -205,5 +224,109 @@ void FileConfigTestCase::HasGroup()
|
||||
CPPUNIT_ASSERT( !fc.HasGroup(_T("root//subgroup")) );
|
||||
}
|
||||
|
||||
void FileConfigTestCase::Save()
|
||||
{
|
||||
wxStringInputStream sis(testconfig);
|
||||
wxFileConfig fc(sis);
|
||||
CPPUNIT_ASSERT( Dump(fc) == testconfig );
|
||||
}
|
||||
|
||||
void FileConfigTestCase::DeleteEntry()
|
||||
{
|
||||
wxStringInputStream sis(testconfig);
|
||||
wxFileConfig fc(sis);
|
||||
|
||||
CPPUNIT_ASSERT( !fc.DeleteEntry(_T("foo")) );
|
||||
|
||||
CPPUNIT_ASSERT( fc.DeleteEntry(_T("root/group1/subgroup/subentry")) );
|
||||
CPPUNIT_ASSERT( Dump(fc) == _T("[root]\n")
|
||||
_T("entry=value\n")
|
||||
_T("[root/group1]\n")
|
||||
_T("[root/group1/subgroup]\n")
|
||||
_T("subentry2=subvalue2\n")
|
||||
_T("[root/group2]\n") );
|
||||
|
||||
// group should be deleted now as well as it became empty
|
||||
wxConfigPathChanger change(&fc, _T("root/group1/subgroup/subentry2"));
|
||||
CPPUNIT_ASSERT( fc.DeleteEntry(_T("subentry2")) );
|
||||
CPPUNIT_ASSERT( Dump(fc) == _T("[root]\n")
|
||||
_T("entry=value\n")
|
||||
_T("[root/group1]\n")
|
||||
_T("[root/group2]\n") );
|
||||
}
|
||||
|
||||
void FileConfigTestCase::DeleteGroup()
|
||||
{
|
||||
wxStringInputStream sis(testconfig);
|
||||
wxFileConfig fc(sis);
|
||||
|
||||
CPPUNIT_ASSERT( !fc.DeleteGroup(_T("foo")) );
|
||||
|
||||
CPPUNIT_ASSERT( fc.DeleteGroup(_T("root/group1")) );
|
||||
CPPUNIT_ASSERT( Dump(fc) == _T("[root]\n")
|
||||
_T("entry=value\n")
|
||||
_T("[root/group2]\n") );
|
||||
|
||||
CPPUNIT_ASSERT( fc.DeleteGroup(_T("root/group2")) );
|
||||
CPPUNIT_ASSERT( Dump(fc) == _T("[root]\n")
|
||||
_T("entry=value\n") );
|
||||
|
||||
CPPUNIT_ASSERT( fc.DeleteGroup(_T("root")) );
|
||||
CPPUNIT_ASSERT( Dump(fc).empty() );
|
||||
}
|
||||
|
||||
void FileConfigTestCase::DeleteAll()
|
||||
{
|
||||
wxStringInputStream sis(testconfig);
|
||||
wxFileConfig fc(sis);
|
||||
|
||||
CPPUNIT_ASSERT( fc.DeleteAll() );
|
||||
CPPUNIT_ASSERT( Dump(fc).empty() );
|
||||
}
|
||||
|
||||
void FileConfigTestCase::RenameEntry()
|
||||
{
|
||||
wxStringInputStream sis(testconfig);
|
||||
wxFileConfig fc(sis);
|
||||
|
||||
fc.SetPath(_T("root"));
|
||||
CPPUNIT_ASSERT( fc.RenameEntry(_T("entry"), _T("newname")) );
|
||||
CPPUNIT_ASSERT( Dump(fc) == _T("[root]\n")
|
||||
_T("newname=value\n")
|
||||
_T("[root/group1]\n")
|
||||
_T("[root/group1/subgroup]\n")
|
||||
_T("subentry=subvalue\n")
|
||||
_T("subentry2=subvalue2\n")
|
||||
_T("[root/group2]\n") );
|
||||
|
||||
fc.SetPath(_T("group1/subgroup"));
|
||||
CPPUNIT_ASSERT( !fc.RenameEntry(_T("entry"), _T("newname")) );
|
||||
CPPUNIT_ASSERT( !fc.RenameEntry(_T("subentry"), _T("subentry2")) );
|
||||
|
||||
CPPUNIT_ASSERT( fc.RenameEntry(_T("subentry"), _T("subentry1")) );
|
||||
CPPUNIT_ASSERT( Dump(fc) == _T("[root]\n")
|
||||
_T("newname=value\n")
|
||||
_T("[root/group1]\n")
|
||||
_T("[root/group1/subgroup]\n")
|
||||
_T("subentry2=subvalue2\n")
|
||||
_T("subentry1=subvalue\n")
|
||||
_T("[root/group2]\n") );
|
||||
}
|
||||
|
||||
void FileConfigTestCase::RenameGroup()
|
||||
{
|
||||
wxStringInputStream sis(testconfig);
|
||||
wxFileConfig fc(sis);
|
||||
|
||||
CPPUNIT_ASSERT( fc.RenameGroup(_T("root"), _T("foot")) );
|
||||
CPPUNIT_ASSERT( Dump(fc) == _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") );
|
||||
}
|
||||
|
||||
#endif // wxUSE_FILECONFIG
|
||||
|
||||
|
Reference in New Issue
Block a user