You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using Unity for a PlatformIO project. I would like to test a C++ library I wrote, which contains user-defined types (UDT). However it seems Unity limits macros to ints, strings (const char*), pointers, etc. It would be nice if there were TEST_X_EQUAL macros that were generic, and be able to check equality == (possibly overloaded for our UDTs).
Are there any plans for this?
The text was updated successfully, but these errors were encountered:
TrebledJ
changed the title
Support for C++ UDTs
Support for Asserting Equality of C++ UDTs
Apr 20, 2023
Unity already has this feature, it's just not documented well. It's used quite a bit in our classes. I need to make sure some of the documentation from the class migrates its way back to here.
You're looking for the unity_helper feature. You can create as many custom assertion types as you want. You place them in a unity_helper.h and unity_helper.c/cpp file. If you follow the same naming patterns as Unity does already, then you automatically can use the assertions with CMock as well.
For example, let's say I have a type BLAH_T, I'd create a function like the following:
#define UNITY_TEST_ASSERT_EQUAL_BLAH_T(e, a, l, m) test_assert_equal_BLAH_T(e, a, l, m)
#define TEST_ASSERT_EQUAL_BLAH_T_MESSAGE(e, a, m) test_assert_equal_BLAH_T(e, a, __LINE__, m)
#define TEST_ASSERT_EQUAL_BLAH_T(e, a) test_assert_equal_BLAH_T(e, a, __LINE__, NULL)
In the C/CPP file you'd flesh out WHAT you actually want to compare... checking important fields of structs, etc... you can use the UNITY_ASSERT_EQUAL_* versions of the macros to pass the line and/or message along.
I'm using Unity for a PlatformIO project. I would like to test a C++ library I wrote, which contains user-defined types (UDT). However it seems Unity limits macros to ints, strings (
const char*
), pointers, etc. It would be nice if there wereTEST_X_EQUAL
macros that were generic, and be able to check equality==
(possibly overloaded for our UDTs).Are there any plans for this?
The text was updated successfully, but these errors were encountered: