hash_system_error_test.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Copyright 2018 Daniel James
  2. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  3. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  4. #include "./config.hpp"
  5. #ifndef BOOST_HASH_TEST_STD_INCLUDES
  6. # include <boost/container_hash/hash.hpp>
  7. #endif
  8. #include <boost/config.hpp>
  9. #include <boost/core/lightweight_test.hpp>
  10. #if !defined(BOOST_NO_CXX11_HDR_SYSTEM_ERROR)
  11. #include <system_error>
  12. void test_error_code()
  13. {
  14. std::error_code err1a = std::make_error_code(std::errc::argument_list_too_long);
  15. std::error_code err1b = std::make_error_code(std::errc::argument_list_too_long);
  16. std::error_code err2 = std::make_error_code(std::errc::bad_file_descriptor);
  17. boost::hash<std::error_code> hasher;
  18. BOOST_TEST(hasher(err1a) == hasher(err1a));
  19. BOOST_TEST(hasher(err1a) == hasher(err1b));
  20. BOOST_TEST(hasher(err1a) != hasher(err2));
  21. }
  22. void test_error_condition()
  23. {
  24. std::error_condition err1a = std::make_error_condition(std::errc::directory_not_empty);
  25. std::error_condition err1b = std::make_error_condition(std::errc::directory_not_empty);
  26. std::error_condition err2 = std::make_error_condition(std::errc::filename_too_long);
  27. boost::hash<std::error_condition> hasher;
  28. BOOST_TEST(hasher(err1a) == hasher(err1a));
  29. BOOST_TEST(hasher(err1a) == hasher(err1b));
  30. BOOST_TEST(hasher(err1a) != hasher(err2));
  31. }
  32. #endif
  33. int main()
  34. {
  35. #if !defined(BOOST_NO_CXX11_HDR_SYSTEM_ERROR)
  36. test_error_code();
  37. test_error_condition();
  38. #else
  39. BOOST_LIGHTWEIGHT_TEST_OSTREAM << "<system_error> not available." << std::endl;
  40. #endif
  41. return boost::report_errors();
  42. }