1 /* Copyright (c) 2010 James Grenning and Contributed to Unity Project 2 * ========================================== 3 * Unity Project - A Test Framework for C 4 * Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams 5 * [Released under MIT License. Please refer to license.txt for details] 6 * ========================================== */ 7 8 #ifndef UNITY_FIXTURE_H_ 9 #define UNITY_FIXTURE_H_ 10 11 #include "unity.h" 12 #include "unity_fixture_internals.h" 13 14 #ifndef UNITY_FIXTURE_NO_EXTRAS 15 #include "unity_memory.h" 16 #endif 17 18 #ifdef __cplusplus 19 extern "C" 20 { 21 #endif 22 23 #include "unity_internals.h" 24 25 26 int UnityMain(int argc, const char* argv[], void (*runAllTests)(void)); 27 28 29 #define TEST_GROUP(group)\ 30 static const char* TEST_GROUP_##group = #group 31 32 #define TEST_SETUP(group) void TEST_##group##_SETUP(void);\ 33 void TEST_##group##_SETUP(void) 34 35 #define TEST_TEAR_DOWN(group) void TEST_##group##_TEAR_DOWN(void);\ 36 void TEST_##group##_TEAR_DOWN(void) 37 38 39 #define TEST(group, name) \ 40 void TEST_##group##_##name##_(void);\ 41 void TEST_##group##_##name##_run(void);\ 42 void TEST_##group##_##name##_run(void)\ 43 {\ 44 UnityTestRunner(TEST_##group##_SETUP,\ 45 TEST_##group##_##name##_,\ 46 TEST_##group##_TEAR_DOWN,\ 47 "TEST(" #group ", " #name ")",\ 48 TEST_GROUP_##group, #name,\ 49 __FILE__, __LINE__);\ 50 }\ 51 void TEST_##group##_##name##_(void) 52 53 #define IGNORE_TEST(group, name) \ 54 void TEST_##group##_##name##_(void);\ 55 void TEST_##group##_##name##_run(void);\ 56 void TEST_##group##_##name##_run(void)\ 57 {\ 58 UnityIgnoreTest("IGNORE_TEST(" #group ", " #name ")", TEST_GROUP_##group, #name);\ 59 }\ 60 void TEST_##group##_##name##_(void) 61 62 /* Call this for each test, insider the group runner */ 63 #define RUN_TEST_CASE(group, name) \ 64 { void TEST_##group##_##name##_run(void);\ 65 TEST_##group##_##name##_run(); } 66 67 /* This goes at the bottom of each test file or in a separate c file */ 68 #define TEST_GROUP_RUNNER(group)\ 69 void TEST_##group##_GROUP_RUNNER(void);\ 70 void TEST_##group##_GROUP_RUNNER(void) 71 72 /* Call this from main */ 73 #define RUN_TEST_GROUP(group)\ 74 { void TEST_##group##_GROUP_RUNNER(void);\ 75 TEST_##group##_GROUP_RUNNER(); } 76 77 /* CppUTest Compatibility Macros */ 78 #ifndef UNITY_EXCLUDE_CPPUTEST_ASSERTS 79 /* Sets a pointer and automatically restores it to its old value after teardown */ 80 #define UT_PTR_SET(ptr, newPointerValue) UnityPointer_Set((void**)&(ptr), (void*)(newPointerValue), __LINE__) 81 #define TEST_ASSERT_POINTERS_EQUAL(expected, actual) TEST_ASSERT_EQUAL_PTR((expected), (actual)) 82 #define TEST_ASSERT_BYTES_EQUAL(expected, actual) TEST_ASSERT_EQUAL_HEX8(0xff & (expected), 0xff & (actual)) 83 #define FAIL(message) TEST_FAIL_MESSAGE((message)) 84 #define CHECK(condition) TEST_ASSERT_TRUE((condition)) 85 #define LONGS_EQUAL(expected, actual) TEST_ASSERT_EQUAL_INT((expected), (actual)) 86 #define STRCMP_EQUAL(expected, actual) TEST_ASSERT_EQUAL_STRING((expected), (actual)) 87 #define DOUBLES_EQUAL(expected, actual, delta) TEST_ASSERT_DOUBLE_WITHIN((delta), (expected), (actual)) 88 #endif 89 90 #ifdef __cplusplus 91 } 92 #endif 93 94 #endif /* UNITY_FIXTURE_H_ */ 95