]>
Commit | Line | Data |
---|---|---|
69fc8587 FM |
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 | |
69fc8587 FM |
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 | #include "wx/utils.h" | |
20 | ||
21 | // ---------------------------------------------------------------------------- | |
22 | // test class | |
23 | // ---------------------------------------------------------------------------- | |
24 | ||
25 | class EnvTestCase : public CppUnit::TestCase | |
26 | { | |
27 | public: | |
28 | EnvTestCase() { } | |
29 | ||
30 | private: | |
31 | CPPUNIT_TEST_SUITE( EnvTestCase ); | |
32 | CPPUNIT_TEST( GetSet ); | |
33 | CPPUNIT_TEST( Path ); | |
34 | CPPUNIT_TEST_SUITE_END(); | |
35 | ||
36 | void GetSet(); | |
37 | void Path(); | |
38 | ||
39 | DECLARE_NO_COPY_CLASS(EnvTestCase) | |
40 | }; | |
41 | ||
42 | // register in the unnamed registry so that these tests are run by default | |
43 | CPPUNIT_TEST_SUITE_REGISTRATION( EnvTestCase ); | |
44 | ||
e3778b4d | 45 | // also include in its own registry so that these tests can be run alone |
69fc8587 FM |
46 | CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( EnvTestCase, "EnvTestCase" ); |
47 | ||
48 | void EnvTestCase::GetSet() | |
49 | { | |
50 | const wxChar *var = wxT("wxTestVar"); | |
51 | wxString contents; | |
52 | ||
53 | CPPUNIT_ASSERT(!wxGetEnv(var, &contents)); | |
54 | CPPUNIT_ASSERT(contents.empty()); | |
55 | ||
56 | wxSetEnv(var, wxT("value for wxTestVar")); | |
57 | CPPUNIT_ASSERT(wxGetEnv(var, &contents)); | |
58 | CPPUNIT_ASSERT(contents == wxT("value for wxTestVar")); | |
59 | ||
60 | wxSetEnv(var, wxT("another value")); | |
61 | CPPUNIT_ASSERT(wxGetEnv(var, &contents)); | |
62 | CPPUNIT_ASSERT(contents == wxT("another value")); | |
63 | ||
64 | wxUnsetEnv(var); | |
65 | CPPUNIT_ASSERT(!wxGetEnv(var, &contents)); | |
66 | } | |
67 | ||
68 | void EnvTestCase::Path() | |
69 | { | |
70 | wxString contents; | |
71 | ||
72 | CPPUNIT_ASSERT(wxGetEnv(wxT("PATH"), &contents)); | |
73 | CPPUNIT_ASSERT(!contents.empty()); | |
74 | } |