Mistake on this page?
Report an issue in GitHub or email us
utest_case.h
1 /****************************************************************************
2  * Copyright (c) 2015, ARM Limited, All Rights Reserved
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License"); you may
6  * not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  ****************************************************************************
17  */
18 
19 #ifndef UTEST_CASES_H
20 #define UTEST_CASES_H
21 
22 #include <stdint.h>
23 #include <stdbool.h>
24 #include <stdio.h>
25 #include "utest/utest_types.h"
26 #include "utest/utest_default_handlers.h"
27 
28 
29 namespace utest {
30 /** \addtogroup frameworks */
31 /** @{*/
32 namespace v1 {
33  /**
34  * POD data structure of the Case class.
35  * Unlike the Case class it can be used as a POD and be put in ROM.
36  *
37  * @warning Initialization of handlers with either default_handler or
38  * ignore_handler helpers will prevent the object to be a POD. Prefer usage
39  * of NULL in favor of ignore_handler or \verbatim <handler_type>(1) \endverbatim for default
40  * handler.
41  *
42  * @see Case.
43  */
44  struct case_t
45  {
46  /**
47  * Textual description of the test case
48  */
49  const char *description;
50 
51  /**
52  * Primitive test case handler
53  * This is called only if the case setup succeeded. It is followed by
54  * the test case teardown handler.
55  */
57 
58  /**
59  * @see case_control_handler_t
60  */
62 
63  /**
64  * @see case_call_count_handler_t
65  */
67 
68  /**
69  * Handler called before the execution of the case handler. It sets up
70  * the case environment.
71  */
73 
74  /**
75  * Handler called after the execution of the case handler. It cleans up
76  * the case environment.
77  */
79 
80  /**
81  * Handler called whenever a faillure occur; at any stage of the case
82  * execution (including setup and teardown).
83  */
85  };
86 
87  /** Test case wrapper class.
88  *
89  * This class contains the description of the test case and all handlers
90  * for setting up, running the test case, tearing down and handling failures.
91  *
92  * By default you only need to provide a description and a test case handler.
93  * You may override the setup, teardown and failure handlers, but you do not have to.
94  * If you do not override these handler, the specified default handlers will be called.
95  *
96  * These constructors are overloaded to allow you a comfortable declaration of all your
97  * callbacks.
98  * The order is always:
99  * - description (required)
100  * - setup handler (optional)
101  * - test case handler (required)
102  * - teardown handler (optional)
103  * - failure handler (optional)
104  *
105  * @note While you can specify an empty test case (ie. use `ignore_handler` for all callbacks),
106  * the harness will abort the test unconditionally.
107  */
108  class Case : private case_t
109  {
110  public:
111  // overloads for case_handler_t
112  Case(const char *description,
114  const case_handler_t case_handler,
117 
118  Case(const char *description,
119  const case_handler_t case_handler,
121 
122  Case(const char *description,
123  const case_handler_t case_handler,
126 
127  // overloads for case_control_handler_t
128  Case(const char *description,
129  const case_setup_handler_t setup_handler,
130  const case_control_handler_t case_handler,
131  const case_teardown_handler_t teardown_handler = default_handler,
133 
134  Case(const char *description,
135  const case_control_handler_t case_handler,
137 
138  Case(const char *description,
139  const case_control_handler_t case_handler,
140  const case_teardown_handler_t teardown_handler,
142 
143  // overloads for case_call_count_handler_t
144  Case(const char *description,
145  const case_setup_handler_t setup_handler,
146  const case_call_count_handler_t case_handler,
147  const case_teardown_handler_t teardown_handler = default_handler,
149 
150  Case(const char *description,
151  const case_call_count_handler_t case_handler,
153 
154  Case(const char *description,
155  const case_call_count_handler_t case_handler,
156  const case_teardown_handler_t teardown_handler,
158 
159 
160  /// @returns the textual description of the test case
161  const char* get_description() const;
162 
163  /// @returns `true` if setup, test and teardown handlers are set to `ignore_handler`
164  bool is_empty() const;
165 
166  private:
167  // IMPORTANT: No data members shall be declared inside this class.
168  // Data members shall be declared in case_t to preserve the layout
169  // and the compatibility between the two types.
170 
171  friend class Harness;
172  friend class Specification;
173  };
174 
175 } // namespace v1
176 } // namespace utest
177 
178  #endif // UTEST_CASES_H
179 
180 /** @}*/
Test case wrapper class.
Definition: utest_case.h:108
utest::v1::status_t(* case_setup_handler_t)(const Case *const source, const size_t index_of_case)
Test case setup handler.
Definition: utest_types.h:326
Test Harness.
Definition: utest_harness.h:46
const case_handler_t handler
Primitive test case handler This is called only if the case setup succeeded.
Definition: utest_case.h:56
utest::v1::status_t(* case_teardown_handler_t)(const Case *const source, const size_t passed, const size_t failed, const failure_t reason)
Test case teardown handler.
Definition: utest_types.h:372
const char * description
Textual description of the test case.
Definition: utest_case.h:49
static const struct utest::v1::@371 default_handler
Default handler hint.
POD data structure of the Case class.
Definition: utest_case.h:44
Test specification containing the setup and teardown handlers and test cases.
void(* case_handler_t)(void)
Primitive test case handler.
Definition: utest_types.h:334
const case_teardown_handler_t teardown_handler
Handler called after the execution of the case handler.
Definition: utest_case.h:78
utest::v1::status_t(* case_failure_handler_t)(const Case *const source, const failure_t reason)
Test case failure handler.
Definition: utest_types.h:386
control_t(* case_call_count_handler_t)(const size_t call_count)
Test case handler (repeatable)
Definition: utest_types.h:356
const case_setup_handler_t setup_handler
Handler called before the execution of the case handler.
Definition: utest_case.h:72
control_t(* case_control_handler_t)(void)
Complex test case handler.
Definition: utest_types.h:344
const case_control_handler_t control_handler
Definition: utest_case.h:61
const case_call_count_handler_t repeat_count_handler
Definition: utest_case.h:66
const case_failure_handler_t failure_handler
Handler called whenever a faillure occur; at any stage of the case execution (including setup and tea...
Definition: utest_case.h:84
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.