environ.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: tests/misc/environ.cpp
  3. // Purpose: Test wxGet/SetEnv
  4. // Author: Francesco Montorsi (extracted from console sample)
  5. // Created: 2010-06-13
  6. // Copyright: (c) 2010 wxWidgets team
  7. ///////////////////////////////////////////////////////////////////////////////
  8. // ----------------------------------------------------------------------------
  9. // headers
  10. // ----------------------------------------------------------------------------
  11. #include "testprec.h"
  12. #ifdef __BORLANDC__
  13. # pragma hdrstop
  14. #endif
  15. #include "wx/utils.h"
  16. // ----------------------------------------------------------------------------
  17. // test class
  18. // ----------------------------------------------------------------------------
  19. class EnvTestCase : public CppUnit::TestCase
  20. {
  21. public:
  22. EnvTestCase() { }
  23. private:
  24. CPPUNIT_TEST_SUITE( EnvTestCase );
  25. CPPUNIT_TEST( GetSet );
  26. CPPUNIT_TEST( Path );
  27. CPPUNIT_TEST_SUITE_END();
  28. void GetSet();
  29. void Path();
  30. DECLARE_NO_COPY_CLASS(EnvTestCase)
  31. };
  32. // register in the unnamed registry so that these tests are run by default
  33. CPPUNIT_TEST_SUITE_REGISTRATION( EnvTestCase );
  34. // also include in its own registry so that these tests can be run alone
  35. CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( EnvTestCase, "EnvTestCase" );
  36. void EnvTestCase::GetSet()
  37. {
  38. const wxChar *var = wxT("wxTestVar");
  39. wxString contents;
  40. CPPUNIT_ASSERT(!wxGetEnv(var, &contents));
  41. CPPUNIT_ASSERT(contents.empty());
  42. wxSetEnv(var, wxT("value for wxTestVar"));
  43. CPPUNIT_ASSERT(wxGetEnv(var, &contents));
  44. CPPUNIT_ASSERT(contents == wxT("value for wxTestVar"));
  45. wxSetEnv(var, wxT("another value"));
  46. CPPUNIT_ASSERT(wxGetEnv(var, &contents));
  47. CPPUNIT_ASSERT(contents == wxT("another value"));
  48. wxUnsetEnv(var);
  49. CPPUNIT_ASSERT(!wxGetEnv(var, &contents));
  50. }
  51. void EnvTestCase::Path()
  52. {
  53. wxString contents;
  54. CPPUNIT_ASSERT(wxGetEnv(wxT("PATH"), &contents));
  55. CPPUNIT_ASSERT(!contents.empty());
  56. }