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