1 //===----------------------------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 // <system_error> 10 11 // class error_category 12 13 // const error_category& system_category(); 14 15 // XFAIL: suse-linux-enterprise-server-11 16 // XFAIL: use_system_cxx_lib && target={{.+}}-apple-macosx10.{{9|10|11|12}} 17 18 #include <system_error> 19 #include <cassert> 20 #include <string> 21 #include <cerrno> 22 23 #include "test_macros.h" 24 test_message_for_bad_value()25void test_message_for_bad_value() { 26 errno = E2BIG; // something that message will never generate 27 const std::error_category& e_cat1 = std::system_category(); 28 const std::string msg = e_cat1.message(-1); 29 // Exact message format varies by platform. 30 #if defined(_AIX) 31 LIBCPP_ASSERT(msg.rfind("Error -1 occurred", 0) == 0); 32 #else 33 LIBCPP_ASSERT(msg.rfind("Unknown error", 0) == 0); 34 #endif 35 assert(errno == E2BIG); 36 } 37 main(int,char **)38int main(int, char**) 39 { 40 const std::error_category& e_cat1 = std::system_category(); 41 std::error_condition e_cond = e_cat1.default_error_condition(5); 42 assert(e_cond.value() == 5); 43 assert(e_cond.category() == std::generic_category()); 44 e_cond = e_cat1.default_error_condition(5000); 45 assert(e_cond.value() == 5000); 46 assert(e_cond.category() == std::system_category()); 47 { 48 test_message_for_bad_value(); 49 } 50 51 return 0; 52 } 53