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