forked from boostorg/system
Rework error_code for better std interop
This commit is contained in:
1 parent
20b8e90dff
commit
344eb1e1f8
8 files changed
+556
-37
No files matched your search
@@ -89,3 +89,7 @@ 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)
|
||||
@@ -93,3 +93,7 @@ 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 ;
|
||||
@@ -0,0 +1,88 @@
|
||||
// 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() );
|
||||
f2( e1, e1.value(), e1.category() );
|
||||
|
||||
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() );
|
||||
f2( e1, e1.value(), e1.category() );
|
||||
|
||||
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() );
|
||||
f2( e1, e1.value(), e1.category() );
|
||||
|
||||
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() );
|
||||
f2( e1, e1.value(), e1.category() );
|
||||
|
||||
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() );
|
||||
f2( e1, e1.value(), e1.category() );
|
||||
|
||||
BOOST_TEST_EQ( e1, e2 );
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,63 @@
|
||||
// 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;
|
||||
std::error_code e3 = e2;
|
||||
|
||||
BOOST_TEST_EQ( e1, e3 );
|
||||
}
|
||||
|
||||
{
|
||||
std::error_code e1( 5, std::system_category() );
|
||||
boost::system::error_code e2 = e1;
|
||||
std::error_code e3 = e2;
|
||||
|
||||
BOOST_TEST_EQ( e1, e3 );
|
||||
}
|
||||
|
||||
{
|
||||
std::error_code e1( 0, std::generic_category() );
|
||||
boost::system::error_code e2 = e1;
|
||||
std::error_code e3 = e2;
|
||||
|
||||
BOOST_TEST_EQ( e1, e3 );
|
||||
}
|
||||
|
||||
{
|
||||
std::error_code e1( ENOENT, std::generic_category() );
|
||||
boost::system::error_code e2 = e1;
|
||||
std::error_code e3 = e2;
|
||||
|
||||
BOOST_TEST_EQ( e1, e3 );
|
||||
}
|
||||
|
||||
{
|
||||
boost::system::error_code e2 = make_error_code( std::errc::no_such_file_or_directory );
|
||||
std::error_code e3 = e2;
|
||||
|
||||
BOOST_TEST_EQ( make_error_code( std::errc::no_such_file_or_directory ), e3 );
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -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
|
||||
Reference in new issue
Block a user