]>
Commit | Line | Data |
---|---|---|
a5544970 | 1 | // Copyright (C) 2018-2019 Free Software Foundation, Inc. |
5ecfbf82 JW |
2 | // |
3 | // This file is part of the GNU ISO C++ Library. This library is free | |
4 | // software; you can redistribute it and/or modify it under the | |
5 | // terms of the GNU General Public License as published by the | |
6 | // Free Software Foundation; either version 3, or (at your option) | |
7 | // any later version. | |
8 | ||
9 | // This library is distributed in the hope that it will be useful, | |
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | // GNU General Public License for more details. | |
13 | ||
14 | // You should have received a copy of the GNU General Public License along | |
15 | // with this library; see the file COPYING3. If not see | |
16 | // <http://www.gnu.org/licenses/>. | |
17 | ||
18 | // { dg-do run { target c++11 } } | |
19 | ||
20 | #include <system_error> | |
21 | #include <locale> | |
22 | #include <testsuite_hooks.h> | |
23 | ||
24 | void | |
25 | test01() | |
26 | { | |
27 | const char* name = std::system_category().name(); | |
28 | VERIFY( name == std::string("system") ); | |
29 | } | |
30 | ||
31 | void | |
32 | test02() | |
33 | { | |
34 | const std::error_category& cat = std::system_category(); | |
35 | std::error_condition cond; | |
36 | ||
d7487e2a JW |
37 | // As of 2011, ISO C only defines EDOM, EILSEQ and ERANGE: |
38 | cond = cat.default_error_condition(EDOM); | |
39 | VERIFY( cond.value() == EDOM ); | |
40 | VERIFY( cond == std::errc::argument_out_of_domain ); | |
41 | VERIFY( cond.category() == std::generic_category() ); | |
42 | cond = cat.default_error_condition(EILSEQ); | |
43 | VERIFY( cond.value() == EILSEQ ); | |
44 | VERIFY( cond == std::errc::illegal_byte_sequence ); | |
45 | VERIFY( cond.category() == std::generic_category() ); | |
46 | cond = cat.default_error_condition(ERANGE); | |
47 | VERIFY( cond.value() == ERANGE ); | |
48 | VERIFY( cond == std::errc::result_out_of_range ); | |
49 | VERIFY( cond.category() == std::generic_category() ); | |
50 | ||
51 | // EBADF and EACCES are defined on all targets, | |
52 | // according to config/os/*/error_constants.h | |
5ecfbf82 JW |
53 | cond = cat.default_error_condition(EBADF); |
54 | VERIFY( cond.value() == EBADF ); | |
55 | VERIFY( cond == std::errc::bad_file_descriptor ); | |
56 | VERIFY( cond.category() == std::generic_category() ); | |
57 | cond = cat.default_error_condition(EACCES); | |
58 | VERIFY( cond.value() == EACCES ); | |
59 | VERIFY( cond == std::errc::permission_denied ); | |
60 | VERIFY( cond.category() == std::generic_category() ); | |
61 | ||
62 | // All POSIX errno values are positive: | |
63 | cond = cat.default_error_condition(-1); | |
64 | VERIFY( cond.value() == -1 ); | |
65 | VERIFY( cond.category() == cat ); | |
66 | cond = cat.default_error_condition(-99); | |
67 | VERIFY( cond.value() == -99 ); | |
68 | VERIFY( cond.category() == cat ); | |
69 | ||
70 | // PR libstdc++/60555 | |
d7487e2a JW |
71 | VERIFY( std::error_code(EDOM, cat) == std::errc::argument_out_of_domain ); |
72 | VERIFY( std::error_code(EILSEQ, cat) == std::errc::illegal_byte_sequence ); | |
73 | VERIFY( std::error_code(ERANGE, cat) == std::errc::result_out_of_range ); | |
5ecfbf82 JW |
74 | VERIFY( std::error_code(EBADF, cat) == std::errc::bad_file_descriptor ); |
75 | VERIFY( std::error_code(EACCES, cat) == std::errc::permission_denied ); | |
d7487e2a JW |
76 | |
77 | // As shown at https://gcc.gnu.org/ml/libstdc++/2018-08/msg00018.html | |
78 | // these two error codes might have the same value on AIX, but we still | |
79 | // expect both to be matched by system_category and so use generic_category: | |
80 | #ifdef EEXIST | |
81 | cond = cat.default_error_condition(EEXIST); | |
82 | VERIFY( cond.value() == EEXIST ); | |
83 | VERIFY( cond == std::errc::file_exists ); | |
84 | VERIFY( cond.category() == std::generic_category() ); | |
85 | VERIFY( std::error_code(EEXIST, cat) == std::errc::file_exists ); | |
86 | #endif | |
87 | #ifdef ENOTEMPTY | |
88 | cond = cat.default_error_condition(ENOTEMPTY); | |
89 | VERIFY( cond.value() == ENOTEMPTY ); | |
90 | VERIFY( cond == std::errc::directory_not_empty ); | |
91 | VERIFY( cond.category() == std::generic_category() ); | |
92 | VERIFY( std::error_code(ENOTEMPTY, cat) == std::errc::directory_not_empty ); | |
93 | #endif | |
5ecfbf82 JW |
94 | } |
95 | ||
96 | void | |
97 | test03() | |
98 | { | |
99 | // set "C" locale to get expected message | |
100 | auto loc = std::locale::global(std::locale::classic()); | |
101 | ||
102 | std::string msg = std::system_category().message(EBADF); | |
103 | VERIFY( msg.find("file") != std::string::npos ); | |
104 | ||
105 | std::locale::global(loc); | |
106 | } | |
107 | ||
108 | int | |
109 | main() | |
110 | { | |
111 | test01(); | |
112 | test02(); | |
113 | test03(); | |
114 | } |