unity_cxx.hpp 999 B

1234567891011121314151617181920212223242526272829303132333435
  1. #ifndef UNITY_CXX_H_
  2. #define UNITY_CXX_H_
  3. #include "unity.h"
  4. #define STR(x) #x
  5. /**
  6. * Very simple helper macro to catch exceptions.
  7. *
  8. * @note
  9. * * If there is any exception which not a child of std::exception, it will terminate the program!
  10. * * If there is no exception, it will jump from the current frame without de-initializing
  11. * destructors!
  12. */
  13. #define TEST_THROW(expr_, exception_) \
  14. do { \
  15. bool caught = false; \
  16. bool caught_different = false; \
  17. try { \
  18. expr_; \
  19. } catch ( exception_ &e) { \
  20. caught = true; \
  21. } catch ( std::exception &e) { \
  22. caught_different = true; \
  23. } \
  24. TEST_ASSERT_FALSE_MESSAGE(caught_different, "ERROR: Expected " STR(exception_) \
  25. ", but caught different exception."); \
  26. TEST_ASSERT_TRUE_MESSAGE(caught, "ERROR: Expected " STR(exception_) \
  27. ", but no exception thrown."); \
  28. } \
  29. while (0)
  30. #endif // UNITY_CXX_H_