Subversion Repositories DashDisplay

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
56 mjames 1
#ifndef _JTEST_TEST_CALL_H_
2
#define _JTEST_TEST_CALL_H_
3
 
4
/*--------------------------------------------------------------------------------*/
5
/* Includes */
6
/*--------------------------------------------------------------------------------*/
7
#include "jtest_test.h"
8
#include "jtest_test_define.h"
9
#include "jtest_fw.h"
10
 
11
/*--------------------------------------------------------------------------------*/
12
/* Macros and Defines */
13
/*--------------------------------------------------------------------------------*/
14
 
15
/**
16
 *  Exectute the test in the #JTEST_TEST_t struct associated with the identifier
17
 *  test_fn and store the result in retval.
18
 */
19
#define JTEST_TEST_RUN(retval, test_fn)                                 \
20
    do                                                                  \
21
    {                                                                   \
22
        JTEST_DUMP_STR("Test Name:\n");                                 \
23
        JTEST_DUMP_STR(JTEST_TEST_STRUCT_NAME(test_fn).test_fn_str);    \
24
        JTEST_DUMP_STR("Function Under Test:\n");                       \
25
        JTEST_DUMP_STR(JTEST_TEST_STRUCT_NAME(test_fn).fut_str);        \
26
        retval = JTEST_TEST_STRUCT_NAME(test_fn).test_fn_ptr();         \
27
    } while (0)
28
 
29
/**
30
 *  Update the enclosing #JTEST_GROUP_t's pass/fail information based on
31
 *  test_retval.
32
 *
33
 *  @param test_retval A #JTEST_TEST_RET_enum for the current test.
34
 *
35
 *  @warning Only use if #JTEST_TEST_t is called in the context of a
36
 *  #JTEST_GROUP_t.
37
 */
38
#define JTEST_TEST_UPDATE_PARENT_GROUP_PF(test_retval)              \
39
    do                                                              \
40
    {                                                               \
41
        /* Update enclosing JTEST_GROUP_t with pass/fail info */    \
42
        if (test_retval == JTEST_TEST_PASSED)                       \
43
        {                                                           \
44
            JTEST_GROUP_INC_PASSED(JTEST_CURRENT_GROUP_PTR(), 1);   \
45
        } else {                                                    \
46
            JTEST_GROUP_INC_FAILED(JTEST_CURRENT_GROUP_PTR(), 1);   \
47
        }                                                           \
48
    } while (0)
49
 
50
/**
51
 *  Update the #JTEST_FW with pass/fail information based on test_retval.
52
 *
53
 *  @param test_retval A #JTEST_TEST_RET_enum for the current test.
54
 */
55
#define JTEST_TEST_UPDATE_FW_PF(test_retval)                        \
56
    do                                                              \
57
    {                                                               \
58
        /* Update the JTEST_FW with pass/fail info */                \
59
        if (test_retval == JTEST_TEST_PASSED)                       \
60
        {                                                           \
61
            JTEST_FW_INC_PASSED( 1);                                \
62
        } else {                                                    \
63
            JTEST_FW_INC_FAILED(1);                                 \
64
        }                                                           \
65
    } while (0)
66
 
67
/**
68
 *  Update the enclosing JTEST_GROUP_t's pass/fail information, or the
69
 *  #JTEST_FW's if this test has no enclosing #JTEST_GROUP_t.
70
 *
71
 *  @param test_retval A #JTEST_TEST_RET_enum for the current test.
72
 */
73
#define JTEST_TEST_UPDATE_PARENT_GROUP_OR_FW_PF(test_retval)            \
74
    do                                                                  \
75
    {                                                                   \
76
        /* Update pass-fail information */                              \
77
        if (JTEST_CURRENT_GROUP_PTR() /* Non-null */)                    \
78
        {                                                               \
79
            JTEST_TEST_UPDATE_PARENT_GROUP_PF(test_retval);             \
80
        } else {                                                        \
81
            JTEST_TEST_UPDATE_FW_PF(test_retval);                       \
82
        }                                                               \
83
    } while (0)
84
 
85
/**
86
 *  Dump the results of the test to the Keil Debugger.
87
 */
88
#define JTEST_TEST_DUMP_RESULTS(test_retval)        \
89
        do                                          \
90
        {                                           \
91
            if (test_retval == JTEST_TEST_PASSED)   \
92
            {                                       \
93
                JTEST_DUMP_STR("Test Passed\n");      \
94
            } else {                                \
95
                JTEST_DUMP_STR("Test Failed\n");      \
96
            }                                       \
97
        } while (0)
98
 
99
/**
100
 *  Call the #JTEST_TEST_t assocaited with the identifier test_fn.
101
 */
102
#define JTEST_TEST_CALL(test_fn)                                        \
103
    do                                                                  \
104
    {                                                                   \
105
        if (JTEST_TEST_IS_ENABLED(&JTEST_TEST_STRUCT_NAME(test_fn)))    \
106
        {                                                               \
107
            /* Default to failure */                                    \
108
            JTEST_TEST_RET_t __jtest_test_ret = JTEST_TEST_FAILED;      \
109
                                                                        \
110
            JTEST_ACT_TEST_START();                                     \
111
            JTEST_TEST_RUN(__jtest_test_ret, test_fn);                  \
112
                                                                        \
113
            /* Update pass-fail information */                          \
114
            JTEST_TEST_UPDATE_PARENT_GROUP_OR_FW_PF(__jtest_test_ret);  \
115
                                                                        \
116
            JTEST_TEST_DUMP_RESULTS(__jtest_test_ret);                  \
117
            JTEST_ACT_TEST_END();                                       \
118
        }                                                               \
119
    } while (0)
120
 
121
#endif /* _JTEST_TEST_CALL_H_ */