]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // system_error_test.cpp ---------------------------------------------------// |
2 | ||
3 | // Copyright Beman Dawes 2006 | |
4 | // Copyright (c) Microsoft Corporation 2014 | |
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) | |
7 | ||
8 | // See library home page at http://www.boost.org/libs/system | |
9 | ||
10 | //----------------------------------------------------------------------------// | |
11 | ||
7c673cae FG |
12 | #include <boost/config/warning_disable.hpp> |
13 | ||
14 | #include <boost/detail/lightweight_test.hpp> | |
15 | #include <boost/system/system_error.hpp> | |
16 | #include <iostream> | |
17 | #include <string> | |
18 | ||
19 | #ifdef BOOST_WINDOWS_API | |
20 | #include <windows.h> | |
21 | #endif | |
22 | ||
23 | using boost::system::system_error; | |
24 | using boost::system::error_code; | |
25 | using boost::system::system_category; | |
26 | using std::string; | |
27 | ||
28 | #define TEST(x,v,w) test(#x,x,v,w) | |
29 | ||
30 | namespace | |
31 | { | |
32 | void test( const char * desc, const system_error & ex, | |
33 | int v, const char * str ) | |
34 | { | |
35 | std::cout << "test " << desc << "\n what() returns \"" << ex.what() << "\"\n"; | |
36 | BOOST_TEST( ex.code().value() == v ); | |
37 | BOOST_TEST( ex.code().category() == system_category() ); | |
38 | # ifdef BOOST_WINDOWS_API | |
39 | LANGID language_id; | |
40 | # if !defined(__MINGW32__) && !defined(__CYGWIN__) && !BOOST_PLAT_WINDOWS_RUNTIME | |
41 | language_id = ::GetUserDefaultUILanguage(); | |
42 | # else | |
43 | language_id = 0x0409; // Assume US English | |
44 | # endif | |
45 | // std::cout << "GetUserDefaultUILanguage() returns " << language_id << '\n'; | |
46 | if ( language_id == 0x0409 ) // English (United States) | |
47 | { | |
48 | BOOST_TEST( std::string( ex.what() ) == str ); | |
49 | if ( std::string( ex.what() ) != str ) | |
50 | std::cout << "expected \"" << str << "\", but what() returned \"" | |
51 | << ex.what() << "\"\n"; | |
52 | } | |
53 | # endif | |
54 | } | |
55 | ||
56 | const boost::uint_least32_t uvalue = 2u; | |
57 | } | |
58 | ||
59 | int main( int, char *[] ) | |
60 | { | |
61 | // all constructors, in the same order as they appear in the header: | |
62 | ||
63 | system_error c1_0( error_code(0, system_category()) ); | |
64 | system_error c1_1( error_code(1, system_category()) ); | |
65 | system_error c1_2u( error_code(uvalue, system_category()) ); | |
66 | ||
67 | system_error c2_0( error_code(0, system_category()), string("c2_0") ); | |
68 | system_error c2_1( error_code(1, system_category()), string("c2_1") ); | |
69 | ||
70 | system_error c3_0( error_code(0, system_category()), "c3_0" ); | |
71 | system_error c3_1( error_code(1, system_category()), "c3_1" ); | |
72 | ||
73 | system_error c4_0( 0, system_category() ); | |
74 | system_error c4_1( 1, system_category() ); | |
75 | system_error c4_2u( uvalue, system_category() ); | |
76 | ||
77 | system_error c5_0( 0, system_category(), string("c5_0") ); | |
78 | system_error c5_1( 1, system_category(), string("c5_1") ); | |
79 | ||
80 | system_error c6_0( 0, system_category(), "c6_0" ); | |
81 | system_error c6_1( 1, system_category(), "c6_1" ); | |
82 | ||
83 | TEST( c1_0, 0, "The operation completed successfully" ); | |
84 | TEST( c1_1, 1, "Incorrect function" ); | |
85 | TEST( c1_2u, 2, "The system cannot find the file specified" ); | |
86 | ||
87 | TEST( c2_0, 0, "c2_0: The operation completed successfully" ); | |
88 | TEST( c2_1, 1, "c2_1: Incorrect function" ); | |
89 | ||
90 | TEST( c3_0, 0, "c3_0: The operation completed successfully" ); | |
91 | TEST( c3_1, 1, "c3_1: Incorrect function" ); | |
92 | ||
93 | TEST( c4_0, 0, "The operation completed successfully" ); | |
94 | TEST( c4_1, 1, "Incorrect function" ); | |
95 | TEST( c4_2u, 2, "The system cannot find the file specified" ); | |
96 | ||
97 | TEST( c5_0, 0, "c5_0: The operation completed successfully" ); | |
98 | TEST( c5_1, 1, "c5_1: Incorrect function" ); | |
99 | ||
100 | TEST( c6_0, 0, "c6_0: The operation completed successfully" ); | |
101 | TEST( c6_1, 1, "c6_1: Incorrect function" ); | |
102 | ||
103 | return ::boost::report_errors(); | |
104 | } | |
105 | ||
106 |