regconf.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. // headers
  10. // ----------------------------------------------------------------------------
  11. #include "testprec.h"
  12. #ifdef __BORLANDC__
  13. #pragma hdrstop
  14. #endif
  15. #if wxUSE_CONFIG && wxUSE_REGKEY
  16. #ifndef WX_PRECOMP
  17. #endif // WX_PRECOMP
  18. #include "wx/msw/regconf.h"
  19. // ----------------------------------------------------------------------------
  20. // test class
  21. // ----------------------------------------------------------------------------
  22. class RegConfigTestCase : public CppUnit::TestCase
  23. {
  24. public:
  25. RegConfigTestCase() { }
  26. private:
  27. CPPUNIT_TEST_SUITE( RegConfigTestCase );
  28. CPPUNIT_TEST( ReadWrite );
  29. CPPUNIT_TEST_SUITE_END();
  30. void ReadWrite();
  31. DECLARE_NO_COPY_CLASS(RegConfigTestCase)
  32. };
  33. // register in the unnamed registry so that these tests are run by default
  34. CPPUNIT_TEST_SUITE_REGISTRATION( RegConfigTestCase );
  35. // also include in its own registry so that these tests can be run alone
  36. CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( RegConfigTestCase, "RegConfigTestCase" );
  37. void RegConfigTestCase::ReadWrite()
  38. {
  39. wxString app = wxT("wxRegConfigTestCase");
  40. wxString vendor = wxT("wxWidgets");
  41. // NOTE: we use wxCONFIG_USE_LOCAL_FILE explicitly to test wxRegConfig
  42. // with something different from the default value wxCONFIG_USE_GLOBAL_FILE
  43. wxConfigBase *config = new wxRegConfig(app, vendor, wxT(""), wxT(""),
  44. wxCONFIG_USE_LOCAL_FILE);
  45. // test writing
  46. config->SetPath(wxT("/group1"));
  47. CPPUNIT_ASSERT( config->Write(wxT("entry1"), wxT("foo")) );
  48. config->SetPath(wxT("/group2"));
  49. CPPUNIT_ASSERT( config->Write(wxT("entry1"), wxT("bar")) );
  50. // test reading
  51. wxString str;
  52. long dummy;
  53. config->SetPath(wxT("/"));
  54. CPPUNIT_ASSERT( config->GetFirstGroup(str, dummy) );
  55. CPPUNIT_ASSERT( str == "group1" );
  56. CPPUNIT_ASSERT( config->Read(wxT("group1/entry1"), wxT("INVALID DEFAULT")) == "foo" );
  57. CPPUNIT_ASSERT( config->GetNextGroup(str, dummy) );
  58. CPPUNIT_ASSERT( str == "group2" );
  59. CPPUNIT_ASSERT( config->Read(wxT("group2/entry1"), wxT("INVALID DEFAULT")) == "bar" );
  60. config->DeleteAll();
  61. delete config;
  62. }
  63. #endif // wxUSE_CONFIG && wxUSE_REGKEY