micro-test-plus 3.2.0
µTest++, a lightweight testing framework for embedded platforms
Loading...
Searching...
No Matches
test-suite.h
Go to the documentation of this file.
1/*
2 * This file is part of the µOS++ distribution.
3 * (https://github.com/micro-os-plus/)
4 * Copyright (c) 2021 Liviu Ionescu. All rights reserved.
5 *
6 * Permission to use, copy, modify, and/or distribute this software
7 * for any purpose is hereby granted, under the terms of the MIT license.
8 *
9 * If a copy of the license was not distributed with this file, it can
10 * be obtained from <https://opensource.org/licenses/MIT/>.
11 *
12 * Major parts of the code are inspired from v1.1.8 of the Boost UT project,
13 * released under the terms of the Boost Version 1.0 Software License,
14 * which can be obtained from <https://www.boost.org/LICENSE_1_0.txt>.
15 */
16
17#ifndef MICRO_TEST_PLUS_TEST_SUITE_H_
18#define MICRO_TEST_PLUS_TEST_SUITE_H_
19
20// ----------------------------------------------------------------------------
21
22#ifdef __cplusplus
23
24// ----------------------------------------------------------------------------
25
26#include <functional>
27
28// ----------------------------------------------------------------------------
29
30#if defined(__GNUC__)
31#pragma GCC diagnostic push
32#pragma GCC diagnostic ignored "-Wpadded"
33#if !defined(__clang__) // GCC only
34#pragma GCC diagnostic ignored "-Wsuggest-final-types"
35#pragma GCC diagnostic ignored "-Wsuggest-final-methods"
36#endif
37#if defined(__clang__)
38#pragma clang diagnostic ignored "-Wc++98-compat"
39#endif
40#endif
41
43{
44 // --------------------------------------------------------------------------
45
51 {
52 public:
57 test_suite_base (const char* name);
58
59 // The rule of five.
64 = delete;
67 = delete;
68
69 virtual ~test_suite_base ();
70
78 virtual void
79 run (void);
80
87 void
88 begin_test_case (const char* name);
89
97 void
98 end_test_case (void);
99
106 [[nodiscard]] constexpr const char*
108 {
109 return name_;
110 }
111
119 void
121
129 void
130 increment_failed (void);
131
138 [[nodiscard]] constexpr int
140 {
141 return successful_checks_;
142 }
143
150 [[nodiscard]] constexpr int
152 {
153 return failed_checks_;
154 }
155
162 [[nodiscard]] constexpr int
164 {
165 return test_cases_;
166 }
167
175 void
176 begin_test_suite (void);
177
185 void
186 end_test_suite (void);
187
194 [[nodiscard]] constexpr bool
196 {
197 // Also fail if none passed.
198 return (failed_checks_ == 0 && successful_checks_ != 0);
199 }
200
207 [[nodiscard]] constexpr bool
208 unused (void)
209 {
210 return (failed_checks_ == 0 && successful_checks_ == 0
211 && test_cases_ == 0);
212 }
213
214 protected:
218 const char* name_;
219
223 const char* test_case_name_;
224
229
234
238 int test_cases_ = 0;
239
240 public:
242 struct
243 {
247 };
248
256 {
257 public:
269 template <typename Callable_T, typename... Args_T>
270 test_suite (const char* name, Callable_T&& callable,
271 Args_T&&... arguments);
272
273 // The rule of five.
274 test_suite (const test_suite&) = delete;
275 test_suite (test_suite&&) = delete;
278 = delete;
281 = delete;
282
283 virtual ~test_suite () override;
284
285 virtual void
286 run (void) override;
287
288 protected:
289 std::function<void (void)> callable_;
290 };
291
292 // --------------------------------------------------------------------------
293} // namespace micro_os_plus::micro_test_plus
294
295#if defined(__GNUC__)
296#pragma GCC diagnostic pop
297#endif
298
299// ----------------------------------------------------------------------------
300
301#endif // __cplusplus
302
303// ----------------------------------------------------------------------------
304
305#endif // MICRO_TEST_PLUS_TEST_SUITE_H_
306
307// ----------------------------------------------------------------------------
Base class for all test suites.
Definition test-suite.h:51
int failed_checks_
Count of test conditions that failed.
Definition test-suite.h:233
virtual void run(void)
Run the sequence of test cases in the suite.
test_suite_base(const char *name)
Construct a test suite.
int test_cases_
Count of test cases in the test suite.
Definition test-suite.h:238
void increment_failed(void)
Count one more failed test conditions.
constexpr bool unused(void)
If all counter are null, it is unused.
Definition test-suite.h:208
constexpr int failed_checks(void)
Get the number of conditions that failed.
Definition test-suite.h:151
void begin_test_case(const char *name)
Mark the beginning of a named test case.
const char * name_
The test suite name.
Definition test-suite.h:218
void increment_successful(void)
Count one more passed test conditions.
constexpr const char * name()
Get the suite name.
Definition test-suite.h:107
void end_test_suite(void)
Mark the end of the test suite.
void end_test_case(void)
Mark the end of a test case.
test_suite_base & operator=(const test_suite_base &)=delete
test_suite_base(const test_suite_base &)=delete
constexpr int successful_checks(void)
Get the number of conditions that passed.
Definition test-suite.h:139
int successful_checks_
Count of test conditions that passed.
Definition test-suite.h:228
void begin_test_suite(void)
Begin the execution of the test suite.
const char * test_case_name_
The current test case name.
Definition test-suite.h:223
constexpr bool was_successful(void)
Get the test suite result.
Definition test-suite.h:195
constexpr int test_cases(void)
Get the number of test cases.
Definition test-suite.h:163
struct micro_os_plus::micro_test_plus::test_suite_base::@0 current_test_case
Test suites are classes that represent a named group of test cases which self register to the runner.
Definition test-suite.h:256
std::function< void(void)> callable_
Definition test-suite.h:289
test_suite(const test_suite &)=delete
test_suite(const char *name, Callable_T &&callable, Args_T &&... arguments)
Construct a test suite.
Definition inlines.h:41
test_suite & operator=(const test_suite &)=delete
virtual void run(void) override
Run the sequence of test cases in the suite.