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