diff --git a/src/unity.c b/src/unity.c index a8e14767b1a32c179b89b50bd2eb7c99256a431b..0219b37268ccf089241ec94cccaee88b6865f1d0 100644 --- a/src/unity.c +++ b/src/unity.c @@ -14,7 +14,7 @@ #define UNITY_SKIP_EXECUTION { if ((Unity.CurrentTestFailed != 0) || (Unity.CurrentTestIgnored != 0)) {return;} } #define UNITY_PRINT_EOL { UNITY_OUTPUT_CHAR('\n'); } -struct _Unity Unity = { 0 }; +struct _Unity Unity = { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , { 0 } }; const char* UnityStrNull = "NULL"; const char* UnityStrSpacer = ". "; diff --git a/test/testunity.c b/test/testunity.c index 9e8f9e90d36a85c0dd72f6b9650f3592ee5e4377..e98ca8f9df93e83d4ccc67ad368bcbfae1a1db33 100755 --- a/test/testunity.c +++ b/test/testunity.c @@ -50,6 +50,36 @@ void tearDown(void) } } +void testUnitySizeInitializationReminder(void) +{ + /* This test ensures that sizeof(struct _Unity) doesn't change. If this + * test breaks, go look at the initialization of the Unity global variable + * in unity.c and make sure we're filling in the proper fields. */ + char * message = "Unexpected size for _Unity struct. Please check that " + "the initialization of the Unity symbol in unity.c is " + "still correct."; + + /* Define a structure with all the same fields as `struct _Unity`. */ + struct { + const char* TestFile; + const char* CurrentTestName; + UNITY_LINE_TYPE CurrentTestLineNumber; + UNITY_COUNTER_TYPE NumberOfTests; + UNITY_COUNTER_TYPE TestFailures; + UNITY_COUNTER_TYPE TestIgnores; + UNITY_COUNTER_TYPE CurrentTestFailed; + UNITY_COUNTER_TYPE CurrentTestIgnored; + jmp_buf AbortFrame; + } _Expected_Unity; + + /* Compare our fake structure's size to the actual structure's size. They + * should be the same. + * + * This accounts for alignment, padding, and packing issues that might come + * up between different architectures. */ + TEST_ASSERT_EQUAL_MESSAGE(sizeof(_Expected_Unity), sizeof(Unity), message); +} + void testTrue(void) { TEST_ASSERT(1); @@ -2526,4 +2556,4 @@ void testNotEqualDoubleArraysNegative3(void) VERIFY_FAILS_END #endif } - \ No newline at end of file +