early-access version 3088

This commit is contained in:
pineappleEA
2022-11-05 15:35:56 +01:00
parent 4e4fc25ce3
commit b601909c6d
35519 changed files with 5996896 additions and 860 deletions

View File

@@ -0,0 +1,138 @@
# Copyright 2018-2020 Peter Dimov
# 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
include(BoostTest OPTIONAL RESULT_VARIABLE HAVE_BOOST_TEST)
if(NOT HAVE_BOOST_TEST)
return()
endif()
macro(system_run s1)
string(MAKE_C_IDENTIFIER ${s1} n1)
boost_test(SOURCES ${s1} ${ARGN})
boost_test(SOURCES ${s1} ${ARGN} COMPILE_DEFINITIONS BOOST_NO_ANSI_APIS NAME ${n1}_no_ansi)
boost_test(SOURCES ${s1} ${ARGN} COMPILE_DEFINITIONS BOOST_SYSTEM_USE_UTF8 NAME ${n1}_utf8)
endmacro()
macro(lib name macro)
add_library(${name} EXCLUDE_FROM_ALL ${ARGN})
target_compile_definitions(${name} PRIVATE $<$<BOOL:BUILD_SHARED_LIBS>:${macro}=1>)
target_link_libraries(${name} PRIVATE Boost::system Boost::config)
endmacro()
set(BOOST_TEST_LINK_LIBRARIES Boost::system Boost::core Boost::static_assert)
boost_test(SOURCES quick.cpp)
system_run(error_code_test.cpp)
system_run(error_code_user_test.cpp)
system_run(system_error_test.cpp)
lib(boost_system_throw_test THROW_DYN_LINK throw_test.cpp)
boost_test(SOURCES dynamic_link_test.cpp LINK_LIBRARIES boost_system_throw_test)
system_run(initialization_test.cpp)
system_run(header_only_test.cpp)
boost_test(SOURCES config_test.cpp)
system_run(std_interop_test.cpp)
system_run(std_mismatch_test.cpp)
lib(boost_system_single_instance_lib1 SINGLE_INSTANCE_DYN_LINK single_instance_1.cpp)
lib(boost_system_single_instance_lib2 SINGLE_INSTANCE_DYN_LINK single_instance_2.cpp)
system_run(single_instance_test.cpp single_instance_1.cpp single_instance_2.cpp)
boost_test(SOURCES single_instance_test.cpp NAME single_instance_test_lib LINK_LIBRARIES boost_system_single_instance_lib1 boost_system_single_instance_lib2)
system_run(before_main_test.cpp)
system_run(constexpr_test.cpp)
system_run(win32_hresult_test.cpp)
system_run(error_category_test.cpp)
system_run(generic_category_test.cpp)
system_run(system_category_test.cpp)
system_run(after_main_test.cpp)
system_run(failed_test.cpp)
system_run(failed_constexpr_test.cpp)
boost_test(SOURCES warnings_test.cpp COMPILE_OPTIONS -Wall -Werror)
lib(boost_system_std_single_instance_lib1 STD_SINGLE_INSTANCE_DYN_LINK std_single_instance_1.cpp)
lib(boost_system_std_single_instance_lib2 STD_SINGLE_INSTANCE_DYN_LINK std_single_instance_2.cpp)
system_run(std_single_instance_test.cpp std_single_instance_1.cpp std_single_instance_2.cpp)
boost_test(SOURCES std_single_instance_test.cpp NAME std_single_instance_test_lib LINK_LIBRARIES boost_system_std_single_instance_lib1 boost_system_std_single_instance_lib2)
boost_test(TYPE run SOURCES is_error_code_enum_test.cpp)
boost_test(TYPE run SOURCES is_error_condition_enum_test.cpp)
boost_test(TYPE run SOURCES errc_test.cpp)
boost_test(TYPE run SOURCES errc_test2.cpp)
boost_test(TYPE run SOURCES error_category_test2.cpp)
boost_test(TYPE run SOURCES error_condition_test.cpp)
boost_test(TYPE run SOURCES error_condition_test2.cpp)
boost_test(TYPE run SOURCES generic_category_test2.cpp)
boost_test(TYPE run SOURCES generic_category_test3.cpp)
boost_test(TYPE run SOURCES system_category_test2.cpp)
boost_test(TYPE run SOURCES system_category_test3.cpp)
boost_test(TYPE run SOURCES windows_error_test.cpp)
boost_test(TYPE run SOURCES cygwin_error_test.cpp)
boost_test(TYPE run SOURCES linux_error_test.cpp)
boost_test(TYPE link SOURCES errc_test3.cpp)
boost_test(TYPE run SOURCES snprintf_test.cpp)
boost_test(TYPE run SOURCES std_interop_test2.cpp)
boost_test(TYPE run SOURCES std_interop_test3.cpp)
boost_test(TYPE run SOURCES std_interop_test4.cpp)
boost_test(TYPE run SOURCES std_interop_test5.cpp)
boost_test(TYPE run SOURCES std_interop_test6.cpp)
boost_test(TYPE run SOURCES std_interop_test7.cpp)
boost_test(TYPE run SOURCES std_interop_test8.cpp)
boost_test(TYPE run SOURCES std_interop_test9.cpp)
boost_test(TYPE run SOURCES ec_location_test.cpp)
boost_test(TYPE run SOURCES error_condition_test3.cpp)
boost_test(TYPE run SOURCES error_code_test2.cpp)
boost_test(TYPE run SOURCES system_error_test2.cpp)
boost_test(TYPE run SOURCES std_interop_test10.cpp)
boost_test(TYPE run SOURCES ec_location_test2.cpp)
boost_test(TYPE run SOURCES ec_what_test.cpp)
boost_test(TYPE run SOURCES system_error_test3.cpp)
boost_test(TYPE run SOURCES std_interop_test11.cpp)
boost_test(TYPE run SOURCES ec_wstream_test.cpp)
boost_test(TYPE run SOURCES std_interop_test12.cpp)
boost_test(TYPE run SOURCES errc_test4.cpp)
# result
set(BOOST_TEST_COMPILE_FEATURES cxx_std_11)
boost_test(TYPE run SOURCES result_default_construct.cpp)
boost_test(TYPE run SOURCES result_value_construct.cpp)
boost_test(TYPE run SOURCES result_error_construct.cpp)
boost_test(TYPE run SOURCES result_copy_construct.cpp)
boost_test(TYPE run SOURCES result_move_construct.cpp)
boost_test(TYPE run SOURCES result_copy_assign.cpp)
boost_test(TYPE run SOURCES result_move_assign.cpp)
boost_test(TYPE run SOURCES result_value_access.cpp)
boost_test(TYPE run SOURCES result_error_access.cpp)
boost_test(TYPE run SOURCES result_swap.cpp)
boost_test(TYPE run SOURCES result_eq.cpp)
boost_test(TYPE run SOURCES result_range_for.cpp)
boost_test(TYPE run SOURCES result_value_construct2.cpp)
boost_test(TYPE run SOURCES result_error_construct2.cpp)

View File

@@ -0,0 +1,165 @@
# Boost System Library test Jamfile
# Copyright Beman Dawes 2003, 2006
# Copyright 2017-2021 Peter Dimov
# Distributed under the Boost Software License, Version 1.0.
# See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt
# See library home page at http://www.boost.org/libs/system
import testing ;
project
: default-build
<warnings>extra
: requirements
<toolset>msvc:<warnings-as-errors>on
<toolset>gcc:<warnings-as-errors>on
<toolset>clang:<warnings-as-errors>on
<toolset>gcc-4.4:<cxxflags>-Wno-sign-compare
;
rule system-run ( sources + )
{
local result ;
result += [ run $(sources) ] ;
result += [ run $(sources) : : : <library>/boost/system//boost_system <link>static : $(sources[1]:B)_static ] ;
result += [ run $(sources) : : : <library>/boost/system//boost_system <link>shared : $(sources[1]:B)_shared ] ;
result += [ run $(sources) : : : <define>BOOST_NO_ANSI_APIS : $(sources[1]:B)_no_ansi ] ;
result += [ run $(sources) : : : <define>BOOST_SYSTEM_USE_UTF8 : $(sources[1]:B)_utf8 ] ;
return $(result) ;
}
system-run error_code_test.cpp ;
system-run error_code_user_test.cpp ;
system-run system_error_test.cpp ;
lib throw_test : throw_test.cpp : <link>shared:<define>THROW_DYN_LINK=1 ;
run dynamic_link_test.cpp throw_test : : : <link>shared : throw_test_shared ;
system-run initialization_test.cpp ;
system-run header_only_test.cpp ;
run config_test.cpp : : : <test-info>always_show_run_output ;
system-run std_interop_test.cpp ;
system-run std_mismatch_test.cpp ;
lib single_instance_lib1 : single_instance_1.cpp : <link>shared:<define>SINGLE_INSTANCE_DYN_LINK ;
lib single_instance_lib2 : single_instance_2.cpp : <link>shared:<define>SINGLE_INSTANCE_DYN_LINK ;
system-run single_instance_test.cpp single_instance_1.cpp single_instance_2.cpp ;
run single_instance_test.cpp single_instance_lib1 single_instance_lib2 : : : <link>static : single_instance_lib_static ;
run single_instance_test.cpp single_instance_lib1 single_instance_lib2 : : : <link>shared : single_instance_lib_shared ;
system-run before_main_test.cpp ;
run-fail throws_assign_fail.cpp ;
system-run constexpr_test.cpp ;
system-run win32_hresult_test.cpp ;
system-run error_category_test.cpp ;
system-run generic_category_test.cpp ;
system-run system_category_test.cpp ;
system-run after_main_test.cpp ;
system-run failed_test.cpp ;
system-run failed_constexpr_test.cpp ;
# Quick (CI) test
run quick.cpp ;
run warnings_test.cpp
: : : <warnings>pedantic
<toolset>msvc:<warnings-as-errors>on
<toolset>gcc:<warnings-as-errors>on
<toolset>clang:<warnings-as-errors>on ;
lib std_single_instance_lib1 : std_single_instance_1.cpp : <link>shared:<define>STD_SINGLE_INSTANCE_DYN_LINK ;
lib std_single_instance_lib2 : std_single_instance_2.cpp : <link>shared:<define>STD_SINGLE_INSTANCE_DYN_LINK ;
system-run std_single_instance_test.cpp std_single_instance_1.cpp std_single_instance_2.cpp ;
run std_single_instance_test.cpp std_single_instance_lib1 std_single_instance_lib2 : : : <link>static : std_single_instance_lib_static ;
run std_single_instance_test.cpp std_single_instance_lib1 std_single_instance_lib2 : : : <link>shared <define>STD_SINGLE_INSTANCE_SHARED : std_single_instance_lib_shared ;
run is_error_code_enum_test.cpp ;
run is_error_condition_enum_test.cpp ;
run errc_test.cpp ;
run errc_test2.cpp ;
run error_category_test2.cpp ;
run error_condition_test.cpp ;
run error_condition_test2.cpp ;
run generic_category_test2.cpp ;
run generic_category_test3.cpp ;
run system_category_test2.cpp ;
run system_category_test3.cpp ;
run windows_error_test.cpp ;
run cygwin_error_test.cpp ;
run linux_error_test.cpp ;
link errc_test3.cpp ;
run snprintf_test.cpp ;
run std_interop_test2.cpp ;
run std_interop_test3.cpp ;
run std_interop_test4.cpp ;
run std_interop_test5.cpp
: : :
# crash on xenial, but the real g++ 4.8 on both centos 7 and trusty works
<toolset>gcc-4.8:<build>no
<toolset>gcc-4.9:<build>no
;
run std_interop_test6.cpp ;
run std_interop_test7.cpp ;
run std_interop_test8.cpp ;
run std_interop_test9.cpp ;
run ec_location_test.cpp ;
run error_condition_test3.cpp ;
run error_code_test2.cpp ;
run system_error_test2.cpp ;
run std_interop_test10.cpp ;
run ec_location_test2.cpp ;
run ec_what_test.cpp ;
run system_error_test3.cpp ;
run std_interop_test11.cpp ;
run ec_wstream_test.cpp ;
run std_interop_test12.cpp ;
run errc_test4.cpp ;
# result
import ../../config/checks/config : requires ;
CPP11 = [ requires cxx11_variadic_templates cxx11_template_aliases cxx11_decltype cxx11_constexpr cxx11_noexcept ] <toolset>gcc-4.7:<build>no ;
run result_default_construct.cpp : : : $(CPP11) ;
run result_value_construct.cpp : : : $(CPP11) ;
run result_error_construct.cpp : : : $(CPP11) ;
run result_copy_construct.cpp : : : $(CPP11) ;
run result_move_construct.cpp : : : $(CPP11) ;
run result_copy_assign.cpp : : : $(CPP11) ;
run result_move_assign.cpp : : : $(CPP11) ;
run result_value_access.cpp : : : $(CPP11) ;
run result_error_access.cpp : : : $(CPP11) ;
run result_swap.cpp : : : $(CPP11) <toolset>gcc-10:<cxxflags>"-Wno-maybe-uninitialized" ;
run result_eq.cpp : : : $(CPP11) ;
run result_range_for.cpp : : : $(CPP11) ;
run result_value_construct2.cpp : : : $(CPP11) ;
run result_error_construct2.cpp : : : $(CPP11) ;
run result_errc_construct.cpp : : : $(CPP11) ;

View File

@@ -0,0 +1,37 @@
// Copyright 2018 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
#include <boost/system/error_code.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/core/quick_exit.hpp>
#include <boost/config.hpp>
#include <cerrno>
#if defined(BOOST_MSVC)
# pragma warning(disable: 4722) // Z::~Z never returns
#endif
using namespace boost::system;
struct Z
{
~Z()
{
BOOST_TEST_CSTR_EQ( generic_category().name(), "generic" );
BOOST_TEST_CSTR_EQ( system_category().name(), "system" );
boost::quick_exit( boost::report_errors() );
}
};
static Z z;
static error_code e1( 1, system_category() );
static error_code e2( ENOENT, generic_category() );
int main()
{
(void)e1;
(void)e2;
}

View File

@@ -0,0 +1,30 @@
// Copyright 2018 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
#include <boost/system/error_code.hpp>
#include <boost/core/lightweight_test.hpp>
#include <cerrno>
using namespace boost::system;
static error_code e1( 1, system_category() );
static std::string m1 = e1.message();
static error_code e2( ENOENT, generic_category() );
static std::string m2 = e2.message();
int main()
{
error_code e1_( 1, system_category() );
BOOST_TEST_EQ( e1, e1_ );
BOOST_TEST_EQ( m1, e1_.message() );
error_code e2_( ENOENT, generic_category() );
BOOST_TEST_EQ( e2, e2_ );
BOOST_TEST_EQ( m2, e2_.message() );
return boost::report_errors();
}

View File

@@ -0,0 +1,17 @@
# Copyright 2018, 2019 Peter Dimov
# 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
cmake_minimum_required(VERSION 3.5...3.16)
project(cmake_install_test LANGUAGES CXX)
find_package(boost_system REQUIRED)
add_executable(main main.cpp)
target_link_libraries(main Boost::system)
enable_testing()
add_test(main main)
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -C $<CONFIG>)

View File

@@ -0,0 +1,44 @@
// Copyright 2017, 2021 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
// See library home page at http://www.boost.org/libs/system
#include <boost/system.hpp>
#include <cassert>
#include <cerrno>
#define BOOST_TEST(expr) assert(expr)
#define BOOST_TEST_EQ(x1, x2) assert((x1)==(x2))
int main()
{
boost::system::error_category const & bt = boost::system::generic_category();
int ev = ENOENT;
boost::system::error_code bc( ev, bt );
BOOST_TEST_EQ( bc.value(), ev );
BOOST_TEST_EQ( &bc.category(), &bt );
boost::system::error_condition bn = bt.default_error_condition( ev );
BOOST_TEST_EQ( bn.value(), ev );
BOOST_TEST_EQ( &bn.category(), &bt );
BOOST_TEST( bt.equivalent( ev, bn ) );
BOOST_TEST( bc == bn );
boost::system::error_code bc2 = make_error_code( boost::system::errc::no_such_file_or_directory );
BOOST_TEST_EQ( bc2, bc );
BOOST_TEST_EQ( bc2.value(), ev );
BOOST_TEST_EQ( &bc.category(), &bt );
boost::system::system_error x( bc, "prefix" );
BOOST_TEST_EQ( x.code(), bc );
BOOST_TEST_EQ( std::string( x.what() ), "prefix: " + bc.what() );
}

View File

@@ -0,0 +1,26 @@
# Copyright 2018-2021 Peter Dimov
# 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
cmake_minimum_required(VERSION 3.5...3.20)
project(cmake_subdir_test LANGUAGES CXX)
add_subdirectory(../.. boostorg/system)
add_subdirectory(../../../assert boostorg/assert)
add_subdirectory(../../../config boostorg/config)
add_subdirectory(../../../core boostorg/core)
add_subdirectory(../../../mp11 boostorg/mp11)
add_subdirectory(../../../predef boostorg/predef)
add_subdirectory(../../../static_assert boostorg/static_assert)
add_subdirectory(../../../throw_exception boostorg/throw_exception)
add_subdirectory(../../../variant2 boostorg/variant2)
add_subdirectory(../../../winapi boostorg/winapi)
add_executable(quick ../quick.cpp)
target_link_libraries(quick Boost::system Boost::core)
enable_testing()
add_test(quick quick)
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure --no-tests=error -C $<CONFIG>)

View File

@@ -0,0 +1,65 @@
// error_code_test.cpp ---------------------------------------------------------------//
// Copyright Beman Dawes 2014
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
// See library home page at http://www.boost.org/libs/system
#include <boost/system/config.hpp>
#include <iostream>
using std::cout;
using std::endl;
int main()
{
#ifdef BOOST_WINDOWS_API
std::cout << "BOOST_WINDOWS_API is defined" << std::endl;
#else
std::cout << "BOOST_WINDOWS_API is not defined" << std::endl;
#endif
#ifdef _MSC_VER
std::cout << "_MSC_VER is defined as " << _MSC_VER << std::endl;
#else
std::cout << "_MSC_VER is not defined" << std::endl;
#endif
#ifdef __CYGWIN__
std::cout << "__CYGWIN__ is defined" << std::endl;
#else
std::cout << "__CYGWIN__ is not defined" << std::endl;
#endif
#ifdef __MINGW32__
std::cout << "__MINGW32__ is defined" << std::endl;
#else
std::cout << "__MINGW32__ is not defined" << std::endl;
#endif
#ifdef BOOST_POSIX_API
std::cout << "BOOST_POSIX_API is defined" << std::endl;
#else
std::cout << "BOOST_POSIX_API is not defined" << std::endl;
#endif
#ifdef BOOST_PLAT_WINDOWS_DESKTOP
std::cout << "BOOST_PLAT_WINDOWS_DESKTOP is defined as "
<< BOOST_PLAT_WINDOWS_DESKTOP << std::endl;
#else
std::cout << "BOOST_PLAT_WINDOWS_DESKTOP is not defined" << std::endl;
#endif
#ifdef BOOST_NO_ANSI_APIS
std::cout << "BOOST_NO_ANSI_APIS is defined" << std::endl;
#else
std::cout << "BOOST_NO_ANSI_APIS is not defined" << std::endl;
#endif
#ifdef BOOST_NO_CXX11_NOEXCEPT
std::cout << "BOOST_NO_CXX11_NOEXCEPT is defined" << std::endl;
#else
std::cout << "BOOST_NO_CXX11_NOEXCEPT is not defined" << std::endl;
#endif
#ifdef BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS
std::cout << "BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS is defined" << std::endl;
#else
std::cout << "BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS is not defined" << std::endl;
#endif
return 0;
}

View File

@@ -0,0 +1,68 @@
// Copyright 2018 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
#include <boost/system/error_code.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/config/pragma_message.hpp>
#include <boost/static_assert.hpp>
#include <boost/config.hpp>
#include <boost/config/workaround.hpp>
#if !defined(BOOST_SYSTEM_HAS_CONSTEXPR)
BOOST_PRAGMA_MESSAGE("Skipping constexpr test, BOOST_SYSTEM_HAS_CONSTEXPR isn't defined")
int main() {}
#else
using namespace boost::system;
constexpr error_code e1( 1, system_category() );
BOOST_STATIC_ASSERT( e1.value() == 1 );
BOOST_STATIC_ASSERT( e1.category() == system_category() );
BOOST_STATIC_ASSERT( e1 );
BOOST_STATIC_ASSERT( e1 == e1 );
constexpr error_code e2( 2, generic_category() );
BOOST_STATIC_ASSERT( e2.value() == 2 );
BOOST_STATIC_ASSERT( e2.category() == generic_category() );
BOOST_STATIC_ASSERT( e2 );
BOOST_STATIC_ASSERT( e2 == e2 );
#if !BOOST_WORKAROUND(BOOST_GCC, < 80200)
BOOST_STATIC_ASSERT( e1 != e2 );
#endif
constexpr error_code e3;
BOOST_STATIC_ASSERT( e3.value() == 0 );
BOOST_STATIC_ASSERT( e3.category() == system_category() );
BOOST_STATIC_ASSERT( !e3 );
BOOST_STATIC_ASSERT( e3 == e3 );
#if !BOOST_WORKAROUND(BOOST_GCC, < 80200)
BOOST_STATIC_ASSERT( e1 != e3 );
#endif
int main()
{
error_code e1_( 1, system_category() );
BOOST_TEST_EQ( e1, e1_ );
error_code e2_( 2, generic_category() );
BOOST_TEST_EQ( e2, e2_ );
error_code e3_;
BOOST_TEST_EQ( e3, e3_ );
return boost::report_errors();
}
#endif

View File

@@ -0,0 +1,29 @@
// Copyright 2020 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/system/cygwin_error.hpp>
#include <boost/config/pragma_message.hpp>
#if !defined(__CYGWIN__)
BOOST_PRAGMA_MESSAGE( "Skipping test, __CYGWIN__ is not defined" )
int main() {}
#else
#include <boost/core/lightweight_test.hpp>
int main()
{
namespace sys = boost::system;
sys::error_code ec = sys::cygwin_error::no_package;
BOOST_TEST_EQ( ec, sys::cygwin_error::no_package );
BOOST_TEST_EQ( ec, sys::error_code( ENOPKG, sys::system_category() ) );
return boost::report_errors();
}
#endif

View File

@@ -0,0 +1,47 @@
// dynamic_link_test.cpp -------------------------------------------------------------//
// Copyright Beman Dawes 2010
// Distributed under the Boost Software License, Version 1.0.
// See www.boost.org/LICENSE_1_0.txt
// Library home page is www.boost.org/libs/system
//--------------------------------------------------------------------------------------//
// Dynamic link libraries (DLL's), also know as dynamic shared objects (DSO's),
// can cause symbol visability problems unless carefully configured. One of the
// manifestations, particularly with GCC, is that a system_error exception thrown from
// a DLL or DSO is not caught.
//
// The purpose of this program is to test for that error.
//--------------------------------------------------------------------------------------//
#include <boost/system/system_error.hpp>
#include <iostream>
void throw_test();
int main()
{
try
{
throw_test();
}
catch (const boost::system::system_error& ex)
{
std::cout << " caught boost::system::system_error as expected\n";
std::cout << " what() reports " << ex.what() << '\n';
return 0;
}
catch (const std::runtime_error& ex)
{
std::cout << " error: caught std::runtime_error instead of boost::system::system_error\n";
std::cout << " what() reports " << ex.what() << '\n';
return 1;
}
std::cout << " error: failed to catch boost::system::system_error\n";
return 1;
}

View File

@@ -0,0 +1,116 @@
// Copyright 2021 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/system.hpp>
#include <boost/core/lightweight_test.hpp>
#include <cerrno>
int main()
{
int const val = ENOENT;
boost::system::error_category const & cat = boost::system::generic_category();
{
boost::system::error_code ec( val, cat );
BOOST_TEST_EQ( ec.value(), val );
BOOST_TEST_EQ( &ec.category(), &cat );
BOOST_TEST( ec.failed() );
BOOST_TEST( !ec.has_location() );
BOOST_TEST_EQ( ec.location().line(), 0 );
}
{
BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION;
boost::system::error_code ec( val, cat, &loc );
BOOST_TEST_EQ( ec.value(), val );
BOOST_TEST_EQ( &ec.category(), &cat );
BOOST_TEST( ec.failed() );
BOOST_TEST( ec.has_location() );
BOOST_TEST_EQ( ec.location().line(), 27 );
}
{
boost::system::error_code ec;
BOOST_TEST_EQ( ec.value(), 0 );
BOOST_TEST_EQ( &ec.category(), &boost::system::system_category() );
BOOST_TEST( !ec.failed() );
BOOST_TEST( !ec.has_location() );
BOOST_TEST_EQ( ec.location().line(), 0 );
BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION;
ec = boost::system::error_code( val, cat, &loc );
BOOST_TEST_EQ( ec.value(), val );
BOOST_TEST_EQ( &ec.category(), &cat );
BOOST_TEST( ec.failed() );
BOOST_TEST( ec.has_location() );
BOOST_TEST_EQ( ec.location().line(), 51 );
}
{
boost::system::error_code ec;
BOOST_TEST_EQ( ec.value(), 0 );
BOOST_TEST_EQ( &ec.category(), &boost::system::system_category() );
BOOST_TEST( !ec.failed() );
BOOST_TEST( !ec.has_location() );
BOOST_TEST_EQ( ec.location().line(), 0 );
BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION;
ec.assign( val, cat, &loc );
BOOST_TEST_EQ( ec.value(), val );
BOOST_TEST_EQ( &ec.category(), &cat );
BOOST_TEST( ec.failed() );
BOOST_TEST( ec.has_location() );
BOOST_TEST_EQ( ec.location().line(), 75 );
}
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
{
std::error_code e2( val, std::generic_category() );
boost::system::error_code ec( e2 );
BOOST_TEST( ec.failed() );
BOOST_TEST( !ec.has_location() );
BOOST_TEST_EQ( ec.location().line(), 0 );
BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION;
ec.assign( val, cat, &loc );
BOOST_TEST_EQ( ec.value(), val );
BOOST_TEST_EQ( &ec.category(), &cat );
BOOST_TEST( ec.failed() );
BOOST_TEST( ec.has_location() );
BOOST_TEST_EQ( ec.location().line(), 100 );
}
#endif
return boost::report_errors();
}

View File

@@ -0,0 +1,287 @@
// Copyright 2021 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/system.hpp>
#include <boost/core/lightweight_test.hpp>
#include <cerrno>
namespace sys = boost::system;
enum E
{
none = 0,
einval = EINVAL
};
namespace boost
{
namespace system
{
template<> struct is_error_code_enum< ::E >
{
static const bool value = true;
};
} // namespace system
} // namespace boost
sys::error_code make_error_code( E e )
{
return e == 0? sys::error_code(): sys::error_code( e, sys::generic_category() );
}
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
enum E2
{
e2inval = EINVAL
};
namespace boost
{
namespace system
{
template<> struct is_error_code_enum< ::E2 >
{
static const bool value = true;
};
} // namespace system
} // namespace boost
std::error_code make_error_code( E2 e )
{
return std::error_code( e, std::generic_category() );
}
#endif
int main()
{
{
sys::error_code ec( einval );
BOOST_TEST_EQ( ec.value(), EINVAL );
BOOST_TEST_EQ( &ec.category(), &sys::generic_category() );
BOOST_TEST( ec.failed() );
BOOST_TEST( !ec.has_location() );
BOOST_TEST_EQ( ec.location().line(), 0 );
}
{
BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION;
sys::error_code ec( einval, &loc );
BOOST_TEST_EQ( ec.value(), EINVAL );
BOOST_TEST_EQ( &ec.category(), &sys::generic_category() );
BOOST_TEST( ec.failed() );
BOOST_TEST( ec.has_location() );
BOOST_TEST_EQ( ec.location().line(), 77 );
}
{
sys::error_code ec( none );
BOOST_TEST_EQ( ec.value(), 0 );
BOOST_TEST_EQ( &ec.category(), &sys::system_category() );
BOOST_TEST( !ec.failed() );
BOOST_TEST( !ec.has_location() );
BOOST_TEST_EQ( ec.location().line(), 0 );
}
{
BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION;
sys::error_code ec( none, &loc );
BOOST_TEST_EQ( ec.value(), 0 );
BOOST_TEST_EQ( &ec.category(), &sys::system_category() );
BOOST_TEST( !ec.failed() );
BOOST_TEST( !ec.has_location() );
BOOST_TEST_EQ( ec.location().line(), 0 );
}
{
sys::error_code ec;
BOOST_TEST_EQ( ec.value(), 0 );
BOOST_TEST_EQ( &ec.category(), &sys::system_category() );
BOOST_TEST( !ec.failed() );
BOOST_TEST( !ec.has_location() );
BOOST_TEST_EQ( ec.location().line(), 0 );
BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION;
ec = sys::error_code( einval, &loc );
BOOST_TEST_EQ( ec.value(), EINVAL );
BOOST_TEST_EQ( &ec.category(), &sys::generic_category() );
BOOST_TEST( ec.failed() );
BOOST_TEST( ec.has_location() );
BOOST_TEST_EQ( ec.location().line(), 127 );
}
{
sys::error_code ec;
BOOST_TEST_EQ( ec.value(), 0 );
BOOST_TEST_EQ( &ec.category(), &sys::system_category() );
BOOST_TEST( !ec.failed() );
BOOST_TEST( !ec.has_location() );
BOOST_TEST_EQ( ec.location().line(), 0 );
BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION;
ec = sys::error_code( none, &loc );
BOOST_TEST_EQ( ec.value(), 0 );
BOOST_TEST_EQ( &ec.category(), &sys::system_category() );
BOOST_TEST( !ec.failed() );
BOOST_TEST( !ec.has_location() );
BOOST_TEST_EQ( ec.location().line(), 0 );
}
{
sys::error_code ec;
BOOST_TEST_EQ( ec.value(), 0 );
BOOST_TEST_EQ( &ec.category(), &sys::system_category() );
BOOST_TEST( !ec.failed() );
BOOST_TEST( !ec.has_location() );
BOOST_TEST_EQ( ec.location().line(), 0 );
BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION;
ec.assign( einval, &loc );
BOOST_TEST_EQ( ec.value(), EINVAL );
BOOST_TEST_EQ( &ec.category(), &sys::generic_category() );
BOOST_TEST( ec.failed() );
BOOST_TEST( ec.has_location() );
BOOST_TEST_EQ( ec.location().line(), 175 );
}
{
sys::error_code ec;
BOOST_TEST_EQ( ec.value(), 0 );
BOOST_TEST_EQ( &ec.category(), &sys::system_category() );
BOOST_TEST( !ec.failed() );
BOOST_TEST( !ec.has_location() );
BOOST_TEST_EQ( ec.location().line(), 0 );
BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION;
ec.assign( none, &loc );
BOOST_TEST_EQ( ec.value(), 0 );
BOOST_TEST_EQ( &ec.category(), &sys::system_category() );
BOOST_TEST( !ec.failed() );
BOOST_TEST( !ec.has_location() );
BOOST_TEST_EQ( ec.location().line(), 0 );
}
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
{
sys::error_code ec( e2inval );
BOOST_TEST_EQ( ec, std::error_code( EINVAL, std::generic_category() ) );
BOOST_TEST( ec.failed() );
BOOST_TEST( !ec.has_location() );
BOOST_TEST_EQ( ec.location().line(), 0 );
}
{
BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION;
sys::error_code ec( e2inval, &loc );
BOOST_TEST_EQ( ec, std::error_code( EINVAL, std::generic_category() ) );
BOOST_TEST( ec.failed() );
BOOST_TEST( !ec.has_location() );
BOOST_TEST_EQ( ec.location().line(), 0 );
}
{
sys::error_code ec;
BOOST_TEST_EQ( ec.value(), 0 );
BOOST_TEST_EQ( &ec.category(), &sys::system_category() );
BOOST_TEST( !ec.failed() );
BOOST_TEST( !ec.has_location() );
BOOST_TEST_EQ( ec.location().line(), 0 );
BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION;
ec = sys::error_code( e2inval, &loc );
BOOST_TEST_EQ( ec, std::error_code( EINVAL, std::generic_category() ) );
BOOST_TEST( ec.failed() );
BOOST_TEST( !ec.has_location() );
BOOST_TEST_EQ( ec.location().line(), 0 );
}
{
sys::error_code ec;
BOOST_TEST_EQ( ec.value(), 0 );
BOOST_TEST_EQ( &ec.category(), &sys::system_category() );
BOOST_TEST( !ec.failed() );
BOOST_TEST( !ec.has_location() );
BOOST_TEST_EQ( ec.location().line(), 0 );
BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION;
ec.assign( e2inval, &loc );
BOOST_TEST_EQ( ec, std::error_code( EINVAL, std::generic_category() ) );
BOOST_TEST( ec.failed() );
BOOST_TEST( !ec.has_location() );
BOOST_TEST_EQ( ec.location().line(), 0 );
}
#endif
return boost::report_errors();
}

View File

@@ -0,0 +1,91 @@
// Copyright 2020, 2021 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// http://www.boost.org/LICENSE_1_0.txt
#include <boost/system/error_code.hpp>
#include <boost/system/generic_category.hpp>
#include <boost/system/system_category.hpp>
#include <boost/core/lightweight_test.hpp>
namespace sys = boost::system;
int main()
{
{
sys::error_code ec;
BOOST_TEST_EQ( ec.value(), 0 );
BOOST_TEST( ec.category() == sys::system_category() );
BOOST_TEST_EQ( ec.what(), ec.message() + " [system:0]" );
}
{
sys::error_code ec( 5, sys::generic_category() );
BOOST_TEST_EQ( ec.value(), 5 );
BOOST_TEST( ec.category() == sys::generic_category() );
BOOST_TEST_EQ( ec.what(), ec.message() + " [generic:5]" );
}
{
sys::error_code ec( 5, sys::system_category() );
BOOST_TEST_EQ( ec.value(), 5 );
BOOST_TEST( ec.category() == sys::system_category() );
BOOST_TEST_EQ( ec.what(), ec.message() + " [system:5]" );
}
{
BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION;
sys::error_code ec( 5, sys::generic_category(), &loc );
BOOST_TEST_EQ( ec.value(), 5 );
BOOST_TEST( ec.category() == sys::generic_category() );
BOOST_TEST_EQ( &ec.location(), &loc );
BOOST_TEST_EQ( ec.what(), ec.message() + " [generic:5 at " + loc.to_string() + "]" );
}
{
BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION;
sys::error_code ec( 5, sys::system_category(), &loc );
BOOST_TEST_EQ( ec.value(), 5 );
BOOST_TEST( ec.category() == sys::system_category() );
BOOST_TEST_EQ( &ec.location(), &loc );
BOOST_TEST_EQ( ec.what(), ec.message() + " [system:5 at " + loc.to_string() + "]" );
}
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
{
std::error_code ec;
sys::error_code ec2( ec );
BOOST_TEST_EQ( ec2.what(), ec2.message() + " [std:system:0]" );
}
{
std::error_code ec( 5, std::generic_category() );
sys::error_code ec2( ec );
BOOST_TEST_EQ( ec2.what(), ec2.message() + " [std:generic:5]" );
}
{
std::error_code ec( 5, std::system_category() );
sys::error_code ec2( ec );
BOOST_TEST_EQ( ec2.what(), ec2.message() + " [std:system:5]" );
}
#endif
return boost::report_errors();
}

View File

@@ -0,0 +1,21 @@
// Copyright 2022 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// http://www.boost.org/LICENSE_1_0.txt
#include <boost/system/error_code.hpp>
#include <boost/core/lightweight_test.hpp>
#include <sstream>
namespace sys = boost::system;
int main()
{
{
std::wostringstream os;
os << sys::error_code();
BOOST_TEST( os.str() == L"system:0" );
}
return boost::report_errors();
}

View File

@@ -0,0 +1,18 @@
// Copyright 2020 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// http://www.boost.org/LICENSE_1_0.txt
#include <boost/system/errc.hpp>
#include <boost/system/is_error_condition_enum.hpp>
#include <boost/core/lightweight_test.hpp>
int main()
{
BOOST_TEST_EQ( static_cast<int>( boost::system::errc::success ), 0 );
BOOST_TEST_EQ( static_cast<int>( boost::system::errc::no_such_file_or_directory ), ENOENT );
BOOST_TEST_EQ( static_cast<int>( boost::system::errc::address_family_not_supported ), EAFNOSUPPORT );
BOOST_TEST( boost::system::is_error_condition_enum< boost::system::errc::errc_t >::value );
return boost::report_errors();
}

View File

@@ -0,0 +1,20 @@
// Copyright 2020 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// http://www.boost.org/LICENSE_1_0.txt
#include <boost/system/errc.hpp>
#include <boost/core/lightweight_test.hpp>
int main()
{
BOOST_TEST_EQ( make_error_code( boost::system::errc::success ).value(), 0 );
BOOST_TEST_EQ( make_error_condition( boost::system::errc::success ).value(), 0 );
BOOST_TEST_EQ( make_error_code( boost::system::errc::no_such_file_or_directory ).value(), ENOENT );
BOOST_TEST_EQ( make_error_condition( boost::system::errc::no_such_file_or_directory ).value(), ENOENT );
BOOST_TEST_EQ( make_error_code( boost::system::errc::address_family_not_supported ).value(), EAFNOSUPPORT );
BOOST_TEST_EQ( make_error_condition( boost::system::errc::address_family_not_supported ).value(), EAFNOSUPPORT );
return boost::report_errors();
}

View File

@@ -0,0 +1,34 @@
// Copyright 2021 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// http://www.boost.org/LICENSE_1_0.txt
#include <boost/system/errc.hpp>
int main()
{
make_error_code( boost::system::errc::success ).value();
make_error_code( boost::system::errc::success ).category();
make_error_code( boost::system::errc::success ).default_error_condition();
make_error_code( boost::system::errc::success ).message();
make_error_code( boost::system::errc::success ).failed();
make_error_code( boost::system::errc::success ).clear();
make_error_condition( boost::system::errc::success ).value();
make_error_condition( boost::system::errc::success ).category();
make_error_condition( boost::system::errc::success ).message();
make_error_condition( boost::system::errc::success ).failed();
make_error_condition( boost::system::errc::success ).clear();
make_error_code( boost::system::errc::no_such_file_or_directory ).value();
make_error_code( boost::system::errc::no_such_file_or_directory ).category();
make_error_code( boost::system::errc::no_such_file_or_directory ).default_error_condition();
make_error_code( boost::system::errc::no_such_file_or_directory ).message();
make_error_code( boost::system::errc::no_such_file_or_directory ).failed();
make_error_code( boost::system::errc::no_such_file_or_directory ).clear();
make_error_condition( boost::system::errc::no_such_file_or_directory ).value();
make_error_condition( boost::system::errc::no_such_file_or_directory ).category();
make_error_condition( boost::system::errc::no_such_file_or_directory ).message();
make_error_condition( boost::system::errc::no_such_file_or_directory ).failed();
make_error_condition( boost::system::errc::no_such_file_or_directory ).clear();
}

View File

@@ -0,0 +1,17 @@
// Copyright 2022 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// http://www.boost.org/LICENSE_1_0.txt
#include <boost/system/errc.hpp>
#include <boost/assert/source_location.hpp>
#include <boost/core/lightweight_test.hpp>
int main()
{
BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION;
BOOST_TEST( make_error_code( boost::system::errc::no_such_file_or_directory, &loc ).has_location() );
BOOST_TEST_EQ( make_error_code( boost::system::errc::no_such_file_or_directory, &loc ).location().to_string(), loc.to_string() );
return boost::report_errors();
}

View File

@@ -0,0 +1,82 @@
// Copyright 2018 Peter Dimov.
//
// 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 library home page at http://www.boost.org/libs/system
// Avoid spurious VC++ warnings
# define _CRT_SECURE_NO_WARNINGS
#include <boost/system/error_code.hpp>
#include <boost/core/lightweight_test.hpp>
#include <cstdio>
//
namespace sys = boost::system;
class user_category: public sys::error_category
{
public:
virtual const char * name() const BOOST_NOEXCEPT
{
return "user";
}
virtual std::string message( int ev ) const
{
char buffer[ 256 ];
std::sprintf( buffer, "user message %d", ev );
return buffer;
}
using sys::error_category::message;
};
static user_category s_cat_1;
static user_category s_cat_2;
int main()
{
// default_error_condition
BOOST_TEST( s_cat_1.default_error_condition( 1 ) == sys::error_condition( 1, s_cat_1 ) );
BOOST_TEST( s_cat_2.default_error_condition( 2 ) == sys::error_condition( 2, s_cat_2 ) );
// equivalent
BOOST_TEST( s_cat_1.equivalent( 1, sys::error_condition( 1, s_cat_1 ) ) );
BOOST_TEST( !s_cat_1.equivalent( 1, sys::error_condition( 2, s_cat_1 ) ) );
BOOST_TEST( !s_cat_1.equivalent( 1, sys::error_condition( 2, s_cat_2 ) ) );
// the other equivalent
BOOST_TEST( s_cat_1.equivalent( sys::error_code( 1, s_cat_1 ), 1 ) );
BOOST_TEST( !s_cat_1.equivalent( sys::error_code( 1, s_cat_1 ), 2 ) );
BOOST_TEST( !s_cat_1.equivalent( sys::error_code( 1, s_cat_2 ), 1 ) );
// message
{
char buffer[ 256 ];
BOOST_TEST_CSTR_EQ( s_cat_1.message( 1, buffer, sizeof( buffer ) ), s_cat_1.message( 1 ).c_str() );
}
{
char buffer[ 4 ];
BOOST_TEST_CSTR_EQ( s_cat_1.message( 1, buffer, sizeof( buffer ) ), "use" );
}
// ==
BOOST_TEST_NOT( s_cat_1 == s_cat_2 );
BOOST_TEST( s_cat_1 != s_cat_2 );
return boost::report_errors();
}

View File

@@ -0,0 +1,79 @@
// Copyright 2018, 2020 Peter Dimov.
//
// 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 library home page at http://www.boost.org/libs/system
// Avoid spurious VC++ warnings
#define _CRT_SECURE_NO_WARNINGS
#include <boost/system/error_category.hpp>
#include <boost/core/lightweight_test.hpp>
#include <cstdio>
//
namespace sys = boost::system;
class user_category: public sys::error_category
{
public:
virtual const char * name() const BOOST_NOEXCEPT
{
return "user";
}
virtual std::string message( int ev ) const
{
char buffer[ 256 ];
std::sprintf( buffer, "user message %d", ev );
return buffer;
}
using sys::error_category::message;
};
static user_category s_cat_1;
static user_category s_cat_2;
int main()
{
// default_error_condition
BOOST_TEST( s_cat_1.default_error_condition( 1 ).value() == 1 );
BOOST_TEST( s_cat_1.default_error_condition( 1 ).category() == s_cat_1 );
BOOST_TEST( s_cat_2.default_error_condition( 2 ).value() == 2 );
BOOST_TEST( s_cat_2.default_error_condition( 2 ).category() == s_cat_2 );
// equivalent
BOOST_TEST( s_cat_1.equivalent( 1, s_cat_1.default_error_condition( 1 ) ) );
BOOST_TEST( !s_cat_1.equivalent( 1, s_cat_1.default_error_condition( 2 ) ) );
BOOST_TEST( !s_cat_1.equivalent( 1, s_cat_2.default_error_condition( 2 ) ) );
// message
{
char buffer[ 256 ];
BOOST_TEST_CSTR_EQ( s_cat_1.message( 1, buffer, sizeof( buffer ) ), s_cat_1.message( 1 ).c_str() );
}
{
char buffer[ 4 ];
BOOST_TEST_CSTR_EQ( s_cat_1.message( 1, buffer, sizeof( buffer ) ), "use" );
}
// ==
BOOST_TEST_NOT( s_cat_1 == s_cat_2 );
BOOST_TEST( s_cat_1 != s_cat_2 );
return boost::report_errors();
}

View File

@@ -0,0 +1,298 @@
// error_code_test.cpp -----------------------------------------------------//
// Copyright Beman Dawes 2006
// 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 library home page at http://www.boost.org/libs/system
//----------------------------------------------------------------------------//
#include <boost/config/warning_disable.hpp>
#include <boost/system/error_code.hpp>
#include <boost/core/lightweight_test.hpp>
#include <iostream>
#include <sstream>
#include <string>
#include <cstring>
#include <functional>
#include <boost/cerrno.hpp>
// Although using directives are not the best programming practice, testing
// with a boost::system using directive increases use scenario coverage.
using namespace boost::system;
#if defined( BOOST_WINDOWS_API )
// Neither MinGW or Cygwin versions of winerror.h work if used alone, so on
// either of those platforms include the full windows.h
# if defined(__MINGW32__) || defined(__CYGWIN__)
# include <windows.h>
# else
# include <winerror.h>
# endif
# define BOOST_ACCESS_ERROR_MACRO ERROR_ACCESS_DENIED
#elif defined( BOOST_POSIX_API )
# define BOOST_ACCESS_ERROR_MACRO EACCES
#else
# error "Only supported for POSIX and Windows"
#endif
namespace
{
void check_ostream( error_code ec, const char * expected )
{
std::stringstream ss;
std::string s;
ss << ec;
ss >> s;
BOOST_TEST( s == expected );
}
// throws_function_test ------------------------------------------------------------//
// usage example
int divide(int dividend, int divisor, boost::system::error_code& ec = boost::throws())
{
if (divisor == 0) // is there an error?
{
if (&ec == &boost::throws()) // throw on error
throw "oops!"; // whatever exception you prefer
ec = error_code(EDOM, generic_category()); // report error via error_code
return 0;
}
if (&ec != &boost::throws()) // error reporting via error_code
ec.clear();
return dividend / divisor;
}
// test usage example
void test_throws_usage()
{
std::cout << "Test throws() example and usage...\n";
error_code ec;
// no error tests
BOOST_TEST_EQ((divide(10, 2)), 5); // no error, report via exception
ec = make_error_code(errc::argument_out_of_domain);
BOOST_TEST_EQ((divide(10, 5, ec)), 2); // no error, report via error_code
BOOST_TEST(!ec);
ec = make_error_code(errc::argument_out_of_domain);
BOOST_TEST_EQ((divide(10, 0, ec)), 0); // error, report via error_code
BOOST_TEST(ec);
bool exception_thrown = false;
try
{ divide(10, 0); } // error, report via exception
catch (...)
{ exception_thrown = true; }
BOOST_TEST(exception_thrown);
//error_code should_fail(boost::throws()); // should fail at runtime
//boost::throws() = ec; // should fail at runtime
}
}
// main ------------------------------------------------------------------------------//
// TODO: add hash_value tests
int main( int, char ** )
{
std::cout << "Conversion use cases...\n";
error_condition x1( errc::file_exists );
(void)x1;
//error_code x2( errc::file_exists ); // should fail to compile
make_error_code(errc::file_exists);
make_error_condition(errc::file_exists);
std::cout << "General tests...\n";
// unit tests:
BOOST_TEST( generic_category() == generic_category() );
BOOST_TEST( system_category() == system_category() );
BOOST_TEST( generic_category() != system_category() );
BOOST_TEST( system_category() != generic_category() );
BOOST_TEST_NE( generic_category() < system_category(), system_category() < generic_category() );
error_code ec;
error_condition econd;
BOOST_TEST( !ec );
BOOST_TEST( ec.value() == 0 );
econd = ec.default_error_condition();
BOOST_TEST( econd.value() == 0 );
BOOST_TEST( econd.category() == generic_category() );
BOOST_TEST( ec == errc::success );
BOOST_TEST( ec.category() == system_category() );
BOOST_TEST( std::strcmp( ec.category().name(), "system") == 0 );
BOOST_TEST( !(ec < error_code( 0, system_category() )) );
BOOST_TEST( !(error_code( 0, system_category() ) < ec) );
BOOST_TEST( ec < error_code( 1, system_category() ) );
BOOST_TEST( !(error_code( 1, system_category() ) < ec) );
error_code ec_0_system( 0, system_category() );
BOOST_TEST( !ec_0_system );
BOOST_TEST( ec_0_system.value() == 0 );
econd = ec_0_system.default_error_condition();
BOOST_TEST( econd.value() == 0 );
BOOST_TEST( econd.category() == generic_category() );
BOOST_TEST( ec_0_system == errc::success );
BOOST_TEST( ec_0_system.category() == system_category() );
BOOST_TEST( std::strcmp( ec_0_system.category().name(), "system") == 0 );
check_ostream( ec_0_system, "system:0" );
BOOST_TEST( ec_0_system == ec );
error_code ec_1_system( 1, system_category() );
BOOST_TEST( ec_1_system );
BOOST_TEST( ec_1_system.value() == 1 );
BOOST_TEST( ec_1_system.value() != 0 );
BOOST_TEST( ec != ec_1_system );
BOOST_TEST( ec_0_system != ec_1_system );
check_ostream( ec_1_system, "system:1" );
ec = error_code( BOOST_ACCESS_ERROR_MACRO, system_category() );
BOOST_TEST( ec );
BOOST_TEST( ec.value() == BOOST_ACCESS_ERROR_MACRO );
econd = ec.default_error_condition();
BOOST_TEST( econd.value() == static_cast<int>(errc::permission_denied) );
BOOST_TEST( econd.category() == generic_category() );
BOOST_TEST( econd == error_condition( errc::permission_denied, generic_category() ) );
BOOST_TEST( econd == errc::permission_denied );
BOOST_TEST( errc::permission_denied == econd );
BOOST_TEST( ec == errc::permission_denied );
BOOST_TEST( ec.category() == system_category() );
BOOST_TEST( std::strcmp( ec.category().name(), "system") == 0 );
// test the explicit make_error_code conversion for errc
ec = make_error_code( errc::bad_message );
BOOST_TEST( ec );
BOOST_TEST( ec == errc::bad_message );
BOOST_TEST( errc::bad_message == ec );
BOOST_TEST( ec != errc::permission_denied );
BOOST_TEST( errc::permission_denied != ec );
BOOST_TEST( ec.category() == generic_category() );
//// test the deprecated predefined error_category synonyms
//BOOST_TEST( &system_category() == &native_ecat );
//BOOST_TEST( &generic_category() == &errno_ecat );
//BOOST_TEST( system_category() == native_ecat );
//BOOST_TEST( generic_category() == errno_ecat );
// test error_code and error_condition message();
// see Boost.Filesystem operations_test for code specific message() tests
ec = error_code( -1, system_category() );
std::cout << "error_code message for -1 is \"" << ec.message() << "\"\n";
std::cout << "error_code message for 0 is \"" << ec_0_system.message() << "\"\n";
#if defined(BOOST_WINDOWS_API)
// Borland appends newline, so just check text
BOOST_TEST( ec.message().substr(0,13) == "Unknown error" );
// Fails when the language isn't US English
// BOOST_TEST( ec_0_system.message().substr(0,36) == "The operation completed successfully" );
#elif defined(linux) || defined(__linux) || defined(__linux__)
// Linux appends value to message as unsigned, so it varies with # of bits
BOOST_TEST( ec.message().substr(0,13) == "Unknown error" );
#elif defined(__hpux)
BOOST_TEST( ec.message() == "" );
#elif defined(__osf__)
BOOST_TEST( ec.message() == "Error -1 occurred." );
#elif defined(__vms)
BOOST_TEST( ec.message() == "error -1" );
#endif
ec = error_code( BOOST_ACCESS_ERROR_MACRO, system_category() );
BOOST_TEST( ec.message() != "" );
BOOST_TEST( ec.message().substr( 0, 13) != "Unknown error" );
econd = error_condition( -1, generic_category() );
error_condition econd_ok;
std::cout << "error_condition message for -1 is \"" << econd.message() << "\"\n";
std::cout << "error_condition message for 0 is \"" << econd_ok.message() << "\"\n";
#if defined(BOOST_WINDOWS_API)
// Borland appends newline, so just check text
BOOST_TEST( econd.message().substr(0,13) == "Unknown error" );
BOOST_TEST( econd_ok.message().substr(0,8) == "No error" );
#elif defined(linux) || defined(__linux) || defined(__linux__)
// Linux appends value to message as unsigned, so it varies with # of bits
BOOST_TEST( econd.message().substr(0,13) == "Unknown error" );
#elif defined(__hpux)
BOOST_TEST( econd.message() == "" );
#elif defined(__osf__)
BOOST_TEST( econd.message() == "Error -1 occurred." );
#elif defined(__vms)
BOOST_TEST( econd.message() == "error -1" );
#endif
econd = error_condition( BOOST_ACCESS_ERROR_MACRO, generic_category() );
BOOST_TEST( econd.message() != "" );
BOOST_TEST( econd.message().substr( 0, 13) != "Unknown error" );
test_throws_usage();
#ifdef BOOST_WINDOWS_API
std::cout << "Windows tests...\n";
// these tests probe the Windows errc decoder
// test the first entry in the decoder table:
ec = error_code( ERROR_ACCESS_DENIED, system_category() );
BOOST_TEST( ec.value() == ERROR_ACCESS_DENIED );
BOOST_TEST( ec == errc::permission_denied );
BOOST_TEST( ec.default_error_condition().value() == errc::permission_denied );
BOOST_TEST( ec.default_error_condition().category() == generic_category() );
// test the second entry in the decoder table:
ec = error_code( ERROR_ALREADY_EXISTS, system_category() );
BOOST_TEST( ec.value() == ERROR_ALREADY_EXISTS );
BOOST_TEST( ec == errc::file_exists );
BOOST_TEST( ec.default_error_condition().value() == errc::file_exists );
BOOST_TEST( ec.default_error_condition().category() == generic_category() );
// test the third entry in the decoder table:
ec = error_code( ERROR_BAD_UNIT, system_category() );
BOOST_TEST( ec.value() == ERROR_BAD_UNIT );
BOOST_TEST( ec == errc::no_such_device );
BOOST_TEST( ec.default_error_condition().value() == errc::no_such_device );
BOOST_TEST( ec.default_error_condition().category() == generic_category() );
// test the last non-Winsock entry in the decoder table:
ec = error_code( ERROR_WRITE_PROTECT, system_category() );
BOOST_TEST( ec.value() == ERROR_WRITE_PROTECT );
BOOST_TEST( ec == errc::permission_denied );
BOOST_TEST( ec.default_error_condition().value() == errc::permission_denied );
BOOST_TEST( ec.default_error_condition().category() == generic_category() );
// test the last Winsock entry in the decoder table:
ec = error_code( WSAEWOULDBLOCK, system_category() );
BOOST_TEST( ec.value() == WSAEWOULDBLOCK );
BOOST_TEST( ec == errc::operation_would_block );
BOOST_TEST( ec.default_error_condition().value() == errc::operation_would_block );
BOOST_TEST( ec.default_error_condition().category() == generic_category() );
// test not-in-table condition:
ec = error_code( 1234567890, system_category() );
BOOST_TEST( ec.value() == 1234567890 );
BOOST_TEST( ec.default_error_condition().value() == 1234567890 );
BOOST_TEST( ec.default_error_condition().category() == system_category() );
#else // POSIX
std::cout << "POSIX tests...\n";
ec = error_code( EACCES, system_category() );
BOOST_TEST( ec == error_code( errc::permission_denied, system_category() ) );
BOOST_TEST( error_code( errc::permission_denied, system_category() ) == ec );
BOOST_TEST( ec == errc::permission_denied );
BOOST_TEST( errc::permission_denied == ec );
BOOST_TEST( ec.default_error_condition().value() == errc::permission_denied );
BOOST_TEST( ec.default_error_condition().category() == generic_category() );
#endif
return ::boost::report_errors();
}

View File

@@ -0,0 +1,94 @@
// Copyright 2020, 2021 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// http://www.boost.org/LICENSE_1_0.txt
#include <boost/system/error_code.hpp>
#include <boost/system/generic_category.hpp>
#include <boost/system/system_category.hpp>
#include <boost/core/lightweight_test.hpp>
namespace sys = boost::system;
int main()
{
char buffer[ 1024 ];
sys::error_code ec;
BOOST_TEST_EQ( ec.value(), 0 );
BOOST_TEST( ec.category() == sys::system_category() );
BOOST_TEST_EQ( ec.message(), ec.category().message( ec.value() ) );
BOOST_TEST_CSTR_EQ( ec.message( buffer, sizeof( buffer ) ), ec.category().message( ec.value(), buffer, sizeof( buffer ) ) );
BOOST_TEST( !ec.failed() );
BOOST_TEST( !ec );
BOOST_TEST_EQ( ec.to_string(), std::string( "system:0" ) );
{
sys::error_code ec2( ec );
BOOST_TEST_EQ( ec2.value(), 0 );
BOOST_TEST( ec2.category() == sys::system_category() );
BOOST_TEST_EQ( ec2.message(), ec2.category().message( ec2.value() ) );
BOOST_TEST_CSTR_EQ( ec2.message( buffer, sizeof( buffer ) ), ec2.category().message( ec2.value(), buffer, sizeof( buffer ) ) );
BOOST_TEST( !ec2.failed() );
BOOST_TEST( !ec2 );
BOOST_TEST_EQ( ec, ec2 );
BOOST_TEST_NOT( ec != ec2 );
BOOST_TEST_EQ( ec2.to_string(), std::string( "system:0" ) );
}
{
sys::error_code ec2( ec.value(), ec.category() );
BOOST_TEST_EQ( ec2.value(), 0 );
BOOST_TEST( ec2.category() == sys::system_category() );
BOOST_TEST_EQ( ec2.message(), ec2.category().message( ec2.value() ) );
BOOST_TEST_CSTR_EQ( ec2.message( buffer, sizeof( buffer ) ), ec2.category().message( ec2.value(), buffer, sizeof( buffer ) ) );
BOOST_TEST( !ec2.failed() );
BOOST_TEST( !ec2 );
BOOST_TEST_EQ( ec, ec2 );
BOOST_TEST_NOT( ec != ec2 );
BOOST_TEST_EQ( ec2.to_string(), std::string( "system:0" ) );
}
{
sys::error_code ec2( 5, sys::generic_category() );
BOOST_TEST_EQ( ec2.value(), 5 );
BOOST_TEST( ec2.category() == sys::generic_category() );
BOOST_TEST_EQ( ec2.message(), ec2.category().message( ec2.value() ) );
BOOST_TEST_CSTR_EQ( ec2.message( buffer, sizeof( buffer ) ), ec2.category().message( ec2.value(), buffer, sizeof( buffer ) ) );
BOOST_TEST( ec2.failed() );
BOOST_TEST( ec2 );
BOOST_TEST_NOT( !ec2 );
BOOST_TEST_NE( ec, ec2 );
BOOST_TEST_NOT( ec == ec2 );
BOOST_TEST_EQ( ec2.to_string(), std::string( "generic:5" ) );
}
{
sys::error_code ec2( 5, sys::system_category() );
BOOST_TEST_EQ( ec2.value(), 5 );
BOOST_TEST( ec2.category() == sys::system_category() );
BOOST_TEST_EQ( ec2.message(), ec2.category().message( ec2.value() ) );
BOOST_TEST_CSTR_EQ( ec2.message( buffer, sizeof( buffer ) ), ec2.category().message( ec2.value(), buffer, sizeof( buffer ) ) );
BOOST_TEST( ec2.failed() );
BOOST_TEST( ec2 );
BOOST_TEST_NOT( !ec2 );
BOOST_TEST_NE( ec, ec2 );
BOOST_TEST_NOT( ec == ec2 );
BOOST_TEST_EQ( ec2.to_string(), std::string( "system:5" ) );
}
return boost::report_errors();
}

View File

@@ -0,0 +1,402 @@
// error_code_user_test.cpp ------------------------------------------------//
// Copyright Beman Dawes 2006
// 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 library home page at http://www.boost.org/libs/system
// ------------------------------------------------------------------------ //
// This program demonstrates creation and use of new categories of error
// codes. Several scenarios are demonstrated and tested.
// Motivation was a Boost posting by Christopher Kohlhoff on June 28, 2006.
#include <boost/system/error_code.hpp>
#include <boost/cerrno.hpp>
#include <string>
#include <cstdio>
#include <boost/detail/lightweight_test.hpp>
#ifdef BOOST_POSIX_API
# include <sys/stat.h>
#else
# include <windows.h>
#endif
// ------------------------------------------------------------------------ //
// Library 1: User function passes through an error code from the
// operating system.
boost::system::error_code my_mkdir( const std::string & path )
{
return boost::system::error_code(
# ifdef BOOST_POSIX_API
::mkdir( path.c_str(), S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH ) == 0 ? 0 : errno,
# else
::CreateDirectoryA( path.c_str(), 0 ) != 0 ? 0 : ::GetLastError(),
# endif
boost::system::system_category() );
}
// ------------------------------------------------------------------------ //
// Library 2: User function passes through errno from the C-runtime.
#include <cstdio>
boost::system::error_code my_remove( const std::string & path )
{
return boost::system::error_code(
std::remove( path.c_str() ) == 0 ? 0 : errno,
boost::system::generic_category() ); // OK for both Windows and POSIX
// Alternatively, could use generic_category()
// on Windows and system_category() on
// POSIX-based systems.
}
// ------------------------------------------------------------------------ //
// Library 3: Library uses enum to identify library specific errors.
// This particular example is for a library within the parent namespace. For
// an example of a library not within the parent namespace, see library 4.
// header lib3.hpp:
namespace boost
{
namespace lib3
{
// lib3 has its own error_category:
const boost::system::error_category & get_lib3_error_category() BOOST_SYSTEM_NOEXCEPT;
const boost::system::error_category & lib3_error_category = get_lib3_error_category();
enum error
{
boo_boo=123,
big_boo_boo
};
}
namespace system
{
template<> struct is_error_code_enum<boost::lib3::error>
{ static const bool value = true; };
}
namespace lib3
{
inline boost::system::error_code make_error_code(error e)
{ return boost::system::error_code(e,lib3_error_category); }
}
}
// implementation file lib3.cpp:
// #include <lib3.hpp>
namespace boost
{
namespace lib3
{
class lib3_error_category_imp : public boost::system::error_category
{
public:
lib3_error_category_imp() : boost::system::error_category() { }
const char * name() const BOOST_SYSTEM_NOEXCEPT
{
return "lib3";
}
boost::system::error_condition default_error_condition( int ev ) const BOOST_SYSTEM_NOEXCEPT
{
return ev == boo_boo
? boost::system::error_condition( boost::system::errc::io_error,
boost::system::generic_category() )
: boost::system::error_condition( ev,
boost::lib3::lib3_error_category );
}
std::string message( int ev ) const
{
if ( ev == boo_boo ) return std::string("boo boo");
if ( ev == big_boo_boo ) return std::string("big boo boo");
return std::string("unknown error");
}
};
const boost::system::error_category & get_lib3_error_category() BOOST_SYSTEM_NOEXCEPT
{
static const lib3_error_category_imp l3ecat;
return l3ecat;
}
}
}
// ------------------------------------------------------------------------ //
// Library 4: Library uses const error_code's to identify library specific
// errors.
// This particular example is for a library not within the parent namespace.
// For an example of a library within the parent namespace, see library 3.
// header lib4.hpp:
namespace lib4
{
// lib4 has its own error_category:
const boost::system::error_category & get_lib4_error_category() BOOST_SYSTEM_NOEXCEPT;
const boost::system::error_category & lib4_error_category = get_lib4_error_category();
extern const boost::system::error_code boo_boo;
extern const boost::system::error_code big_boo_boo;
}
// implementation file lib4.cpp:
// #include <lib4.hpp>
namespace lib4
{
class lib4_error_category_imp : public boost::system::error_category
{
public:
lib4_error_category_imp() : boost::system::error_category() { }
const char * name() const BOOST_SYSTEM_NOEXCEPT
{
return "lib4";
}
boost::system::error_condition default_error_condition( int ev ) const BOOST_SYSTEM_NOEXCEPT
{
return ev == boo_boo.value()
? boost::system::error_condition( boost::system::errc::io_error,
boost::system::generic_category() )
: boost::system::error_condition( ev, lib4::lib4_error_category );
}
std::string message( int ev ) const
{
if ( ev == boo_boo.value() ) return std::string("boo boo");
if ( ev == big_boo_boo.value() ) return std::string("big boo boo");
return std::string("unknown error");
}
};
const boost::system::error_category & get_lib4_error_category() BOOST_SYSTEM_NOEXCEPT
{
static const lib4_error_category_imp l4ecat;
return l4ecat;
}
const boost::system::error_code boo_boo( 456, lib4_error_category );
const boost::system::error_code big_boo_boo( 789, lib4_error_category );
}
// ------------------------------------------------------------------------ //
// Chris Kolhoff's Test3, modified to work with error_code.hpp
// Test3
// =====
// Define error classes to check for success, permission_denied and
// out_of_memory, but add additional mappings for a user-defined error category.
//
//namespace test3 {
// enum user_err
// {
// user_success = 0,
// user_permission_denied,
// user_out_of_memory
// };
//
// class user_error_category_imp : public boost::system::error_category
// {
// public:
// const std::string & name() const
// {
// static std::string s( "test3" );
// return s;
// }
//
// boost::system::error_code portable_error_code( int ev ) const
// {
// switch (ev)
// {
// case user_success:
// return boost::system::error_code(boost::system::errc::success, boost::system::generic_category());
// case user_permission_denied:
// return boost::system::error_code(boost::system::errc::permission_denied, boost::system::generic_category());
// case user_out_of_memory:
// return boost::system::error_code(boost::system::errc::not_enough_memory, boost::system::generic_category());
// default:
// break;
// }
// return boost::system::error_code(boost::system::errc::no_posix_equivalent, boost::system::generic_category());
// }
//
// };
//
// const user_error_category_imp user_error_category_const;
//
// const boost::system::error_category & user_error_category
// = user_error_category_const;
//
// template<> inline boost::system::error_code make_error_code(user_err e)
// {
// return boost::system::error_code(e, user_error_category);
// }
//
// // test code
//
// void check_success(const boost::system::error_code& ec, bool expect)
// {
// BOOST_TEST( (ec == boost::system::errc::success) == expect );
// if (ec == boost::system::errc::success)
// std::cout << "yes... " << (expect ? "ok" : "fail") << '\n';
// else
// std::cout << "no... " << (expect ? "fail" : "ok") << '\n';
// }
//
// void check_permission_denied(const boost::system::error_code& ec, bool expect)
// {
// BOOST_TEST( (ec == boost::system::errc::permission_denied) == expect );
// if (ec == boost::system::errc::permission_denied)
// std::cout << "yes... " << (expect ? "ok" : "fail") << '\n';
// else
// std::cout << "no... " << (expect ? "fail" : "ok") << '\n';
// }
//
// void check_out_of_memory(const boost::system::error_code& ec, bool expect)
// {
// BOOST_TEST( (ec == boost::system::errc::not_enough_memory) == expect );
// if (ec == boost::system::errc::not_enough_memory)
// std::cout << "yes... " << (expect ? "ok" : "fail") << '\n';
// else
// std::cout << "no... " << (expect ? "fail" : "ok") << '\n';
// }
//
// void run()
// {
// printf("Test3\n");
// printf("=====\n");
// boost::system::error_code ec;
// check_success(ec, true);
// check_success(boost::system::errc::success, true);
// check_success(boost::system::errc::permission_denied, false);
// check_success(boost::system::errc::not_enough_memory, false);
// check_success(user_success, true);
// check_success(user_permission_denied, false);
// check_success(user_out_of_memory, false);
// check_permission_denied(ec, false);
// check_permission_denied(boost::system::errc::success, false);
// check_permission_denied(boost::system::errc::permission_denied, true);
// check_permission_denied(boost::system::errc::not_enough_memory, false);
// check_permission_denied(user_success, false);
// check_permission_denied(user_permission_denied, true);
// check_permission_denied(user_out_of_memory, false);
// check_out_of_memory(ec, false);
// check_out_of_memory(boost::system::errc::success, false);
// check_out_of_memory(boost::system::errc::permission_denied, false);
// check_out_of_memory(boost::system::errc::not_enough_memory, true);
// check_out_of_memory(user_success, false);
// check_out_of_memory(user_permission_denied, false);
// check_out_of_memory(user_out_of_memory, true);
//
//# ifdef BOOST_WINDOWS_API
// check_success(boost::system::windows::success, true);
// check_success(boost::system::windows::access_denied, false);
// check_success(boost::system::windows::not_enough_memory, false);
// check_permission_denied(boost::system::windows::success, false);
// check_permission_denied(boost::system::windows::access_denied, true);
// check_permission_denied(boost::system::windows::not_enough_memory, false);
// check_out_of_memory(boost::system::windows::success, false);
// check_out_of_memory(boost::system::windows::access_denied, false);
// check_out_of_memory(boost::system::windows::not_enough_memory, true);
//# endif
//
// printf("\n");
// }
//
//} // namespace test3
// ------------------------------------------------------------------------ //
int main( int, char *[] )
{
boost::system::error_code ec;
// Library 1 tests:
ec = my_mkdir( "/no-such-file-or-directory/will-not-succeed" );
std::cout << "ec.value() is " << ec.value() << '\n';
BOOST_TEST( ec );
BOOST_TEST( ec == boost::system::errc::no_such_file_or_directory );
BOOST_TEST( ec.category() == boost::system::system_category() );
// Library 2 tests:
ec = my_remove( "/no-such-file-or-directory" );
std::cout << "ec.value() is " << ec.value() << '\n';
BOOST_TEST( ec );
BOOST_TEST( ec == boost::system::errc::no_such_file_or_directory );
BOOST_TEST( ec.category() == boost::system::generic_category() );
// Library 3 tests:
ec = boost::lib3::boo_boo;
std::cout << "ec.value() is " << ec.value() << '\n';
BOOST_TEST( ec );
BOOST_TEST( ec == boost::lib3::boo_boo );
BOOST_TEST( ec.value() == boost::lib3::boo_boo );
BOOST_TEST( ec.category() == boost::lib3::lib3_error_category );
BOOST_TEST( ec == boost::system::errc::io_error );
boost::system::error_code ec3( boost::lib3::boo_boo+100,
boost::lib3::lib3_error_category );
BOOST_TEST( ec3.category() == boost::lib3::lib3_error_category );
BOOST_TEST( ec3.default_error_condition().category()
== boost::lib3::lib3_error_category );
// Library 4 tests:
ec = lib4::boo_boo;
std::cout << "ec.value() is " << ec.value() << '\n';
BOOST_TEST( ec );
BOOST_TEST( ec == lib4::boo_boo );
BOOST_TEST( ec.value() == lib4::boo_boo.value() );
BOOST_TEST( ec.category() == lib4::lib4_error_category );
BOOST_TEST( ec == boost::system::errc::io_error );
boost::system::error_code ec4( lib4::boo_boo.value()+100,
lib4::lib4_error_category );
BOOST_TEST( ec4.default_error_condition().category()
== lib4::lib4_error_category );
// Test 3
//test3::run();
return ::boost::report_errors();
}

View File

@@ -0,0 +1,31 @@
// Copyright 2020 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// http://www.boost.org/LICENSE_1_0.txt
#include <boost/system/error_condition.hpp>
#include <boost/core/lightweight_test.hpp>
namespace sys = boost::system;
int main()
{
sys::error_condition en;
BOOST_TEST_EQ( en.value(), 0 );
BOOST_TEST( !en );
sys::error_condition en2( en );
BOOST_TEST( en == en2 );
BOOST_TEST_NOT( en != en2 );
en2.assign( 1, en.category() );
BOOST_TEST_EQ( en2.value(), 1 );
BOOST_TEST( en2 );
BOOST_TEST_NOT( en == en2 );
BOOST_TEST( en != en2 );
return boost::report_errors();
}

View File

@@ -0,0 +1,25 @@
// Copyright 2020 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// http://www.boost.org/LICENSE_1_0.txt
#include <boost/system/error_condition.hpp>
#include <boost/system/errc.hpp>
#include <boost/core/lightweight_test.hpp>
namespace sys = boost::system;
int main()
{
sys::error_condition en( sys::errc::no_such_file_or_directory );
BOOST_TEST_EQ( en.value(), ENOENT );
BOOST_TEST( en );
BOOST_TEST( !!en );
BOOST_TEST( en == make_error_condition( sys::errc::no_such_file_or_directory ) );
BOOST_TEST( en.category() == sys::error_condition().category() );
return boost::report_errors();
}

View File

@@ -0,0 +1,94 @@
// Copyright 2020, 2021 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// http://www.boost.org/LICENSE_1_0.txt
#include <boost/system/error_condition.hpp>
#include <boost/system/generic_category.hpp>
#include <boost/system/system_category.hpp>
#include <boost/core/lightweight_test.hpp>
namespace sys = boost::system;
int main()
{
char buffer[ 1024 ];
sys::error_condition en;
BOOST_TEST_EQ( en.value(), 0 );
BOOST_TEST( en.category() == sys::generic_category() );
BOOST_TEST_EQ( en.message(), en.category().message( en.value() ) );
BOOST_TEST_CSTR_EQ( en.message( buffer, sizeof( buffer ) ), en.category().message( en.value(), buffer, sizeof( buffer ) ) );
BOOST_TEST( !en.failed() );
BOOST_TEST( !en );
BOOST_TEST_EQ( en.to_string(), std::string( "cond:generic:0" ) );
{
sys::error_condition en2( en );
BOOST_TEST_EQ( en2.value(), 0 );
BOOST_TEST( en2.category() == sys::generic_category() );
BOOST_TEST_EQ( en2.message(), en2.category().message( en2.value() ) );
BOOST_TEST_CSTR_EQ( en2.message( buffer, sizeof( buffer ) ), en2.category().message( en2.value(), buffer, sizeof( buffer ) ) );
BOOST_TEST( !en2.failed() );
BOOST_TEST( !en2 );
BOOST_TEST_EQ( en, en2 );
BOOST_TEST_NOT( en != en2 );
BOOST_TEST_EQ( en2.to_string(), std::string( "cond:generic:0" ) );
}
{
sys::error_condition en2( en.value(), en.category() );
BOOST_TEST_EQ( en2.value(), 0 );
BOOST_TEST( en2.category() == sys::generic_category() );
BOOST_TEST_EQ( en2.message(), en2.category().message( en2.value() ) );
BOOST_TEST_CSTR_EQ( en2.message( buffer, sizeof( buffer ) ), en2.category().message( en2.value(), buffer, sizeof( buffer ) ) );
BOOST_TEST( !en2.failed() );
BOOST_TEST( !en2 );
BOOST_TEST_EQ( en, en2 );
BOOST_TEST_NOT( en != en2 );
BOOST_TEST_EQ( en2.to_string(), std::string( "cond:generic:0" ) );
}
{
sys::error_condition en2( 5, sys::generic_category() );
BOOST_TEST_EQ( en2.value(), 5 );
BOOST_TEST( en2.category() == sys::generic_category() );
BOOST_TEST_EQ( en2.message(), en2.category().message( en2.value() ) );
BOOST_TEST_CSTR_EQ( en2.message( buffer, sizeof( buffer ) ), en2.category().message( en2.value(), buffer, sizeof( buffer ) ) );
BOOST_TEST( en2.failed() );
BOOST_TEST( en2 );
BOOST_TEST_NOT( !en2 );
BOOST_TEST_NE( en, en2 );
BOOST_TEST_NOT( en == en2 );
BOOST_TEST_EQ( en2.to_string(), std::string( "cond:generic:5" ) );
}
{
sys::error_condition en2( 5, sys::system_category() );
BOOST_TEST_EQ( en2.value(), 5 );
BOOST_TEST( en2.category() == sys::system_category() );
BOOST_TEST_EQ( en2.message(), en2.category().message( en2.value() ) );
BOOST_TEST_CSTR_EQ( en2.message( buffer, sizeof( buffer ) ), en2.category().message( en2.value(), buffer, sizeof( buffer ) ) );
BOOST_TEST( en2.failed() );
BOOST_TEST( en2 );
BOOST_TEST_NOT( !en2 );
BOOST_TEST_NE( en, en2 );
BOOST_TEST_NOT( en == en2 );
BOOST_TEST_EQ( en2.to_string(), std::string( "cond:system:5" ) );
}
return boost::report_errors();
}

View File

@@ -0,0 +1,66 @@
// Copyright 2018 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
#include <boost/system/error_code.hpp>
#include <boost/config/pragma_message.hpp>
#include <boost/static_assert.hpp>
#if !defined(BOOST_SYSTEM_HAS_CONSTEXPR)
BOOST_PRAGMA_MESSAGE("Skipping constexpr test, BOOST_SYSTEM_HAS_CONSTEXPR isn't defined")
int main() {}
#else
using namespace boost::system;
constexpr error_code ec1( 1, system_category() );
BOOST_STATIC_ASSERT( ec1.failed() );
BOOST_STATIC_ASSERT( ec1 );
BOOST_STATIC_ASSERT( !!ec1 );
constexpr error_code ec2( 2, generic_category() );
BOOST_STATIC_ASSERT( ec2.failed() );
BOOST_STATIC_ASSERT( ec2 );
BOOST_STATIC_ASSERT( !!ec2 );
constexpr error_code ec3;
BOOST_STATIC_ASSERT( !ec3.failed() );
BOOST_STATIC_ASSERT( ec3? false: true );
BOOST_STATIC_ASSERT( !ec3 );
#if defined(__GNUC__) && __GNUC__ == 7 && __cplusplus == 201703L
// 'cat_' is not a constant expression
#else
constexpr error_condition en1( 1, system_category() );
BOOST_STATIC_ASSERT( en1.failed() );
BOOST_STATIC_ASSERT( en1 );
BOOST_STATIC_ASSERT( !!en1 );
constexpr error_condition en2( 2, generic_category() );
BOOST_STATIC_ASSERT( en2.failed() );
BOOST_STATIC_ASSERT( en2 );
BOOST_STATIC_ASSERT( !!en2 );
constexpr error_condition en3;
BOOST_STATIC_ASSERT( !en3.failed() );
BOOST_STATIC_ASSERT( en3? false: true );
BOOST_STATIC_ASSERT( !en3 );
#endif
int main()
{
}
#endif

View File

@@ -0,0 +1,185 @@
// Copyright 2018 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// Avoid spurious VC++ warnings
#define _CRT_SECURE_NO_WARNINGS
#include <boost/system/error_code.hpp>
#include <boost/core/lightweight_test.hpp>
#include <cstdio>
using namespace boost::system;
struct http_category_impl: public error_category
{
// clang++ 3.8 and below: initialization of const object
// requires a user-provided default constructor
BOOST_SYSTEM_CONSTEXPR http_category_impl() BOOST_NOEXCEPT
{
}
char const * name() const BOOST_NOEXCEPT
{
return "http";
}
std::string message( int ev ) const
{
char buffer[ 32 ];
std::sprintf( buffer, "HTTP/1.0 %d", ev );
return buffer;
}
bool failed( int ev ) const BOOST_NOEXCEPT
{
return !( ev >= 200 && ev < 300 );
}
};
error_category const & http_category()
{
static const http_category_impl instance;
return instance;
}
#define TEST_NOT_FAILED(ec) BOOST_TEST( !ec.failed() ); BOOST_TEST( ec? false: true ); BOOST_TEST( !ec );
#define TEST_FAILED(ec) BOOST_TEST( ec.failed() ); BOOST_TEST( ec ); BOOST_TEST( !!ec );
template<class Ec> void test()
{
{
Ec ec;
TEST_NOT_FAILED( ec );
ec.assign( 1, generic_category() );
TEST_FAILED( ec );
ec.clear();
TEST_NOT_FAILED( ec );
ec = Ec( 1, generic_category() );
TEST_FAILED( ec );
ec = Ec();
TEST_NOT_FAILED( ec );
}
{
Ec ec;
TEST_NOT_FAILED( ec );
ec.assign( 1, system_category() );
TEST_FAILED( ec );
ec.clear();
TEST_NOT_FAILED( ec );
ec = Ec( 1, system_category() );
TEST_FAILED( ec );
ec = Ec();
TEST_NOT_FAILED( ec );
}
{
Ec ec( 0, generic_category() );
TEST_NOT_FAILED( ec );
ec.assign( 1, system_category() );
TEST_FAILED( ec );
ec = Ec( 0, system_category() );
TEST_NOT_FAILED( ec );
}
{
Ec ec( 1, generic_category() );
TEST_FAILED( ec );
ec.assign( 0, system_category() );
TEST_NOT_FAILED( ec );
}
{
Ec ec( 0, system_category() );
TEST_NOT_FAILED( ec );
ec.assign( 1, generic_category() );
TEST_FAILED( ec );
ec = Ec( 0, generic_category() );
TEST_NOT_FAILED( ec );
}
{
Ec ec( 1, system_category() );
TEST_FAILED( ec );
ec.assign( 0, generic_category() );
TEST_NOT_FAILED( ec );
}
{
Ec ec( 0, http_category() );
TEST_FAILED( ec );
ec.assign( 200, http_category() );
TEST_NOT_FAILED( ec );
ec = Ec( 404, http_category() );
TEST_FAILED( ec );
}
}
int main()
{
BOOST_TEST( !generic_category().failed( 0 ) );
BOOST_TEST( generic_category().failed( 7 ) );
BOOST_TEST( !system_category().failed( 0 ) );
BOOST_TEST( system_category().failed( 7 ) );
BOOST_TEST( http_category().failed( 0 ) );
BOOST_TEST( !http_category().failed( 200 ) );
BOOST_TEST( http_category().failed( 404 ) );
test<error_code>();
test<error_condition>();
{
error_condition ec( errc::success );
TEST_NOT_FAILED( ec );
ec = errc::address_family_not_supported;
TEST_FAILED( ec );
}
{
error_condition ec( errc::address_family_not_supported );
TEST_FAILED( ec );
ec = errc::success;
TEST_NOT_FAILED( ec );
}
{
error_code ec( make_error_code( errc::success ) );
TEST_NOT_FAILED( ec );
ec = make_error_code( errc::address_family_not_supported );
TEST_FAILED( ec );
}
{
error_code ec( make_error_code( errc::address_family_not_supported ) );
TEST_FAILED( ec );
ec = make_error_code( errc::success );
TEST_NOT_FAILED( ec );
}
return boost::report_errors();
}

View File

@@ -0,0 +1,41 @@
// Copyright 2018 Peter Dimov.
//
// 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 library home page at http://www.boost.org/libs/system
// Avoid spurious VC++ warnings
# define _CRT_SECURE_NO_WARNINGS
#include <boost/system/error_code.hpp>
#include <boost/core/lightweight_test.hpp>
#include <cstring>
//
namespace sys = boost::system;
int main()
{
sys::error_category const & cat = sys::generic_category();
// message
for( int i = -2; i < 1024; ++i )
{
{
BOOST_TEST_CSTR_EQ( cat.message( i ).c_str(), std::strerror( i ) );
}
{
char buffer[ 256 ];
BOOST_TEST_CSTR_EQ( cat.message( i, buffer, sizeof( buffer ) ), std::strerror( i ) );
}
}
return boost::report_errors();
}

View File

@@ -0,0 +1,20 @@
// Copyright 2020 Peter Dimov
// Distributed under the Boost Software License, Version 1.0
// http://www.boost.org/LICENSE_1_0.txt
#include <boost/system/generic_category.hpp>
#include <boost/core/lightweight_test.hpp>
// Tests whether generic_category() is functional when only
// generic_category.hpp is included
namespace sys = boost::system;
int main()
{
sys::error_category const & cat = sys::generic_category();
BOOST_TEST_CSTR_EQ( cat.name(), "generic" );
return boost::report_errors();
}

View File

@@ -0,0 +1,30 @@
// Copyright 2020 Peter Dimov
// Distributed under the Boost Software License, Version 1.0
// http://www.boost.org/LICENSE_1_0.txt
#include <boost/system/generic_category.hpp>
#include <boost/system/error_condition.hpp>
#include <boost/core/lightweight_test.hpp>
#include <cerrno>
namespace sys = boost::system;
int main()
{
sys::error_category const & cat = sys::generic_category();
// name
BOOST_TEST_CSTR_EQ( cat.name(), "generic" );
// default_error_condition
BOOST_TEST( cat.default_error_condition( 0 ) == sys::error_condition( 0, cat ) );
BOOST_TEST( cat.default_error_condition( ENOENT ) == sys::error_condition( ENOENT, cat ) );
BOOST_TEST( cat.default_error_condition( -1 ) == sys::error_condition( -1, cat ) );
// failed
BOOST_TEST( !cat.failed( 0 ) );
BOOST_TEST( cat.failed( ENOENT ) );
BOOST_TEST( cat.failed( -1 ) );
return boost::report_errors();
}

View File

@@ -0,0 +1,25 @@
// header_only_test.cpp -----------------------------------------------------//
// Copyright Beman Dawes 2007
// 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 library home page at http://www.boost.org/libs/system
//----------------------------------------------------------------------------//
#include <boost/config/warning_disable.hpp>
#define BOOST_ERROR_CODE_HEADER_ONLY
#include <boost/detail/lightweight_test.hpp>
#include <boost/system/error_code.hpp>
int main()
{
boost::system::error_code ec( 0, boost::system::system_category() );
(void)ec;
return ::boost::report_errors();
}

View File

@@ -0,0 +1,28 @@
// initialization_test.cpp -------------------------------------------------//
// Copyright Christoper Kohlhoff 2007
// 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 library home page at http://www.boost.org/libs/system
// This test verifiies that the error_category vtable does not suffer from
// order-of-initialization problems.
#include <boost/system/error_code.hpp>
#include <boost/core/lightweight_test.hpp>
struct foo
{
foo()
{
boost::system::error_code ec;
BOOST_TEST_NE( ec, boost::system::errc::permission_denied );
}
} f;
int main()
{
return boost::report_errors();
}

View File

@@ -0,0 +1,41 @@
// Copyright 2020 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// http://www.boost.org/LICENSE_1_0.txt
#include <boost/system/is_error_code_enum.hpp>
#include <boost/core/lightweight_test.hpp>
enum error
{
success = 0,
e1,
e2,
e3
};
namespace boost
{
namespace system
{
template<> struct is_error_code_enum< ::error >
{
static const bool value = true;
};
}
}
boost::system::error_code make_error_code( ::error e );
enum not_error
{
};
int main()
{
BOOST_TEST( boost::system::is_error_code_enum< ::error >::value );
BOOST_TEST( !boost::system::is_error_code_enum< ::not_error >::value );
return boost::report_errors();
}

View File

@@ -0,0 +1,40 @@
// Copyright 2020 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// http://www.boost.org/LICENSE_1_0.txt
#include <boost/system/is_error_condition_enum.hpp>
#include <boost/core/lightweight_test.hpp>
enum condition
{
c1 = 1,
c2,
c3
};
namespace boost
{
namespace system
{
template<> struct is_error_condition_enum< ::condition >
{
static const bool value = true;
};
}
}
boost::system::error_condition make_error_condition( ::condition e );
enum not_condition
{
};
int main()
{
BOOST_TEST( boost::system::is_error_condition_enum< ::condition >::value );
BOOST_TEST( !boost::system::is_error_condition_enum< ::not_condition >::value );
return boost::report_errors();
}

View File

@@ -0,0 +1,29 @@
// Copyright 2020 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/system/linux_error.hpp>
#include <boost/config/pragma_message.hpp>
#if !defined(__linux__)
BOOST_PRAGMA_MESSAGE( "Skipping test, __linux__ is not defined" )
int main() {}
#else
#include <boost/core/lightweight_test.hpp>
int main()
{
namespace sys = boost::system;
sys::error_code ec = sys::linux_error::dot_dot_error;
BOOST_TEST_EQ( ec, sys::linux_error::dot_dot_error );
BOOST_TEST_EQ( ec, sys::error_code( EDOTDOT, sys::system_category() ) );
return boost::report_errors();
}
#endif

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ImportGroup Label="PropertySheets" />
<PropertyGroup Label="UserMacros" />
<PropertyGroup />
<ItemDefinitionGroup>
<ClCompile>
<AdditionalIncludeDirectories>../../../../..</AdditionalIncludeDirectories>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup>
<ClCompile>
<WarningLevel>Level4</WarningLevel>
<PreprocessorDefinitions>BOOST_ALL_NO_LIB;BOOST_ALL_DYN_LINK;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ExceptionHandling>Async</ExceptionHandling>
</ClCompile>
<PostBuildEvent>
<Command>"$(TargetDir)\$(TargetName).exe"</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemGroup />
</Project>

View File

@@ -0,0 +1,97 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{E18C2B56-DCEC-438F-9C38-3C8B08B65247}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>config_test</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\common.props" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\common.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\config_test.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\include\boost\system\api_config.hpp" />
<ClInclude Include="..\..\..\include\boost\system\config.hpp" />
<ClInclude Include="..\..\..\include\boost\system\cygwin_error.hpp" />
<ClInclude Include="..\..\..\include\boost\system\error_code.hpp" />
<ClInclude Include="..\..\..\include\boost\system\linux_error.hpp" />
<ClInclude Include="..\..\..\include\boost\system\system_error.hpp" />
<ClInclude Include="..\..\..\include\boost\system\windows_error.hpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{E50C14DC-547D-4C33-83EA-653C0D0D4E64}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>error_code_test</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\common.props" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\common.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ProjectReference Include="..\system-dll\system-dll.vcxproj">
<Project>{419402d4-f990-4b05-a459-655e2dc33dc2}</Project>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\error_code_test.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@@ -0,0 +1,151 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>15.0</VCProjectVersion>
<ProjectGuid>{C25D7BD7-1B99-4DA9-A1A5-3034410CBEF7}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>header_only_error_code_test</RootNamespace>
<WindowsTargetPlatformVersion>10.0.14393.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\common.props" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\common.props" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\common.props" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\common.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions);BOOST_ERROR_CODE_HEADER_ONLY</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions);BOOST_ERROR_CODE_HEADER_ONLY</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions);BOOST_ERROR_CODE_HEADER_ONLY</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions);BOOST_ERROR_CODE_HEADER_ONLY</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\error_code_test.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@@ -0,0 +1,86 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{3773451B-A618-4A26-A7F2-85554F4BD21B}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>header_only_test</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\common.props" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\common.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\header_only_test.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@@ -0,0 +1,156 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>15.0</VCProjectVersion>
<ProjectGuid>{47B0A041-1EB5-4842-BD17-BA0DCC5E0313}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>std_interop_test</RootNamespace>
<WindowsTargetPlatformVersion>10.0.14393.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\common.props" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\common.props" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\common.props" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\common.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\std_interop_test.cpp" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\system-dll\system-dll.vcxproj">
<Project>{419402d4-f990-4b05-a459-655e2dc33dc2}</Project>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@@ -0,0 +1,90 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{419402D4-F990-4B05-A459-655E2DC33DC2}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>systemdll</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\common.props" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\common.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;SYSTEMDLL_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<LanguageStandard>stdcpplatest</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
<PostBuildEvent>
<Command />
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;SYSTEMDLL_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\..\src\error_code.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@@ -0,0 +1,83 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26430.6
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "system-dll", "system-dll\system-dll.vcxproj", "{419402D4-F990-4B05-A459-655E2DC33DC2}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "error_code_test", "error_code_test\error_code_test.vcxproj", "{E50C14DC-547D-4C33-83EA-653C0D0D4E64}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "header_only_test", "header_only_test\header_only_test.vcxproj", "{3773451B-A618-4A26-A7F2-85554F4BD21B}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "config_test", "config_test\config_test.vcxproj", "{E18C2B56-DCEC-438F-9C38-3C8B08B65247}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "clang-system-dll", "clang-system-dll\clang-system-dll.vcxproj", "{30993F97-5E77-4B5A-B25F-B545C276077A}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "std_interop_test", "std_interop_test\std_interop_test.vcxproj", "{47B0A041-1EB5-4842-BD17-BA0DCC5E0313}"
ProjectSection(ProjectDependencies) = postProject
{419402D4-F990-4B05-A459-655E2DC33DC2} = {419402D4-F990-4B05-A459-655E2DC33DC2}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "header_only_error_code_test", "header_only_error_code_test\header_only_error_code_test.vcxproj", "{C25D7BD7-1B99-4DA9-A1A5-3034410CBEF7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Debug|x64 = Debug|x64
Release|Win32 = Release|Win32
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{419402D4-F990-4B05-A459-655E2DC33DC2}.Debug|Win32.ActiveCfg = Debug|Win32
{419402D4-F990-4B05-A459-655E2DC33DC2}.Debug|Win32.Build.0 = Debug|Win32
{419402D4-F990-4B05-A459-655E2DC33DC2}.Debug|x64.ActiveCfg = Debug|Win32
{419402D4-F990-4B05-A459-655E2DC33DC2}.Release|Win32.ActiveCfg = Release|Win32
{419402D4-F990-4B05-A459-655E2DC33DC2}.Release|Win32.Build.0 = Release|Win32
{419402D4-F990-4B05-A459-655E2DC33DC2}.Release|x64.ActiveCfg = Release|Win32
{E50C14DC-547D-4C33-83EA-653C0D0D4E64}.Debug|Win32.ActiveCfg = Debug|Win32
{E50C14DC-547D-4C33-83EA-653C0D0D4E64}.Debug|Win32.Build.0 = Debug|Win32
{E50C14DC-547D-4C33-83EA-653C0D0D4E64}.Debug|x64.ActiveCfg = Debug|Win32
{E50C14DC-547D-4C33-83EA-653C0D0D4E64}.Release|Win32.ActiveCfg = Release|Win32
{E50C14DC-547D-4C33-83EA-653C0D0D4E64}.Release|Win32.Build.0 = Release|Win32
{E50C14DC-547D-4C33-83EA-653C0D0D4E64}.Release|x64.ActiveCfg = Release|Win32
{3773451B-A618-4A26-A7F2-85554F4BD21B}.Debug|Win32.ActiveCfg = Debug|Win32
{3773451B-A618-4A26-A7F2-85554F4BD21B}.Debug|Win32.Build.0 = Debug|Win32
{3773451B-A618-4A26-A7F2-85554F4BD21B}.Debug|x64.ActiveCfg = Debug|Win32
{3773451B-A618-4A26-A7F2-85554F4BD21B}.Release|Win32.ActiveCfg = Release|Win32
{3773451B-A618-4A26-A7F2-85554F4BD21B}.Release|Win32.Build.0 = Release|Win32
{3773451B-A618-4A26-A7F2-85554F4BD21B}.Release|x64.ActiveCfg = Release|Win32
{E18C2B56-DCEC-438F-9C38-3C8B08B65247}.Debug|Win32.ActiveCfg = Debug|Win32
{E18C2B56-DCEC-438F-9C38-3C8B08B65247}.Debug|Win32.Build.0 = Debug|Win32
{E18C2B56-DCEC-438F-9C38-3C8B08B65247}.Debug|x64.ActiveCfg = Debug|Win32
{E18C2B56-DCEC-438F-9C38-3C8B08B65247}.Release|Win32.ActiveCfg = Release|Win32
{E18C2B56-DCEC-438F-9C38-3C8B08B65247}.Release|Win32.Build.0 = Release|Win32
{E18C2B56-DCEC-438F-9C38-3C8B08B65247}.Release|x64.ActiveCfg = Release|Win32
{30993F97-5E77-4B5A-B25F-B545C276077A}.Debug|Win32.ActiveCfg = Debug|Win32
{30993F97-5E77-4B5A-B25F-B545C276077A}.Debug|Win32.Build.0 = Debug|Win32
{30993F97-5E77-4B5A-B25F-B545C276077A}.Debug|x64.ActiveCfg = Debug|x64
{30993F97-5E77-4B5A-B25F-B545C276077A}.Debug|x64.Build.0 = Debug|x64
{30993F97-5E77-4B5A-B25F-B545C276077A}.Release|Win32.ActiveCfg = Release|Win32
{30993F97-5E77-4B5A-B25F-B545C276077A}.Release|Win32.Build.0 = Release|Win32
{30993F97-5E77-4B5A-B25F-B545C276077A}.Release|x64.ActiveCfg = Release|x64
{30993F97-5E77-4B5A-B25F-B545C276077A}.Release|x64.Build.0 = Release|x64
{47B0A041-1EB5-4842-BD17-BA0DCC5E0313}.Debug|Win32.ActiveCfg = Debug|Win32
{47B0A041-1EB5-4842-BD17-BA0DCC5E0313}.Debug|Win32.Build.0 = Debug|Win32
{47B0A041-1EB5-4842-BD17-BA0DCC5E0313}.Debug|x64.ActiveCfg = Debug|x64
{47B0A041-1EB5-4842-BD17-BA0DCC5E0313}.Debug|x64.Build.0 = Debug|x64
{47B0A041-1EB5-4842-BD17-BA0DCC5E0313}.Release|Win32.ActiveCfg = Release|Win32
{47B0A041-1EB5-4842-BD17-BA0DCC5E0313}.Release|Win32.Build.0 = Release|Win32
{47B0A041-1EB5-4842-BD17-BA0DCC5E0313}.Release|x64.ActiveCfg = Release|x64
{47B0A041-1EB5-4842-BD17-BA0DCC5E0313}.Release|x64.Build.0 = Release|x64
{C25D7BD7-1B99-4DA9-A1A5-3034410CBEF7}.Debug|Win32.ActiveCfg = Debug|Win32
{C25D7BD7-1B99-4DA9-A1A5-3034410CBEF7}.Debug|Win32.Build.0 = Debug|Win32
{C25D7BD7-1B99-4DA9-A1A5-3034410CBEF7}.Debug|x64.ActiveCfg = Debug|x64
{C25D7BD7-1B99-4DA9-A1A5-3034410CBEF7}.Debug|x64.Build.0 = Debug|x64
{C25D7BD7-1B99-4DA9-A1A5-3034410CBEF7}.Release|Win32.ActiveCfg = Release|Win32
{C25D7BD7-1B99-4DA9-A1A5-3034410CBEF7}.Release|Win32.Build.0 = Release|Win32
{C25D7BD7-1B99-4DA9-A1A5-3034410CBEF7}.Release|x64.ActiveCfg = Release|x64
{C25D7BD7-1B99-4DA9-A1A5-3034410CBEF7}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,43 @@
// Copyright 2017, 2021 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
// See library home page at http://www.boost.org/libs/system
#include <boost/system.hpp>
#include <boost/core/lightweight_test.hpp>
#include <cerrno>
int main()
{
boost::system::error_category const & bt = boost::system::generic_category();
int ev = ENOENT;
boost::system::error_code bc( ev, bt );
BOOST_TEST_EQ( bc.value(), ev );
BOOST_TEST_EQ( &bc.category(), &bt );
boost::system::error_condition bn = bt.default_error_condition( ev );
BOOST_TEST_EQ( bn.value(), ev );
BOOST_TEST_EQ( &bn.category(), &bt );
BOOST_TEST( bt.equivalent( ev, bn ) );
BOOST_TEST( bc == bn );
boost::system::error_code bc2 = make_error_code( boost::system::errc::no_such_file_or_directory );
BOOST_TEST_EQ( bc2, bc );
BOOST_TEST_EQ( bc2.value(), ev );
BOOST_TEST_EQ( &bc.category(), &bt );
boost::system::system_error x( bc, "prefix" );
BOOST_TEST_EQ( x.code(), bc );
BOOST_TEST_EQ( std::string( x.what() ), "prefix: " + bc.what() );
return boost::report_errors();
}

View File

@@ -0,0 +1,686 @@
// Copyright 2017, 2021 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/system/result.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/core/lightweight_test_trait.hpp>
#include <iosfwd>
#include <cerrno>
using namespace boost::system;
struct X
{
static int instances;
int v_;
explicit X( int v = 0 ): v_( v ) { ++instances; }
X( X const& r ): v_( r.v_ ) { ++instances; }
X& operator=( X const& ) = default;
~X() { --instances; }
};
bool operator==( X const & x1, X const & x2 )
{
return x1.v_ == x2.v_;
}
std::ostream& operator<<( std::ostream& os, X const & x )
{
os << "X:" << x.v_;
return os;
}
int X::instances = 0;
struct Y
{
static int instances;
int v_;
explicit Y( int v = 0 ): v_( v ) { ++instances; }
Y( Y const& r ) noexcept: v_( r.v_ ) { ++instances; }
Y& operator=( Y const& ) = default;
~Y() { --instances; }
};
bool operator==( Y const & y1, Y const & y2 )
{
return y1.v_ == y2.v_;
}
std::ostream& operator<<( std::ostream& os, Y const & y )
{
os << "Y:" << y.v_;
return os;
}
int Y::instances = 0;
int main()
{
// default-initialized lhs
{
result<int> r;
result<int> r2;
r2 = r;
BOOST_TEST_EQ( r, r2 );
}
{
result<int> r;
result<int> r2( 1 );
r2 = r;
BOOST_TEST_EQ( r, r2 );
}
{
result<int> r;
result<int> r2( ENOENT, generic_category() );
r2 = r;
BOOST_TEST_EQ( r, r2 );
}
{
result<int> const r;
result<int> r2;
r2 = r;
BOOST_TEST_EQ( r, r2 );
}
{
result<int> const r;
result<int> r2( 1 );
r2 = r;
BOOST_TEST_EQ( r, r2 );
}
{
result<int> const r;
result<int> r2( ENOENT, generic_category() );
r2 = r;
BOOST_TEST_EQ( r, r2 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
result<X> r;
result<X> r2;
BOOST_TEST_EQ( X::instances, 2 );
r2 = r;
BOOST_TEST_EQ( X::instances, 2 );
BOOST_TEST_EQ( r, r2 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
result<X> r;
result<X> r2( 1 );
BOOST_TEST_EQ( X::instances, 2 );
r2 = r;
BOOST_TEST_EQ( X::instances, 2 );
BOOST_TEST_EQ( r, r2 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
result<X> r;
result<X> r2( ENOENT, generic_category() );
BOOST_TEST_EQ( X::instances, 1 );
r2 = r;
BOOST_TEST_EQ( X::instances, 2 );
BOOST_TEST_EQ( r, r2 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
result<X> const r;
result<X> r2;
BOOST_TEST_EQ( X::instances, 2 );
r2 = r;
BOOST_TEST_EQ( X::instances, 2 );
BOOST_TEST_EQ( r, r2 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
result<X> const r;
result<X> r2( 1 );
BOOST_TEST_EQ( X::instances, 2 );
r2 = r;
BOOST_TEST_EQ( X::instances, 2 );
BOOST_TEST_EQ( r, r2 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
result<X> const r;
result<X> r2( ENOENT, generic_category() );
BOOST_TEST_EQ( X::instances, 1 );
r2 = r;
BOOST_TEST_EQ( X::instances, 2 );
BOOST_TEST_EQ( r, r2 );
}
BOOST_TEST_EQ( X::instances, 0 );
// value lhs
{
result<int> r( 0 );
result<int> r2;
r2 = r;
BOOST_TEST_EQ( r, r2 );
}
{
result<int> r( 0 );
result<int> r2( 1 );
r2 = r;
BOOST_TEST_EQ( r, r2 );
}
{
result<int> r( 0 );
result<int> r2( ENOENT, generic_category() );
r2 = r;
BOOST_TEST_EQ( r, r2 );
}
{
result<int> const r( 0 );
result<int> r2;
r2 = r;
BOOST_TEST_EQ( r, r2 );
}
{
result<int> const r( 0 );
result<int> r2( 1 );
r2 = r;
BOOST_TEST_EQ( r, r2 );
}
{
result<int> const r( 0 );
result<int> r2( ENOENT, generic_category() );
r2 = r;
BOOST_TEST_EQ( r, r2 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
result<X> r( 1 );
result<X> r2;
BOOST_TEST_EQ( X::instances, 2 );
r2 = r;
BOOST_TEST_EQ( X::instances, 2 );
BOOST_TEST_EQ( r, r2 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
result<X> r( 1 );
result<X> r2( 2 );
BOOST_TEST_EQ( X::instances, 2 );
r2 = r;
BOOST_TEST_EQ( X::instances, 2 );
BOOST_TEST_EQ( r, r2 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
result<X> r( 1 );
result<X> r2( ENOENT, generic_category() );
BOOST_TEST_EQ( X::instances, 1 );
r2 = r;
BOOST_TEST_EQ( X::instances, 2 );
BOOST_TEST_EQ( r, r2 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
result<X> const r( 1 );
result<X> r2;
BOOST_TEST_EQ( X::instances, 2 );
r2 = r;
BOOST_TEST_EQ( X::instances, 2 );
BOOST_TEST_EQ( r, r2 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
result<X> const r( 1 );
result<X> r2( 2 );
BOOST_TEST_EQ( X::instances, 2 );
r2 = r;
BOOST_TEST_EQ( X::instances, 2 );
BOOST_TEST_EQ( r, r2 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
result<X> const r( 1 );
result<X> r2( ENOENT, generic_category() );
BOOST_TEST_EQ( X::instances, 1 );
r2 = r;
BOOST_TEST_EQ( X::instances, 2 );
BOOST_TEST_EQ( r, r2 );
}
BOOST_TEST_EQ( X::instances, 0 );
// error lhs
{
auto ec = make_error_code( errc::invalid_argument );
result<int> r( ec );
result<int> r2;
r2 = r;
BOOST_TEST_EQ( r, r2 );
}
{
auto ec = make_error_code( errc::invalid_argument );
result<int> r( ec );
result<int> r2( 1 );
r2 = r;
BOOST_TEST_EQ( r, r2 );
}
{
auto ec = make_error_code( errc::invalid_argument );
result<int> r( ec );
result<int> r2( ENOENT, generic_category() );
r2 = r;
BOOST_TEST_EQ( r, r2 );
}
{
auto ec = make_error_code( errc::invalid_argument );
result<int> const r( ec );
result<int> r2;
r2 = r;
BOOST_TEST_EQ( r, r2 );
}
{
auto ec = make_error_code( errc::invalid_argument );
result<int> const r( ec );
result<int> r2( 1 );
r2 = r;
BOOST_TEST_EQ( r, r2 );
}
{
auto ec = make_error_code( errc::invalid_argument );
result<int> const r( ec );
result<int> r2( ENOENT, generic_category() );
r2 = r;
BOOST_TEST_EQ( r, r2 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
auto ec = make_error_code( errc::invalid_argument );
result<X> r( ec );
result<X> r2;
BOOST_TEST_EQ( X::instances, 1 );
r2 = r;
BOOST_TEST_EQ( X::instances, 0 );
BOOST_TEST_EQ( r, r2 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
auto ec = make_error_code( errc::invalid_argument );
result<X> r( ec );
result<X> r2( 1 );
BOOST_TEST_EQ( X::instances, 1 );
r2 = r;
BOOST_TEST_EQ( X::instances, 0 );
BOOST_TEST_EQ( r, r2 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
auto ec = make_error_code( errc::invalid_argument );
result<X> r( ec );
result<X> r2( ENOENT, generic_category() );
BOOST_TEST_EQ( X::instances, 0 );
r2 = r;
BOOST_TEST_EQ( X::instances, 0 );
BOOST_TEST_EQ( r, r2 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
auto ec = make_error_code( errc::invalid_argument );
result<X> const r( ec );
result<X> r2;
BOOST_TEST_EQ( X::instances, 1 );
r2 = r;
BOOST_TEST_EQ( X::instances, 0 );
BOOST_TEST_EQ( r, r2 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
auto ec = make_error_code( errc::invalid_argument );
result<X> const r( ec );
result<X> r2( 1 );
BOOST_TEST_EQ( X::instances, 1 );
r2 = r;
BOOST_TEST_EQ( X::instances, 0 );
BOOST_TEST_EQ( r, r2 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
auto ec = make_error_code( errc::invalid_argument );
result<X> const r( ec );
result<X> r2( ENOENT, generic_category() );
BOOST_TEST_EQ( X::instances, 0 );
r2 = r;
BOOST_TEST_EQ( X::instances, 0 );
BOOST_TEST_EQ( r, r2 );
}
BOOST_TEST_EQ( X::instances, 0 );
//
BOOST_TEST_EQ( Y::instances, 0 );
{
result<std::string, Y> r( 1 );
result<std::string, Y> r2( 2 );
BOOST_TEST_EQ( Y::instances, 2 );
r2 = r;
BOOST_TEST_EQ( Y::instances, 2 );
BOOST_TEST_EQ( r, r2 );
}
BOOST_TEST_EQ( Y::instances, 0 );
{
result<std::string, Y> r( 1 );
result<std::string, Y> r2( "str" );
BOOST_TEST_EQ( Y::instances, 1 );
r2 = r;
BOOST_TEST_EQ( Y::instances, 2 );
BOOST_TEST_EQ( r, r2 );
}
BOOST_TEST_EQ( Y::instances, 0 );
{
result<std::string, Y> const r( 1 );
result<std::string, Y> r2( 2 );
BOOST_TEST_EQ( Y::instances, 2 );
r2 = r;
BOOST_TEST_EQ( Y::instances, 2 );
BOOST_TEST_EQ( r, r2 );
}
BOOST_TEST_EQ( Y::instances, 0 );
{
result<std::string, Y> const r( 1 );
result<std::string, Y> r2( "str" );
BOOST_TEST_EQ( Y::instances, 1 );
r2 = r;
BOOST_TEST_EQ( Y::instances, 2 );
BOOST_TEST_EQ( r, r2 );
}
BOOST_TEST_EQ( Y::instances, 0 );
// void
{
result<void> r;
result<void> r2;
r2 = r;
BOOST_TEST_EQ( r, r2 );
}
{
result<void> r;
result<void> r2( ENOENT, generic_category() );
r2 = r;
BOOST_TEST_EQ( r, r2 );
}
{
result<void> const r;
result<void> r2;
r2 = r;
BOOST_TEST_EQ( r, r2 );
}
{
result<void> const r;
result<void> r2( ENOENT, generic_category() );
r2 = r;
BOOST_TEST_EQ( r, r2 );
}
{
auto ec = make_error_code( errc::invalid_argument );
result<void> r( ec );
result<void> r2;
r2 = r;
BOOST_TEST_EQ( r, r2 );
}
{
auto ec = make_error_code( errc::invalid_argument );
result<void> r( ec );
result<void> r2( ENOENT, generic_category() );
r2 = r;
BOOST_TEST_EQ( r, r2 );
}
{
auto ec = make_error_code( errc::invalid_argument );
result<void> const r( ec );
result<void> r2;
r2 = r;
BOOST_TEST_EQ( r, r2 );
}
{
auto ec = make_error_code( errc::invalid_argument );
result<void> const r( ec );
result<void> r2( ENOENT, generic_category() );
r2 = r;
BOOST_TEST_EQ( r, r2 );
}
return boost::report_errors();
}

View File

@@ -0,0 +1,181 @@
// Copyright 2017, 2021 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/system/result.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/core/lightweight_test_trait.hpp>
using namespace boost::system;
struct X
{
static int instances;
int v_;
X(): v_() { ++instances; }
explicit X( int v ): v_( v ) { ++instances; }
X( int v1, int v2 ): v_( v1+v2 ) { ++instances; }
X( int v1, int v2, int v3 ): v_( v1+v2+v3 ) { ++instances; }
X( X const& r ): v_( r.v_ ) { ++instances; }
X& operator=( X const& ) = delete;
~X() { --instances; }
};
bool operator==( X const & x1, X const & x2 )
{
return x1.v_ == x2.v_;
}
std::ostream& operator<<( std::ostream& os, X const & x )
{
os << "X:" << x.v_;
return os;
}
int X::instances = 0;
int main()
{
{
result<int> r;
result<int> r2( r );
BOOST_TEST_EQ( r, r2 );
}
{
result<int> const r;
result<int> r2( r );
BOOST_TEST_EQ( r, r2 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
result<X> r;
result<X> r2( r );
BOOST_TEST_EQ( r, r2 );
BOOST_TEST_EQ( X::instances, 2 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
result<int> r( 1 );
result<int> r2( r );
BOOST_TEST_EQ( r, r2 );
}
{
result<int> const r( 1 );
result<int> r2( r );
BOOST_TEST_EQ( r, r2 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
result<X> r( 1 );
result<X> r2( r );
BOOST_TEST_EQ( r, r2 );
BOOST_TEST_EQ( X::instances, 2 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
result<X> const r( 1 );
result<X> r2( r );
BOOST_TEST_EQ( r, r2 );
BOOST_TEST_EQ( X::instances, 2 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
auto ec = make_error_code( errc::invalid_argument );
result<int> r( ec );
result<int> r2( r );
BOOST_TEST_EQ( r, r2 );
}
{
auto ec = make_error_code( errc::invalid_argument );
result<int> const r( ec );
result<int> r2( r );
BOOST_TEST_EQ( r, r2 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
result<std::string, X> r( 1 );
result<std::string, X> r2( r );
BOOST_TEST_EQ( r, r2 );
BOOST_TEST_EQ( X::instances, 2 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
result<std::string, X> const r( 1 );
result<std::string, X> r2( r );
BOOST_TEST_EQ( r, r2 );
BOOST_TEST_EQ( X::instances, 2 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
result<void> r;
result<void> r2( r );
BOOST_TEST_EQ( r, r2 );
}
{
result<void> const r;
result<void> r2( r );
BOOST_TEST_EQ( r, r2 );
}
{
auto ec = make_error_code( errc::invalid_argument );
result<void> r( ec );
result<void> r2( r );
BOOST_TEST_EQ( r, r2 );
}
{
auto ec = make_error_code( errc::invalid_argument );
result<void> const r( ec );
result<void> r2( r );
BOOST_TEST_EQ( r, r2 );
}
return boost::report_errors();
}

View File

@@ -0,0 +1,41 @@
// Copyright 2017, 2021 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/system/result.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/core/lightweight_test_trait.hpp>
using namespace boost::system;
struct X
{
};
int main()
{
{
result<int> r;
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
BOOST_TEST_EQ( r.value(), 0 );
}
{
result<X> r;
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
}
{
result<void> r;
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
}
return boost::report_errors();
}

View File

@@ -0,0 +1,153 @@
// Copyright 2017, 2021 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/system/result.hpp>
#include <boost/core/lightweight_test.hpp>
#include <iosfwd>
#include <cerrno>
using namespace boost::system;
struct X
{
static int instances;
int v_;
explicit X( int v ): v_( v ) { ++instances; }
X( X const& r ) = delete;
X( X&& r ): v_( r.v_ ) { r.v_ = 0; ++instances; }
X& operator=( X const& ) = delete;
X& operator=( X&& r )
{
v_ = r.v_;
r.v_ = 0;
return *this;
}
~X() { --instances; }
};
bool operator==( X const & x1, X const & x2 )
{
return x1.v_ == x2.v_;
}
std::ostream& operator<<( std::ostream& os, X const & x )
{
os << "X:" << x.v_;
return os;
}
int X::instances = 0;
struct Y
{
static int instances;
int v_;
explicit Y( int v = 0 ): v_( v ) { ++instances; }
Y( Y const& r ) noexcept: v_( r.v_ ) { ++instances; }
Y( Y&& r ) noexcept: v_( r.v_ ) { r.v_ = 0; ++instances; }
Y& operator=( Y const& ) = default;
Y& operator=( Y&& r )
{
v_ = r.v_;
r.v_ = 0;
return *this;
}
~Y() { --instances; }
};
bool operator==( Y const & y1, Y const & y2 )
{
return y1.v_ == y2.v_;
}
std::ostream& operator<<( std::ostream& os, Y const & y )
{
os << "Y:" << y.v_;
return os;
}
int Y::instances = 0;
int main()
{
{
result<int> r1( 1 );
result<int> r2( 2 );
BOOST_TEST_EQ( r1, r1 );
BOOST_TEST_NE( r1, r2 );
}
{
result<int> r1( 1, generic_category() );
result<int> r2( 2, generic_category() );
BOOST_TEST_EQ( r1, r1 );
BOOST_TEST_NE( r1, r2 );
}
{
result<int> r1( 1 );
result<int> r2( 2, generic_category() );
BOOST_TEST_EQ( r1, r1 );
BOOST_TEST_NE( r1, r2 );
}
{
result<X, Y> r1( in_place_value, 1 );
result<X, Y> r2( in_place_value, 2 );
BOOST_TEST_EQ( r1, r1 );
BOOST_TEST_NE( r1, r2 );
}
{
result<X, Y> r1( in_place_error, 1 );
result<X, Y> r2( in_place_error, 2 );
BOOST_TEST_EQ( r1, r1 );
BOOST_TEST_NE( r1, r2 );
}
{
result<X, Y> r1( in_place_value, 1 );
result<X, Y> r2( in_place_error, 2 );
BOOST_TEST_EQ( r1, r1 );
BOOST_TEST_NE( r1, r2 );
}
{
result<void> r1;
result<void> r2;
BOOST_TEST_EQ( r1, r1 );
BOOST_TEST_EQ( r1, r2 );
}
{
result<void> r1( 1, generic_category() );
result<void> r2( 2, generic_category() );
BOOST_TEST_EQ( r1, r1 );
BOOST_TEST_NE( r1, r2 );
}
return boost::report_errors();
}

View File

@@ -0,0 +1,23 @@
// Copyright 2021 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/system/result.hpp>
#include <boost/core/lightweight_test_trait.hpp>
#include <type_traits>
using namespace boost::system;
int main()
{
BOOST_TEST_TRAIT_FALSE((std::is_convertible<errc::errc_t, result<int>>));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<int>, errc::errc_t>));
BOOST_TEST_TRAIT_FALSE((std::is_convertible<errc::errc_t, result<double>>));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<double>, errc::errc_t>));
BOOST_TEST_TRAIT_FALSE((std::is_convertible<errc::errc_t, result<bool>>));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<bool>, errc::errc_t>));
return boost::report_errors();
}

View File

@@ -0,0 +1,212 @@
// Copyright 2017, 2021 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/system/result.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/core/lightweight_test_trait.hpp>
#include <string>
using namespace boost::system;
struct X
{
int v_;
explicit X( int v = 0 ): v_( v ) {}
X( X const& ) = default;
X& operator=( X const& ) = delete;
};
int main()
{
{
result<int> r;
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
BOOST_TEST_EQ( r.error(), error_code() );
}
{
result<int> const r;
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
BOOST_TEST_EQ( r.error(), error_code() );
}
{
BOOST_TEST( result<int>().has_value() );
BOOST_TEST( !result<int>().has_error() );
BOOST_TEST_EQ( result<int>().error(), error_code() );
}
{
result<int> r( 1 );
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
BOOST_TEST_EQ( r.error(), error_code() );
}
{
result<int> const r( 1 );
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
BOOST_TEST_EQ( r.error(), error_code() );
}
{
BOOST_TEST( result<int>( 1 ).has_value() );
BOOST_TEST( !result<int>( 1 ).has_error() );
BOOST_TEST_EQ( result<int>( 1 ).error(), error_code() );
}
{
auto ec = make_error_code( errc::invalid_argument );
result<int> r( ec );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_EQ( r.error(), ec );
}
{
auto ec = make_error_code( errc::invalid_argument );
result<int> const r( ec );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_EQ( r.error(), ec );
}
{
auto ec = make_error_code( errc::invalid_argument );
BOOST_TEST( !result<int>( ec ).has_value() );
BOOST_TEST( result<int>( ec ).has_error() );
BOOST_TEST_EQ( result<int>( ec ).error(), ec );
}
{
result<std::string, X> r( 1 );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_EQ( r.error().v_, 1 );
}
{
result<std::string, X> const r( 1 );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_EQ( r.error().v_, 1 );
}
{
BOOST_TEST(( !result<std::string, X>( 1 ).has_value() ));
BOOST_TEST(( result<std::string, X>( 1 ).has_error() ));
BOOST_TEST_EQ( (result<std::string, X>( 1 ).error().v_), 1 );
}
{
result<std::string, X> r( "s" );
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
BOOST_TEST_EQ( r.error().v_, 0 );
}
{
result<std::string, X> const r( "s" );
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
BOOST_TEST_EQ( r.error().v_, 0 );
}
{
BOOST_TEST(( result<std::string, X>( "s" ).has_value() ));
BOOST_TEST(( !result<std::string, X>( "s" ).has_error() ));
BOOST_TEST_EQ( (result<std::string, X>( "s" ).error().v_), 0 );
}
{
result<void> r;
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
BOOST_TEST_EQ( r.error(), error_code() );
}
{
result<void> const r;
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
BOOST_TEST_EQ( r.error(), error_code() );
}
{
BOOST_TEST( result<void>().has_value() );
BOOST_TEST( !result<void>().has_error() );
BOOST_TEST_EQ( result<void>().error(), error_code() );
}
{
auto ec = make_error_code( errc::invalid_argument );
result<void> r( ec );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_EQ( r.error(), ec );
}
{
auto ec = make_error_code( errc::invalid_argument );
result<void> const r( ec );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_EQ( r.error(), ec );
}
{
auto ec = make_error_code( errc::invalid_argument );
BOOST_TEST( !result<void>( ec ).has_value() );
BOOST_TEST( result<void>( ec ).has_error() );
BOOST_TEST_EQ( result<void>( ec ).error(), ec );
}
return boost::report_errors();
}

View File

@@ -0,0 +1,185 @@
// Copyright 2017, 2021 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/system/result.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/core/lightweight_test_trait.hpp>
#include <string>
#include <cerrno>
using namespace boost::system;
struct X
{
static int instances;
int v_;
X(): v_() { ++instances; }
explicit X( int v ): v_( v ) { ++instances; }
X( int v1, int v2 ): v_( v1+v2 ) { ++instances; }
X( int v1, int v2, int v3 ): v_( v1+v2+v3 ) { ++instances; }
X( X const& r ): v_( r.v_ ) { ++instances; }
X& operator=( X const& ) = delete;
~X() { --instances; }
};
int X::instances = 0;
int main()
{
{
auto ec = make_error_code( errc::invalid_argument );
result<int> r( ec );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_EQ( r.error(), ec );
}
{
auto ec = make_error_code( errc::invalid_argument );
result<int> r = ec;
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_EQ( r.error(), ec );
}
{
result<int> r( EINVAL, generic_category() );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_EQ( r.error(), std::error_code( EINVAL, generic_category() ) );
}
{
auto ec = make_error_code( errc::invalid_argument );
result<std::error_code> r( in_place_error, ec );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_EQ( r.error(), ec );
}
{
result<std::error_code> r( in_place_error, EINVAL, generic_category() );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_EQ( r.error(), std::error_code( EINVAL, generic_category() ) );
}
BOOST_TEST_EQ( X::instances, 0 );
{
result<std::string, X> r( 1 );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_EQ( r.error().v_, 1 );
BOOST_TEST_EQ( X::instances, 1 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
result<int, X> r( 1, 2 );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_EQ( r.error().v_, 1+2 );
BOOST_TEST_EQ( X::instances, 1 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
result<int, X> r( 1, 2, 3 );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_EQ( r.error().v_, 1+2+3 );
BOOST_TEST_EQ( X::instances, 1 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
result<X, X> r( in_place_error, 1 );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_EQ( r.error().v_, 1 );
BOOST_TEST_EQ( X::instances, 1 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
BOOST_TEST_TRAIT_TRUE((std::is_constructible<result<int>, std::error_code>));
BOOST_TEST_TRAIT_TRUE((std::is_convertible<std::error_code, result<int>>));
BOOST_TEST_TRAIT_TRUE((std::is_constructible<result<std::string, X>, int>));
BOOST_TEST_TRAIT_FALSE((std::is_convertible<int, result<std::string, X>>));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<int, X>, int>));
BOOST_TEST_TRAIT_FALSE((std::is_convertible<int, result<int, X>>));
}
{
auto ec = make_error_code( errc::invalid_argument );
result<void> r( ec );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_EQ( r.error(), ec );
}
{
auto ec = make_error_code( errc::invalid_argument );
result<void> r = ec;
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_EQ( r.error(), ec );
}
{
result<void> r( EINVAL, generic_category() );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_EQ( r.error(), std::error_code( EINVAL, generic_category() ) );
}
return boost::report_errors();
}

View File

@@ -0,0 +1,57 @@
// Copyright 2021 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/system/result.hpp>
#include <boost/core/lightweight_test.hpp>
#include <string>
using namespace boost::system;
struct X
{
int a, b;
};
result<X> fx1()
{
return {{ EINVAL, generic_category() }};
}
struct Y
{
std::string v;
};
struct E
{
int v;
};
result<Y, E> fy1()
{
return {{ 42 }};
}
int main()
{
{
result<X> r = fx1();
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_EQ( r.error(), std::error_code( EINVAL, generic_category() ) );
}
{
result<Y, E> r = fy1();
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_EQ( r.error().v, 42 );
}
return boost::report_errors();
}

View File

@@ -0,0 +1,604 @@
// Copyright 2017, 2021 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/system/result.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/core/lightweight_test_trait.hpp>
#include <iosfwd>
#include <cerrno>
using namespace boost::system;
struct X
{
static int instances;
int v_;
explicit X( int v = 0 ): v_( v ) { ++instances; }
X( X const& r ) = delete;
X( X&& r ): v_( r.v_ ) { r.v_ = 0; ++instances; }
X& operator=( X const& ) = delete;
X& operator=( X&& r )
{
v_ = r.v_;
r.v_ = 0;
return *this;
}
~X() { --instances; }
};
bool operator==( X const & x1, X const & x2 )
{
return x1.v_ == x2.v_;
}
std::ostream& operator<<( std::ostream& os, X const & x )
{
os << "X:" << x.v_;
return os;
}
int X::instances = 0;
struct Y
{
static int instances;
int v_;
explicit Y( int v = 0 ): v_( v ) { ++instances; }
Y( Y const& r ) noexcept: v_( r.v_ ) { ++instances; }
Y( Y&& r ) noexcept: v_( r.v_ ) { r.v_ = 0; ++instances; }
Y& operator=( Y const& ) = default;
Y& operator=( Y&& r )
{
v_ = r.v_;
r.v_ = 0;
return *this;
}
~Y() { --instances; }
};
bool operator==( Y const & y1, Y const & y2 )
{
return y1.v_ == y2.v_;
}
std::ostream& operator<<( std::ostream& os, Y const & y )
{
os << "Y:" << y.v_;
return os;
}
int Y::instances = 0;
int main()
{
// default-initialized lhs
{
result<int> r;
result<int> r2;
r2 = std::move( r );
BOOST_TEST( r2.has_value() );
BOOST_TEST( !r2.has_error() );
BOOST_TEST_EQ( r2.value(), 0 );
}
{
result<int> r2;
r2 = result<int>();
BOOST_TEST( r2.has_value() );
BOOST_TEST( !r2.has_error() );
BOOST_TEST_EQ( r2.value(), 0 );
}
{
result<int> r;
result<int> r2( 1 );
r2 = std::move( r );
BOOST_TEST( r2.has_value() );
BOOST_TEST( !r2.has_error() );
BOOST_TEST_EQ( r2.value(), 0 );
}
{
result<int> r2( 1 );
r2 = result<int>();
BOOST_TEST( r2.has_value() );
BOOST_TEST( !r2.has_error() );
BOOST_TEST_EQ( r2.value(), 0 );
}
{
result<int> r;
result<int> r2( ENOENT, generic_category() );
r2 = std::move( r );
BOOST_TEST( r2.has_value() );
BOOST_TEST( !r2.has_error() );
BOOST_TEST_EQ( r2.value(), 0 );
}
{
result<int> r2( ENOENT, generic_category() );
r2 = result<int>();
BOOST_TEST( r2.has_value() );
BOOST_TEST( !r2.has_error() );
BOOST_TEST_EQ( r2.value(), 0 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
result<X> r;
result<X> r2;
BOOST_TEST_EQ( X::instances, 2 );
r2 = std::move( r );
BOOST_TEST_EQ( X::instances, 2 );
BOOST_TEST( r2.has_value() );
BOOST_TEST( !r2.has_error() );
BOOST_TEST_EQ( r2.value(), X() );
}
BOOST_TEST_EQ( X::instances, 0 );
{
result<X> r;
result<X> r2( 1 );
BOOST_TEST_EQ( X::instances, 2 );
r2 = std::move( r );
BOOST_TEST_EQ( X::instances, 2 );
BOOST_TEST( r2.has_value() );
BOOST_TEST( !r2.has_error() );
BOOST_TEST_EQ( r2.value(), X() );
}
BOOST_TEST_EQ( X::instances, 0 );
{
result<X> r;
result<X> r2( ENOENT, generic_category() );
BOOST_TEST_EQ( X::instances, 1 );
r2 = std::move( r );
BOOST_TEST_EQ( X::instances, 2 );
BOOST_TEST( r2.has_value() );
BOOST_TEST( !r2.has_error() );
BOOST_TEST_EQ( r2.value(), X() );
}
BOOST_TEST_EQ( X::instances, 0 );
// value lhs
{
result<int> r( 1 );
result<int> r2;
r2 = std::move( r );
BOOST_TEST( r2.has_value() );
BOOST_TEST( !r2.has_error() );
BOOST_TEST_EQ( r2.value(), 1 );
BOOST_TEST_EQ( r, r2 );
}
{
result<int> r( 1 );
result<int> r2( 2 );
r2 = std::move( r );
BOOST_TEST( r2.has_value() );
BOOST_TEST( !r2.has_error() );
BOOST_TEST_EQ( r2.value(), 1 );
BOOST_TEST_EQ( r, r2 );
}
{
result<int> r( 1 );
result<int> r2( ENOENT, generic_category() );
r2 = std::move( r );
BOOST_TEST( r2.has_value() );
BOOST_TEST( !r2.has_error() );
BOOST_TEST_EQ( r2.value(), 1 );
BOOST_TEST_EQ( r, r2 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
result<X> r( 1 );
result<X> r2;
BOOST_TEST_EQ( X::instances, 2 );
r2 = std::move( r );
BOOST_TEST_EQ( X::instances, 2 );
BOOST_TEST( r2.has_value() );
BOOST_TEST( !r2.has_error() );
BOOST_TEST_EQ( r2.value().v_, 1 );
BOOST_TEST_EQ( r.value().v_, 0 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
result<X> r( 1 );
result<X> r2( 2 );
BOOST_TEST_EQ( X::instances, 2 );
r2 = std::move( r );
BOOST_TEST_EQ( X::instances, 2 );
BOOST_TEST( r2.has_value() );
BOOST_TEST( !r2.has_error() );
BOOST_TEST_EQ( r2.value().v_, 1 );
BOOST_TEST_EQ( r.value().v_, 0 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
result<X> r( 1 );
result<X> r2( ENOENT, generic_category() );
BOOST_TEST_EQ( X::instances, 1 );
r2 = std::move( r );
BOOST_TEST_EQ( X::instances, 2 );
BOOST_TEST( r2.has_value() );
BOOST_TEST( !r2.has_error() );
BOOST_TEST_EQ( r2.value().v_, 1 );
BOOST_TEST_EQ( r.value().v_, 0 );
}
BOOST_TEST_EQ( X::instances, 0 );
// error lhs
{
auto ec = make_error_code( errc::invalid_argument );
result<int> r( ec );
result<int> r2;
r2 = std::move( r );
BOOST_TEST( !r2.has_value() );
BOOST_TEST( r2.has_error() );
BOOST_TEST_EQ( r2.error(), ec );
}
{
auto ec = make_error_code( errc::invalid_argument );
result<int> r2;
r2 = result<int>( ec );
BOOST_TEST( !r2.has_value() );
BOOST_TEST( r2.has_error() );
BOOST_TEST_EQ( r2.error(), ec );
}
{
auto ec = make_error_code( errc::invalid_argument );
result<int> r( ec );
result<int> r2( 1 );
r2 = std::move( r );
BOOST_TEST( !r2.has_value() );
BOOST_TEST( r2.has_error() );
BOOST_TEST_EQ( r2.error(), ec );
}
{
auto ec = make_error_code( errc::invalid_argument );
result<int> r2( 1 );
r2 = result<int>( ec );
BOOST_TEST( !r2.has_value() );
BOOST_TEST( r2.has_error() );
BOOST_TEST_EQ( r2.error(), ec );
}
{
auto ec = make_error_code( errc::invalid_argument );
result<int> r( ec );
result<int> r2( ENOENT, generic_category() );
r2 = std::move( r );
BOOST_TEST( !r2.has_value() );
BOOST_TEST( r2.has_error() );
BOOST_TEST_EQ( r2.error(), ec );
}
{
auto ec = make_error_code( errc::invalid_argument );
result<int> r2( ENOENT, generic_category() );
r2 = result<int>( ec );
BOOST_TEST( !r2.has_value() );
BOOST_TEST( r2.has_error() );
BOOST_TEST_EQ( r2.error(), ec );
}
BOOST_TEST_EQ( X::instances, 0 );
{
auto ec = make_error_code( errc::invalid_argument );
result<X> r( ec );
result<X> r2;
BOOST_TEST_EQ( X::instances, 1 );
r2 = std::move( r );
BOOST_TEST_EQ( X::instances, 0 );
BOOST_TEST( !r2.has_value() );
BOOST_TEST( r2.has_error() );
BOOST_TEST_EQ( r2.error(), ec );
}
BOOST_TEST_EQ( X::instances, 0 );
{
auto ec = make_error_code( errc::invalid_argument );
result<X> r( ec );
result<X> r2( 1 );
BOOST_TEST_EQ( X::instances, 1 );
r2 = std::move( r );
BOOST_TEST_EQ( X::instances, 0 );
BOOST_TEST( !r2.has_value() );
BOOST_TEST( r2.has_error() );
BOOST_TEST_EQ( r2.error(), ec );
}
BOOST_TEST_EQ( X::instances, 0 );
{
auto ec = make_error_code( errc::invalid_argument );
result<X> r( ec );
result<X> r2( ENOENT, generic_category() );
BOOST_TEST_EQ( X::instances, 0 );
r2 = std::move( r );
BOOST_TEST_EQ( X::instances, 0 );
BOOST_TEST( !r2.has_value() );
BOOST_TEST( r2.has_error() );
BOOST_TEST_EQ( r2.error(), ec );
}
BOOST_TEST_EQ( X::instances, 0 );
//
BOOST_TEST_EQ( Y::instances, 0 );
{
result<std::string, Y> r( 1 );
result<std::string, Y> r2( 2 );
BOOST_TEST_EQ( Y::instances, 2 );
r2 = std::move( r );
BOOST_TEST_EQ( Y::instances, 2 );
BOOST_TEST( !r2.has_value() );
BOOST_TEST( r2.has_error() );
BOOST_TEST_EQ( r2.error().v_, 1 );
BOOST_TEST_EQ( r.error().v_, 0 );
}
BOOST_TEST_EQ( Y::instances, 0 );
{
result<std::string, Y> r( 1 );
result<std::string, Y> r2( "str" );
BOOST_TEST_EQ( Y::instances, 1 );
r2 = std::move( r );
BOOST_TEST_EQ( Y::instances, 2 );
BOOST_TEST( !r2.has_value() );
BOOST_TEST( r2.has_error() );
BOOST_TEST_EQ( r2.error().v_, 1 );
BOOST_TEST_EQ( r.error().v_, 0 );
}
BOOST_TEST_EQ( Y::instances, 0 );
{
result<void> r;
result<void> r2;
r2 = std::move( r );
BOOST_TEST( r2.has_value() );
BOOST_TEST( !r2.has_error() );
}
{
result<void> r2;
r2 = result<void>();
BOOST_TEST( r2.has_value() );
BOOST_TEST( !r2.has_error() );
}
{
result<void> r;
result<void> r2( ENOENT, generic_category() );
r2 = std::move( r );
BOOST_TEST( r2.has_value() );
BOOST_TEST( !r2.has_error() );
}
{
result<void> r2( ENOENT, generic_category() );
r2 = result<void>();
BOOST_TEST( r2.has_value() );
BOOST_TEST( !r2.has_error() );
}
{
auto ec = make_error_code( errc::invalid_argument );
result<void> r( ec );
result<void> r2;
r2 = std::move( r );
BOOST_TEST( !r2.has_value() );
BOOST_TEST( r2.has_error() );
BOOST_TEST_EQ( r2.error(), ec );
}
{
auto ec = make_error_code( errc::invalid_argument );
result<void> r2;
r2 = result<void>( ec );
BOOST_TEST( !r2.has_value() );
BOOST_TEST( r2.has_error() );
BOOST_TEST_EQ( r2.error(), ec );
}
{
auto ec = make_error_code( errc::invalid_argument );
result<void> r( ec );
result<void> r2( ENOENT, generic_category() );
r2 = std::move( r );
BOOST_TEST( !r2.has_value() );
BOOST_TEST( r2.has_error() );
BOOST_TEST_EQ( r2.error(), ec );
}
{
auto ec = make_error_code( errc::invalid_argument );
result<void> r2( ENOENT, generic_category() );
r2 = result<void>( ec );
BOOST_TEST( !r2.has_value() );
BOOST_TEST( r2.has_error() );
BOOST_TEST_EQ( r2.error(), ec );
}
return boost::report_errors();
}

View File

@@ -0,0 +1,249 @@
// Copyright 2017, 2021 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/system/result.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/core/lightweight_test_trait.hpp>
using namespace boost::system;
struct X
{
static int instances;
int v_;
X(): v_() { ++instances; }
explicit X( int v ): v_( v ) { ++instances; }
X( int v1, int v2 ): v_( v1+v2 ) { ++instances; }
X( int v1, int v2, int v3 ): v_( v1+v2+v3 ) { ++instances; }
X( X const& r ): v_( r.v_ ) { ++instances; }
X( X&& r ): v_( r.v_ ) { r.v_ = 0; ++instances; }
X& operator=( X const& ) = delete;
~X() { --instances; }
};
bool operator==( X const & x1, X const & x2 )
{
return x1.v_ == x2.v_;
}
std::ostream& operator<<( std::ostream& os, X const & x )
{
os << "X:" << x.v_;
return os;
}
int X::instances = 0;
int main()
{
{
result<int> r;
result<int> r2( std::move( r ) );
BOOST_TEST( r2.has_value() );
BOOST_TEST( !r2.has_error() );
BOOST_TEST_EQ( r2.value(), 0 );
}
{
result<int> r2( result<int>{} );
BOOST_TEST( r2.has_value() );
BOOST_TEST( !r2.has_error() );
BOOST_TEST_EQ( r2.value(), 0 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
result<X> r;
result<X> r2( std::move( r ) );
BOOST_TEST( r2.has_value() );
BOOST_TEST( !r2.has_error() );
BOOST_TEST_EQ( r2.value(), X() );
BOOST_TEST_EQ( X::instances, 2 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
result<X> r2( result<X>{} );
BOOST_TEST( r2.has_value() );
BOOST_TEST( !r2.has_error() );
BOOST_TEST_EQ( r2.value(), X() );
BOOST_TEST_EQ( X::instances, 1 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
result<int> r( 1 );
result<int> r2( std::move( r ) );
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
BOOST_TEST_EQ( r.value(), 1 );
BOOST_TEST( r2.has_value() );
BOOST_TEST( !r2.has_error() );
BOOST_TEST_EQ( r2.value(), 1 );
}
{
result<int> r2( result<int>( 1 ) );
BOOST_TEST( r2.has_value() );
BOOST_TEST( !r2.has_error() );
BOOST_TEST_EQ( r2.value(), 1 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
result<X> r( 1 );
result<X> r2( std::move( r ) );
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
BOOST_TEST_EQ( r.value().v_, 0 );
BOOST_TEST( r2.has_value() );
BOOST_TEST( !r2.has_error() );
BOOST_TEST_EQ( r2.value().v_, 1 );
BOOST_TEST_EQ( X::instances, 2 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
result<X> r2( result<X>( 1 ) );
BOOST_TEST( r2.has_value() );
BOOST_TEST( !r2.has_error() );
BOOST_TEST_EQ( r2.value().v_, 1 );
BOOST_TEST_EQ( X::instances, 1 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
auto ec = make_error_code( errc::invalid_argument );
result<int> r( ec );
result<int> r2( std::move( r ) );
BOOST_TEST( !r2.has_value() );
BOOST_TEST( r2.has_error() );
BOOST_TEST_EQ( r2.error(), ec );
}
{
auto ec = make_error_code( errc::invalid_argument );
result<int> r2( result<int>{ ec } );
BOOST_TEST( !r2.has_value() );
BOOST_TEST( r2.has_error() );
BOOST_TEST_EQ( r2.error(), ec );
}
BOOST_TEST_EQ( X::instances, 0 );
{
result<std::string, X> r( 1 );
result<std::string, X> r2( std::move( r ) );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_EQ( r.error().v_, 0 );
BOOST_TEST( !r2.has_value() );
BOOST_TEST( r2.has_error() );
BOOST_TEST_EQ( r2.error().v_, 1 );
BOOST_TEST_EQ( X::instances, 2 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
result<std::string, X> r2( result<std::string, X>( 1 ) );
BOOST_TEST( !r2.has_value() );
BOOST_TEST( r2.has_error() );
BOOST_TEST_EQ( r2.error().v_, 1 );
BOOST_TEST_EQ( X::instances, 1 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
result<void> r;
result<void> r2( std::move( r ) );
BOOST_TEST( r2.has_value() );
BOOST_TEST( !r2.has_error() );
}
{
result<void> r2( result<void>{} );
BOOST_TEST( r2.has_value() );
BOOST_TEST( !r2.has_error() );
}
{
auto ec = make_error_code( errc::invalid_argument );
result<void> r( ec );
result<void> r2( std::move( r ) );
BOOST_TEST( !r2.has_value() );
BOOST_TEST( r2.has_error() );
BOOST_TEST_EQ( r2.error(), ec );
}
{
auto ec = make_error_code( errc::invalid_argument );
result<void> r2( result<void>{ ec } );
BOOST_TEST( !r2.has_value() );
BOOST_TEST( r2.has_error() );
BOOST_TEST_EQ( r2.error(), ec );
}
return boost::report_errors();
}

View File

@@ -0,0 +1,30 @@
// Copyright 2021 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/system/result.hpp>
#include <boost/core/lightweight_test.hpp>
#include <vector>
using namespace boost::system;
result<std::vector<int>> f()
{
return std::vector<int>{ 1, 2, 3 };
}
int main()
{
{
int s = 0;
for( int x: f().value() )
{
s += x;
}
BOOST_TEST_EQ( s, 6 );
}
return boost::report_errors();
}

View File

@@ -0,0 +1,263 @@
// Copyright 2017, 2021 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/system/result.hpp>
#include <boost/core/lightweight_test.hpp>
#include <iosfwd>
#include <cerrno>
using namespace boost::system;
struct X
{
static int instances;
int v_;
explicit X( int v ): v_( v ) { ++instances; }
X( X const& r ) = delete;
X( X&& r ): v_( r.v_ ) { r.v_ = 0; ++instances; }
X& operator=( X const& ) = delete;
X& operator=( X&& r )
{
v_ = r.v_;
r.v_ = 0;
return *this;
}
~X() { --instances; }
};
bool operator==( X const & x1, X const & x2 )
{
return x1.v_ == x2.v_;
}
std::ostream& operator<<( std::ostream& os, X const & x )
{
os << "X:" << x.v_;
return os;
}
int X::instances = 0;
struct Y
{
static int instances;
int v_;
explicit Y( int v = 0 ): v_( v ) { ++instances; }
Y( Y const& r ) noexcept: v_( r.v_ ) { ++instances; }
Y( Y&& r ) noexcept: v_( r.v_ ) { r.v_ = 0; ++instances; }
Y& operator=( Y const& ) = default;
Y& operator=( Y&& r )
{
v_ = r.v_;
r.v_ = 0;
return *this;
}
~Y() { --instances; }
};
bool operator==( Y const & y1, Y const & y2 )
{
return y1.v_ == y2.v_;
}
std::ostream& operator<<( std::ostream& os, Y const & y )
{
os << "Y:" << y.v_;
return os;
}
int Y::instances = 0;
int main()
{
{
result<int> r1( 1 ), r1c( r1 );
result<int> r2( 2 ), r2c( r2 );
r1.swap( r2 );
BOOST_TEST_EQ( r1, r2c );
BOOST_TEST_EQ( r2, r1c );
swap( r1, r2 );
BOOST_TEST_EQ( r1, r1c );
BOOST_TEST_EQ( r2, r2c );
}
{
result<int> r1( 1, generic_category() ), r1c( r1 );
result<int> r2( 2, generic_category() ), r2c( r2 );
r1.swap( r2 );
BOOST_TEST_EQ( r1, r2c );
BOOST_TEST_EQ( r2, r1c );
swap( r1, r2 );
BOOST_TEST_EQ( r1, r1c );
BOOST_TEST_EQ( r2, r2c );
}
{
result<int> r1( 1 ), r1c( r1 );
result<int> r2( 2, generic_category() ), r2c( r2 );
r1.swap( r2 );
BOOST_TEST_EQ( r1, r2c );
BOOST_TEST_EQ( r2, r1c );
swap( r1, r2 );
BOOST_TEST_EQ( r1, r1c );
BOOST_TEST_EQ( r2, r2c );
}
BOOST_TEST_EQ( X::instances, 0 );
BOOST_TEST_EQ( Y::instances, 0 );
{
result<X, Y> r1( in_place_value, 1 ), r1c( in_place_value, 1 );
result<X, Y> r2( in_place_value, 2 ), r2c( in_place_value, 2 );
BOOST_TEST_EQ( X::instances, 4 );
BOOST_TEST_EQ( Y::instances, 0 );
r1.swap( r2 );
BOOST_TEST_EQ( r1, r2c );
BOOST_TEST_EQ( r2, r1c );
BOOST_TEST_EQ( X::instances, 4 );
BOOST_TEST_EQ( Y::instances, 0 );
swap( r1, r2 );
BOOST_TEST_EQ( r1, r1c );
BOOST_TEST_EQ( r2, r2c );
BOOST_TEST_EQ( X::instances, 4 );
BOOST_TEST_EQ( Y::instances, 0 );
}
BOOST_TEST_EQ( X::instances, 0 );
BOOST_TEST_EQ( Y::instances, 0 );
{
result<X, Y> r1( in_place_error, 1 ), r1c( in_place_error, 1 );
result<X, Y> r2( in_place_error, 2 ), r2c( in_place_error, 2 );
BOOST_TEST_EQ( X::instances, 0 );
BOOST_TEST_EQ( Y::instances, 4 );
r1.swap( r2 );
BOOST_TEST_EQ( r1, r2c );
BOOST_TEST_EQ( r2, r1c );
BOOST_TEST_EQ( X::instances, 0 );
BOOST_TEST_EQ( Y::instances, 4 );
swap( r1, r2 );
BOOST_TEST_EQ( r1, r1c );
BOOST_TEST_EQ( r2, r2c );
BOOST_TEST_EQ( X::instances, 0 );
BOOST_TEST_EQ( Y::instances, 4 );
}
BOOST_TEST_EQ( X::instances, 0 );
BOOST_TEST_EQ( Y::instances, 0 );
{
result<X, Y> r1( in_place_value, 1 ), r1c( in_place_value, 1 );
result<X, Y> r2( in_place_error, 2 ), r2c( in_place_error, 2 );
BOOST_TEST_EQ( X::instances, 2 );
BOOST_TEST_EQ( Y::instances, 2 );
r1.swap( r2 );
BOOST_TEST_EQ( r1, r2c );
BOOST_TEST_EQ( r2, r1c );
BOOST_TEST_EQ( X::instances, 2 );
BOOST_TEST_EQ( Y::instances, 2 );
swap( r1, r2 );
BOOST_TEST_EQ( r1, r1c );
BOOST_TEST_EQ( r2, r2c );
BOOST_TEST_EQ( X::instances, 2 );
BOOST_TEST_EQ( Y::instances, 2 );
}
BOOST_TEST_EQ( X::instances, 0 );
BOOST_TEST_EQ( Y::instances, 0 );
{
result<void> r1, r1c( r1 );
result<void> r2, r2c( r2 );
r1.swap( r2 );
BOOST_TEST_EQ( r1, r2c );
BOOST_TEST_EQ( r2, r1c );
swap( r1, r2 );
BOOST_TEST_EQ( r1, r1c );
BOOST_TEST_EQ( r2, r2c );
}
{
result<void> r1( 1, generic_category() ), r1c( r1 );
result<void> r2( 2, generic_category() ), r2c( r2 );
r1.swap( r2 );
BOOST_TEST_EQ( r1, r2c );
BOOST_TEST_EQ( r2, r1c );
swap( r1, r2 );
BOOST_TEST_EQ( r1, r1c );
BOOST_TEST_EQ( r2, r2c );
}
{
result<void> r1, r1c( r1 );
result<void> r2( 2, generic_category() ), r2c( r2 );
r1.swap( r2 );
BOOST_TEST_EQ( r1, r2c );
BOOST_TEST_EQ( r2, r1c );
swap( r1, r2 );
BOOST_TEST_EQ( r1, r1c );
BOOST_TEST_EQ( r2, r2c );
}
return boost::report_errors();
}

View File

@@ -0,0 +1,494 @@
// Copyright 2017, 2021, 2022 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/system/result.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/core/lightweight_test_trait.hpp>
#include <system_error>
using namespace boost::system;
struct X
{
int v_;
explicit X( int v ): v_( v ) {}
X( X const& ) = delete;
X& operator=( X const& ) = delete;
};
struct Y
{
};
struct E
{
};
BOOST_NORETURN void throw_exception_from_error( Y const &, boost::source_location const& )
{
throw E();
}
struct E2
{
};
int main()
{
{
result<int> r;
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
BOOST_TEST( r );
BOOST_TEST_NOT( !r );
BOOST_TEST_EQ( r.value(), 0 );
BOOST_TEST_EQ( *r, 0 );
BOOST_TEST_EQ( r.operator->(), &*r );
}
{
result<int> const r;
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
BOOST_TEST( r );
BOOST_TEST_NOT( !r );
BOOST_TEST_EQ( r.value(), 0 );
BOOST_TEST_EQ( *r, 0 );
BOOST_TEST_EQ( r.operator->(), &*r );
}
{
BOOST_TEST( result<int>().has_value() );
BOOST_TEST( !result<int>().has_error() );
BOOST_TEST( result<int>() );
BOOST_TEST_NOT( !result<int>() );
BOOST_TEST_EQ( result<int>().value(), 0 );
BOOST_TEST_EQ( *result<int>(), 0 );
BOOST_TEST( result<int>().operator->() != 0 );
}
{
result<int> r( 1 );
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
BOOST_TEST( r );
BOOST_TEST_NOT( !r );
BOOST_TEST_EQ( r.value(), 1 );
BOOST_TEST_EQ( *r, 1 );
BOOST_TEST_EQ( r.operator->(), &*r );
}
{
result<int> const r( 1 );
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
BOOST_TEST( r );
BOOST_TEST_NOT( !r );
BOOST_TEST_EQ( r.value(), 1 );
BOOST_TEST_EQ( *r, 1 );
BOOST_TEST_EQ( r.operator->(), &*r );
}
{
BOOST_TEST( result<int>( 1 ).has_value() );
BOOST_TEST( !result<int>( 1 ).has_error() );
BOOST_TEST( result<int>( 1 ) );
BOOST_TEST_NOT( !result<int>( 1 ) );
BOOST_TEST_EQ( result<int>( 1 ).value(), 1 );
BOOST_TEST_EQ( *result<int>( 1 ), 1 );
BOOST_TEST( result<int>( 1 ).operator->() != 0 );
}
{
auto ec = make_error_code( errc::invalid_argument );
result<int> r( ec );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_NOT( r );
BOOST_TEST( !r );
BOOST_TEST_THROWS( r.value(), system_error );
BOOST_TEST_EQ( r.operator->(), static_cast<int*>(0) );
}
{
auto ec = make_error_code( errc::invalid_argument );
result<int> const r( ec );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_NOT( r );
BOOST_TEST( !r );
BOOST_TEST_THROWS( r.value(), system_error );
BOOST_TEST_EQ( r.operator->(), static_cast<int*>(0) );
}
{
auto ec = make_error_code( errc::invalid_argument );
BOOST_TEST( !result<int>( ec ).has_value() );
BOOST_TEST( result<int>( ec ).has_error() );
BOOST_TEST_NOT( result<int>( ec ) );
BOOST_TEST( !result<int>( ec ) );
BOOST_TEST_THROWS( result<int>( ec ).value(), system_error );
BOOST_TEST_EQ( result<int>( ec ).operator->(), static_cast<int*>(0) );
}
{
auto ec = make_error_code( std::errc::invalid_argument );
result<int, std::error_code> const r( ec );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_NOT( r );
BOOST_TEST( !r );
BOOST_TEST_THROWS( r.value(), std::system_error );
BOOST_TEST_EQ( r.operator->(), static_cast<int*>(0) );
}
{
result<int, errc::errc_t> const r( in_place_error, errc::invalid_argument );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_NOT( r );
BOOST_TEST( !r );
BOOST_TEST_THROWS( r.value(), system_error );
BOOST_TEST_EQ( r.operator->(), static_cast<int*>(0) );
}
{
result<int, std::errc> const r( std::errc::invalid_argument );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_NOT( r );
BOOST_TEST( !r );
BOOST_TEST_THROWS( r.value(), std::system_error );
BOOST_TEST_EQ( r.operator->(), static_cast<int*>(0) );
}
{
result<int, std::exception_ptr> const r( std::make_exception_ptr( E2() ) );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_NOT( r );
BOOST_TEST( !r );
BOOST_TEST_THROWS( r.value(), E2 );
BOOST_TEST_EQ( r.operator->(), static_cast<int*>(0) );
}
{
result<int, std::exception_ptr> const r( in_place_error );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_NOT( r );
BOOST_TEST( !r );
BOOST_TEST_THROWS( r.value(), std::bad_exception );
BOOST_TEST_EQ( r.operator->(), static_cast<int*>(0) );
}
{
result<X> r( 1 );
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
BOOST_TEST( r );
BOOST_TEST_NOT( !r );
BOOST_TEST_EQ( r.value().v_, 1 );
BOOST_TEST_EQ( (*r).v_, 1 );
BOOST_TEST_EQ( r->v_, 1 );
BOOST_TEST_EQ( r.operator->(), &*r );
}
{
result<X> const r( 1 );
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
BOOST_TEST( r );
BOOST_TEST_NOT( !r );
BOOST_TEST_EQ( r.value().v_, 1 );
BOOST_TEST_EQ( (*r).v_, 1 );
BOOST_TEST_EQ( r->v_, 1 );
BOOST_TEST_EQ( r.operator->(), &*r );
}
{
BOOST_TEST( result<X>( 1 ).has_value() );
BOOST_TEST( !result<X>( 1 ).has_error() );
BOOST_TEST( result<X>( 1 ) );
BOOST_TEST_NOT( !result<X>( 1 ) );
BOOST_TEST_EQ( result<X>( 1 ).value().v_, 1 );
BOOST_TEST_EQ( (*result<X>( 1 )).v_, 1 );
BOOST_TEST_EQ( result<X>( 1 )->v_, 1 );
}
{
auto ec = Y();
result<X, Y> r( ec );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_NOT( r );
BOOST_TEST( !r );
BOOST_TEST_THROWS( r.value(), E );
BOOST_TEST_EQ( r.operator->(), static_cast<X*>(0) );
}
{
auto ec = Y();
result<X, Y> const r( ec );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_NOT( r );
BOOST_TEST( !r );
BOOST_TEST_THROWS( r.value(), E );
BOOST_TEST_EQ( r.operator->(), static_cast<X*>(0) );
}
{
auto ec = Y();
BOOST_TEST(( !result<X, Y>( ec ).has_value() ));
BOOST_TEST(( result<X, Y>( ec ).has_error() ));
BOOST_TEST_NOT(( result<X, Y>( ec ) ));
BOOST_TEST(( !result<X, Y>( ec ) ));
BOOST_TEST_THROWS( (result<X, Y>( ec ).value()), E );
BOOST_TEST_EQ( (result<X, Y>( ec ).operator->()), static_cast<X*>(0) );
}
{
result<void> r;
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
BOOST_TEST( r );
BOOST_TEST_NOT( !r );
BOOST_TEST_NO_THROW( r.value() );
BOOST_TEST( r.operator->() != 0 );
}
{
result<void> const r;
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
BOOST_TEST( r );
BOOST_TEST_NOT( !r );
BOOST_TEST_NO_THROW( r.value() );
BOOST_TEST( r.operator->() != 0 );
}
{
BOOST_TEST( result<void>().has_value() );
BOOST_TEST( !result<void>().has_error() );
BOOST_TEST( result<void>() );
BOOST_TEST_NOT( !result<void>() );
BOOST_TEST_NO_THROW( result<void>().value() );
BOOST_TEST( result<void>().operator->() != 0 );
}
{
auto ec = make_error_code( errc::invalid_argument );
result<void> r( ec );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_NOT( r );
BOOST_TEST( !r );
BOOST_TEST_THROWS( r.value(), system_error );
BOOST_TEST_EQ( r.operator->(), static_cast<void*>(0) );
}
{
auto ec = make_error_code( errc::invalid_argument );
result<void> const r( ec );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_NOT( r );
BOOST_TEST( !r );
BOOST_TEST_THROWS( r.value(), system_error );
BOOST_TEST_EQ( r.operator->(), static_cast<void*>(0) );
}
{
auto ec = make_error_code( errc::invalid_argument );
BOOST_TEST( !result<void>( ec ).has_value() );
BOOST_TEST( result<void>( ec ).has_error() );
BOOST_TEST_NOT( result<void>( ec ) );
BOOST_TEST( !result<void>( ec ) );
BOOST_TEST_THROWS( result<void>( ec ).value(), system_error );
BOOST_TEST_EQ( result<void>( ec ).operator->(), static_cast<void*>(0) );
}
{
auto ec = make_error_code( std::errc::invalid_argument );
result<void, std::error_code> const r( ec );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_NOT( r );
BOOST_TEST( !r );
BOOST_TEST_THROWS( r.value(), std::system_error );
BOOST_TEST_EQ( r.operator->(), static_cast<void*>(0) );
}
{
result<void, errc::errc_t> const r( in_place_error, errc::invalid_argument );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_NOT( r );
BOOST_TEST( !r );
BOOST_TEST_THROWS( r.value(), system_error );
BOOST_TEST_EQ( r.operator->(), static_cast<void*>(0) );
}
{
result<void, std::errc> const r( std::errc::invalid_argument );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_NOT( r );
BOOST_TEST( !r );
BOOST_TEST_THROWS( r.value(), std::system_error );
BOOST_TEST_EQ( r.operator->(), static_cast<void*>(0) );
}
{
result<void, std::exception_ptr> const r( std::make_exception_ptr( E2() ) );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_NOT( r );
BOOST_TEST( !r );
BOOST_TEST_THROWS( r.value(), E2 );
BOOST_TEST_EQ( r.operator->(), static_cast<void*>(0) );
}
{
result<void, std::exception_ptr> const r( in_place_error );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_NOT( r );
BOOST_TEST( !r );
BOOST_TEST_THROWS( r.value(), std::bad_exception );
BOOST_TEST_EQ( r.operator->(), static_cast<void*>(0) );
}
return boost::report_errors();
}

View File

@@ -0,0 +1,132 @@
// Copyright 2017, 2021 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/system/result.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/core/lightweight_test_trait.hpp>
using namespace boost::system;
struct X
{
static int instances;
int v_;
explicit X( int v ): v_( v ) { ++instances; }
X( int v1, int v2 ): v_( v1+v2 ) { ++instances; }
X( int v1, int v2, int v3 ): v_( v1+v2+v3 ) { ++instances; }
X( X const& ) = delete;
X& operator=( X const& ) = delete;
~X() { --instances; }
};
int X::instances = 0;
int main()
{
{
result<int> r( 0 );
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
BOOST_TEST_EQ( r.value(), 0 );
}
{
result<int> r = 0;
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
BOOST_TEST_EQ( r.value(), 0 );
}
{
result<int, int> r( in_place_value, 1 );
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
BOOST_TEST_EQ( *r, 1 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
result<X> r( 1 );
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
BOOST_TEST_EQ( r.value().v_, 1 );
BOOST_TEST_EQ( X::instances, 1 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
result<X> r( 1, 2 );
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
BOOST_TEST_EQ( r.value().v_, 1+2 );
BOOST_TEST_EQ( X::instances, 1 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
result<X> r( 1, 2, 3 );
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
BOOST_TEST_EQ( r.value().v_, 1+2+3 );
BOOST_TEST_EQ( X::instances, 1 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
result<X, X> r( in_place_value, 1 );
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
BOOST_TEST_EQ( r->v_, 1 );
BOOST_TEST_EQ( X::instances, 1 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
BOOST_TEST_TRAIT_TRUE((std::is_constructible<result<int>, int>));
BOOST_TEST_TRAIT_TRUE((std::is_convertible<int, result<int>>));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<int, int>, int>));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<int, float>, int>));
BOOST_TEST_TRAIT_TRUE((std::is_constructible<result<X>, int>));
BOOST_TEST_TRAIT_FALSE((std::is_convertible<int, result<X>>));
}
{
result<void> r( in_place_value );
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
}
return boost::report_errors();
}

View File

@@ -0,0 +1,152 @@
// Copyright 2021 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/system/result.hpp>
#include <boost/core/lightweight_test.hpp>
#include <vector>
#include <string>
using namespace boost::system;
struct X
{
int a;
};
struct Y
{
int a, b;
};
struct E
{
std::string v;
};
result<X> fx0()
{
return {};
}
result<X> fx1()
{
return {{ 1 }};
}
result<Y> fy0()
{
return {};
}
result<Y> fy2()
{
return {{ 1, 2 }};
}
result<X, E> fxe0()
{
return {};
}
result<X, E> fxe1()
{
return {{ 1 }};
}
result<std::vector<int>> fv0()
{
return {};
}
result<std::vector<int>> fv1()
{
return {{ 1 }};
}
result<std::vector<int>> fv2()
{
return {{ 1, 2 }};
}
int main()
{
{
result<X> r = fx0();
BOOST_TEST( r.has_value() );
BOOST_TEST_EQ( r->a, 0 );
}
{
result<X> r = fx1();
BOOST_TEST( r.has_value() );
BOOST_TEST_EQ( r->a, 1 );
}
{
result<Y> r = fy0();
BOOST_TEST( r.has_value() );
BOOST_TEST_EQ( r->a, 0 );
BOOST_TEST_EQ( r->b, 0 );
}
{
result<Y> r = fy2();
BOOST_TEST( r.has_value() );
BOOST_TEST_EQ( r->a, 1 );
BOOST_TEST_EQ( r->b, 2 );
}
{
result<X, E> r = fxe0();
BOOST_TEST( r.has_value() );
BOOST_TEST_EQ( r->a, 0 );
}
{
result<X, E> r = fxe1();
BOOST_TEST( r.has_value() );
BOOST_TEST_EQ( r->a, 1 );
}
{
result<std::vector<int>> r = fv0();
BOOST_TEST( r.has_value() );
BOOST_TEST_EQ( r->size(), 0 );
}
{
result<std::vector<int>> r = fv1();
BOOST_TEST( r.has_value() );
BOOST_TEST_EQ( r->size(), 1 );
BOOST_TEST_EQ( r->at(0), 1 );
}
{
result<std::vector<int>> r = fv2();
BOOST_TEST( r.has_value() );
BOOST_TEST_EQ( r->size(), 2 );
BOOST_TEST_EQ( r->at(0), 1 );
BOOST_TEST_EQ( r->at(1), 2 );
}
return boost::report_errors();
}

View File

@@ -0,0 +1,29 @@
// Copyright 2018 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
#include <boost/config.hpp>
#if defined(SINGLE_INSTANCE_DYN_LINK)
# define EXPORT BOOST_SYMBOL_EXPORT
#else
# define EXPORT
#endif
#include <boost/system/error_code.hpp>
using namespace boost::system;
namespace lib1
{
EXPORT error_code get_system_code()
{
return error_code( 0, system_category() );
}
EXPORT error_code get_generic_code()
{
return error_code( 0, generic_category() );
}
} // namespace lib1

View File

@@ -0,0 +1,29 @@
// Copyright 2018 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
#include <boost/config.hpp>
#if defined(SINGLE_INSTANCE_DYN_LINK)
# define EXPORT BOOST_SYMBOL_EXPORT
#else
# define EXPORT
#endif
#include <boost/system/error_code.hpp>
using namespace boost::system;
namespace lib2
{
EXPORT error_code get_system_code()
{
return error_code( 0, system_category() );
}
EXPORT error_code get_generic_code()
{
return error_code( 0, generic_category() );
}
} // namespace lib2

View File

@@ -0,0 +1,47 @@
// Copyright 2018 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
#include <boost/system/error_code.hpp>
#include <boost/core/lightweight_test.hpp>
using namespace boost::system;
namespace lib1
{
error_code get_system_code();
error_code get_generic_code();
} // namespace lib1
namespace lib2
{
error_code get_system_code();
error_code get_generic_code();
} // namespace lib2
int main()
{
{
error_code e1 = lib1::get_system_code();
error_code e2 = lib2::get_system_code();
BOOST_TEST_EQ( e1, e2 );
BOOST_TEST_EQ( hash_value( e1 ), hash_value( e2 ) );
}
{
error_code e1 = lib1::get_generic_code();
error_code e2 = lib2::get_generic_code();
BOOST_TEST_EQ( e1, e2 );
BOOST_TEST_EQ( hash_value( e1 ), hash_value( e2 ) );
}
return boost::report_errors();
}

View File

@@ -0,0 +1,60 @@
// Copyright 2021 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// http://www.boost.org/LICENSE_1_0.txt
#include <boost/system/detail/snprintf.hpp>
#include <boost/core/lightweight_test.hpp>
int main()
{
{
char buffer[ 64 ];
boost::system::detail::snprintf( buffer, sizeof(buffer), "...%s...%d...", "xy", 151 );
BOOST_TEST_CSTR_EQ( buffer, "...xy...151..." );
}
{
char buffer[ 64 ];
boost::system::detail::snprintf( buffer, sizeof(buffer), "...%s...%d...", "xy", 151 );
BOOST_TEST_CSTR_EQ( buffer, "...xy...151..." );
}
{
char buffer[ 15 ];
boost::system::detail::snprintf( buffer, sizeof(buffer), "...%s...%d...", "xy", 151 );
BOOST_TEST_CSTR_EQ( buffer, "...xy...151..." );
}
{
char buffer[ 14 ];
boost::system::detail::snprintf( buffer, sizeof(buffer), "...%s...%d...", "xy", 151 );
BOOST_TEST_CSTR_EQ( buffer, "...xy...151.." );
}
{
char buffer[ 5 ];
boost::system::detail::snprintf( buffer, sizeof(buffer), "...%s...%d...", "xy", 151 );
BOOST_TEST_CSTR_EQ( buffer, "...x" );
}
{
char buffer[ 1 ];
boost::system::detail::snprintf( buffer, sizeof(buffer), "...%s...%d...", "xy", 151 );
BOOST_TEST_CSTR_EQ( buffer, "" );
}
{
char buffer[ 1 ] = { 'Q' };
boost::system::detail::snprintf( buffer, 0, "...%s...%d...", "xy", 151 );
BOOST_TEST_EQ( buffer[0], 'Q' );
}
return boost::report_errors();
}

View File

@@ -0,0 +1,353 @@
// Copyright 2017 Peter Dimov.
//
// 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 library home page at http://www.boost.org/libs/system
// Avoid spurious VC++ warnings
# define _CRT_SECURE_NO_WARNINGS
#include <boost/system/error_code.hpp>
#include <boost/config.hpp>
#include <boost/config/pragma_message.hpp>
#include <iostream>
#if !defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
BOOST_PRAGMA_MESSAGE( "BOOST_SYSTEM_HAS_SYSTEM_ERROR not defined, test will be skipped" )
int main()
{
std::cout
<< "The version of the C++ standard library being used does not"
" support header <system_error> so interoperation will not be tested.\n";
}
#else
#include <boost/core/lightweight_test.hpp>
#include <system_error>
#include <cerrno>
#include <string>
#include <cstdio>
static void test_generic_category()
{
boost::system::error_category const & bt = boost::system::generic_category();
std::error_category const & st = bt;
BOOST_TEST_CSTR_EQ( bt.name(), st.name() );
int ev = ENOENT;
// Under MSVC, it's "no such file or directory" instead of "No such file or directory"
BOOST_TEST_EQ( bt.message( ev ).substr( 1 ), st.message( ev ).substr( 1 ) );
{
boost::system::error_code bc( ev, bt );
BOOST_TEST_EQ( bc.value(), ev );
BOOST_TEST_EQ( &bc.category(), &bt );
std::error_code sc( bc );
BOOST_TEST_EQ( sc.value(), ev );
BOOST_TEST_EQ( &sc.category(), &st );
}
{
boost::system::error_condition bn = bt.default_error_condition( ev );
BOOST_TEST_EQ( bn.value(), ev );
BOOST_TEST_EQ( &bn.category(), &bt );
BOOST_TEST( bt.equivalent( ev, bn ) );
std::error_condition sn( bn );
BOOST_TEST_EQ( sn.value(), ev );
BOOST_TEST_EQ( &sn.category(), &st );
BOOST_TEST( st.equivalent( ev, sn ) );
}
}
static void test_system_category()
{
boost::system::error_category const & bt = boost::system::system_category();
std::error_category const & st = bt;
BOOST_TEST_CSTR_EQ( bt.name(), st.name() );
for( int ev = 1; ev < 6; ++ev )
{
std::string bm = bt.message( ev );
std::string sm = st.message( ev );
// We strip whitespace and the trailing dot, MSVC not so much
BOOST_TEST_EQ( bm, sm.substr( 0, bm.size() ) );
{
boost::system::error_code bc( ev, bt );
BOOST_TEST_EQ( bc.value(), ev );
BOOST_TEST_EQ( &bc.category(), &bt );
std::error_code sc( bc );
BOOST_TEST_EQ( sc.value(), ev );
BOOST_TEST_EQ( &sc.category(), &st );
}
{
boost::system::error_condition bn = bt.default_error_condition( ev );
BOOST_TEST( bt.equivalent( ev, bn ) );
std::error_condition sn( bn );
BOOST_TEST( st.equivalent( ev, sn ) );
}
}
}
// test_user_category
class user_category_impl: public boost::system::error_category
{
public:
virtual const char * name() const BOOST_NOEXCEPT
{
return "user";
}
virtual std::string message( int ev ) const
{
char buffer[ 256 ];
std::sprintf( buffer, "user message %d", ev );
return buffer;
}
virtual boost::system::error_condition default_error_condition( int ev ) const BOOST_NOEXCEPT
{
if( ev == 4 )
{
return boost::system::error_condition( EMFILE, boost::system::generic_category() );
}
else if( ev == 5 )
{
return boost::system::error_condition( EACCES, boost::system::generic_category() );
}
else
{
return boost::system::error_condition( ev, *this );
}
}
virtual bool equivalent( int code, const boost::system::error_condition & condition ) const BOOST_NOEXCEPT
{
if( code == 4 && condition == make_error_condition( boost::system::errc::too_many_files_open_in_system ) )
{
return true;
}
if( code == 4 && condition == make_error_condition( boost::system::errc::too_many_files_open ) )
{
return true;
}
return default_error_condition( code ) == condition;
}
// virtual bool equivalent( const error_code & code, int condition ) const BOOST_NOEXCEPT;
};
boost::system::error_category const & user_category()
{
static user_category_impl cat_;
return cat_;
}
static void test_user_category()
{
boost::system::error_category const & bt = user_category();
std::error_category const & st = bt;
BOOST_TEST_CSTR_EQ( bt.name(), st.name() );
{
int ev = 5;
BOOST_TEST_EQ( bt.message( ev ), st.message( ev ) );
{
boost::system::error_code bc( ev, bt );
BOOST_TEST_EQ( bc.value(), ev );
BOOST_TEST_EQ( &bc.category(), &bt );
std::error_code sc( bc );
BOOST_TEST_EQ( sc.value(), ev );
BOOST_TEST_EQ( &sc.category(), &st );
}
{
boost::system::error_condition bn = bt.default_error_condition( ev );
BOOST_TEST( bt.equivalent( ev, bn ) );
std::error_condition sn( bn );
BOOST_TEST( st.equivalent( ev, sn ) );
}
}
{
int ev = 4;
BOOST_TEST_EQ( bt.message( ev ), st.message( ev ) );
{
boost::system::error_code bc( ev, bt );
BOOST_TEST_EQ( bc.value(), ev );
BOOST_TEST_EQ( &bc.category(), &bt );
std::error_code sc( bc );
BOOST_TEST_EQ( sc.value(), ev );
BOOST_TEST_EQ( &sc.category(), &st );
}
{
boost::system::error_condition bn = bt.default_error_condition( ev );
BOOST_TEST( bt.equivalent( ev, bn ) );
std::error_condition sn( bn );
BOOST_TEST( st.equivalent( ev, sn ) );
}
{
boost::system::error_condition bn = make_error_condition( boost::system::errc::too_many_files_open_in_system );
BOOST_TEST( bt.equivalent( ev, bn ) );
std::error_condition sn( bn );
BOOST_TEST( st.equivalent( ev, sn ) );
}
{
boost::system::error_condition bn = make_error_condition( boost::system::errc::too_many_files_open );
BOOST_TEST( bt.equivalent( ev, bn ) );
std::error_condition sn( bn );
BOOST_TEST( st.equivalent( ev, sn ) );
}
}
}
// test_user2_category
enum user2_errc
{
my_enoent = 1,
my_einval,
my_other
};
class user2_category_impl: public boost::system::error_category
{
public:
virtual const char * name() const BOOST_NOEXCEPT
{
return "user2";
}
virtual std::string message( int ev ) const
{
char buffer[ 256 ];
std::sprintf( buffer, "user2 message %d", ev );
return buffer;
}
virtual boost::system::error_condition default_error_condition( int ev ) const BOOST_NOEXCEPT
{
return boost::system::error_condition( ev, *this );
}
virtual bool equivalent( int code, const boost::system::error_condition & condition ) const BOOST_NOEXCEPT
{
return default_error_condition( code ) == condition;
}
virtual bool equivalent( const boost::system::error_code & code, int condition ) const BOOST_NOEXCEPT
{
if( code.category() == *this )
{
return condition == code.value();
}
else if( condition == my_enoent )
{
return code == boost::system::errc::no_such_file_or_directory;
}
else if( condition == my_einval )
{
return code == boost::system::errc::invalid_argument;
}
else
{
return false;
}
}
};
boost::system::error_category const & user2_category()
{
static user2_category_impl cat_;
return cat_;
}
static void test_user2_category()
{
boost::system::error_category const & bt = user2_category();
std::error_category const & st = bt;
int ev = my_enoent;
boost::system::error_condition bn( ev, bt );
BOOST_TEST_EQ( bn.value(), ev );
BOOST_TEST_EQ( &bn.category(), &bt );
boost::system::error_code bc = make_error_code( boost::system::errc::no_such_file_or_directory );
BOOST_TEST( bc == bn );
std::error_condition sn( bn );
BOOST_TEST_EQ( sn.value(), ev );
BOOST_TEST_EQ( &sn.category(), &st );
std::error_code sc( bc );
BOOST_TEST( sc == sn );
}
//
int main()
{
std::cout
<< "The version of the C++ standard library being used"
" supports header <system_error> so interoperation will be tested.\n";
test_generic_category();
test_system_category();
test_user_category();
test_user2_category();
return boost::report_errors();
}
#endif

View File

@@ -0,0 +1,66 @@
// Copyright 2021 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// http://www.boost.org/LICENSE_1_0.txt
#include <boost/system/error_code.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/config/pragma_message.hpp>
#include <cerrno>
#if !defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
BOOST_PRAGMA_MESSAGE( "BOOST_SYSTEM_HAS_SYSTEM_ERROR not defined, test will be skipped" )
int main() {}
#else
#include <system_error>
int main()
{
{
boost::system::error_code e1;
boost::system::error_code e2( 0, boost::system::system_category() );
BOOST_TEST_EQ( e1, e2 );
std::error_code e3( e1 );
std::error_code e4( e2 );
BOOST_TEST_EQ( e3, e4 );
}
{
boost::system::error_code e1;
std::error_code e2( e1 );
std::error_code e3( e1.value(), e1.category() );
BOOST_TEST_EQ( e2, e3 );
}
{
boost::system::error_condition e1;
boost::system::error_condition e2( 0, boost::system::generic_category() );
BOOST_TEST_EQ( e1, e2 );
std::error_condition e3( e1 );
std::error_condition e4( e2 );
BOOST_TEST( e3 == e4 );
}
{
boost::system::error_condition e1;
std::error_condition e2( e1 );
std::error_condition e3( e1.value(), e1.category() );
BOOST_TEST( e2 == e3 );
}
return boost::report_errors();
}
#endif

View File

@@ -0,0 +1,47 @@
// Copyright 2021 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// http://www.boost.org/LICENSE_1_0.txt
#include <boost/system/error_code.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/config/pragma_message.hpp>
#include <boost/config.hpp>
#include <ios>
#if !defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
BOOST_PRAGMA_MESSAGE( "Skipping test, BOOST_SYSTEM_HAS_SYSTEM_ERROR not defined" )
int main() {}
#elif defined(BOOST_LIBSTDCXX_VERSION) && BOOST_LIBSTDCXX_VERSION < 50000
BOOST_PRAGMA_MESSAGE( "Skipping test, BOOST_LIBSTDCXX_VERSION < 50000" )
int main() {}
#else
#include <system_error>
int main()
{
{
boost::system::error_code ec = std::io_errc::stream;
BOOST_TEST( ec == std::io_errc::stream );
BOOST_TEST_NOT( ec != std::io_errc::stream );
ec.clear();
BOOST_TEST_NOT( ec == std::io_errc::stream );
BOOST_TEST( ec != std::io_errc::stream );
ec = std::io_errc::stream;
BOOST_TEST( ec == std::io_errc::stream );
BOOST_TEST_NOT( ec != std::io_errc::stream );
}
return boost::report_errors();
}
#endif

View File

@@ -0,0 +1,127 @@
// Copyright 2021, 2022 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// http://www.boost.org/LICENSE_1_0.txt
#include <boost/system/error_code.hpp>
#include <boost/system/error_category.hpp>
#include <boost/system/errc.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/config/pragma_message.hpp>
#include <boost/config.hpp>
#include <cerrno>
#if !defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
BOOST_PRAGMA_MESSAGE( "BOOST_SYSTEM_HAS_SYSTEM_ERROR not defined, test will be skipped" )
int main() {}
#else
#include <system_error>
enum my_errc
{
my_enoent = ENOENT
};
class my_category: public boost::system::error_category
{
public:
char const* name() const BOOST_NOEXCEPT
{
return "mycat";
}
boost::system::error_condition default_error_condition( int ev ) const BOOST_NOEXCEPT
{
switch( ev )
{
case my_enoent:
return boost::system::error_condition( ENOENT, boost::system::generic_category() );
default:
return boost::system::error_condition( ev, *this );
}
}
std::string message( int ev ) const
{
switch( ev )
{
case my_enoent:
return "No such entity";
default:
return "Unknown error";
}
}
};
#if defined(BOOST_GCC) && BOOST_GCC < 70000
// g++ 6 and earlier do not allow specializations outside the namespace
namespace boost
{
namespace system
{
template<> struct is_error_code_enum<my_errc>: std::true_type {};
} // namespace system
} // namespace boost
namespace std
{
template<> struct is_error_code_enum<my_errc>: std::true_type {};
} // namespace std
#else
template<> struct boost::system::is_error_code_enum<my_errc>: std::true_type {};
template<> struct std::is_error_code_enum<my_errc>: std::true_type {};
#endif
boost::system::error_code make_error_code( my_errc e )
{
// If `cat` is declared constexpr or const, msvc-14.1 and
// msvc-14.2 before 19.29 put it in read-only memory,
// despite the `ps_` member being mutable. So it crashes.
static /*BOOST_SYSTEM_CONSTEXPR*/ my_category cat;
return boost::system::error_code( e, cat );
}
int main()
{
{
boost::system::error_code e1 = my_enoent;
BOOST_TEST( e1 == my_enoent );
BOOST_TEST_NOT( e1 != my_enoent );
BOOST_TEST( e1 == boost::system::errc::no_such_file_or_directory );
BOOST_TEST( e1 == std::errc::no_such_file_or_directory );
}
{
std::error_code e1 = my_enoent;
BOOST_TEST( e1 == my_enoent );
BOOST_TEST_NOT( e1 != my_enoent );
BOOST_TEST( e1 == std::errc::no_such_file_or_directory );
}
return boost::report_errors();
}
#endif

View File

@@ -0,0 +1,98 @@
// Copyright 2021 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// http://www.boost.org/LICENSE_1_0.txt
#include <boost/system/error_code.hpp>
#include <boost/system/system_category.hpp>
#include <boost/system/generic_category.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/config/pragma_message.hpp>
#include <cerrno>
#if !defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
BOOST_PRAGMA_MESSAGE( "BOOST_SYSTEM_HAS_SYSTEM_ERROR not defined, test will be skipped" )
int main() {}
#else
#include <system_error>
void f1( std::error_code ec, int value, std::error_category const& category )
{
BOOST_TEST_EQ( ec.value(), value );
BOOST_TEST_EQ( &ec.category(), &category );
}
void f2( std::error_code const& ec, int value, std::error_category const& category )
{
BOOST_TEST_EQ( ec.value(), value );
BOOST_TEST_EQ( &ec.category(), &category );
}
int main()
{
{
boost::system::error_code e1;
boost::system::error_code e2( e1 );
f1( e1, e1.value(), e1.category() );
#if !defined(BOOST_SYSTEM_CLANG_6)
f2( e1, e1.value(), e1.category() );
#endif
BOOST_TEST_EQ( e1, e2 );
}
{
boost::system::error_code e1( 0, boost::system::system_category() );
boost::system::error_code e2( e1 );
f1( e1, e1.value(), e1.category() );
#if !defined(BOOST_SYSTEM_CLANG_6)
f2( e1, e1.value(), e1.category() );
#endif
BOOST_TEST_EQ( e1, e2 );
}
{
boost::system::error_code e1( 5, boost::system::system_category() );
boost::system::error_code e2( e1 );
f1( e1, e1.value(), e1.category() );
#if !defined(BOOST_SYSTEM_CLANG_6)
f2( e1, e1.value(), e1.category() );
#endif
BOOST_TEST_EQ( e1, e2 );
}
{
boost::system::error_code e1( 0, boost::system::generic_category() );
boost::system::error_code e2( e1 );
f1( e1, e1.value(), e1.category() );
#if !defined(BOOST_SYSTEM_CLANG_6)
f2( e1, e1.value(), e1.category() );
#endif
BOOST_TEST_EQ( e1, e2 );
}
{
boost::system::error_code e1( ENOENT, boost::system::generic_category() );
boost::system::error_code e2( e1 );
f1( e1, e1.value(), e1.category() );
#if !defined(BOOST_SYSTEM_CLANG_6)
f2( e1, e1.value(), e1.category() );
#endif
BOOST_TEST_EQ( e1, e2 );
}
return boost::report_errors();
}
#endif

View File

@@ -0,0 +1,79 @@
// Copyright 2021 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// http://www.boost.org/LICENSE_1_0.txt
#include <boost/system/error_code.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/config/pragma_message.hpp>
#include <cerrno>
#if !defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
BOOST_PRAGMA_MESSAGE( "BOOST_SYSTEM_HAS_SYSTEM_ERROR not defined, test will be skipped" )
int main() {}
#else
#include <system_error>
int main()
{
{
std::error_code e1;
boost::system::error_code e2 = e1;
BOOST_TEST( !e2.failed() );
BOOST_TEST_EQ( e1.message(), e2.message() );
std::error_code e3 = e2;
BOOST_TEST_EQ( e1, e3 );
}
{
std::error_code e1( 5, std::system_category() );
boost::system::error_code e2 = e1;
BOOST_TEST( e2.failed() );
BOOST_TEST_EQ( e1.message(), e2.message() );
std::error_code e3 = e2;
BOOST_TEST_EQ( e1, e3 );
}
{
std::error_code e1( 0, std::generic_category() );
boost::system::error_code e2 = e1;
BOOST_TEST( !e2.failed() );
BOOST_TEST_EQ( e1.message(), e2.message() );
std::error_code e3 = e2;
BOOST_TEST_EQ( e1, e3 );
}
{
std::error_code e1( ENOENT, std::generic_category() );
boost::system::error_code e2 = e1;
BOOST_TEST( e2.failed() );
BOOST_TEST_EQ( e1.message(), e2.message() );
std::error_code e3 = e2;
BOOST_TEST_EQ( e1, e3 );
}
{
std::error_code e1 = make_error_code( std::errc::no_such_file_or_directory );
boost::system::error_code e2 = e1;
BOOST_TEST( e2.failed() );
BOOST_TEST_EQ( e1.message(), e2.message() );
std::error_code e3 = e2;
BOOST_TEST_EQ( e1, e3 );
}
return boost::report_errors();
}
#endif

View File

@@ -0,0 +1,89 @@
// Copyright 2021 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// http://www.boost.org/LICENSE_1_0.txt
#include <boost/system/error_code.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/config/pragma_message.hpp>
#include <cerrno>
#if !defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
BOOST_PRAGMA_MESSAGE( "BOOST_SYSTEM_HAS_SYSTEM_ERROR not defined, test will be skipped" )
int main() {}
#else
#include <system_error>
void f( std::error_code& e1, std::error_code e2 )
{
e1 = e2;
}
int main()
{
{
boost::system::error_code e1;
std::error_code e2;
f( e1, e2 );
BOOST_TEST_EQ( e1, boost::system::error_code( e2 ) );
std::error_code e3( e1 );
BOOST_TEST_EQ( e3, e2 );
}
{
boost::system::error_code e1;
std::error_code e2( 0, std::system_category() );
f( e1, e2 );
BOOST_TEST_EQ( e1, boost::system::error_code( e2 ) );
std::error_code e3( e1 );
BOOST_TEST_EQ( e3, e2 );
}
{
boost::system::error_code e1;
std::error_code e2( 5, std::system_category() );
f( e1, e2 );
BOOST_TEST_EQ( e1, boost::system::error_code( e2 ) );
std::error_code e3( e1 );
BOOST_TEST_EQ( e3, e2 );
}
{
boost::system::error_code e1;
std::error_code e2( 0, std::generic_category() );
f( e1, e2 );
BOOST_TEST_EQ( e1, boost::system::error_code( e2 ) );
std::error_code e3( e1 );
BOOST_TEST_EQ( e3, e2 );
}
{
boost::system::error_code e1;
std::error_code e2( ENOENT, std::generic_category() );
f( e1, e2 );
BOOST_TEST_EQ( e1, boost::system::error_code( e2 ) );
std::error_code e3( e1 );
BOOST_TEST_EQ( e3, e2 );
}
return boost::report_errors();
}
#endif

View File

@@ -0,0 +1,108 @@
// Copyright 2021 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// http://www.boost.org/LICENSE_1_0.txt
#include <boost/system/error_code.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/config/pragma_message.hpp>
#include <cerrno>
#if !defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
BOOST_PRAGMA_MESSAGE( "BOOST_SYSTEM_HAS_SYSTEM_ERROR not defined, test will be skipped" )
int main() {}
#else
#include <system_error>
int main()
{
{
std::error_code e1;
std::error_condition en = e1.default_error_condition();
BOOST_TEST( e1 == en );
BOOST_TEST_NOT( e1 != en );
boost::system::error_code e2( e1 );
BOOST_TEST_EQ( e2, e1 );
BOOST_TEST_NOT( e2 != e1 );
BOOST_TEST( e2 == en );
BOOST_TEST_NOT( e2 != en );
std::error_code e3( e2 );
BOOST_TEST( e3 == en );
BOOST_TEST_NOT( e3 != en );
}
{
std::error_code e1( 5, std::system_category() );
std::error_condition en = e1.default_error_condition();
BOOST_TEST( e1 == en );
BOOST_TEST_NOT( e1 != en );
boost::system::error_code e2( e1 );
BOOST_TEST_EQ( e2, e1 );
BOOST_TEST_NOT( e2 != e1 );
BOOST_TEST( e2 == en );
BOOST_TEST_NOT( e2 != en );
std::error_code e3( e2 );
BOOST_TEST( e3 == en );
BOOST_TEST_NOT( e3 != en );
}
{
std::error_code e1( 0, std::generic_category() );
std::error_condition en = e1.default_error_condition();
BOOST_TEST( e1 == en );
BOOST_TEST_NOT( e1 != en );
boost::system::error_code e2( e1 );
BOOST_TEST_EQ( e2, e1 );
BOOST_TEST_NOT( e2 != e1 );
BOOST_TEST( e2 == en );
BOOST_TEST_NOT( e2 != en );
std::error_code e3( e2 );
BOOST_TEST( e3 == en );
BOOST_TEST_NOT( e3 != en );
}
{
std::error_code e1( 5, std::generic_category() );
std::error_condition en = e1.default_error_condition();
BOOST_TEST( e1 == en );
BOOST_TEST_NOT( e1 != en );
boost::system::error_code e2( e1 );
BOOST_TEST_EQ( e2, e1 );
BOOST_TEST_NOT( e2 != e1 );
BOOST_TEST( e2 == en );
BOOST_TEST_NOT( e2 != en );
std::error_code e3( e2 );
BOOST_TEST( e3 == en );
BOOST_TEST_NOT( e3 != en );
}
return boost::report_errors();
}
#endif

View File

@@ -0,0 +1,140 @@
// Copyright 2021 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// http://www.boost.org/LICENSE_1_0.txt
#include <boost/system/error_code.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/config/pragma_message.hpp>
#include <cerrno>
#if !defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
BOOST_PRAGMA_MESSAGE( "BOOST_SYSTEM_HAS_SYSTEM_ERROR not defined, test will be skipped" )
int main() {}
#else
#include <system_error>
int main()
{
{
boost::system::error_code e1;
boost::system::error_condition en = e1.default_error_condition();
BOOST_TEST_EQ( e1, en );
BOOST_TEST_NOT( e1 != en );
std::error_code e2( e1 );
BOOST_TEST_EQ( e2, e1 );
BOOST_TEST_NOT( e2 != e1 );
#if defined(_LIBCPP_VERSION)
// Under MS STL and libstdc++, std::error_code() does not compare
// equal to std::error_condition(). Go figure.
BOOST_TEST_EQ( e2, en );
BOOST_TEST_NOT( e2 != en );
boost::system::error_code e3( e2 );
BOOST_TEST_EQ( e3, en );
BOOST_TEST_NOT( e3 != en );
#endif
}
{
boost::system::error_code e1( 0, boost::system::system_category() );
boost::system::error_condition en = e1.default_error_condition();
BOOST_TEST_EQ( e1, en );
BOOST_TEST_NOT( e1 != en );
std::error_code e2( e1 );
BOOST_TEST_EQ( e2, e1 );
BOOST_TEST_NOT( e2 != e1 );
#if defined(_LIBCPP_VERSION)
BOOST_TEST_EQ( e2, en );
BOOST_TEST_NOT( e2 != en );
boost::system::error_code e3( e2 );
BOOST_TEST_EQ( e3, en );
BOOST_TEST_NOT( e3 != en );
#endif
}
{
boost::system::error_code e1( 5, boost::system::system_category() );
boost::system::error_condition en = e1.default_error_condition();
BOOST_TEST_EQ( e1, en );
BOOST_TEST_NOT( e1 != en );
std::error_code e2( e1 );
BOOST_TEST_EQ( e2, e1 );
BOOST_TEST_NOT( e2 != e1 );
BOOST_TEST_EQ( e2, en );
BOOST_TEST_NOT( e2 != en );
boost::system::error_code e3( e2 );
BOOST_TEST_EQ( e3, en );
BOOST_TEST_NOT( e3 != en );
}
{
boost::system::error_code e1( 0, boost::system::generic_category() );
boost::system::error_condition en = e1.default_error_condition();
BOOST_TEST_EQ( e1, en );
BOOST_TEST_NOT( e1 != en );
std::error_code e2( e1 );
BOOST_TEST_EQ( e2, e1 );
BOOST_TEST_NOT( e2 != e1 );
BOOST_TEST_EQ( e2, en );
BOOST_TEST_NOT( e2 != en );
boost::system::error_code e3( e2 );
BOOST_TEST_EQ( e3, en );
BOOST_TEST_NOT( e3 != en );
}
{
boost::system::error_code e1( 5, boost::system::generic_category() );
boost::system::error_condition en = e1.default_error_condition();
BOOST_TEST_EQ( e1, en );
BOOST_TEST_NOT( e1 != en );
std::error_code e2( e1 );
BOOST_TEST_EQ( e2, e1 );
BOOST_TEST_NOT( e2 != e1 );
BOOST_TEST_EQ( e2, en );
BOOST_TEST_NOT( e2 != en );
boost::system::error_code e3( e2 );
BOOST_TEST_EQ( e3, en );
BOOST_TEST_NOT( e3 != en );
}
return boost::report_errors();
}
#endif

View File

@@ -0,0 +1,52 @@
// Copyright 2021 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// http://www.boost.org/LICENSE_1_0.txt
#include <boost/system/error_code.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/config/pragma_message.hpp>
#include <boost/config.hpp>
#include <cerrno>
#if !defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
BOOST_PRAGMA_MESSAGE( "BOOST_SYSTEM_HAS_SYSTEM_ERROR not defined, test will be skipped" )
int main() {}
#else
#include <system_error>
int main()
{
{
boost::system::error_code e1 = make_error_code( boost::system::errc::bad_address );
BOOST_TEST( e1 == boost::system::errc::bad_address );
BOOST_TEST_NOT( e1 != boost::system::errc::bad_address );
BOOST_TEST( e1 == std::errc::bad_address );
BOOST_TEST_NOT( e1 != std::errc::bad_address );
}
{
boost::system::error_code e1 = make_error_code( std::errc::bad_address );
BOOST_TEST( e1 == boost::system::errc::bad_address );
BOOST_TEST_NOT( e1 != boost::system::errc::bad_address );
#if defined(BOOST_GCC) && BOOST_GCC >= 40800 && BOOST_GCC < 50000
// fails on g++ 4.8.5 and g++ 4.9.4 from ubuntu-toolchain-r-test for unknown reasons
// works on the system g++ 4.8.4 on Trusty and the system g++ 4.8.5 on CentOS 7
#else
BOOST_TEST( e1 == std::errc::bad_address );
BOOST_TEST_NOT( e1 != std::errc::bad_address );
#endif
}
return boost::report_errors();
}
#endif

View File

@@ -0,0 +1,82 @@
// Copyright 2021 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// http://www.boost.org/LICENSE_1_0.txt
#include <boost/system/error_code.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/config/pragma_message.hpp>
#include <boost/config.hpp>
#include <cerrno>
#if !defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
BOOST_PRAGMA_MESSAGE( "BOOST_SYSTEM_HAS_SYSTEM_ERROR not defined, test will be skipped" )
int main() {}
#else
#include <system_error>
enum my_errc
{
my_enoent = ENOENT
};
#if defined(BOOST_GCC) && BOOST_GCC < 70000
// g++ 6 and earlier do not allow specializations outside the namespace
namespace boost
{
namespace system
{
template<> struct is_error_condition_enum<my_errc>: std::true_type {};
} // namespace system
} // namespace boost
namespace std
{
template<> struct is_error_condition_enum<my_errc>: std::true_type {};
} // namespace std
#else
template<> struct boost::system::is_error_condition_enum<my_errc>: std::true_type {};
template<> struct std::is_error_condition_enum<my_errc>: std::true_type {};
#endif
boost::system::error_condition make_error_condition( my_errc e )
{
return boost::system::error_condition( e, boost::system::generic_category() );
}
boost::system::error_code make_error_code( my_errc e )
{
return boost::system::error_code( e, boost::system::generic_category() );
}
int main()
{
{
boost::system::error_code e1 = make_error_code( my_enoent );
BOOST_TEST( e1 == my_enoent );
BOOST_TEST_NOT( e1 != my_enoent );
}
{
std::error_code e1 = make_error_code( my_enoent );
BOOST_TEST( e1 == my_enoent );
BOOST_TEST_NOT( e1 != my_enoent );
}
return boost::report_errors();
}
#endif

View File

@@ -0,0 +1,77 @@
// Copyright 2021 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// http://www.boost.org/LICENSE_1_0.txt
#include <boost/system/error_code.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/config/pragma_message.hpp>
#include <boost/config.hpp>
#include <cerrno>
#if !defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
BOOST_PRAGMA_MESSAGE( "BOOST_SYSTEM_HAS_SYSTEM_ERROR not defined, test will be skipped" )
int main() {}
#else
#include <system_error>
enum my_errc
{
my_enoent = ENOENT
};
#if defined(BOOST_GCC) && BOOST_GCC < 70000
// g++ 6 and earlier do not allow specializations outside the namespace
namespace boost
{
namespace system
{
template<> struct is_error_code_enum<my_errc>: std::true_type {};
} // namespace system
} // namespace boost
namespace std
{
template<> struct is_error_code_enum<my_errc>: std::true_type {};
} // namespace std
#else
template<> struct boost::system::is_error_code_enum<my_errc>: std::true_type {};
template<> struct std::is_error_code_enum<my_errc>: std::true_type {};
#endif
boost::system::error_code make_error_code( my_errc e )
{
return boost::system::error_code( e, boost::system::generic_category() );
}
int main()
{
{
boost::system::error_code e1 = my_enoent;
BOOST_TEST( e1 == my_enoent );
BOOST_TEST_NOT( e1 != my_enoent );
}
{
std::error_code e1 = my_enoent;
BOOST_TEST( e1 == my_enoent );
BOOST_TEST_NOT( e1 != my_enoent );
}
return boost::report_errors();
}
#endif

View File

@@ -0,0 +1,66 @@
// Copyright 2017 Peter Dimov.
//
// 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 library home page at http://www.boost.org/libs/system
// Avoid spurious VC++ warnings
# define _CRT_SECURE_NO_WARNINGS
#include <boost/system/error_code.hpp>
#include <boost/config.hpp>
#include <boost/config/pragma_message.hpp>
#include <iostream>
#if !defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
BOOST_PRAGMA_MESSAGE( "BOOST_SYSTEM_HAS_SYSTEM_ERROR not defined, test will be skipped" )
int main()
{
std::cout
<< "The version of the C++ standard library being used does not"
" support header <system_error> so interoperation will not be tested.\n";
}
#else
#include <boost/core/lightweight_test.hpp>
#include <system_error>
#include <cerrno>
#include <string>
#include <cstdio>
static void test_generic_category()
{
boost::system::error_category const & bt = boost::system::generic_category();
std::error_category const & st = bt;
BOOST_TEST_CSTR_EQ( bt.name(), st.name() );
}
static void test_system_category()
{
boost::system::error_category const & bt = boost::system::system_category();
std::error_category const & st = bt;
BOOST_TEST_CSTR_EQ( bt.name(), st.name() );
}
int main()
{
std::cout
<< "The version of the C++ standard library being used"
" supports header <system_error> so interoperation will be tested.\n";
test_generic_category();
test_system_category();
return boost::report_errors();
}
#endif

View File

@@ -0,0 +1,40 @@
// Copyright 2019 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
#include <boost/config.hpp>
#if defined(STD_SINGLE_INSTANCE_DYN_LINK)
# define EXPORT BOOST_SYMBOL_EXPORT
#else
# define EXPORT
#endif
#include <boost/system/error_code.hpp>
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
#include <system_error>
namespace lib1
{
EXPORT std::error_code get_system_code()
{
return boost::system::error_code( 0, boost::system::system_category() );
}
EXPORT std::error_code get_generic_code()
{
return boost::system::error_code( 0, boost::system::generic_category() );
}
} // namespace lib1
#else
EXPORT void lib1_f()
{
}
#endif

View File

@@ -0,0 +1,40 @@
// Copyright 2019 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
#include <boost/config.hpp>
#if defined(STD_SINGLE_INSTANCE_DYN_LINK)
# define EXPORT BOOST_SYMBOL_EXPORT
#else
# define EXPORT
#endif
#include <boost/system/error_code.hpp>
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
#include <system_error>
namespace lib2
{
EXPORT std::error_code get_system_code()
{
return boost::system::error_code( 0, boost::system::system_category() );
}
EXPORT std::error_code get_generic_code()
{
return boost::system::error_code( 0, boost::system::generic_category() );
}
} // namespace lib2
#else
EXPORT void lib2_f()
{
}
#endif

View File

@@ -0,0 +1,76 @@
// Copyright 2019 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
#include <boost/system/error_code.hpp>
#include <boost/config/pragma_message.hpp>
#include <boost/config/helper_macros.hpp>
#if !defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
BOOST_PRAGMA_MESSAGE( "BOOST_SYSTEM_HAS_SYSTEM_ERROR not defined, test will be skipped" )
int main() {}
#elif defined(STD_SINGLE_INSTANCE_SHARED) && defined(__CYGWIN__)
BOOST_PRAGMA_MESSAGE( "Skipping Windows/DLL test, __CYGWIN__" )
int main() {}
#elif defined(STD_SINGLE_INSTANCE_SHARED) && defined(_WIN32) && !defined(_MSC_VER)
BOOST_PRAGMA_MESSAGE( "Skipping Windows/DLL test, no _MSC_VER" )
int main() {}
#elif defined(STD_SINGLE_INSTANCE_SHARED) && defined(_WIN32) && !defined(_CPPLIB_VER)
BOOST_PRAGMA_MESSAGE( "Skipping Windows/DLL test, no _CPPLIB_VER" )
int main() {}
#elif defined(STD_SINGLE_INSTANCE_SHARED) && defined(_WIN32) && (_MSC_VER < 1900 || _MSC_VER >= 2000)
BOOST_PRAGMA_MESSAGE( "Skipping Windows/DLL test, _MSC_VER is " BOOST_STRINGIZE(_MSC_VER) )
int main() {}
#else
#include <boost/core/lightweight_test.hpp>
#include <system_error>
using namespace boost::system;
namespace lib1
{
std::error_code get_system_code();
std::error_code get_generic_code();
} // namespace lib1
namespace lib2
{
std::error_code get_system_code();
std::error_code get_generic_code();
} // namespace lib2
int main()
{
{
std::error_code e1 = lib1::get_system_code();
std::error_code e2 = lib2::get_system_code();
BOOST_TEST_EQ( e1, e2 );
}
{
std::error_code e1 = lib1::get_generic_code();
std::error_code e2 = lib2::get_generic_code();
BOOST_TEST_EQ( e1, e2 );
}
return boost::report_errors();
}
#endif

View File

@@ -0,0 +1,122 @@
// Copyright 2018 Peter Dimov.
//
// 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 library home page at http://www.boost.org/libs/system
// Avoid spurious VC++ warnings
# define _CRT_SECURE_NO_WARNINGS
#include <boost/system/error_code.hpp>
#include <boost/core/lightweight_test.hpp>
#include <cstring>
#include <cstdio>
//
#if defined(BOOST_WINDOWS_API) && defined(BOOST_SYSTEM_USE_UTF8)
#include <boost/config/pragma_message.hpp>
BOOST_PRAGMA_MESSAGE( "Skipping test due to BOOST_WINDOWS_API && BOOST_SYSTEM_USE_UTF8" )
int main() {}
#else
#if defined(BOOST_WINDOWS_API)
#include <windows.h>
std::string sys_strerror( int ev )
{
void * lpMsgBuf = 0;
DWORD retval = FormatMessageA(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
ev,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPSTR) &lpMsgBuf,
0,
NULL
);
struct local_free
{
void * p_;
~local_free()
{
LocalFree( p_ );
}
};
local_free lf_ = { lpMsgBuf };
(void)lf_;
if( retval == 0 )
{
char buffer[ 38 ];
std::sprintf( buffer, "Unknown error (%d)", ev );
return buffer;
}
std::string str( static_cast<char const*>( lpMsgBuf ) );
while( !str.empty() && (str[str.size()-1] == '\n' || str[str.size()-1] == '\r') )
{
str.erase( str.size()-1 );
}
if( !str.empty() && str[str.size()-1] == '.' )
{
str.erase( str.size()-1 );
}
return str;
}
#else
std::string sys_strerror( int ev )
{
return std::strerror( ev );
}
#endif
//
namespace sys = boost::system;
static void test_message( sys::error_category const & cat, int ev )
{
BOOST_TEST_EQ( cat.message( ev ), sys_strerror( ev ) );
char buffer[ 4096 ]; // yes, really
BOOST_TEST_CSTR_EQ( cat.message( ev, buffer, sizeof( buffer ) ), sys_strerror( ev ).c_str() );
}
int main()
{
sys::error_category const & cat = sys::system_category();
// message
for( int i = -2; i < 16000; ++i )
{
test_message( cat, i );
}
return boost::report_errors();
}
#endif // #if defined(BOOST_WINDOWS_API) && defined(BOOST_SYSTEM_USE_UTF8)

View File

@@ -0,0 +1,20 @@
// Copyright 2020 Peter Dimov
// Distributed under the Boost Software License, Version 1.0
// http://www.boost.org/LICENSE_1_0.txt
#include <boost/system/system_category.hpp>
#include <boost/core/lightweight_test.hpp>
// Tests whether system_category() is functional when only
// system_category.hpp is included
namespace sys = boost::system;
int main()
{
sys::error_category const & cat = sys::system_category();
BOOST_TEST_CSTR_EQ( cat.name(), "system" );
return boost::report_errors();
}

View File

@@ -0,0 +1,41 @@
// Copyright 2020 Peter Dimov
// Distributed under the Boost Software License, Version 1.0
// http://www.boost.org/LICENSE_1_0.txt
#include <boost/system/system_category.hpp>
#include <boost/system/generic_category.hpp>
#include <boost/system/error_condition.hpp>
#include <boost/core/lightweight_test.hpp>
namespace sys = boost::system;
int main()
{
sys::error_category const & cat = sys::system_category();
// name
BOOST_TEST_CSTR_EQ( cat.name(), "system" );
// default_error_condition
BOOST_TEST( cat.default_error_condition( 0 ) == sys::error_condition() );
// No longer holds; returns a generic condition
// BOOST_TEST( cat.default_error_condition( -1 ) == sys::error_condition( -1, cat ) );
#if defined(BOOST_WINDOWS_API)
BOOST_TEST( cat.default_error_condition( 5 ) == sys::error_condition( EACCES, sys::generic_category() ) );
#else
BOOST_TEST( cat.default_error_condition( EACCES ) == sys::error_condition( EACCES, sys::generic_category() ) );
#endif
// failed
BOOST_TEST( !cat.failed( 0 ) );
BOOST_TEST( cat.failed( 5 ) );
BOOST_TEST( cat.failed( -1 ) );
return boost::report_errors();
}

View File

@@ -0,0 +1,105 @@
// system_error_test.cpp ---------------------------------------------------//
// Copyright Beman Dawes 2006
// Copyright (c) Microsoft Corporation 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 library home page at http://www.boost.org/libs/system
//----------------------------------------------------------------------------//
#include <boost/config/warning_disable.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <boost/system/system_error.hpp>
#include <iostream>
#include <string>
#ifdef BOOST_WINDOWS_API
#include <windows.h>
#endif
using boost::system::system_error;
using boost::system::error_code;
using boost::system::system_category;
using std::string;
#define TEST(x,v,w) test(#x,x,v,w)
namespace
{
void test( const char * desc, const system_error & ex,
int v, const char * str )
{
std::cout << "test " << desc << "\n what() returns \"" << ex.what() << "\"\n";
BOOST_TEST( ex.code().value() == v );
BOOST_TEST( ex.code().category() == system_category() );
# ifdef BOOST_WINDOWS_API
LANGID language_id;
# if !BOOST_PLAT_WINDOWS_RUNTIME
language_id = ::GetUserDefaultUILanguage();
# else
language_id = 0x0409; // Assume US English
# endif
// std::cout << "GetUserDefaultUILanguage() returns " << language_id << '\n';
if ( language_id == 0x0409 ) // English (United States)
{
BOOST_TEST( std::string( ex.what() ) == str );
if ( std::string( ex.what() ) != str )
std::cout << "expected \"" << str << "\", but what() returned \""
<< ex.what() << "\"\n";
}
# endif
(void)str;
}
const boost::uint_least32_t uvalue = 2u;
}
int main( int, char *[] )
{
// all constructors, in the same order as they appear in the header:
system_error c1_0( error_code(0, system_category()) );
system_error c1_1( error_code(1, system_category()) );
system_error c1_2u( error_code(uvalue, system_category()) );
system_error c2_0( error_code(0, system_category()), string("c2_0") );
system_error c2_1( error_code(1, system_category()), string("c2_1") );
system_error c3_0( error_code(0, system_category()), "c3_0" );
system_error c3_1( error_code(1, system_category()), "c3_1" );
system_error c4_0( 0, system_category() );
system_error c4_1( 1, system_category() );
system_error c4_2u( uvalue, system_category() );
system_error c5_0( 0, system_category(), string("c5_0") );
system_error c5_1( 1, system_category(), string("c5_1") );
system_error c6_0( 0, system_category(), "c6_0" );
system_error c6_1( 1, system_category(), "c6_1" );
TEST( c1_0, 0, "The operation completed successfully [system:0]" );
TEST( c1_1, 1, "Incorrect function [system:1]" );
TEST( c1_2u, 2, "The system cannot find the file specified [system:2]" );
TEST( c2_0, 0, "c2_0: The operation completed successfully [system:0]" );
TEST( c2_1, 1, "c2_1: Incorrect function [system:1]" );
TEST( c3_0, 0, "c3_0: The operation completed successfully [system:0]" );
TEST( c3_1, 1, "c3_1: Incorrect function [system:1]" );
TEST( c4_0, 0, "The operation completed successfully [system:0]" );
TEST( c4_1, 1, "Incorrect function [system:1]" );
TEST( c4_2u, 2, "The system cannot find the file specified [system:2]" );
TEST( c5_0, 0, "c5_0: The operation completed successfully [system:0]" );
TEST( c5_1, 1, "c5_1: Incorrect function [system:1]" );
TEST( c6_0, 0, "c6_0: The operation completed successfully [system:0]" );
TEST( c6_1, 1, "c6_1: Incorrect function [system:1]" );
return ::boost::report_errors();
}

View File

@@ -0,0 +1,41 @@
// Copyright 2021 Peter Dimov
// Distributed under the Boost Software License, Version 1.0
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/system/system_error.hpp>
#include <boost/core/lightweight_test.hpp>
#include <cerrno>
namespace sys = boost::system;
int main()
{
{
sys::error_code ec( 5, sys::generic_category() );
sys::system_error x1( ec );
(void)x1;
}
{
sys::error_code ec( 5, sys::system_category() );
sys::system_error x1( ec );
(void)x1;
}
{
sys::system_error x1( make_error_code( sys::errc::invalid_argument ) );
(void)x1;
}
{
sys::system_error x1( 5, sys::generic_category() );
(void)x1;
}
{
sys::system_error x1( 5, sys::system_category() );
(void)x1;
}
return boost::report_errors();
}

View File

@@ -0,0 +1,62 @@
// Copyright 2021, 2022 Peter Dimov
// Distributed under the Boost Software License, Version 1.0
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/system/system_error.hpp>
#include <boost/core/lightweight_test.hpp>
#include <cerrno>
namespace sys = boost::system;
int main()
{
{
sys::error_code ec( 5, sys::generic_category() );
sys::system_error x1( ec );
BOOST_TEST_EQ( std::string( x1.what() ), ec.what() );
}
{
sys::error_code ec( 5, sys::generic_category() );
sys::system_error x1( ec, "prefix" );
BOOST_TEST_EQ( std::string( x1.what() ), "prefix: " + ec.what() );
}
{
sys::error_code ec( 5, sys::generic_category() );
sys::system_error x1( ec, std::string( "prefix2" ) );
BOOST_TEST_EQ( std::string( x1.what() ), "prefix2: " + ec.what() );
}
{
BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION;
sys::error_code ec( 5, sys::generic_category(), &loc );
sys::system_error x1( ec, "prefix3" );
BOOST_TEST_EQ( std::string( x1.what() ), "prefix3: " + ec.what() );
}
{
sys::system_error x1( 5, sys::system_category() );
BOOST_TEST_EQ( std::string( x1.what() ), sys::error_code( 5, sys::system_category() ).what() );
}
{
sys::system_error x1( 5, sys::system_category(), "prefix" );
BOOST_TEST_EQ( std::string( x1.what() ), "prefix: " + sys::error_code( 5, sys::system_category() ).what() );
}
{
sys::system_error x1( 5, sys::system_category(), std::string( "prefix2" ) );
BOOST_TEST_EQ( std::string( x1.what() ), "prefix2: " + sys::error_code( 5, sys::system_category() ).what() );
}
return boost::report_errors();
}

View File

@@ -0,0 +1,28 @@
// throw_test.cpp --------------------------------------------------------===========-//
// Copyright Beman Dawes 2010
// Distributed under the Boost Software License, Version 1.0.
// See www.boost.org/LICENSE_1_0.txt
// Library home page is www.boost.org/libs/system
//--------------------------------------------------------------------------------------//
// See dynamic_link_test.cpp comments for use case.
//--------------------------------------------------------------------------------------//
#include <boost/system/system_error.hpp>
#include <boost/config.hpp>
#if defined(THROW_DYN_LINK)
# define EXPORT BOOST_SYMBOL_EXPORT
#else
# define EXPORT
#endif
EXPORT void throw_test()
{
throw boost::system::system_error( 9999, boost::system::system_category(), "boo boo" );
}

View File

@@ -0,0 +1,28 @@
// Copyright 2018 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
#include <boost/system/error_code.hpp>
using namespace boost::system;
static void f( error_code & ec )
{
ec = error_code();
}
#if defined(_WIN32)
# include <windows.h> // SetErrorMode
#endif
int main()
{
#if defined(_WIN32)
SetErrorMode( SetErrorMode( 0 ) | SEM_NOGPFAULTERRORBOX );
#endif
// this should crash
f( boost::throws() );
}

View File

@@ -0,0 +1,52 @@
// Copyright 2017, 2019 Peter Dimov.
//
// 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 library home page at http://www.boost.org/libs/system
#if defined(__GNUC__) && __GNUC__ >= 5 && __cplusplus >= 201103L
# pragma GCC diagnostic error "-Wsuggest-override"
#endif
#include <boost/config.hpp>
#if defined( BOOST_GCC ) && BOOST_GCC < 40600
#pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
#endif
#include <boost/system/system_error.hpp>
#include <boost/system/error_code.hpp>
#include <boost/core/lightweight_test.hpp>
#include <cerrno>
int main()
{
boost::system::error_category const & bt = boost::system::generic_category();
int ev = ENOENT;
boost::system::error_code bc( ev, bt );
BOOST_TEST_EQ( bc.value(), ev );
BOOST_TEST_EQ( &bc.category(), &bt );
boost::system::error_condition bn = bt.default_error_condition( ev );
BOOST_TEST_EQ( bn.value(), ev );
BOOST_TEST_EQ( &bn.category(), &bt );
BOOST_TEST( bt.equivalent( ev, bn ) );
BOOST_TEST( bc == bn );
boost::system::system_error x( bc, "prefix" );
BOOST_TEST_EQ( x.code(), bc );
BOOST_TEST_EQ( std::string( x.what() ), "prefix: " + bc.what() );
return boost::report_errors();
}

View File

@@ -0,0 +1,41 @@
// Copyright 2018 Peter Dimov.
//
// 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 library home page at http://www.boost.org/libs/system
#include <boost/system/error_code.hpp>
#include <boost/config/pragma_message.hpp>
#if !defined(BOOST_WINDOWS_API)
BOOST_PRAGMA_MESSAGE( "Skipping test, BOOST_WINDOWS_API is not defined" )
int main() {}
#else
#include <boost/core/lightweight_test.hpp>
#include <windows.h>
int main()
{
namespace sys = boost::system;
HRESULT r = HRESULT_FROM_WIN32( ERROR_ACCESS_DENIED );
sys::error_code ec( r, sys::system_category() );
sys::error_condition en = make_error_condition( sys::errc::permission_denied );
BOOST_TEST( ec == en );
BOOST_TEST( ec.default_error_condition() == en );
BOOST_TEST_EQ( ec.default_error_condition().value(), en.value() );
return boost::report_errors();
}
#endif

View File

@@ -0,0 +1,31 @@
// Copyright 2020 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/system/windows_error.hpp>
#include <boost/config/pragma_message.hpp>
#if !defined(BOOST_WINDOWS_API)
BOOST_PRAGMA_MESSAGE( "Skipping test, BOOST_WINDOWS_API is not defined" )
int main() {}
#else
#include <boost/core/lightweight_test.hpp>
#include <windows.h>
int main()
{
namespace sys = boost::system;
sys::error_code ec = sys::windows_error::invalid_function;
BOOST_TEST_EQ( ec, sys::windows_error::invalid_function );
BOOST_TEST_EQ( ec, sys::error_code( ERROR_INVALID_FUNCTION, sys::system_category() ) );
BOOST_TEST( ec == make_error_condition( sys::errc::function_not_supported ) );
return boost::report_errors();
}
#endif