Statistics
| Branch: | Tag: | Revision:

amiro-os / core / inc / aos_unittest.h @ 5668089d

History | View | Annotate | Download (4.866 KB)

1
/*
2
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
3
Copyright (C) 2016..2019  Thomas Schöpping et al.
4

5
This program is free software: you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation, either version 3 of the License, or
8
(at your option) any later version.
9

10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
GNU General Public License for more details.
14

15
You should have received a copy of the GNU General Public License
16
along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
*/
18

    
19
/**
20
 * @file    aos_unittest.h
21
 * @brief   Unittest structures.
22
 *
23
 * @addtogroup aos_unittests
24
 * @{
25
 */
26

    
27
#ifndef AMIROOS_UNITTEST_H
28
#define AMIROOS_UNITTEST_H
29

    
30
#include <amiroos.h>
31

    
32
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
33

    
34
/******************************************************************************/
35
/* CONSTANTS                                                                  */
36
/******************************************************************************/
37

    
38
/******************************************************************************/
39
/* SETTINGS                                                                   */
40
/******************************************************************************/
41

    
42
/******************************************************************************/
43
/* CHECKS                                                                     */
44
/******************************************************************************/
45

    
46
/******************************************************************************/
47
/* DATA STRUCTURES AND TYPES                                                  */
48
/******************************************************************************/
49

    
50
/*
51
 * forward declarations
52
 */
53
typedef struct aos_utresult aos_utresult_t;
54
typedef struct aos_unittest aos_unittest_t;
55

    
56
/**
57
 * @brief   Unit test interface function definition.
58
 *
59
 * @param[in] stream  The stream to use for printing messages.
60
 * @param[in] ut      The object to run the test on.
61
 *
62
 * @return    A result containing the number of passed and failed tests.
63
 */
64
typedef aos_utresult_t (*aos_utfunction_t)(BaseSequentialStream*, aos_unittest_t*);
65

    
66
/**
67
 * @brief   Unit test result struct.
68
 */
69
struct aos_utresult {
70
  /**
71
   * @brief   Number of passed tests.
72
   */
73
  uint32_t passed;
74

    
75
  /**
76
   * @brief   Number of failed tests.
77
   */
78
  uint32_t failed;
79
};
80

    
81
/**
82
 * @brief   Unit test definition struct.
83
 */
84
struct aos_unittest {
85
  /**
86
   * @brief   Name of the unit test.
87
   */
88
  const char* name;
89

    
90
  /**
91
   * @brief   Further information about the test.
92
   */
93
  const char* info;
94

    
95
  /**
96
   * @brief   Callback function to run that executes the unit test.
97
   */
98
  aos_utfunction_t testfunc;
99

    
100
  /**
101
   * @brief   Shell command to add to an shell command list.
102
   */
103
  aos_shellcommand_t shellcmd;
104

    
105
  /**
106
   * @brief   Further test specific data.
107
   */
108
  void* data;
109
};
110

    
111

    
112
/******************************************************************************/
113
/* MACROS                                                                     */
114
/******************************************************************************/
115

    
116
/******************************************************************************/
117
/* EXTERN DECLARATIONS                                                        */
118
/******************************************************************************/
119

    
120
#if defined(__cplusplus)
121
extern "C" {
122
#endif /* defined(__cplusplus) */
123
  uint32_t aosUtResultTotal(aos_utresult_t* result);
124
  float aosUtResultRatio(aos_utresult_t* result);
125
  void aosUtResultPrintSummary(BaseSequentialStream* stream, aos_utresult_t* result, char* heading);
126
  void aosUtObjectInit(aos_unittest_t* ut, char* name, char* info, aos_utfunction_t func, void* data, char* shellname, aos_shellcmdcb_t shellcb);
127
  aos_utresult_t aosUtRun(BaseSequentialStream* stream, aos_unittest_t* ut, char* note);
128
  void aosUtPassed(BaseSequentialStream* stream, aos_utresult_t* result);
129
  void aosUtPassedMsg(BaseSequentialStream* stream, aos_utresult_t* result, const char* fmt, ...);
130
  void aosUtFailed(BaseSequentialStream* stream, aos_utresult_t* result);
131
  void aosUtFailedMsg(BaseSequentialStream* stream, aos_utresult_t* result, const char* fmt, ...);
132
  void aosUtInfoMsg(BaseSequentialStream* stream, const char* fmt, ...);
133
#if defined(__cplusplus)
134
}
135
#endif /* defined(__cplusplus) */
136

    
137
/******************************************************************************/
138
/* INLINE FUNCTIONS                                                           */
139
/******************************************************************************/
140

    
141
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
142

    
143
#endif /* AMIROOS_UNITTEST_H */
144

    
145
/** @} */