mirror of
https://github.com/boostorg/test.git
synced 2026-02-26 17:02:23 +00:00
31
example/env/Jamfile
vendored
Executable file
31
example/env/Jamfile
vendored
Executable file
@@ -0,0 +1,31 @@
|
||||
# (C) Copyright Gennadiy Rozental 2001-2006.
|
||||
# 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.
|
||||
|
||||
subproject libs/test/example/env ;
|
||||
|
||||
# bring in the rules for testing
|
||||
import testing ;
|
||||
|
||||
# Make tests run by default.
|
||||
DEPENDS all : test ;
|
||||
|
||||
rule boost-runtime-param-example ( example-name )
|
||||
{
|
||||
return [ compile $(example-name).cpp
|
||||
: <stlport-iostream>on <borland><*><cxxflags>-w-8080
|
||||
: $(example-name)
|
||||
] ;
|
||||
}
|
||||
|
||||
test-suite "cla_examples"
|
||||
[ boost-runtime-param-example custom_interpreter_env ]
|
||||
[ boost-runtime-param-example env_var_default_value ]
|
||||
[ boost-runtime-param-example environment_ex ]
|
||||
[ boost-runtime-param-example global_id ]
|
||||
[ boost-runtime-param-example modifier_combination ]
|
||||
[ boost-runtime-param-example variable_ex ]
|
||||
;
|
||||
42
example/env/custom_interpreter_env.cpp
vendored
Normal file
42
example/env/custom_interpreter_env.cpp
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
// (C) Copyright Gennadiy Rozental 2001-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.
|
||||
|
||||
// Boost.Runtime.Param
|
||||
#include <boost/test/utils/runtime/env/variable.hpp>
|
||||
#include <boost/test/utils/basic_cstring/io.hpp>
|
||||
|
||||
namespace rt = boost::runtime;
|
||||
namespace env = boost::runtime::env;
|
||||
|
||||
// STL
|
||||
#include <iostream>
|
||||
|
||||
void
|
||||
named_integer( rt::cstring source, boost::optional<int>& value )
|
||||
{
|
||||
if( source == "one" )
|
||||
value = 1;
|
||||
else if( source == "two" )
|
||||
value = 2;
|
||||
else
|
||||
value = 0;
|
||||
}
|
||||
|
||||
env::variable<int> NUMBER1( "NUMBER1", env::interpreter = &named_integer );
|
||||
|
||||
int main() {
|
||||
|
||||
std::cout << NUMBER1 << std::endl;
|
||||
|
||||
std::cout << env::var<int>( "NUMBER2", ( env::interpreter = &named_integer, env::default_value = 10 ))
|
||||
<< std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// EOF
|
||||
|
||||
27
example/env/env_var_default_value.cpp
vendored
Normal file
27
example/env/env_var_default_value.cpp
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
// (C) Copyright Gennadiy Rozental 2001-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.
|
||||
|
||||
// Boost.Runtime.Param
|
||||
#include <boost/test/utils/runtime/env/variable.hpp>
|
||||
#include <boost/test/utils/basic_cstring/io.hpp>
|
||||
|
||||
namespace rt = boost::runtime;
|
||||
namespace env = boost::runtime::env;
|
||||
|
||||
// STL
|
||||
#include <iostream>
|
||||
|
||||
int main() {
|
||||
env::variable<int> TEMP( "abc", env::default_value = 5 );
|
||||
|
||||
std::cout << TEMP << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// EOF
|
||||
|
||||
32
example/env/environment_ex.cpp
vendored
Normal file
32
example/env/environment_ex.cpp
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
// (C) Copyright Gennadiy Rozental 2001-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.
|
||||
|
||||
// Boost.Runtime.Param
|
||||
#include <boost/test/utils/runtime/env/variable.hpp>
|
||||
#include <boost/test/utils/basic_cstring/io.hpp>
|
||||
|
||||
namespace rt = boost::runtime;
|
||||
namespace env = boost::runtime::env;
|
||||
|
||||
// STL
|
||||
#include <iostream>
|
||||
|
||||
int main() {
|
||||
std::cout << env::get<int>("NUMBER_OF_PROCESSORS") << '\n' << env::get<rt::cstring>("TEMP") << std::endl;
|
||||
|
||||
boost::optional<int> n;
|
||||
|
||||
env::get( "NUMBER_OF_PROCESSORS", n );
|
||||
|
||||
if( n )
|
||||
std::cout << n << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// EOF
|
||||
|
||||
25
example/env/global_id.cpp
vendored
Normal file
25
example/env/global_id.cpp
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
// (C) Copyright Gennadiy Rozental 2001-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.
|
||||
|
||||
// Boost.Runtime.Param
|
||||
#include <boost/test/utils/runtime/env/variable.hpp>
|
||||
#include <boost/test/utils/basic_cstring/io.hpp>
|
||||
|
||||
namespace rt = boost::runtime;
|
||||
namespace env = boost::runtime::env;
|
||||
|
||||
// STL
|
||||
#include <iostream>
|
||||
|
||||
int main() {
|
||||
env::variable<> TEMP( "TEMP", env::global_id = "temp_dir_location" );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// EOF
|
||||
|
||||
27
example/env/modifier_combination.cpp
vendored
Normal file
27
example/env/modifier_combination.cpp
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
// (C) Copyright Gennadiy Rozental 2001-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.
|
||||
|
||||
// Boost.Runtime.Param
|
||||
#include <boost/test/utils/runtime/env/variable.hpp>
|
||||
#include <boost/test/utils/basic_cstring/io.hpp>
|
||||
|
||||
namespace rt = boost::runtime;
|
||||
namespace env = boost::runtime::env;
|
||||
|
||||
// STL
|
||||
#include <iostream>
|
||||
|
||||
int main() {
|
||||
env::variable<int> TEMP( "abc", (env::global_id = "temp_dir_location", env::default_value = 5) );
|
||||
|
||||
std::cout << TEMP << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// EOF
|
||||
|
||||
20
example/env/validation/Jamfile
vendored
Executable file
20
example/env/validation/Jamfile
vendored
Executable file
@@ -0,0 +1,20 @@
|
||||
# (C) Copyright Gennadiy Rozental 2001-2006.
|
||||
# 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.
|
||||
|
||||
subproject libs/test/example/env/validation ;
|
||||
|
||||
DEPENDS test : all ;
|
||||
|
||||
rule boost-runtime-param-example ( example-name )
|
||||
{
|
||||
exe $(example-name) : $(example-name).cpp
|
||||
: <sysinclude>$(BOOST_ROOT)
|
||||
<stlport-iostream>on
|
||||
<borland><*><cxxflags>-w-8080 ;
|
||||
}
|
||||
|
||||
boost-runtime-param-example need_typed_access ;
|
||||
41
example/env/validation/need_typed_access.cpp
vendored
Normal file
41
example/env/validation/need_typed_access.cpp
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
// (C) Copyright Gennadiy Rozental 2001-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.
|
||||
|
||||
// Boost.Runtime.Param
|
||||
#include <boost/test/utils/runtime/env/variable.hpp>
|
||||
#include <boost/test/utils/basic_cstring/io.hpp>
|
||||
|
||||
namespace rt = boost::runtime;
|
||||
namespace env = boost::runtime::env;
|
||||
|
||||
// STL
|
||||
#include <iostream>
|
||||
|
||||
// Boost.Runtime.Param
|
||||
#include <boost/test/utils/runtime/env/environment.hpp>
|
||||
namespace rt = boost::runtime;
|
||||
namespace env = boost::runtime::environment;
|
||||
|
||||
// Boost.Test
|
||||
#include <boost/test/utils/basic_cstring/io.hpp>
|
||||
|
||||
// STL
|
||||
#include <iostream>
|
||||
|
||||
int main() {
|
||||
try {
|
||||
std::cout << env::var("ABC").value<int>();
|
||||
}
|
||||
catch ( rt::logic_error const& ex ) {
|
||||
std::cout << ex.msg();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// EOF
|
||||
|
||||
67
example/env/variable_ex.cpp
vendored
Normal file
67
example/env/variable_ex.cpp
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
// (C) Copyright Gennadiy Rozental 2001-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.
|
||||
|
||||
// Boost.Runtime.Param
|
||||
#include <boost/test/utils/runtime/env/variable.hpp>
|
||||
#include <boost/test/utils/basic_cstring/io.hpp>
|
||||
|
||||
namespace rt = boost::runtime;
|
||||
namespace env = boost::runtime::env;
|
||||
|
||||
// STL
|
||||
#include <iostream>
|
||||
|
||||
env::variable<> TEMP( "TEMP" );
|
||||
|
||||
env::variable<int> ProcNumber( "NUMBER_OF_PROCESSORS" );
|
||||
|
||||
env::variable<int> abc( "abccccc" );
|
||||
|
||||
void print_int( env::variable_base const& var ) {
|
||||
std::cout << var.name() << (var.has_value() ? " is present: " : " is not present: " ) << var.value<int>() << std::endl;
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::cout << TEMP << '\n' << ProcNumber << std::endl;
|
||||
|
||||
rt::cstring val = TEMP.value();
|
||||
std::cout << " val=" << val << std::endl;
|
||||
|
||||
int n = ProcNumber.value();
|
||||
|
||||
std::cout << " n=" << n << std::endl;
|
||||
|
||||
boost::optional<int> opt_n;
|
||||
ProcNumber.value( opt_n );
|
||||
|
||||
std::cout << " n=" << opt_n << std::endl;
|
||||
|
||||
print_int( ProcNumber );
|
||||
|
||||
if( ProcNumber == 1 )
|
||||
std::cout << "ProcNumber = 1\n";
|
||||
|
||||
if( 2 != ProcNumber )
|
||||
std::cout << "ProcNumber != 2\n";
|
||||
|
||||
if( abc != 1 )
|
||||
std::cout << "abc != 1\n";
|
||||
|
||||
abc = 1;
|
||||
|
||||
if( abc == 1 )
|
||||
std::cout << "abc == 1\n";
|
||||
|
||||
TEMP = "../tmp";
|
||||
|
||||
std::cout << TEMP << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// EOF
|
||||
|
||||
Reference in New Issue
Block a user