ErrorTests.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include "../Tests.hpp"
  2. #include "core/utils/Error.hpp"
  3. void Core::testError() {
  4. CORE_TEST_STRING("0", ErrorCode::NONE);
  5. CORE_TEST_STRING("1", ErrorCode::NEGATIVE_ARGUMENT);
  6. CORE_TEST_STRING("01", ErrorCode::CAPACITY_REACHED);
  7. CORE_TEST_STRING("001", ErrorCode::BLOCKED_STDOUT);
  8. CORE_TEST_STRING("0001", ErrorCode::OUT_OF_MEMORY);
  9. CORE_TEST_STRING("00001", ErrorCode::INVALID_CHAR);
  10. CORE_TEST_STRING("000001", ErrorCode::NOT_FOUND);
  11. CORE_TEST_STRING("0000001", ErrorCode::INVALID_STATE);
  12. CORE_TEST_STRING("00000001", ErrorCode::INVALID_INDEX);
  13. CORE_TEST_STRING("000000001", ErrorCode::INVALID_ARGUMENT);
  14. CORE_TEST_STRING("0000000001", ErrorCode::TIME_NOT_AVAILABLE);
  15. CORE_TEST_STRING("00000000001", ErrorCode::SLEEP_INTERRUPTED);
  16. CORE_TEST_STRING("000000000001", ErrorCode::THREAD_ERROR);
  17. CORE_TEST_STRING("0000000000001", ErrorCode::MUTEX_ERROR);
  18. CORE_TEST_STRING("00000000000001", ErrorCode::EXISTING_KEY);
  19. CORE_TEST_STRING("000000000000001", ErrorCode::CANNOT_OPEN_FILE);
  20. CORE_TEST_STRING("0000000000000001", ErrorCode::END_OF_FILE);
  21. CORE_TEST_STRING(
  22. "1111111111111111",
  23. ErrorCode::NEGATIVE_ARGUMENT | ErrorCode::CAPACITY_REACHED |
  24. ErrorCode::BLOCKED_STDOUT | ErrorCode::OUT_OF_MEMORY |
  25. ErrorCode::INVALID_CHAR | ErrorCode::NOT_FOUND |
  26. ErrorCode::INVALID_STATE | ErrorCode::INVALID_INDEX |
  27. ErrorCode::INVALID_ARGUMENT | ErrorCode::TIME_NOT_AVAILABLE |
  28. ErrorCode::SLEEP_INTERRUPTED | ErrorCode::THREAD_ERROR |
  29. ErrorCode::MUTEX_ERROR | ErrorCode::EXISTING_KEY |
  30. ErrorCode::CANNOT_OPEN_FILE | ErrorCode::END_OF_FILE);
  31. char buffer[4];
  32. CORE_TEST_EQUAL(
  33. ErrorCode::CAPACITY_REACHED,
  34. Core::toString(ErrorCode::INVALID_STATE, buffer, sizeof(buffer)));
  35. CORE_TEST_STRING("000", buffer);
  36. }