1 //  (C) Copyright Gennadiy Rozental 2005-2014.
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 : Runtime.Param library configuration
13 // ***************************************************************************
14 
15 #ifndef BOOST_TEST_UTILS_RUNTIME_CONFIG_HPP
16 #define BOOST_TEST_UTILS_RUNTIME_CONFIG_HPP
17 
18 // Boost
19 #include <boost/config.hpp>
20 #ifdef BOOST_MSVC
21 # pragma warning(disable: 4511) // copy constructor could not be generated
22 # pragma warning(disable: 4512) // assignment operator could not be generated
23 # pragma warning(disable: 4181) // qualifier applied to reference type; ignored
24 # pragma warning(disable: 4675) // resolved overload was found by argument-dependent lookup
25 #endif
26 
27 // Boost.Test
28 #include <boost/test/detail/config.hpp>
29 #include <boost/test/utils/basic_cstring/basic_cstring.hpp>
30 #include <boost/test/utils/wrap_stringstream.hpp>
31 #include <boost/test/utils/basic_cstring/io.hpp> // operator<<(boost::runtime::cstring)
32 
33 // STL
34 #include <string>
35 #include <cstdlib>
36 
37 #ifdef __SUNPRO_CC
38   #include <stdlib.h>
39 #endif
40 
41 //____________________________________________________________________________//
42 
43 #ifndef BOOST_TEST_UTILS_RUNTIME_PARAM_CUSTOM_STRING
44 #  ifndef BOOST_TEST_UTILS_RUNTIME_PARAM_WIDE_STRING
45 #    define BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE                            runtime
46 #  else
47 #    define BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE                            wide_runtime
48 #  endif
49 #endif
50 
51 
52 
53 namespace boost {
54 
55 namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE {
56 
57 #ifndef BOOST_TEST_UTILS_RUNTIME_PARAM_CUSTOM_STRING
58 #  ifndef BOOST_TEST_UTILS_RUNTIME_PARAM_WIDE_STRING
59 
60 typedef char                                                    char_type;
61 typedef std::string                                             dstring;
62 typedef unit_test::const_string                                 cstring;
63 typedef unit_test::literal_string                               literal_cstring;
64 typedef wrap_stringstream                                       format_stream;
65 
66 #ifdef BOOST_CLASSIC_IOSTREAMS
67 typedef std::ostream                                            out_stream;
68 #else
69 typedef std::basic_ostream<char_type>                           out_stream;
70 #endif
71 
72 #ifdef BOOST_MSVC
73 #pragma warning(push)
74 #pragma warning(disable:4996) // putenv
75 #endif
76 
77 #if defined(__MINGW32__)
78 extern "C" int putenv( const char * );
79 #endif
80 
81 #ifndef UNDER_CE
82 #if defined(__COMO__) && 0
83 inline void
putenv_impl(cstring name,cstring value)84 putenv_impl( cstring name, cstring value )
85 {
86     using namespace std;
87     // !! this may actually fail. What should we do?
88     setenv( name.begin(), value.begin(), 1 );
89 }
90 #else
91 inline void
putenv_impl(cstring name,cstring value)92 putenv_impl( cstring name, cstring value )
93 {
94     format_stream fs;
95 
96     fs << name << '=' << value;
97 
98     // !! this may actually fail. What should we do?
99     // const_cast is used to satisfy putenv interface
100     using namespace std;
101     putenv( const_cast<char*>( fs.str().c_str() ) );
102 }
103 #endif
104 #endif
105 
106 #ifdef BOOST_MSVC
107 #pragma warning(pop)
108 #endif
109 
110 #define BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( l ) l
111 #define BOOST_TEST_UTILS_RUNTIME_PARAM_CSTRING_LITERAL( l ) cstring( l, sizeof( l ) - 1 )
112 #define BOOST_TEST_UTILS_RUNTIME_PARAM_GETENV getenv
113 #define BOOST_TEST_UTILS_RUNTIME_PARAM_PUTENV ::boost::BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE::putenv_impl
114 #define BOOST_TEST_UTILS_RUNTIME_PARAM_EXCEPTION_INHERIT_STD
115 
116 //____________________________________________________________________________//
117 
118 #  else
119 
120 typedef wchar_t                                                 char_type;
121 typedef std::basic_string<char_type>                            dstring;
122 typedef unit_test::basic_cstring<wchar_t const>                 cstring;
123 typedef const unit_test::basic_cstring<wchar_t const>           literal_cstring;
124 typedef wrap_wstringstream                                      format_stream;
125 typedef std::wostream                                           out_stream;
126 
127 #ifndef UNDER_CE
128 inline void
129 putenv_impl( cstring name, cstring value )
130 {
131     format_stream fs;
132 
133     fs << name << '=' << value;
134 
135     // !! this may actually fail. What should we do?
136     // const_cast is used to satisfy putenv interface
137     using namespace std;
138     wputenv( const_cast<wchar_t*>( fs.str().c_str() ) );
139 }
140 #endif
141 
142 #define BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( l ) L ## l
143 #define BOOST_TEST_UTILS_RUNTIME_PARAM_CSTRING_LITERAL( l ) cstring( L ## l, sizeof( L ## l )/sizeof(wchar_t) - 1 )
144 #define BOOST_TEST_UTILS_RUNTIME_PARAM_GETENV wgetenv
145 #define BOOST_TEST_UTILS_RUNTIME_PARAM_PUTENV putenv_impl
146 
147 #  endif
148 #endif
149 
150 #ifdef __GNUC__
151 #define BOOST_TEST_UTILS_RUNTIME_PARAM_UNNEEDED_VIRTUAL virtual
152 #else
153 #define BOOST_TEST_UTILS_RUNTIME_PARAM_UNNEEDED_VIRTUAL
154 #endif
155 
156 //____________________________________________________________________________//
157 
158 } // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE
159 
160 } // namespace boost
161 
162 #endif // BOOST_TEST_UTILS_RUNTIME_CONFIG_HPP
163