PageRenderTime 58ms CodeModel.GetById 32ms RepoModel.GetById 1ms app.codeStats 0ms

/asio/src/tests/unit/error.cpp

http://github.com/chriskohlhoff/asio
C++ | 89 lines | 68 code | 10 blank | 11 comment | 7 complexity | 53fd16d00cbc44da5a70b26c5f868ec8 MD5 | raw file
  1. //
  2. // error.cpp
  3. // ~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. // Disable autolinking for unit tests.
  11. #if !defined(BOOST_ALL_NO_LIB)
  12. #define BOOST_ALL_NO_LIB 1
  13. #endif // !defined(BOOST_ALL_NO_LIB)
  14. // Test that header file is self-contained.
  15. #include "asio/error.hpp"
  16. #include <sstream>
  17. #include "unit_test.hpp"
  18. void test_error_code(const asio::error_code& code)
  19. {
  20. asio::error_code error(code);
  21. ASIO_CHECK(code == error);
  22. ASIO_CHECK(!code || error);
  23. ASIO_CHECK(!code || !!error);
  24. asio::error_code error2(error);
  25. ASIO_CHECK(error == error2);
  26. ASIO_CHECK(!(error != error2));
  27. asio::error_code error3;
  28. error3 = error;
  29. ASIO_CHECK(error == error3);
  30. ASIO_CHECK(!(error != error3));
  31. std::ostringstream os;
  32. os << error;
  33. ASIO_CHECK(!os.str().empty());
  34. }
  35. void error_test()
  36. {
  37. test_error_code(asio::error::access_denied);
  38. test_error_code(asio::error::address_family_not_supported);
  39. test_error_code(asio::error::address_in_use);
  40. test_error_code(asio::error::already_connected);
  41. test_error_code(asio::error::already_started);
  42. test_error_code(asio::error::connection_aborted);
  43. test_error_code(asio::error::connection_refused);
  44. test_error_code(asio::error::connection_reset);
  45. test_error_code(asio::error::bad_descriptor);
  46. test_error_code(asio::error::eof);
  47. test_error_code(asio::error::fault);
  48. test_error_code(asio::error::host_not_found);
  49. test_error_code(asio::error::host_not_found_try_again);
  50. test_error_code(asio::error::host_unreachable);
  51. test_error_code(asio::error::in_progress);
  52. test_error_code(asio::error::interrupted);
  53. test_error_code(asio::error::invalid_argument);
  54. test_error_code(asio::error::message_size);
  55. test_error_code(asio::error::network_down);
  56. test_error_code(asio::error::network_reset);
  57. test_error_code(asio::error::network_unreachable);
  58. test_error_code(asio::error::no_descriptors);
  59. test_error_code(asio::error::no_buffer_space);
  60. test_error_code(asio::error::no_data);
  61. test_error_code(asio::error::no_memory);
  62. test_error_code(asio::error::no_permission);
  63. test_error_code(asio::error::no_protocol_option);
  64. test_error_code(asio::error::no_recovery);
  65. test_error_code(asio::error::not_connected);
  66. test_error_code(asio::error::not_socket);
  67. test_error_code(asio::error::operation_aborted);
  68. test_error_code(asio::error::operation_not_supported);
  69. test_error_code(asio::error::service_not_found);
  70. test_error_code(asio::error::shut_down);
  71. test_error_code(asio::error::timed_out);
  72. test_error_code(asio::error::try_again);
  73. test_error_code(asio::error::would_block);
  74. }
  75. ASIO_TEST_SUITE
  76. (
  77. "error",
  78. ASIO_TEST_CASE(error_test)
  79. )