error_ut.cpp 776 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include "error.h"
  2. #include <library/cpp/testing/unittest/registar.h>
  3. #include <util/generic/ylimits.h>
  4. #ifdef _win_
  5. #include "winint.h"
  6. #else
  7. #include <fcntl.h>
  8. #endif
  9. class TSysErrorTest: public TTestBase {
  10. UNIT_TEST_SUITE(TSysErrorTest);
  11. UNIT_TEST(TestErrorCode)
  12. UNIT_TEST(TestErrorMessage)
  13. UNIT_TEST_SUITE_END();
  14. private:
  15. inline void TestErrorCode() {
  16. GenFailure();
  17. UNIT_ASSERT(LastSystemError() != 0);
  18. }
  19. inline void TestErrorMessage() {
  20. GenFailure();
  21. UNIT_ASSERT(*LastSystemErrorText() != 0);
  22. }
  23. inline void GenFailure() {
  24. #ifdef _win_
  25. SetLastError(3);
  26. #else
  27. UNIT_ASSERT(open("/non-existent", O_RDONLY) < 0);
  28. #endif
  29. }
  30. };
  31. UNIT_TEST_SUITE_REGISTRATION(TSysErrorTest);