OVMS3-idf/examples/cxx/experimental/experimental_cpp_component/test/test_cxx_exceptions.cpp
Jakob Hasse 31edd48b43 C++: Moved all C++ examples to own folder
* moved C++ examples to a new cxx folder in
  examples
* added experimental C++ component
* added ESPException class to the C++ experimental
  component
* added test cases for ESPException and
  corresponding test macros
2020-02-18 12:48:57 +08:00

45 lines
982 B
C++

#include <stdio.h>
#include "unity.h"
#include "unity_cxx.hpp"
#include "esp_exception.hpp"
#ifdef __cpp_exceptions
using namespace std;
using namespace idf;
#define TAG "CXX Exception Test"
TEST_CASE("TEST_THROW catches exception", "[cxx exception]")
{
TEST_THROW(throw ESPException(ESP_FAIL);, ESPException);
}
/* The following two test cases are expected to fail */
TEST_CASE("TEST_THROW asserts catching different exception", "[cxx exception][ignore]")
{
TEST_THROW(throw std::exception();, ESPException);
}
TEST_CASE("TEST_THROW asserts not catching any exception", "[cxx exception][ignore]")
{
TEST_THROW(printf(" ");, ESPException); // need statement with effect
}
TEST_CASE("CHECK_THROW continues on ESP_OK", "[cxx exception]")
{
esp_err_t error = ESP_OK;
CHECK_THROW(error);
}
TEST_CASE("CHECK_THROW throws", "[cxx exception]")
{
esp_err_t error = ESP_FAIL;
TEST_THROW(CHECK_THROW(error), ESPException);
}
#endif // __cpp_exceptions