unity_fixture.h 3.0 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 15

#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, const char* argv[], void (*runAllTests)(void));
17 18 19


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

22 23
#define TEST_SETUP(group) void TEST_##group##_SETUP(void);\
    void TEST_##group##_SETUP(void)
24

25 26
#define TEST_TEAR_DOWN(group) void TEST_##group##_TEAR_DOWN(void);\
    void TEST_##group##_TEAR_DOWN(void)
27 28 29


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

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

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

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

J
jsalling 已提交
61
/* Call this from main */
62
#define RUN_TEST_GROUP(group)\
63
    { void TEST_##group##_GROUP_RUNNER(void);\
64
      TEST_##group##_GROUP_RUNNER(); }
65

J
jsalling 已提交
66
/* CppUTest Compatibility Macros */
67
#define UT_PTR_SET(ptr, newPointerValue)               UnityPointer_Set((void**)&(ptr), (void*)(newPointerValue), __LINE__)
68
#define TEST_ASSERT_POINTERS_EQUAL(expected, actual)   TEST_ASSERT_EQUAL_PTR((expected), (actual))
69
#define TEST_ASSERT_BYTES_EQUAL(expected, actual)      TEST_ASSERT_EQUAL_HEX8(0xff & (expected), 0xff & (actual))
70
#define FAIL(message)                                  TEST_FAIL_MESSAGE((message))
71 72 73 74 75 76 77 78
#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_ */