+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") );
+}
+
+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")) );
+}
+