Line data Source code
1 : // (C) Copyright Gennadiy Rozental 2001. 2 : // Distributed under the Boost Software License, Version 1.0. 3 : // (See accompanying file LICENSE_1_0.txt or copy at 4 : // http://www.boost.org/LICENSE_1_0.txt) 5 : 6 : // See http://www.boost.org/libs/test for the library home page. 7 : // 8 : // File : $RCSfile$ 9 : // 10 : // Version : $Revision$ 11 : // 12 : // Description : implements fetching absent parameter athuments from environment 13 : // *************************************************************************** 14 : 15 : #ifndef BOOST_TEST_UTILS_RUNTIME_ENV_FETCH_HPP 16 : #define BOOST_TEST_UTILS_RUNTIME_ENV_FETCH_HPP 17 : 18 : // Boost.Test Runtime parameters 19 : #include <boost/test/utils/runtime/parameter.hpp> 20 : #include <boost/test/utils/runtime/argument.hpp> 21 : 22 : #include <boost/test/detail/suppress_warnings.hpp> 23 : 24 : // C Runtime 25 : #include <stdlib.h> 26 : 27 : namespace boost { 28 : namespace runtime { 29 : namespace env { 30 : 31 : namespace env_detail { 32 : 33 : #ifndef UNDER_CE 34 : 35 : #ifdef _MSC_VER 36 : #pragma warning(push) 37 : #pragma warning(disable:4996) // getenv 38 : #endif 39 : 40 : inline std::pair<cstring,bool> 41 3212 : sys_read_var( cstring var_name ) 42 : { 43 : using namespace std; 44 3212 : char const* res = getenv( var_name.begin() ); 45 : 46 3212 : return std::make_pair( cstring(res), res != NULL ); 47 : } 48 : 49 : #ifdef _MSC_VER 50 : #pragma warning(pop) 51 : #endif 52 : 53 : #else 54 : 55 : inline std::pair<cstring,bool> 56 : sys_read_var( cstring var_name ) 57 : { 58 : return std::make_pair( cstring(), false ); 59 : } 60 : 61 : #endif 62 : 63 : //____________________________________________________________________________// 64 : 65 : template<typename ReadFunc> 66 : inline void 67 146 : fetch_absent( parameters_store const& params, runtime::arguments_store& args, ReadFunc read_func ) 68 : { 69 8322 : BOOST_TEST_FOREACH( parameters_store::storage_type::value_type const&, v, params.all() ) { 70 4088 : basic_param_ptr param = v.second; 71 : 72 4088 : if( args.has( param->p_name ) || param->p_env_var.empty() ) 73 876 : continue; 74 : 75 3212 : std::pair<cstring,bool> value = read_func( param->p_env_var ); 76 : 77 3212 : if( !value.second ) 78 3212 : continue; 79 : 80 : // Validate against unexpected empty value 81 0 : BOOST_TEST_I_ASSRT( !value.first.is_empty() || param->p_has_optional_value, 82 : format_error( param->p_name ) 83 : << "Missing an argument value for the parameter " << param->p_name 84 : << " in the environment." ); 85 : 86 : // Produce argument value 87 0 : param->produce_argument( value.first, false, args ); 88 : 89 4088 : } 90 146 : } 91 : 92 : //____________________________________________________________________________// 93 : 94 : } // namespace env_detail 95 : 96 : inline void 97 146 : fetch_absent( parameters_store const& params, runtime::arguments_store& args ) 98 : { 99 146 : env_detail::fetch_absent( params, args, &env_detail::sys_read_var ); 100 146 : } 101 : 102 : } // namespace env 103 : } // namespace runtime 104 : } // namespace boost 105 : 106 : #include <boost/test/detail/enable_warnings.hpp> 107 : 108 : #endif // BOOST_TEST_UTILS_RUNTIME_ENV_FETCH_HPP