test_cxx_exceptions.cpp 982 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #include <stdio.h>
  2. #include "unity.h"
  3. #include "unity_cxx.hpp"
  4. #include "esp_exception.hpp"
  5. #ifdef __cpp_exceptions
  6. using namespace std;
  7. using namespace idf;
  8. #define TAG "CXX Exception Test"
  9. TEST_CASE("TEST_THROW catches exception", "[cxx exception]")
  10. {
  11. TEST_THROW(throw ESPException(ESP_FAIL);, ESPException);
  12. }
  13. /* The following two test cases are expected to fail */
  14. TEST_CASE("TEST_THROW asserts catching different exception", "[cxx exception][ignore]")
  15. {
  16. TEST_THROW(throw std::exception();, ESPException);
  17. }
  18. TEST_CASE("TEST_THROW asserts not catching any exception", "[cxx exception][ignore]")
  19. {
  20. TEST_THROW(printf(" ");, ESPException); // need statement with effect
  21. }
  22. TEST_CASE("CHECK_THROW continues on ESP_OK", "[cxx exception]")
  23. {
  24. esp_err_t error = ESP_OK;
  25. CHECK_THROW(error);
  26. }
  27. TEST_CASE("CHECK_THROW throws", "[cxx exception]")
  28. {
  29. esp_err_t error = ESP_FAIL;
  30. TEST_THROW(CHECK_THROW(error), ESPException);
  31. }
  32. #endif // __cpp_exceptions