]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/19_diagnostics/error_category/generic_category.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 19_diagnostics / error_category / generic_category.cc
CommitLineData
8d9254fc 1// Copyright (C) 2018-2020 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
24void
25test01()
26{
27 const char* name = std::generic_category().name();
28 VERIFY( name == std::string("generic") );
29}
30
31void
32test02()
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
51void
52test03()
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
63int
64main()
65{
66 test01();
67 test02();
68 test03();
69}