Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / ACE / tests / Env_Value_Test.cpp
blob1cdce91776829ab9ec6e34a8ae0f9a31d21f56b1
1 // ============================================================================
2 //
3 // = LIBRARY
4 // tests
5 //
6 // = DESCRIPTION
7 // This is a simple test to make sure the Env_Value template is
8 // working correctly.
9 //
10 // = AUTHOR
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) \
23 do { \
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))); \
29 } \
30 } while (0)
32 int
33 run_main (int, ACE_TCHAR* [])
35 #ifdef ACE_LACKS_PUTENV
36 ACE_START_TEST (ACE_TEXT ("Env_Value_Test"));
37 ACE_END_TEST;
38 #else
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"));
44 # else
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"),
68 defstr);
69 if (ACE_OS::strcmp (static_cast<ACE_TString>(sval1).c_str(), defstr) != 0) {
70 ACE_ERROR ((LM_ERROR,
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"),
78 defstr);
79 if (ACE_OS::strcmp (static_cast<ACE_TString>(sval2).c_str(), strval.c_str()) != 0) {
80 ACE_ERROR ((LM_ERROR,
81 ACE_TEXT ("Mismatch: %s should be %s\n"),
82 static_cast<ACE_TString>(sval2).c_str(), strval.c_str()));
84 ACE_END_TEST;
86 #endif // ACE_LACKS_PUTENV
87 return 0;