test_cxx_exceptions.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. #if CONFIG_IDF_TARGET_ESP32
  10. #define LEAKS "300"
  11. #elif CONFIG_IDF_TARGET_ESP32S2
  12. #define LEAKS "800"
  13. #else
  14. #error "unknown target in CXX tests, can't set leaks threshold"
  15. #endif
  16. TEST_CASE("TEST_THROW catches exception", "[cxx exception][leaks=" LEAKS "]")
  17. {
  18. TEST_THROW(throw ESPException(ESP_FAIL);, ESPException);
  19. }
  20. /* The following two test cases are expected to fail */
  21. TEST_CASE("TEST_THROW asserts catching different exception", "[cxx exception][ignore]")
  22. {
  23. TEST_THROW(throw std::exception();, ESPException);
  24. }
  25. TEST_CASE("TEST_THROW asserts not catching any exception", "[cxx exception][ignore]")
  26. {
  27. TEST_THROW(printf(" ");, ESPException); // need statement with effect
  28. }
  29. TEST_CASE("CHECK_THROW continues on ESP_OK", "[cxx exception][leaks=" LEAKS "]")
  30. {
  31. esp_err_t error = ESP_OK;
  32. CHECK_THROW(error);
  33. }
  34. TEST_CASE("CHECK_THROW throws", "[cxx exception][leaks=" LEAKS "]")
  35. {
  36. esp_err_t error = ESP_FAIL;
  37. TEST_THROW(CHECK_THROW(error), ESPException);
  38. }
  39. #endif // __cpp_exceptions