unity_fixture.h 3.0 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
//- Copyright (c) 2010 James Grenning and Contributed to Unity Project
/* ==========================================
    Unity Project - A Test Framework for C
    Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
    [Released under MIT License. Please refer to license.txt for details]
========================================== */

#ifndef UNITY_FIXTURE_H_
#define UNITY_FIXTURE_H_

#include "unity.h"
#include "unity_internals.h"
#include "unity_fixture_malloc_overrides.h"
#include "unity_fixture_internals.h"

16
int UnityMain(int argc, char* argv[], void (*runAllTests)(void));
17 18 19


#define TEST_GROUP(group)\
20
    static const char* TEST_GROUP_##group = #group
21

22
#define TEST_SETUP(group) void TEST_##group##_SETUP(void)
23

24
#define TEST_TEAR_DOWN(group) void TEST_##group##_TEAR_DOWN(void)
25 26 27


#define TEST(group, name) \
28 29
    void TEST_##group##_##name##_(void);\
    void TEST_##group##_##name##_run(void)\
30 31
    {\
        UnityTestRunner(TEST_##group##_SETUP,\
32
            TEST_##group##_##name##_,\
33 34
            TEST_##group##_TEAR_DOWN,\
            "TEST(" #group ", " #name ")",\
35
            TEST_GROUP_##group, #name,\
36 37
            __FILE__, __LINE__);\
    }\
38
    void  TEST_##group##_##name##_(void)
39 40

#define IGNORE_TEST(group, name) \
41 42
    void TEST_##group##_##name##_(void);\
    void TEST_##group##_##name##_run(void)\
43
    {\
44
        UnityIgnoreTest("IGNORE_TEST(" #group ", " #name ")");\
45
    }\
46
    void TEST_##group##_##name##_(void)
47 48

#define DECLARE_TEST_CASE(group, name) \
49
    void TEST_##group##_##name##_run(void)
50 51

#define RUN_TEST_CASE(group, name) \
52 53
    { DECLARE_TEST_CASE(group, name);\
      TEST_##group##_##name##_run(); }
54 55 56

//This goes at the bottom of each test file or in a separate c file
#define TEST_GROUP_RUNNER(group)\
57 58 59
    void TEST_##group##_GROUP_RUNNER_runAll(void);\
    void TEST_##group##_GROUP_RUNNER(void);\
    void TEST_##group##_GROUP_RUNNER(void)\
60 61 62 63 64 65 66
    {\
        TEST_##group##_GROUP_RUNNER_runAll();\
    }\
    void TEST_##group##_GROUP_RUNNER_runAll()

//Call this from main
#define RUN_TEST_GROUP(group)\
67
    { void TEST_##group##_GROUP_RUNNER(void);\
68
      TEST_##group##_GROUP_RUNNER(); }
69 70 71 72 73 74 75 76 77 78 79 80 81 82

//CppUTest Compatibility Macros
#define UT_PTR_SET(ptr, newPointerValue)               UnityPointer_Set((void**)&ptr, (void*)newPointerValue)
#define TEST_ASSERT_POINTERS_EQUAL(expected, actual)   TEST_ASSERT_EQUAL_PTR(expected, actual)
#define TEST_ASSERT_BYTES_EQUAL(expected, actual)      TEST_ASSERT_EQUAL_HEX8(0xff & (expected), 0xff & (actual))
#define FAIL(message)                                  TEST_FAIL((message))
#define CHECK(condition)                               TEST_ASSERT_TRUE((condition))
#define LONGS_EQUAL(expected, actual)                  TEST_ASSERT_EQUAL_INT((expected), (actual))
#define STRCMP_EQUAL(expected, actual)                 TEST_ASSERT_EQUAL_STRING((expected), (actual))
#define DOUBLES_EQUAL(expected, actual, delta)         TEST_ASSERT_FLOAT_WITHIN(((expected), (actual), (delta))

void UnityMalloc_MakeMallocFailAfterCount(int count);

#endif /* UNITY_FIXTURE_H_ */