esp-idf/examples/cxx/experimental/experimental_cpp_component/test/unity_cxx.hpp
Jakob Hasse f835bead45 C++: ESP Event wrapper classes
* Provide easy interface to esp_event in C++
* Extended functionality linke synchronous
  waiting for events

* Closes IDF-1048
* Closes IDF-232
2020-10-22 09:56:52 +08:00

33 lines
1000 B
C++

#pragma once
#include "unity.h"
#define CXX_UNITY_TYPE_TO_STR(x) #x
/**
* Very simple helper macro to catch exceptions.
*
* @note
* * If there is any exception which not a child of std::exception, it will terminate the program!
* * If there is no exception, it will jump from the current frame without de-initializing
* destructors!
*/
#define TEST_THROW(expr_, exception_) \
do { \
bool caught = false; \
bool caught_different = false; \
try { \
expr_; \
} catch ( exception_ &e) { \
caught = true; \
} catch ( std::exception &e) { \
caught_different = true; \
} \
TEST_ASSERT_FALSE_MESSAGE(caught_different, "ERROR: Expected " CXX_UNITY_TYPE_TO_STR(exception_) \
", but caught different exception."); \
TEST_ASSERT_TRUE_MESSAGE(caught, "ERROR: Expected " CXX_UNITY_TYPE_TO_STR(exception_) \
", but no exception thrown."); \
} \
while (0)