]>
git.saurik.com Git - wxWidgets.git/blob - tests/config/regconf.cpp
296b208f679f94a1f5c4fe841858893b82ee1626
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/config/regconf.cpp
3 // Purpose: wxRegConfig unit test
4 // Author: Francesco Montorsi (extracted from console sample)
7 // Copyright: (c) 2010 wxWidgets team
8 ///////////////////////////////////////////////////////////////////////////////
10 // ----------------------------------------------------------------------------
12 // ----------------------------------------------------------------------------
20 #if wxUSE_CONFIG && wxUSE_REGKEY
25 #include "wx/msw/regconf.h"
27 // ----------------------------------------------------------------------------
29 // ----------------------------------------------------------------------------
31 class RegConfigTestCase
: public CppUnit::TestCase
34 RegConfigTestCase() { }
37 CPPUNIT_TEST_SUITE( RegConfigTestCase
);
38 CPPUNIT_TEST( ReadWrite
);
39 CPPUNIT_TEST_SUITE_END();
43 DECLARE_NO_COPY_CLASS(RegConfigTestCase
)
46 // register in the unnamed registry so that these tests are run by default
47 CPPUNIT_TEST_SUITE_REGISTRATION( RegConfigTestCase
);
49 // also include in its own registry so that these tests can be run alone
50 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( RegConfigTestCase
, "RegConfigTestCase" );
52 void RegConfigTestCase::ReadWrite()
54 wxString app
= wxT("wxRegConfigTestCase");
55 wxString vendor
= wxT("wxWidgets");
57 // NOTE: we use wxCONFIG_USE_LOCAL_FILE explicitly to test wxRegConfig
58 // with something different from the default value wxCONFIG_USE_GLOBAL_FILE
59 wxConfigBase
*config
= new wxRegConfig(app
, vendor
, wxT(""), wxT(""),
60 wxCONFIG_USE_LOCAL_FILE
);
63 config
->SetPath(wxT("/group1"));
64 CPPUNIT_ASSERT( config
->Write(wxT("entry1"), wxT("foo")) );
65 config
->SetPath(wxT("/group2"));
66 CPPUNIT_ASSERT( config
->Write(wxT("entry1"), wxT("bar")) );
72 config
->SetPath(wxT("/"));
73 CPPUNIT_ASSERT( config
->GetFirstGroup(str
, dummy
) );
74 CPPUNIT_ASSERT( str
== "group1" );
75 CPPUNIT_ASSERT( config
->Read(wxT("group1/entry1"), wxT("INVALID DEFAULT")) == "foo" );
76 CPPUNIT_ASSERT( config
->GetNextGroup(str
, dummy
) );
77 CPPUNIT_ASSERT( str
== "group2" );
78 CPPUNIT_ASSERT( config
->Read(wxT("group2/entry1"), wxT("INVALID DEFAULT")) == "bar" );
84 #endif // wxUSE_CONFIG && wxUSE_REGKEY