unity_fixture.h 3.1 KB
Newer Older
J
jsalling 已提交
1 2 3 4 5 6
/* 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]
 * ========================================== */
7 8 9 10 11 12 13 14

#ifndef UNITY_FIXTURE_H_
#define UNITY_FIXTURE_H_

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

15 16 17 18
#ifndef UNITY_FIXTURE_NO_EXTRAS
#include "unity_memory.h"
#endif

19
int UnityMain(int argc, const char* argv[], void (*runAllTests)(void));
20 21 22


#define TEST_GROUP(group)\
23
    static const char* TEST_GROUP_##group = #group
24

25 26
#define TEST_SETUP(group) void TEST_##group##_SETUP(void);\
    void TEST_##group##_SETUP(void)
27

28 29
#define TEST_TEAR_DOWN(group) void TEST_##group##_TEAR_DOWN(void);\
    void TEST_##group##_TEAR_DOWN(void)
30 31 32


#define TEST(group, name) \
33
    void TEST_##group##_##name##_(void);\
34
    void TEST_##group##_##name##_run(void);\
35
    void TEST_##group##_##name##_run(void)\
36 37
    {\
        UnityTestRunner(TEST_##group##_SETUP,\
38
            TEST_##group##_##name##_,\
39 40
            TEST_##group##_TEAR_DOWN,\
            "TEST(" #group ", " #name ")",\
41
            TEST_GROUP_##group, #name,\
42 43
            __FILE__, __LINE__);\
    }\
44
    void  TEST_##group##_##name##_(void)
45 46

#define IGNORE_TEST(group, name) \
47
    void TEST_##group##_##name##_(void);\
48
    void TEST_##group##_##name##_run(void);\
49
    void TEST_##group##_##name##_run(void)\
50
    {\
51
        UnityIgnoreTest("IGNORE_TEST(" #group ", " #name ")", TEST_GROUP_##group, #name);\
52
    }\
53
    void TEST_##group##_##name##_(void)
54

55
/* Call this for each test, insider the group runner */
56
#define RUN_TEST_CASE(group, name) \
57
    { void TEST_##group##_##name##_run(void);\
58
      TEST_##group##_##name##_run(); }
59

J
jsalling 已提交
60
/* This goes at the bottom of each test file or in a separate c file */
61
#define TEST_GROUP_RUNNER(group)\
62
    void TEST_##group##_GROUP_RUNNER(void);\
63
    void TEST_##group##_GROUP_RUNNER(void)
64

J
jsalling 已提交
65
/* Call this from main */
66
#define RUN_TEST_GROUP(group)\
67
    { void TEST_##group##_GROUP_RUNNER(void);\
68
      TEST_##group##_GROUP_RUNNER(); }
69

J
jsalling 已提交
70
/* CppUTest Compatibility Macros */
71
#ifndef UNITY_EXCLUDE_CPPUTEST_ASSERTS
72
/* Sets a pointer and automatically restores it to its old value after teardown */
73
#define UT_PTR_SET(ptr, newPointerValue)               UnityPointer_Set((void**)&(ptr), (void*)(newPointerValue), __LINE__)
74
#define TEST_ASSERT_POINTERS_EQUAL(expected, actual)   TEST_ASSERT_EQUAL_PTR((expected), (actual))
75
#define TEST_ASSERT_BYTES_EQUAL(expected, actual)      TEST_ASSERT_EQUAL_HEX8(0xff & (expected), 0xff & (actual))
76
#define FAIL(message)                                  TEST_FAIL_MESSAGE((message))
77 78 79
#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))
80
#define DOUBLES_EQUAL(expected, actual, delta)         TEST_ASSERT_DOUBLE_WITHIN((delta), (expected), (actual))
81
#endif
82 83

#endif /* UNITY_FIXTURE_H_ */