Home | History | Annotate | Download | only in syserr.errcat.objects
      1 //===----------------------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 // <system_error>
     11 
     12 // class error_category
     13 
     14 // const error_category& system_category();
     15 
     16 // XFAIL: suse-linux-enterprise-server-11
     17 // XFAIL: with_system_cxx_lib=macosx10.12
     18 // XFAIL: with_system_cxx_lib=macosx10.11
     19 // XFAIL: with_system_cxx_lib=macosx10.10
     20 // XFAIL: with_system_cxx_lib=macosx10.9
     21 // XFAIL: with_system_cxx_lib=macosx10.7
     22 // XFAIL: with_system_cxx_lib=macosx10.8
     23 
     24 #include <system_error>
     25 #include <cassert>
     26 #include <string>
     27 #include <cerrno>
     28 
     29 #include "test_macros.h"
     30 
     31 void test_message_for_bad_value() {
     32     errno = E2BIG; // something that message will never generate
     33     const std::error_category& e_cat1 = std::system_category();
     34     const std::string msg = e_cat1.message(-1);
     35     LIBCPP_ASSERT(msg == "Unknown error -1" || msg == "Unknown error");
     36     assert(errno == E2BIG);
     37 }
     38 
     39 int main()
     40 {
     41     const std::error_category& e_cat1 = std::system_category();
     42     std::error_condition e_cond = e_cat1.default_error_condition(5);
     43     assert(e_cond.value() == 5);
     44     assert(e_cond.category() == std::generic_category());
     45     e_cond = e_cat1.default_error_condition(5000);
     46     assert(e_cond.value() == 5000);
     47     assert(e_cond.category() == std::system_category());
     48     {
     49         test_message_for_bad_value();
     50     }
     51 }
     52