]>
git.saurik.com Git - wxWidgets.git/blob - tests/config/regconf.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/config/regconf.cpp
3 // Purpose: wxRegConfig unit test
4 // Author: Francesco Montorsi (extracted from console sample)
6 // Copyright: (c) 2010 wxWidgets team
7 ///////////////////////////////////////////////////////////////////////////////
9 // ----------------------------------------------------------------------------
11 // ----------------------------------------------------------------------------
19 #if wxUSE_CONFIG && wxUSE_REGKEY
24 #include "wx/msw/regconf.h"
26 // ----------------------------------------------------------------------------
28 // ----------------------------------------------------------------------------
30 class RegConfigTestCase
: public CppUnit::TestCase
33 RegConfigTestCase() { }
36 CPPUNIT_TEST_SUITE( RegConfigTestCase
);
37 CPPUNIT_TEST( ReadWrite
);
38 CPPUNIT_TEST_SUITE_END();
42 DECLARE_NO_COPY_CLASS(RegConfigTestCase
)
45 // register in the unnamed registry so that these tests are run by default
46 CPPUNIT_TEST_SUITE_REGISTRATION( RegConfigTestCase
);
48 // also include in its own registry so that these tests can be run alone
49 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( RegConfigTestCase
, "RegConfigTestCase" );
51 void RegConfigTestCase::ReadWrite()
53 wxString app
= wxT("wxRegConfigTestCase");
54 wxString vendor
= wxT("wxWidgets");
56 // NOTE: we use wxCONFIG_USE_LOCAL_FILE explicitly to test wxRegConfig
57 // with something different from the default value wxCONFIG_USE_GLOBAL_FILE
58 wxConfigBase
*config
= new wxRegConfig(app
, vendor
, wxT(""), wxT(""),
59 wxCONFIG_USE_LOCAL_FILE
);
62 config
->SetPath(wxT("/group1"));
63 CPPUNIT_ASSERT( config
->Write(wxT("entry1"), wxT("foo")) );
64 config
->SetPath(wxT("/group2"));
65 CPPUNIT_ASSERT( config
->Write(wxT("entry1"), wxT("bar")) );
71 config
->SetPath(wxT("/"));
72 CPPUNIT_ASSERT( config
->GetFirstGroup(str
, dummy
) );
73 CPPUNIT_ASSERT( str
== "group1" );
74 CPPUNIT_ASSERT( config
->Read(wxT("group1/entry1"), wxT("INVALID DEFAULT")) == "foo" );
75 CPPUNIT_ASSERT( config
->GetNextGroup(str
, dummy
) );
76 CPPUNIT_ASSERT( str
== "group2" );
77 CPPUNIT_ASSERT( config
->Read(wxT("group2/entry1"), wxT("INVALID DEFAULT")) == "bar" );
83 #endif // wxUSE_CONFIG && wxUSE_REGKEY