Statistics
| Branch: | Tag: | Revision:

amiro-os / os / core / inc / aos_unittest.h @ 2c99037f

History | View | Annotate | Download (3.07 KB)

1
/*
2
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
3
Copyright (C) 2016..2018  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
#ifndef _AMIROOS_UNITTEST_H_
20
#define _AMIROOS_UNITTEST_H_
21

    
22
#include <aosconf.h>
23
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
24
#include <hal.h>
25
#include <aos_shell.h>
26

    
27
/*
28
 * Forward declarations.
29
 */
30
typedef struct aos_unittest aos_unittest_t;
31
typedef struct aos_utresult aos_utresult_t;
32

    
33
/**
34
 * @brief   Unit test interface function definition.
35
 *
36
 * @param[in] stream  The stream to use for printing messages.
37
 * @param[in] ut      The object to run the test on.
38
 *
39
 * @return    A result containing the number of passed and failed tests.
40
 */
41
typedef aos_utresult_t (*aos_utfunction_t)(BaseSequentialStream* stream, aos_unittest_t* ut);
42

    
43
/**
44
 * @brief   Unit test result struct.
45
 */
46
struct aos_utresult {
47
  /**
48
   * @brief   Number of passed tests.
49
   */
50
  uint32_t passed;
51

    
52
  /**
53
   * @brief   Number of failed tests.
54
   */
55
  uint32_t failed;
56
};
57

    
58
/**
59
 * @brief   Unit test definition struct.
60
 */
61
struct aos_unittest {
62
  /**
63
   * @brief   Name of the unit test.
64
   */
65
  const char* name;
66

    
67
  /**
68
   * @brief   Further information about the test.
69
   */
70
  const char* info;
71

    
72
  /**
73
   * @brief   Callback function to run that executes the unit test.
74
   */
75
  aos_utfunction_t testfunc;
76

    
77
  /**
78
   * @brief   Shell command to add to an shell command list.
79
   */
80
  aos_shellcommand_t shellcmd;
81

    
82
  /**
83
   * @brief   Further test specific data.
84
   */
85
  void* data;
86
};
87

    
88
#ifdef __cplusplus
89
extern "C" {
90
#endif
91
  uint32_t aosUtResultTotal(aos_utresult_t* result);
92
  float aosUtResultRatio(aos_utresult_t* result);
93
  void aosUtResultPrintSummary(BaseSequentialStream* stream, aos_utresult_t* result, char* heading);
94
  void aosUtObjectInit(aos_unittest_t* ut, char* name, char* info, aos_utfunction_t func, void* data, char* shellname, aos_shellcmdcb_t shellcb);
95
  aos_utresult_t aosUtRun(BaseSequentialStream* stream, aos_unittest_t* ut, char* note);
96
  void aosUtPassed(BaseSequentialStream* stream, aos_utresult_t* result);
97
  void aosUtPassedMsg(BaseSequentialStream* stream, aos_utresult_t* result, const char* fmt, ...);
98
  void aosUtFailed(BaseSequentialStream* stream, aos_utresult_t* result);
99
  void aosUtFailedMsg(BaseSequentialStream* stream, aos_utresult_t* result, const char* fmt, ...);
100
  void aosUtInfoMsg(BaseSequentialStream* stream, const char* fmt, ...);
101
#ifdef __cplusplus
102
}
103
#endif
104

    
105
#endif /* AMIROOS_CFG_TESTS_ENABLE == true */
106

    
107
#endif /* _AMIROOS_UNITTEST_H_ */