Statistics
| Branch: | Tag: | Revision:

amiro-os / core / inc / aos_unittest.h @ 07ff44a7

History | View | Annotate | Download (3.186 KB)

1 e545e620 Thomas Schöpping
/*
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 53710ca3 Marc Rothmann
/**
20
 * @file    aos_unittest.h
21
 * @brief   Unittest structures.
22
 *
23
 * @addtogroup aos_unittests
24
 * @{
25
 */
26
27 e545e620 Thomas Schöpping
#ifndef _AMIROOS_UNITTEST_H_
28
#define _AMIROOS_UNITTEST_H_
29
30
#include <aosconf.h>
31 bc5cdb79 Thomas Schöpping
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
32 e545e620 Thomas Schöpping
#include <hal.h>
33
#include <aos_shell.h>
34
35
/*
36
 * Forward declarations.
37
 */
38
typedef struct aos_unittest aos_unittest_t;
39
typedef struct aos_utresult aos_utresult_t;
40
41
/**
42
 * @brief   Unit test interface function definition.
43
 *
44
 * @param[in] stream  The stream to use for printing messages.
45
 * @param[in] ut      The object to run the test on.
46
 *
47
 * @return    A result containing the number of passed and failed tests.
48
 */
49
typedef aos_utresult_t (*aos_utfunction_t)(BaseSequentialStream* stream, aos_unittest_t* ut);
50
51
/**
52
 * @brief   Unit test result struct.
53
 */
54
struct aos_utresult {
55
  /**
56
   * @brief   Number of passed tests.
57
   */
58
  uint32_t passed;
59
60
  /**
61
   * @brief   Number of failed tests.
62
   */
63
  uint32_t failed;
64
};
65
66
/**
67
 * @brief   Unit test definition struct.
68
 */
69
struct aos_unittest {
70
  /**
71
   * @brief   Name of the unit test.
72
   */
73
  const char* name;
74
75
  /**
76
   * @brief   Further information about the test.
77
   */
78
  const char* info;
79
80
  /**
81
   * @brief   Callback function to run that executes the unit test.
82
   */
83
  aos_utfunction_t testfunc;
84
85
  /**
86
   * @brief   Shell command to add to an shell command list.
87
   */
88
  aos_shellcommand_t shellcmd;
89
90
  /**
91
   * @brief   Further test specific data.
92
   */
93
  void* data;
94
};
95
96
#ifdef __cplusplus
97
extern "C" {
98
#endif
99
  uint32_t aosUtResultTotal(aos_utresult_t* result);
100
  float aosUtResultRatio(aos_utresult_t* result);
101
  void aosUtResultPrintSummary(BaseSequentialStream* stream, aos_utresult_t* result, char* heading);
102
  void aosUtObjectInit(aos_unittest_t* ut, char* name, char* info, aos_utfunction_t func, void* data, char* shellname, aos_shellcmdcb_t shellcb);
103
  aos_utresult_t aosUtRun(BaseSequentialStream* stream, aos_unittest_t* ut, char* note);
104
  void aosUtPassed(BaseSequentialStream* stream, aos_utresult_t* result);
105
  void aosUtPassedMsg(BaseSequentialStream* stream, aos_utresult_t* result, const char* fmt, ...);
106
  void aosUtFailed(BaseSequentialStream* stream, aos_utresult_t* result);
107
  void aosUtFailedMsg(BaseSequentialStream* stream, aos_utresult_t* result, const char* fmt, ...);
108
  void aosUtInfoMsg(BaseSequentialStream* stream, const char* fmt, ...);
109
#ifdef __cplusplus
110
}
111
#endif
112
113
#endif /* AMIROOS_CFG_TESTS_ENABLE == true */
114
115
#endif /* _AMIROOS_UNITTEST_H_ */
116 53710ca3 Marc Rothmann
117
/** @} */