1 // ============================================================================
7 // This is a simple test to make sure the Env_Value template is
11 // Chris Cleeland <cleeland@cs.wustl.edu>
13 // ============================================================================
15 #include "test_config.h"
16 #include "ace/OS_NS_stdlib.h"
17 #include "ace/OS_NS_string.h"
18 #include "ace/Process.h"
19 #include "ace/Env_Value_T.h"
20 #include "ace/SString.h"
22 #define TEST_THIS(type, varname, defval, expval) \
24 ACE_Env_Value<type> val (varname, (defval)); \
25 if (val != (expval)) { \
26 ACE_ERROR ((LM_ERROR, \
27 ACE_TEXT ("val %d does not match expected value of %d\n"), \
28 (int) (type) val, (int) (expval))); \
33 run_main (int, ACE_TCHAR
* [])
35 #ifdef ACE_LACKS_PUTENV
36 ACE_START_TEST (ACE_TEXT ("Env_Value_Test"));
39 // Only Win32 can set wide-char environment strings. So, for all
40 // others, use char string literals regardless of ACE_USES_WCHAR.
41 # if defined (ACE_WIN32)
42 ACE_OS::putenv (ACE_TEXT ("TEST_VALUE_POSITIVE=10.2"));
43 ACE_OS::putenv (ACE_TEXT ("TEST_VALUE_NEGATIVE=-10.2"));
45 ACE_OS::putenv ("TEST_VALUE_POSITIVE=10.2");
46 ACE_OS::putenv ("TEST_VALUE_NEGATIVE=-10.2");
47 # endif /* ACE_WIN32 */
49 ACE_START_TEST (ACE_TEXT ("Env_Value_Test"));
51 TEST_THIS (int, ACE_TEXT ("TEST_VALUE_POSITIVE"), 4, 10);
52 TEST_THIS (double, ACE_TEXT ("TEST_VALUE_POSITIVE"), -1.0, 10.2);
53 TEST_THIS (long, ACE_TEXT ("TEST_VALUE_POSITIVE"), 0, 10);
54 TEST_THIS (unsigned long, ACE_TEXT ("TEST_VALUE_POSITIVE"), 0, 10);
55 TEST_THIS (short, ACE_TEXT ("TEST_VALUE_POSITIVE"), 0, 10);
56 TEST_THIS (unsigned short, ACE_TEXT ("TEST_VALUE_POSITIVE"), 0, 10);
58 TEST_THIS (int, ACE_TEXT ("TEST_VALUE_NEGATIVE"), 4, -10);
59 TEST_THIS (double, ACE_TEXT ("TEST_VALUE_NEGATIVE"), -1.0, -10.2);
60 TEST_THIS (long, ACE_TEXT ("TEST_VALUE_NEGATIVE"), 0, -10L);
61 TEST_THIS (unsigned long, ACE_TEXT ("TEST_VALUE_NEGATIVE"), 0, (unsigned long) -10);
62 TEST_THIS (short, ACE_TEXT ("TEST_VALUE_NEGATIVE"), 0, -10);
63 TEST_THIS (unsigned short, ACE_TEXT ("TEST_VALUE_NEGATIVE"), 0, (unsigned short) -10);
65 const ACE_TCHAR
* const defstr
= ACE_TEXT ("Sarah Cleeland is Two!");
67 ACE_Env_Value
<ACE_TString
> sval1 (ACE_TEXT ("This_Shouldnt_Be_Set_Hopefully"),
69 if (ACE_OS::strcmp (static_cast<ACE_TString
>(sval1
).c_str(), defstr
) != 0) {
71 ACE_TEXT ("Mismatch: %s should be %s\n"),
72 static_cast<ACE_TString
>(sval1
).c_str(), defstr
));
75 const ACE_TString
strval(ACE_TEXT("-10.2"));
77 ACE_Env_Value
<ACE_TString
> sval2 (ACE_TEXT ("TEST_VALUE_NEGATIVE"),
79 if (ACE_OS::strcmp (static_cast<ACE_TString
>(sval2
).c_str(), strval
.c_str()) != 0) {
81 ACE_TEXT ("Mismatch: %s should be %s\n"),
82 static_cast<ACE_TString
>(sval2
).c_str(), strval
.c_str()));
86 #endif // ACE_LACKS_PUTENV