summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorChris Cleeland <chris.cleeland@gmail.com>1997-12-31 22:37:40 +0000
committerChris Cleeland <chris.cleeland@gmail.com>1997-12-31 22:37:40 +0000
commitcfa8353c086d114acd8bd8bdff3ed3dba8e200b1 (patch)
treee15b6719d24d79df2127b9928a9d888f95851366 /tests
parent07e05a5237293863f8e4712fd7a353495a342094 (diff)
downloadATCD-cfa8353c086d114acd8bd8bdff3ed3dba8e200b1.tar.gz
* ace/Env_Value_T.*: Added a new template (ACE_Env_Value) which is
a typesafe encapsulation of environment variables with the ability to provide a value to be used as a default if the variable isn't set. An example of its use can be seen in the corresponding test, tests/Env_Value_Test.cpp. * tests/Env_Value_Test.cpp: Added test for the new template added above. * tests/Makefile: Added new Env_Value_Test test to the Makefile.
Diffstat (limited to 'tests')
-rw-r--r--tests/Env_Value_Test.cpp87
-rw-r--r--tests/Makefile3
2 files changed, 89 insertions, 1 deletions
diff --git a/tests/Env_Value_Test.cpp b/tests/Env_Value_Test.cpp
new file mode 100644
index 00000000000..13b51ec65df
--- /dev/null
+++ b/tests/Env_Value_Test.cpp
@@ -0,0 +1,87 @@
+// $Id$
+
+// ============================================================================
+//
+// = LIBRARY
+// tests
+//
+// = DESCRIPTION
+// This is a simple test to make sure the Env_Value template is
+// working correctly.
+//
+// = AUTHOR
+// Chris Cleeland
+//
+// ============================================================================
+
+#include "test_config.h"
+#include "ace/OS.h"
+#include "ace/Process.h"
+#include "ace/Env_Value_T.h"
+
+int
+main (int argc, char *argv[], char* environ[])
+{
+ if (argc == 1)
+ {
+ // No arguments means we're the initial test
+ ACE_Process_Options options (1);
+ options.setenv (environ);
+
+ char* const* envargv;
+
+ options.command_line ("Env_Value_Test run_as_test");
+
+ options.setenv("TEST_VALUE_POSITIVE", "%s", "10.2");
+ options.setenv("TEST_VALUE_NEGATIVE", "%s", "-10.2");
+
+ ACE_Process p;
+ ACE_ASSERT (p.spawn (options) != -1);
+ p.wait ();
+ }
+ else
+ {
+ // In this case we're the child
+ ACE_START_TEST ("Env_Value");
+
+#define TEST_THIS(type,varname,defval,expval) \
+ do { \
+ ACE_Env_Value<type> val(varname, (defval));\
+ ACE_ASSERT (val == (expval)); \
+ } while (0)
+
+ ;
+
+ TEST_THIS (int, "TEST_VALUE_POSITIVE", 4, 10);
+ TEST_THIS (double, "TEST_VALUE_POSITIVE", -1.0, 10.2);
+ TEST_THIS (unsigned long, "TEST_VALUE_POSITIVE", 0, 10);
+ TEST_THIS (short, "TEST_VALUE_POSITIVE", 0, 10);
+
+ TEST_THIS (int, "TEST_VALUE_NEGATIVE", 4, -10);
+ TEST_THIS (double, "TEST_VALUE_NEGATIVE", -1.0, -10.2);
+ TEST_THIS (unsigned long, "TEST_VALUE_NEGATIVE", 0, -10);
+ TEST_THIS (short, "TEST_VALUE_NEGATIVE", 0, -10);
+
+ char* defstr = "Sarah Cleeland is Two!";
+ ACE_Env_Value<char*> sval("This_Shouldnt_Be_Set_Hopefully", defstr);
+ ACE_ASSERT (ACE_OS::strcmp (sval, defstr) == 0);
+
+ ACE_END_TEST;
+ }
+
+ return 0;
+}
+
+#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
+template class ACE_Env_Value<int>;
+template class ACE_Env_Value<double>;
+template class ACE_Env_Value<unsigned long>;
+template class ACE_Env_Value<short>;
+template class ACE_Env_Value<char*>;
+#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
+#pragma instantiate ACE_Env_Value<int>
+#pragma instantiate ACE_Env_Value<double>
+#pragma instantiate ACE_Env_Value<unsigned long>
+#pragma instantiate ACE_Env_Value<short>
+#pragma instantiate ACE_Env_Value<char*>
+#endif
diff --git a/tests/Makefile b/tests/Makefile
index 56a8b1fc9a3..3a508f65f13 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -9,7 +9,8 @@
# Local macros
#----------------------------------------------------------------------------
-BIN = Atomic_Op_Test \
+BIN = Env_Value_Test \
+ Atomic_Op_Test \
Barrier_Test \
Basic_Types_Test \
Buffer_Stream_Test \