]> git.saurik.com Git - wxWidgets.git/blob - tests/config/regconf.cpp
Rewrite wxLogXXX() macros to avoid "ambiguous else" warnings.
[wxWidgets.git] / tests / config / regconf.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/config/regconf.cpp
3 // Purpose: wxRegConfig unit test
4 // Author: Francesco Montorsi (extracted from console sample)
5 // Created: 2010-06-02
6 // Copyright: (c) 2010 wxWidgets team
7 ///////////////////////////////////////////////////////////////////////////////
8
9 // ----------------------------------------------------------------------------
10 // headers
11 // ----------------------------------------------------------------------------
12
13 #include "testprec.h"
14
15 #ifdef __BORLANDC__
16 #pragma hdrstop
17 #endif
18
19 #if wxUSE_CONFIG && wxUSE_REGKEY
20
21 #ifndef WX_PRECOMP
22 #endif // WX_PRECOMP
23
24 #include "wx/msw/regconf.h"
25
26 // ----------------------------------------------------------------------------
27 // test class
28 // ----------------------------------------------------------------------------
29
30 class RegConfigTestCase : public CppUnit::TestCase
31 {
32 public:
33 RegConfigTestCase() { }
34
35 private:
36 CPPUNIT_TEST_SUITE( RegConfigTestCase );
37 CPPUNIT_TEST( ReadWrite );
38 CPPUNIT_TEST_SUITE_END();
39
40 void ReadWrite();
41
42 DECLARE_NO_COPY_CLASS(RegConfigTestCase)
43 };
44
45 // register in the unnamed registry so that these tests are run by default
46 CPPUNIT_TEST_SUITE_REGISTRATION( RegConfigTestCase );
47
48 // also include in its own registry so that these tests can be run alone
49 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( RegConfigTestCase, "RegConfigTestCase" );
50
51 void RegConfigTestCase::ReadWrite()
52 {
53 wxString app = wxT("wxRegConfigTestCase");
54 wxString vendor = wxT("wxWidgets");
55
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);
60
61 // test writing
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")) );
66
67 // test reading
68 wxString str;
69 long dummy;
70
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" );
78
79 config->DeleteAll();
80 delete config;
81 }
82
83 #endif // wxUSE_CONFIG && wxUSE_REGKEY
84