1
// system_error_test.cpp ---------------------------------------------------//
3
// Copyright Beman Dawes 2006
5
// Distributed under the Boost Software License, Version 1.0. (See accompanying
6
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8
// See library home page at http://www.boost.org/libs/system
10
//----------------------------------------------------------------------------//
12
// test without deprecated features
13
#define BOOST_SYSTEM_NO_DEPRECATED
15
#include <boost/config/warning_disable.hpp>
17
#include <boost/detail/lightweight_test.hpp>
18
#include <boost/system/system_error.hpp>
22
#ifdef BOOST_WINDOWS_API
26
using boost::system::system_error;
27
using boost::system::error_code;
28
using boost::system::system_category;
31
#define TEST(x,v,w) test(#x,x,v,w)
35
void test( const char * desc, const system_error & ex,
36
int v, const char * str )
38
std::cout << "test " << desc << "\n what() returns \"" << ex.what() << "\"\n";
39
BOOST_TEST( ex.code().value() == v );
40
BOOST_TEST( ex.code().category() == system_category() );
41
# ifdef BOOST_WINDOWS_API
43
# if !defined(__MINGW32__) && !defined(__CYGWIN__)
44
language_id = ::GetUserDefaultUILanguage();
46
language_id = 0x0409; // Assume US English
48
// std::cout << "GetUserDefaultUILanguage() returns " << language_id << '\n';
49
if ( language_id == 0x0409 ) // English (United States)
51
BOOST_TEST( std::string( ex.what() ) == str );
52
if ( std::string( ex.what() ) != str )
53
std::cout << "expected \"" << str << "\", but what() returned \""
54
<< ex.what() << "\"\n";
59
const boost::uint_least32_t uvalue = 2u;
62
int main( int, char *[] )
64
// all constructors, in the same order as they appear in the header:
66
system_error c1_0( error_code(0, system_category()) );
67
system_error c1_1( error_code(1, system_category()) );
68
system_error c1_2u( error_code(uvalue, system_category()) );
70
system_error c2_0( error_code(0, system_category()), string("c2_0") );
71
system_error c2_1( error_code(1, system_category()), string("c2_1") );
73
system_error c3_0( error_code(0, system_category()), "c3_0" );
74
system_error c3_1( error_code(1, system_category()), "c3_1" );
76
system_error c4_0( 0, system_category() );
77
system_error c4_1( 1, system_category() );
78
system_error c4_2u( uvalue, system_category() );
80
system_error c5_0( 0, system_category(), string("c5_0") );
81
system_error c5_1( 1, system_category(), string("c5_1") );
83
system_error c6_0( 0, system_category(), "c6_0" );
84
system_error c6_1( 1, system_category(), "c6_1" );
86
TEST( c1_0, 0, "The operation completed successfully" );
87
TEST( c1_1, 1, "Incorrect function" );
88
TEST( c1_2u, 2, "The system cannot find the file specified" );
90
TEST( c2_0, 0, "c2_0: The operation completed successfully" );
91
TEST( c2_1, 1, "c2_1: Incorrect function" );
93
TEST( c3_0, 0, "c3_0: The operation completed successfully" );
94
TEST( c3_1, 1, "c3_1: Incorrect function" );
96
TEST( c4_0, 0, "The operation completed successfully" );
97
TEST( c4_1, 1, "Incorrect function" );
98
TEST( c4_2u, 2, "The system cannot find the file specified" );
100
TEST( c5_0, 0, "c5_0: The operation completed successfully" );
101
TEST( c5_1, 1, "c5_1: Incorrect function" );
103
TEST( c6_0, 0, "c6_0: The operation completed successfully" );
104
TEST( c6_1, 1, "c6_1: Incorrect function" );
106
return ::boost::report_errors();