throw_errno.cpp 1007 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include<__vic/throw_errno.h>
  2. #include<__vic/error.h>
  3. #include<iostream>
  4. #include<exception>
  5. #include<cstring>
  6. #include<cassert>
  7. void run_tests()
  8. {
  9. try
  10. {
  11. errno = EDOM;
  12. __vic::throw_errno("");
  13. assert(false);
  14. }
  15. catch(const __vic::libc_error &ex)
  16. {
  17. __vic::libc_error err("");
  18. assert(ex.code() == errno);
  19. assert(ex.code() == err.code());
  20. assert(std::strcmp(ex.what(), err.what()) == 0);
  21. }
  22. const int err_no = ERANGE;
  23. try
  24. {
  25. errno = 0;
  26. __vic::throw_errno("", err_no);
  27. assert(false);
  28. }
  29. catch(const __vic::libc_error &ex)
  30. {
  31. __vic::libc_error err("", err_no);
  32. assert(ex.code() == err_no);
  33. assert(ex.code() == err.code());
  34. assert(std::strcmp(ex.what(), err.what()) == 0);
  35. }
  36. }
  37. int main()
  38. {
  39. try
  40. {
  41. run_tests();
  42. return 0;
  43. }
  44. catch(const std::exception &ex)
  45. {
  46. std::cerr << ex.what() << '\n';
  47. }
  48. return 1;
  49. }