From cfa8353c086d114acd8bd8bdff3ed3dba8e200b1 Mon Sep 17 00:00:00 2001 From: Chris Cleeland Date: Wed, 31 Dec 1997 22:37:40 +0000 Subject: * 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. --- tests/Env_Value_Test.cpp | 87 ++++++++++++++++++++++++++++++++++++++++++++++++ tests/Makefile | 3 +- 2 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 tests/Env_Value_Test.cpp (limited to 'tests') 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 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 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; +template class ACE_Env_Value; +template class ACE_Env_Value; +template class ACE_Env_Value; +template class ACE_Env_Value; +#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) +#pragma instantiate ACE_Env_Value +#pragma instantiate ACE_Env_Value +#pragma instantiate ACE_Env_Value +#pragma instantiate ACE_Env_Value +#pragma instantiate ACE_Env_Value +#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 \ -- cgit v1.2.1