File indexing completed on 2025-01-18 09:52:42
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef BOOST_TEST_UTILS_RUNTIME_ENV_FETCH_HPP
0016 #define BOOST_TEST_UTILS_RUNTIME_ENV_FETCH_HPP
0017
0018
0019 #include <boost/test/utils/runtime/parameter.hpp>
0020 #include <boost/test/utils/runtime/argument.hpp>
0021
0022 #include <boost/test/detail/suppress_warnings.hpp>
0023
0024
0025 #include <stdlib.h>
0026
0027 namespace boost {
0028 namespace runtime {
0029 namespace env {
0030
0031 namespace env_detail {
0032
0033 #ifndef UNDER_CE
0034
0035 #ifdef BOOST_MSVC
0036 #pragma warning(push)
0037 #pragma warning(disable:4996)
0038 #endif
0039
0040 inline std::pair<cstring,bool>
0041 sys_read_var( cstring var_name )
0042 {
0043 using namespace std;
0044 char const* res = getenv( var_name.begin() );
0045
0046 return std::make_pair( cstring(res), res != NULL );
0047 }
0048
0049 #ifdef BOOST_MSVC
0050 #pragma warning(pop)
0051 #endif
0052
0053 #else
0054
0055 inline std::pair<cstring,bool>
0056 sys_read_var( cstring var_name )
0057 {
0058 return std::make_pair( cstring(), false );
0059 }
0060
0061 #endif
0062
0063
0064
0065 template<typename ReadFunc>
0066 inline void
0067 fetch_absent( parameters_store const& params, runtime::arguments_store& args, ReadFunc read_func )
0068 {
0069 BOOST_TEST_FOREACH( parameters_store::storage_type::value_type const&, v, params.all() ) {
0070 basic_param_ptr param = v.second;
0071
0072 if( args.has( param->p_name ) || param->p_env_var.empty() )
0073 continue;
0074
0075 std::pair<cstring,bool> value = read_func( param->p_env_var );
0076
0077 if( !value.second )
0078 continue;
0079
0080
0081 BOOST_TEST_I_ASSRT( !value.first.is_empty() || param->p_has_optional_value,
0082 format_error( param->p_name )
0083 << "Missing an argument value for the parameter " << param->p_name
0084 << " in the environment." );
0085
0086
0087 param->produce_argument( value.first, false, args );
0088
0089 }
0090 }
0091
0092
0093
0094 }
0095
0096 inline void
0097 fetch_absent( parameters_store const& params, runtime::arguments_store& args )
0098 {
0099 env_detail::fetch_absent( params, args, &env_detail::sys_read_var );
0100 }
0101
0102 }
0103 }
0104 }
0105
0106 #include <boost/test/detail/enable_warnings.hpp>
0107
0108 #endif