]>
Commit | Line | Data |
---|---|---|
99dee823 | 1 | // Copyright (C) 2018-2021 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::generic_category().name(); | |
28 | VERIFY( name == std::string("generic") ); | |
29 | } | |
30 | ||
31 | void | |
32 | test02() | |
33 | { | |
34 | const std::error_category& cat = std::generic_category(); | |
35 | std::error_condition cond; | |
36 | ||
37 | cond = cat.default_error_condition(EBADF); | |
38 | VERIFY( cond.value() == EBADF ); | |
39 | VERIFY( cond == std::errc::bad_file_descriptor ); | |
40 | VERIFY( cond.category() == std::generic_category() ); | |
41 | cond = cat.default_error_condition(EACCES); | |
42 | VERIFY( cond.value() == EACCES ); | |
43 | VERIFY( cond == std::errc::permission_denied ); | |
44 | VERIFY( cond.category() == std::generic_category() ); | |
45 | ||
46 | // PR libstdc++/60555 | |
47 | VERIFY( std::error_code(EBADF, cat) == std::errc::bad_file_descriptor ); | |
48 | VERIFY( std::error_code(EACCES, cat) == std::errc::permission_denied ); | |
49 | } | |
50 | ||
51 | void | |
52 | test03() | |
53 | { | |
54 | // set "C" locale to get expected message | |
55 | auto loc = std::locale::global(std::locale::classic()); | |
56 | ||
57 | std::string msg = std::generic_category().message(EBADF); | |
58 | VERIFY( msg.find("file") != std::string::npos ); | |
59 | ||
60 | std::locale::global(loc); | |
61 | } | |
62 | ||
63 | int | |
64 | main() | |
65 | { | |
66 | test01(); | |
67 | test02(); | |
68 | test03(); | |
69 | } |