2004-10-03 19:17:19 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: tests/fileconf/fileconf.cpp
|
|
|
|
// Purpose: wxFileConf unit test
|
|
|
|
// Author: Vadim Zeitlin
|
|
|
|
// Created: 2004-09-19
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) 2004 Vadim Zeitlin
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// headers
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2004-11-22 00:00:19 -05:00
|
|
|
#include "testprec.h"
|
2004-10-03 19:17:19 -04:00
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if wxUSE_FILECONFIG
|
|
|
|
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#endif // WX_PRECOMP
|
|
|
|
|
|
|
|
#include "wx/fileconf.h"
|
|
|
|
#include "wx/sstream.h"
|
2005-01-05 02:28:04 -05:00
|
|
|
#include "wx/log.h"
|
2004-10-03 19:17:19 -04:00
|
|
|
|
|
|
|
static const wxChar *testconfig =
|
|
|
|
_T("[root]\n")
|
|
|
|
_T("entry=value\n")
|
|
|
|
_T("[root/group1]\n")
|
|
|
|
_T("[root/group1/subgroup]\n")
|
|
|
|
_T("subentry=subvalue\n")
|
2004-10-04 04:24:28 -04:00
|
|
|
_T("subentry2=subvalue2\n")
|
2004-10-03 19:17:19 -04:00
|
|
|
_T("[root/group2]\n")
|
|
|
|
;
|
|
|
|
|
2006-11-11 16:59:17 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// local functions
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
static wxString Dump(wxFileConfig& fc)
|
|
|
|
{
|
|
|
|
wxStringOutputStream sos;
|
|
|
|
fc.Save(sos);
|
|
|
|
return wxTextFile::Translate(sos.GetString(), wxTextFileType_Unix);
|
|
|
|
}
|
|
|
|
|
|
|
|
// helper macro to test wxFileConfig contents
|
|
|
|
#define wxVERIFY_FILECONFIG(t, fc) CPPUNIT_ASSERT_EQUAL(wxString(t), Dump(fc))
|
|
|
|
|
2004-10-03 19:17:19 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// test class
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class FileConfigTestCase : public CppUnit::TestCase
|
|
|
|
{
|
|
|
|
public:
|
2004-11-22 00:00:19 -05:00
|
|
|
FileConfigTestCase() { }
|
2004-10-03 19:17:19 -04:00
|
|
|
|
|
|
|
private:
|
|
|
|
CPPUNIT_TEST_SUITE( FileConfigTestCase );
|
2004-10-04 04:24:28 -04:00
|
|
|
CPPUNIT_TEST( Path );
|
2004-10-16 21:13:54 -04:00
|
|
|
CPPUNIT_TEST( AddEntries );
|
2004-10-04 04:24:28 -04:00
|
|
|
CPPUNIT_TEST( GetEntries );
|
|
|
|
CPPUNIT_TEST( GetGroups );
|
|
|
|
CPPUNIT_TEST( HasEntry );
|
2004-10-03 19:17:19 -04:00
|
|
|
CPPUNIT_TEST( HasGroup );
|
2007-07-11 20:11:03 -04:00
|
|
|
CPPUNIT_TEST( Binary );
|
2004-10-04 06:38:08 -04:00
|
|
|
CPPUNIT_TEST( Save );
|
|
|
|
CPPUNIT_TEST( DeleteEntry );
|
|
|
|
CPPUNIT_TEST( DeleteGroup );
|
|
|
|
CPPUNIT_TEST( DeleteAll );
|
|
|
|
CPPUNIT_TEST( RenameEntry );
|
|
|
|
CPPUNIT_TEST( RenameGroup );
|
2005-04-05 20:21:51 -04:00
|
|
|
CPPUNIT_TEST( CreateEntriesAndSubgroup );
|
|
|
|
CPPUNIT_TEST( CreateSubgroupAndEntries );
|
2004-12-22 06:12:05 -05:00
|
|
|
CPPUNIT_TEST( DeleteLastGroup );
|
2007-04-21 11:04:52 -04:00
|
|
|
CPPUNIT_TEST( DeleteAndRecreateGroup );
|
2004-10-03 19:17:19 -04:00
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
|
2004-10-04 04:24:28 -04:00
|
|
|
void Path();
|
2004-10-16 21:13:54 -04:00
|
|
|
void AddEntries();
|
2004-10-04 04:24:28 -04:00
|
|
|
void GetEntries();
|
|
|
|
void GetGroups();
|
|
|
|
void HasEntry();
|
2004-10-03 19:17:19 -04:00
|
|
|
void HasGroup();
|
2007-07-11 20:11:03 -04:00
|
|
|
void Binary();
|
2004-10-04 06:38:08 -04:00
|
|
|
void Save();
|
|
|
|
void DeleteEntry();
|
|
|
|
void DeleteGroup();
|
|
|
|
void DeleteAll();
|
|
|
|
void RenameEntry();
|
|
|
|
void RenameGroup();
|
2005-04-05 20:21:51 -04:00
|
|
|
void CreateEntriesAndSubgroup();
|
|
|
|
void CreateSubgroupAndEntries();
|
2004-12-22 06:12:05 -05:00
|
|
|
void DeleteLastGroup();
|
2007-04-21 11:04:52 -04:00
|
|
|
void DeleteAndRecreateGroup();
|
2004-10-03 19:17:19 -04:00
|
|
|
|
2004-10-04 04:24:28 -04:00
|
|
|
static wxString ChangePath(wxFileConfig& fc, const wxChar *path)
|
|
|
|
{
|
|
|
|
fc.SetPath(path);
|
|
|
|
|
|
|
|
return fc.GetPath();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CheckGroupEntries(const wxFileConfig& fc,
|
|
|
|
const wxChar *path,
|
|
|
|
size_t nEntries,
|
|
|
|
...);
|
|
|
|
void CheckGroupSubgroups(const wxFileConfig& fc,
|
|
|
|
const wxChar *path,
|
|
|
|
size_t nGroups,
|
|
|
|
...);
|
|
|
|
|
2004-10-03 19:17:19 -04:00
|
|
|
DECLARE_NO_COPY_CLASS(FileConfigTestCase)
|
|
|
|
};
|
|
|
|
|
|
|
|
// register in the unnamed registry so that these tests are run by default
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION( FileConfigTestCase );
|
|
|
|
|
|
|
|
// also include in it's own registry so that these tests can be run alone
|
|
|
|
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( FileConfigTestCase, "FileConfigTestCase" );
|
|
|
|
|
2004-10-04 04:24:28 -04:00
|
|
|
void FileConfigTestCase::Path()
|
|
|
|
{
|
|
|
|
wxStringInputStream sis(testconfig);
|
|
|
|
wxFileConfig fc(sis);
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT( ChangePath(fc, _T("")) == _T("") );
|
|
|
|
CPPUNIT_ASSERT( ChangePath(fc, _T("/")) == _T("") );
|
|
|
|
CPPUNIT_ASSERT( ChangePath(fc, _T("root")) == _T("/root") );
|
|
|
|
CPPUNIT_ASSERT( ChangePath(fc, _T("/root")) == _T("/root") );
|
|
|
|
CPPUNIT_ASSERT( ChangePath(fc, _T("/root/group1/subgroup")) == _T("/root/group1/subgroup") );
|
|
|
|
CPPUNIT_ASSERT( ChangePath(fc, _T("/root/group2")) == _T("/root/group2") );
|
|
|
|
}
|
|
|
|
|
2004-10-16 21:13:54 -04:00
|
|
|
void FileConfigTestCase::AddEntries()
|
|
|
|
{
|
|
|
|
wxFileConfig fc;
|
|
|
|
|
2006-11-11 16:59:17 -05:00
|
|
|
wxVERIFY_FILECONFIG( _T(""), fc );
|
2004-10-16 21:13:54 -04:00
|
|
|
|
|
|
|
fc.Write(_T("/Foo"), _T("foo"));
|
2006-11-11 16:59:17 -05:00
|
|
|
wxVERIFY_FILECONFIG( _T("Foo=foo\n"), fc );
|
2004-10-16 21:13:54 -04:00
|
|
|
|
|
|
|
fc.Write(_T("/Bar/Baz"), _T("baz"));
|
2006-11-11 16:59:17 -05:00
|
|
|
wxVERIFY_FILECONFIG( _T("Foo=foo\n[Bar]\nBaz=baz\n"), fc );
|
2004-10-16 21:13:54 -04:00
|
|
|
|
|
|
|
fc.DeleteAll();
|
2006-11-11 16:59:17 -05:00
|
|
|
wxVERIFY_FILECONFIG( _T(""), fc );
|
2004-10-16 21:13:54 -04:00
|
|
|
|
|
|
|
fc.Write(_T("/Bar/Baz"), _T("baz"));
|
2006-11-11 16:59:17 -05:00
|
|
|
wxVERIFY_FILECONFIG( _T("[Bar]\nBaz=baz\n"), fc );
|
2004-10-16 21:13:54 -04:00
|
|
|
|
|
|
|
fc.Write(_T("/Foo"), _T("foo"));
|
2006-11-11 16:59:17 -05:00
|
|
|
wxVERIFY_FILECONFIG( _T("Foo=foo\n[Bar]\nBaz=baz\n"), fc );
|
2004-10-16 21:13:54 -04:00
|
|
|
}
|
|
|
|
|
2004-10-04 04:24:28 -04:00
|
|
|
void
|
|
|
|
FileConfigTestCase::CheckGroupEntries(const wxFileConfig& fc,
|
|
|
|
const wxChar *path,
|
|
|
|
size_t nEntries,
|
|
|
|
...)
|
|
|
|
{
|
|
|
|
wxConfigPathChanger change(&fc, wxString(path) + _T("/"));
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT( fc.GetNumberOfEntries() == nEntries );
|
|
|
|
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, nEntries);
|
|
|
|
|
|
|
|
long cookie;
|
|
|
|
wxString name;
|
|
|
|
for ( bool cont = fc.GetFirstEntry(name, cookie);
|
|
|
|
cont;
|
|
|
|
cont = fc.GetNextEntry(name, cookie), nEntries-- )
|
|
|
|
{
|
|
|
|
CPPUNIT_ASSERT( name == va_arg(ap, wxChar *) );
|
|
|
|
}
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT( nEntries == 0 );
|
|
|
|
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FileConfigTestCase::CheckGroupSubgroups(const wxFileConfig& fc,
|
|
|
|
const wxChar *path,
|
|
|
|
size_t nGroups,
|
|
|
|
...)
|
|
|
|
{
|
|
|
|
wxConfigPathChanger change(&fc, wxString(path) + _T("/"));
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT( fc.GetNumberOfGroups() == nGroups );
|
|
|
|
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, nGroups);
|
|
|
|
|
|
|
|
long cookie;
|
|
|
|
wxString name;
|
|
|
|
for ( bool cont = fc.GetFirstGroup(name, cookie);
|
|
|
|
cont;
|
|
|
|
cont = fc.GetNextGroup(name, cookie), nGroups-- )
|
|
|
|
{
|
|
|
|
CPPUNIT_ASSERT( name == va_arg(ap, wxChar *) );
|
|
|
|
}
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT( nGroups == 0 );
|
|
|
|
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FileConfigTestCase::GetEntries()
|
|
|
|
{
|
|
|
|
wxStringInputStream sis(testconfig);
|
|
|
|
wxFileConfig fc(sis);
|
|
|
|
|
|
|
|
CheckGroupEntries(fc, _T(""), 0);
|
|
|
|
CheckGroupEntries(fc, _T("/root"), 1, _T("entry"));
|
|
|
|
CheckGroupEntries(fc, _T("/root/group1"), 0);
|
|
|
|
CheckGroupEntries(fc, _T("/root/group1/subgroup"),
|
|
|
|
2, _T("subentry"), _T("subentry2"));
|
|
|
|
}
|
|
|
|
|
|
|
|
void FileConfigTestCase::GetGroups()
|
|
|
|
{
|
|
|
|
wxStringInputStream sis(testconfig);
|
|
|
|
wxFileConfig fc(sis);
|
|
|
|
|
|
|
|
CheckGroupSubgroups(fc, _T(""), 1, _T("root"));
|
|
|
|
CheckGroupSubgroups(fc, _T("/root"), 2, _T("group1"), _T("group2"));
|
|
|
|
CheckGroupSubgroups(fc, _T("/root/group1"), 1, _T("subgroup"));
|
|
|
|
CheckGroupSubgroups(fc, _T("/root/group2"), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FileConfigTestCase::HasEntry()
|
|
|
|
{
|
|
|
|
wxStringInputStream sis(testconfig);
|
|
|
|
wxFileConfig fc(sis);
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT( !fc.HasEntry(_T("root")) );
|
|
|
|
CPPUNIT_ASSERT( fc.HasEntry(_T("root/entry")) );
|
|
|
|
CPPUNIT_ASSERT( fc.HasEntry(_T("/root/entry")) );
|
|
|
|
CPPUNIT_ASSERT( fc.HasEntry(_T("root/group1/subgroup/subentry")) );
|
|
|
|
CPPUNIT_ASSERT( !fc.HasEntry(_T("")) );
|
|
|
|
CPPUNIT_ASSERT( !fc.HasEntry(_T("root/group1")) );
|
|
|
|
CPPUNIT_ASSERT( !fc.HasEntry(_T("subgroup/subentry")) );
|
2006-07-14 18:48:00 -04:00
|
|
|
CPPUNIT_ASSERT( !fc.HasEntry(_T("/root/no_such_group/entry")) );
|
|
|
|
CPPUNIT_ASSERT( !fc.HasGroup(_T("/root/no_such_group")) );
|
2004-10-04 04:24:28 -04:00
|
|
|
}
|
|
|
|
|
2004-10-03 19:17:19 -04:00
|
|
|
void FileConfigTestCase::HasGroup()
|
|
|
|
{
|
|
|
|
wxStringInputStream sis(testconfig);
|
|
|
|
wxFileConfig fc(sis);
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT( fc.HasGroup(_T("root")) );
|
|
|
|
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("")) );
|
|
|
|
CPPUNIT_ASSERT( !fc.HasGroup(_T("root/group")) );
|
|
|
|
CPPUNIT_ASSERT( !fc.HasGroup(_T("root//subgroup")) );
|
2005-07-01 14:04:11 -04:00
|
|
|
CPPUNIT_ASSERT( !fc.HasGroup(_T("foot/subgroup")) );
|
|
|
|
CPPUNIT_ASSERT( !fc.HasGroup(_T("foot")) );
|
2004-10-03 19:17:19 -04:00
|
|
|
}
|
|
|
|
|
2007-07-11 20:11:03 -04:00
|
|
|
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
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2004-10-04 06:38:08 -04:00
|
|
|
void FileConfigTestCase::Save()
|
|
|
|
{
|
|
|
|
wxStringInputStream sis(testconfig);
|
|
|
|
wxFileConfig fc(sis);
|
2006-11-11 16:59:17 -05:00
|
|
|
wxVERIFY_FILECONFIG( testconfig, fc );
|
2004-10-04 06:38:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void FileConfigTestCase::DeleteEntry()
|
|
|
|
{
|
|
|
|
wxStringInputStream sis(testconfig);
|
|
|
|
wxFileConfig fc(sis);
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT( !fc.DeleteEntry(_T("foo")) );
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT( fc.DeleteEntry(_T("root/group1/subgroup/subentry")) );
|
2006-11-11 16:59:17 -05:00
|
|
|
wxVERIFY_FILECONFIG( _T("[root]\n")
|
|
|
|
_T("entry=value\n")
|
|
|
|
_T("[root/group1]\n")
|
|
|
|
_T("[root/group1/subgroup]\n")
|
|
|
|
_T("subentry2=subvalue2\n")
|
|
|
|
_T("[root/group2]\n"),
|
|
|
|
fc );
|
2004-10-04 06:38:08 -04:00
|
|
|
|
|
|
|
// 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")) );
|
2006-11-11 16:59:17 -05:00
|
|
|
wxVERIFY_FILECONFIG( _T("[root]\n")
|
|
|
|
_T("entry=value\n")
|
|
|
|
_T("[root/group1]\n")
|
|
|
|
_T("[root/group2]\n"),
|
|
|
|
fc );
|
2004-10-04 06:38:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void FileConfigTestCase::DeleteGroup()
|
|
|
|
{
|
|
|
|
wxStringInputStream sis(testconfig);
|
|
|
|
wxFileConfig fc(sis);
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT( !fc.DeleteGroup(_T("foo")) );
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT( fc.DeleteGroup(_T("root/group1")) );
|
2006-11-11 16:59:17 -05:00
|
|
|
wxVERIFY_FILECONFIG( _T("[root]\n")
|
|
|
|
_T("entry=value\n")
|
|
|
|
_T("[root/group2]\n"),
|
|
|
|
fc );
|
2004-10-04 06:38:08 -04:00
|
|
|
|
2007-01-07 11:36:54 -05:00
|
|
|
// notice trailing slash: it should be ignored
|
|
|
|
CPPUNIT_ASSERT( fc.DeleteGroup(_T("root/group2/")) );
|
2006-11-11 16:59:17 -05:00
|
|
|
wxVERIFY_FILECONFIG( _T("[root]\n")
|
|
|
|
_T("entry=value\n"),
|
|
|
|
fc );
|
2004-10-04 06:38:08 -04:00
|
|
|
|
|
|
|
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")) );
|
2006-11-11 16:59:17 -05:00
|
|
|
wxVERIFY_FILECONFIG( _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 );
|
2004-10-04 06:38:08 -04:00
|
|
|
|
|
|
|
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")) );
|
2006-11-11 16:59:17 -05:00
|
|
|
wxVERIFY_FILECONFIG( _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"),
|
|
|
|
fc );
|
2004-10-04 06:38:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void FileConfigTestCase::RenameGroup()
|
|
|
|
{
|
|
|
|
wxStringInputStream sis(testconfig);
|
|
|
|
wxFileConfig fc(sis);
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT( fc.RenameGroup(_T("root"), _T("foot")) );
|
2006-11-11 16:59:17 -05:00
|
|
|
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 );
|
2006-11-11 17:00:59 -05:00
|
|
|
|
2006-11-11 17:12:34 -05:00
|
|
|
// renaming a path doesn't work, it must be the immediate group
|
|
|
|
CPPUNIT_ASSERT( !fc.RenameGroup(_T("foot/group1"), _T("group2")) );
|
|
|
|
|
|
|
|
|
2006-11-11 17:00:59 -05:00
|
|
|
fc.SetPath(_T("foot"));
|
|
|
|
|
2006-11-11 17:12:34 -05:00
|
|
|
// 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
|
2006-11-11 17:00:59 -05:00
|
|
|
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 );
|
2006-11-11 17:12:34 -05:00
|
|
|
|
|
|
|
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 );
|
2004-10-04 06:38:08 -04:00
|
|
|
}
|
|
|
|
|
2005-04-05 20:21:51 -04:00
|
|
|
void FileConfigTestCase::CreateSubgroupAndEntries()
|
|
|
|
{
|
|
|
|
wxFileConfig fc;
|
|
|
|
fc.Write(_T("sub/sub_first"), _T("sub_one"));
|
|
|
|
fc.Write(_T("first"), _T("one"));
|
|
|
|
|
2006-11-11 16:59:17 -05:00
|
|
|
wxVERIFY_FILECONFIG( _T("first=one\n")
|
|
|
|
_T("[sub]\n")
|
|
|
|
_T("sub_first=sub_one\n"),
|
|
|
|
fc );
|
2005-04-05 20:21:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
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"));
|
|
|
|
|
2006-11-11 16:59:17 -05:00
|
|
|
wxVERIFY_FILECONFIG( _T("first=one\n")
|
|
|
|
_T("second=two\n")
|
|
|
|
_T("[sub]\n")
|
|
|
|
_T("sub_first=sub_one\n"),
|
|
|
|
fc );
|
2005-04-05 20:21:51 -04:00
|
|
|
}
|
2004-12-22 06:12:05 -05:00
|
|
|
|
|
|
|
static void EmptyConfigAndWriteKey()
|
|
|
|
{
|
|
|
|
wxFileConfig fc(_T("deleteconftest"));
|
|
|
|
|
|
|
|
const wxString groupPath = _T("/root");
|
|
|
|
|
2005-04-05 20:21:51 -04:00
|
|
|
if ( fc.Exists(groupPath) )
|
2004-12-22 06:12:05 -05:00
|
|
|
{
|
|
|
|
// 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;
|
2005-04-05 20:21:51 -04:00
|
|
|
(void) ::wxRemoveFile(wxFileConfig::GetLocalFileName(_T("deleteconftest")));
|
2004-12-22 06:12:05 -05:00
|
|
|
}
|
|
|
|
|
2007-04-21 11:04:52 -04:00
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
2004-10-03 19:17:19 -04:00
|
|
|
#endif // wxUSE_FILECONFIG
|
|
|
|
|