diff options
Diffstat (limited to 'boost/test/utils/runtime/env')
-rw-r--r-- | boost/test/utils/runtime/env/environment.cpp | 23 | ||||
-rw-r--r-- | boost/test/utils/runtime/env/environment.hpp | 171 | ||||
-rw-r--r-- | boost/test/utils/runtime/env/environment.ipp | 125 | ||||
-rw-r--r-- | boost/test/utils/runtime/env/fetch.hpp | 108 | ||||
-rw-r--r-- | boost/test/utils/runtime/env/fwd.hpp | 61 | ||||
-rw-r--r-- | boost/test/utils/runtime/env/modifier.hpp | 47 | ||||
-rw-r--r-- | boost/test/utils/runtime/env/variable.hpp | 223 |
7 files changed, 108 insertions, 650 deletions
diff --git a/boost/test/utils/runtime/env/environment.cpp b/boost/test/utils/runtime/env/environment.cpp deleted file mode 100644 index ddf47b342c..0000000000 --- a/boost/test/utils/runtime/env/environment.cpp +++ /dev/null @@ -1,23 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2004-2014. -// Use, modification, and distribution are subject to the -// Boost Software License, Version 1.0. (See accompanying file -// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - -// See http://www.boost.org/libs/test for the library home page. -// -// File : $RCSfile$ -// -// Version : $Revision$ -// -// Description : implements offline model of program environment -// *************************************************************************** - -#include <boost/test/utils/runtime/config.hpp> - -#ifdef BOOST_MSVC -# pragma warning(disable: 4127) // conditional expression is constant -# pragma warning(disable: 4701) // local environment 'result' may be used without having been initialized -#endif - -#define BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE -#include <boost/test/utils/runtime/env/environment.ipp> diff --git a/boost/test/utils/runtime/env/environment.hpp b/boost/test/utils/runtime/env/environment.hpp deleted file mode 100644 index 62b2ae6dc1..0000000000 --- a/boost/test/utils/runtime/env/environment.hpp +++ /dev/null @@ -1,171 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -// See http://www.boost.org/libs/test for the library home page. -// -// File : $RCSfile$ -// -// Version : $Revision$ -// -// Description : defines and implements inline model of program environment -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_RUNTIME_ENV_ENVIRONMENT_HPP -#define BOOST_TEST_UTILS_RUNTIME_ENV_ENVIRONMENT_HPP - -#ifdef UNDER_CE -#error Windows CE does not support environment variables. -#endif - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> -#include <boost/test/utils/runtime/fwd.hpp> -#include <boost/test/utils/runtime/argument.hpp> -#include <boost/test/utils/runtime/interpret_argument_value.hpp> - -#include <boost/test/utils/runtime/env/fwd.hpp> -#include <boost/test/utils/runtime/env/modifier.hpp> -#include <boost/test/utils/runtime/env/variable.hpp> - -// Boost -#include <boost/optional.hpp> - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -// ************************************************************************** // -// ************** runtime::environment implementation ************** // -// ************************************************************************** // - -namespace environment { - -namespace rt_env_detail { - -template<typename T, typename Modifiers> -variable_data& -init_new_var( cstring var_name, Modifiers m = nfp::no_params ) -{ - rt_env_detail::variable_data& new_vd = new_var_record( var_name ); - - cstring str_value = sys_read_var( new_vd.m_var_name ); - - if( !str_value.is_empty() ) { - BOOST_TEST_IMPL_TRY { - boost::optional<T> value; - - if( m.has( interpreter ) ) - m[interpreter]( str_value, value ); - else - interpret_argument_value( str_value, value, 0 ); - - if( !!value ) { - new_vd.m_value.reset( new typed_argument<T>( new_vd ) ); - - arg_value<T>( *new_vd.m_value ) = *value; - } - } - BOOST_TEST_IMPL_CATCHALL() { // !! could we do that - // !! should we report an error? - } - } - - if( !new_vd.m_value && m.has( default_value ) ) { - new_vd.m_value.reset( new typed_argument<T>( new_vd ) ); - - nfp::optionally_assign( arg_value<T>( *new_vd.m_value ), m[default_value] ); - } - - nfp::optionally_assign( new_vd.m_global_id, m, global_id ); - - return new_vd; -} - -//____________________________________________________________________________// - -} // namespace rt_env_detail - -} // namespace environment - -// ************************************************************************** // -// ************** runtime::environment ************** // -// ************************************************************************** // - -namespace environment { - - // variable access - variable_base - var( cstring var_name ); - - //________________________________________________________________________// - - template<typename T> - inline variable<T> - var( cstring var_name ) - { - rt_env_detail::variable_data* vd = rt_env_detail::find_var_record( var_name ); - - return environment::variable<T>( !vd ? rt_env_detail::init_new_var<T>( var_name, nfp::no_params ) : *vd ); - } - - //________________________________________________________________________// - - template<typename T, typename Modifiers> - inline variable<T> - var( cstring var_name, Modifiers const& m ) - { - rt_env_detail::variable_data* vd = rt_env_detail::find_var_record( var_name ); - - return environment::variable<T>( !vd ? rt_env_detail::init_new_var<T>( var_name, m ) : *vd ); - } - - //________________________________________________________________________// - - // direct variable value access - inline cstring - get( cstring var_name ) - { - return environment::var<cstring>( var_name ).value(); - } - - //________________________________________________________________________// - - template<typename T> - inline T const& - get( cstring var_name ) - { - return environment::var<T>( var_name ).value(); - } - - //________________________________________________________________________// - - template<typename T> - inline void - get( cstring var_name, boost::optional<T>& res ) - { - variable<T> const& v = environment::var<T>( var_name ); - v.value( res ); - } - - //________________________________________________________________________// - -} // namespace environment - -namespace env = environment; - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace boost - -#ifndef BOOST_TEST_UTILS_RUNTIME_PARAM_OFFLINE - -#ifndef BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE -# define BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE inline -#endif -# include <boost/test/utils/runtime/env/environment.ipp> - -#endif - -#endif // BOOST_TEST_UTILS_RUNTIME_ENV_ENVIRONMENT_HPP diff --git a/boost/test/utils/runtime/env/environment.ipp b/boost/test/utils/runtime/env/environment.ipp deleted file mode 100644 index 6baf72f430..0000000000 --- a/boost/test/utils/runtime/env/environment.ipp +++ /dev/null @@ -1,125 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -// See http://www.boost.org/libs/test for the library home page. -// -// File : $RCSfile$ -// -// Version : $Revision$ -// -// Description : implements model of program environment -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_RUNTIME_ENV_ENVIRONMENT_IPP -#define BOOST_TEST_UTILS_RUNTIME_ENV_ENVIRONMENT_IPP - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> -#include <boost/test/utils/runtime/validation.hpp> - -#include <boost/test/utils/runtime/env/variable.hpp> - -// Boost.Test -#include <boost/test/utils/basic_cstring/compare.hpp> -#include <boost/test/utils/basic_cstring/io.hpp> - -// STL -#include <map> -#include <list> - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -namespace environment { - -// ************************************************************************** // -// ************** runtime::environment ************** // -// ************************************************************************** // - -namespace rt_env_detail { - -typedef std::map<cstring,rt_env_detail::variable_data> registry; -typedef std::list<dstring> keys; - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE registry& s_registry() { static registry instance; return instance; } -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE keys& s_keys() { static keys instance; return instance; } - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE variable_data& -new_var_record( cstring var_name ) -{ - // save the name in list of keys - s_keys().push_back( dstring() ); - dstring& key = s_keys().back(); - assign_op( key, var_name, 0 ); - - // create and return new record - variable_data& new_var_data = s_registry()[key]; - - new_var_data.m_var_name = key; - - return new_var_data; -} - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE variable_data* -find_var_record( cstring var_name ) -{ - registry::iterator it = s_registry().find( var_name ); - - return it == s_registry().end() ? 0 : &(it->second); -} - -//____________________________________________________________________________// - -#ifdef BOOST_MSVC -#pragma warning(push) -#pragma warning(disable:4996) // getenv -#endif - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE cstring -sys_read_var( cstring var_name ) -{ - using namespace std; - return BOOST_TEST_UTILS_RUNTIME_PARAM_GETENV( var_name.begin() ); -} - -#ifdef BOOST_MSVC -#pragma warning(pop) -#endif -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE void -sys_write_var( cstring var_name, format_stream& var_value ) -{ - BOOST_TEST_UTILS_RUNTIME_PARAM_PUTENV( var_name, cstring( var_value.str() ) ); -} - -//____________________________________________________________________________// - -} // namespace rt_env_detail - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE variable_base -var( cstring var_name ) -{ - rt_env_detail::variable_data* vd = rt_env_detail::find_var_record( var_name ); - - BOOST_TEST_UTILS_RUNTIME_PARAM_VALIDATE_LOGIC( !!vd, - BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( "First access to the environment variable " ) - << var_name << BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( " should be typed" ) ); - - return variable_base( *vd ); -} - -//____________________________________________________________________________// - -} // namespace environment - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace boost - -#endif // BOOST_TEST_UTILS_RUNTIME_ENV_ENVIRONMENT_IPP_062904GER diff --git a/boost/test/utils/runtime/env/fetch.hpp b/boost/test/utils/runtime/env/fetch.hpp new file mode 100644 index 0000000000..97d54d4905 --- /dev/null +++ b/boost/test/utils/runtime/env/fetch.hpp @@ -0,0 +1,108 @@ +// (C) Copyright Gennadiy Rozental 2001. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org/libs/test for the library home page. +// +// File : $RCSfile$ +// +// Version : $Revision$ +// +// Description : implements fetching absent parameter athuments from environment +// *************************************************************************** + +#ifndef BOOST_TEST_UTILS_RUNTIME_ENV_FETCH_HPP +#define BOOST_TEST_UTILS_RUNTIME_ENV_FETCH_HPP + +// Boost.Test Runtime parameters +#include <boost/test/utils/runtime/parameter.hpp> +#include <boost/test/utils/runtime/argument.hpp> + +#include <boost/test/detail/suppress_warnings.hpp> + +// C Runtime +#include <stdlib.h> + +namespace boost { +namespace runtime { +namespace env { + +namespace env_detail { + +#ifndef UNDER_CE + +#ifdef BOOST_MSVC +#pragma warning(push) +#pragma warning(disable:4996) // getenv +#endif + +inline std::pair<cstring,bool> +sys_read_var( cstring var_name ) +{ + using namespace std; + char const* res = getenv( var_name.begin() ); + + return std::make_pair( cstring(res), res != NULL ); +} + +#ifdef BOOST_MSVC +#pragma warning(pop) +#endif + +#else + +inline std::pair<cstring,bool> +sys_read_var( cstring var_name ) +{ + return std::make_pair( cstring(), false ); +} + +#endif + +//____________________________________________________________________________// + +template<typename ReadFunc> +inline void +fetch_absent( parameters_store const& params, runtime::arguments_store& args, ReadFunc read_func ) +{ + BOOST_TEST_FOREACH( parameters_store::storage_type::value_type const&, v, params.all() ) { + basic_param_ptr param = v.second; + + if( args.has( param->p_name ) || param->p_env_var.empty() ) + continue; + + std::pair<cstring,bool> value = read_func( param->p_env_var ); + + if( !value.second ) + continue; + + // Validate against unexpected empty value + BOOST_TEST_I_ASSRT( !value.first.is_empty() || param->p_has_optional_value, + format_error( param->p_name ) + << "Missing an argument value for the parameter " << param->p_name + << " in the environment." ); + + // Produce argument value + param->produce_argument( value.first, false, args ); + + } +} + +//____________________________________________________________________________// + +} // namespace env_detail + +inline void +fetch_absent( parameters_store const& params, runtime::arguments_store& args ) +{ + env_detail::fetch_absent( params, args, &env_detail::sys_read_var ); +} + +} // namespace env +} // namespace runtime +} // namespace boost + +#include <boost/test/detail/enable_warnings.hpp> + +#endif // BOOST_TEST_UTILS_RUNTIME_ENV_FETCH_HPP diff --git a/boost/test/utils/runtime/env/fwd.hpp b/boost/test/utils/runtime/env/fwd.hpp deleted file mode 100644 index 438795ea8f..0000000000 --- a/boost/test/utils/runtime/env/fwd.hpp +++ /dev/null @@ -1,61 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -// See http://www.boost.org/libs/test for the library home page. -// -// File : $RCSfile$ -// -// Version : $Revision$ -// -// Description : environment subsystem forward declarations -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_RUNTIME_ENV_FWD_HPP -#define BOOST_TEST_UTILS_RUNTIME_ENV_FWD_HPP - -#ifdef UNDER_CE -#error Windows CE does not support environment variables. -#endif - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -namespace environment { - -template<typename T> -class variable; - -class variable_base; -variable_base var( cstring var_name ); - -template<typename T> -inline variable<T> - var( cstring var_name ); - -namespace rt_env_detail { - -struct variable_data; - -variable_data& new_var_record( cstring var_name ); -variable_data* find_var_record( cstring var_name ); - -cstring sys_read_var( cstring var_name ); -void sys_write_var( cstring var_name, format_stream& var_value ); - -} - -template <typename T> class variable; - -} // namespace environment - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace boost - -#endif // BOOST_TEST_UTILS_RUNTIME_ENV_FWD_HPP diff --git a/boost/test/utils/runtime/env/modifier.hpp b/boost/test/utils/runtime/env/modifier.hpp deleted file mode 100644 index 536461a549..0000000000 --- a/boost/test/utils/runtime/env/modifier.hpp +++ /dev/null @@ -1,47 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to the -// Boost Software License, Version 1.0. (See accompanying file -// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - -// See http://www.boost.org/libs/test for the library home page. -// -// File : $RCSfile$ -// -// Version : $Revision$ -// -// Description : defines variable modifiers -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_RUNTIME_ENV_MODIFIER_HPP -#define BOOST_TEST_UTILS_RUNTIME_ENV_MODIFIER_HPP - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> - -// Boost.Test -#include <boost/test/utils/named_params.hpp> - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -namespace environment { - -// ************************************************************************** // -// ************** environment variable modifiers ************** // -// ************************************************************************** // - -namespace { - -nfp::typed_keyword<cstring,struct global_id_t> global_id; -nfp::keyword<struct default_value_t> default_value; -nfp::keyword<struct interpreter_t> interpreter; - -} // local namespace -} // namespace environment - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace boost - -#endif // BOOST_TEST_UTILS_RUNTIME_ENV_MODIFIER_HPP diff --git a/boost/test/utils/runtime/env/variable.hpp b/boost/test/utils/runtime/env/variable.hpp deleted file mode 100644 index df776a619a..0000000000 --- a/boost/test/utils/runtime/env/variable.hpp +++ /dev/null @@ -1,223 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -// See http://www.boost.org/libs/test for the library home page. -// -// File : $RCSfile$ -// -// Version : $Revision$ -// -// Description : defines model of program environment variable -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_RUNTIME_ENV_VARIABLE_HPP -#define BOOST_TEST_UTILS_RUNTIME_ENV_VARIABLE_HPP - -#ifdef UNDER_CE -#error Windows CE does not support environment variables. -#endif - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> -#include <boost/test/utils/runtime/fwd.hpp> -#include <boost/test/utils/runtime/parameter.hpp> -#include <boost/test/utils/runtime/argument.hpp> - -#include <boost/test/utils/runtime/env/fwd.hpp> - -// Boost -#include <boost/optional.hpp> - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -namespace environment { - -// ************************************************************************** // -// ************** runtime::environment::variable_data ************** // -// ************************************************************************** // - -namespace rt_env_detail { - -struct variable_data : public runtime::parameter { - cstring m_var_name; - dstring m_global_id; - argument_ptr m_value; -}; - -} // namespace rt_env_detail - -// ************************************************************************** // -// ************** runtime::environment::variable_base ************** // -// ************************************************************************** // - -class variable_base { -public: - explicit variable_base( rt_env_detail::variable_data& data ) : m_data( &data ) {} - - // arguments access - template<typename T> - T const& value() const - { - return arg_value<T>( *m_data->m_value ); - } - - template<typename T> - void value( boost::optional<T>& res ) const - { - if( has_value() ) - res = arg_value<T>( *m_data->m_value ); - else - res.reset(); - } - - bool has_value() const { return !!m_data->m_value; } - cstring name() const { return m_data->m_var_name; } - -protected: - // Data members - rt_env_detail::variable_data* m_data; -} ; - -// ************************************************************************** // -// ************** runtime::environment::variable ************** // -// ************************************************************************** // - -template<typename T = cstring> -class variable : public variable_base { -public: - // Constructors - explicit variable( cstring var_name ); - - template<typename Modifiers> - explicit variable( cstring var_name, Modifiers const& m ); - - explicit variable( rt_env_detail::variable_data& data ) - : variable_base( data ) {} - - // other variable assignment - void operator=( variable const& v ) { m_data = v.m_data; } - - // access methods - T const& value() const { return variable_base::value<T>(); } - -#if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3206)) || \ - BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x0593)) - template<typename T> - void value( boost::optional<T>& res ) const { variable_base::value( res ); } -#else - using variable_base::value; -#endif - - // Value assignment - template<typename V> - void operator=( V const& v ) - { - if( !has_value() ) - m_data->m_value.reset( new typed_argument<T>( *m_data ) ); - - arg_value<T>( *m_data->m_value ) = v; - - rt_env_detail::sys_write_var( m_data->m_var_name, format_stream().ref() << value() ); - } -}; // class variable - -//____________________________________________________________________________// - -template<typename CharT, typename Tr,typename T> -inline std::basic_ostream<CharT,Tr>& -operator<<( std::basic_ostream<CharT,Tr>& os, variable<T> const& v ) -{ - os << v.name() << '='; - - if( v.has_value() ) - os << v.value(); - - return os; -} - -//____________________________________________________________________________// - -template<typename T, typename V> -inline bool -operator==( variable<T> ev, V const& v ) -{ - return ev.has_value() && ev.value() == v; -} - -//____________________________________________________________________________// - -template<typename T, typename V> -inline bool -operator==( V const& v, variable<T> ev ) -{ - return ev.has_value() && ev.value() == v; -} - -//____________________________________________________________________________// - -template<typename T, typename V> -inline bool -operator!=( variable<T> ev, V const& v ) -{ - return !ev.has_value() || ev.value() != v; -} - -//____________________________________________________________________________// - -template<typename T, typename V> -inline bool -operator!=( V const& v, variable<T> ev ) -{ - return !ev.has_value() || ev.value() != v; -} - -//____________________________________________________________________________// - -} // namespace environment - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace boost - -// ************************************************************************** // -// ************************************************************************** // -// Implementation - -#include <boost/test/utils/runtime/env/environment.hpp> - -// ************************************************************************** // -// ************** runtime::environment::variable ************** // -// ************************************************************************** // - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -namespace environment { - -template<typename T> -variable<T>::variable( cstring var_name ) -: variable_base( environment::var<T>( var_name ) ) -{} - -//____________________________________________________________________________// - -template<typename T> -template<typename Modifiers> -variable<T>::variable( cstring var_name, Modifiers const& m ) -: variable_base( environment::var<T>( var_name, m ) ) -{} - -//____________________________________________________________________________// - -} // namespace environment - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace boost - -#endif // BOOST_TEST_UTILS_RUNTIME_ENV_VARIABLE_HPP |