Skip to main content

The test-suite.h File Reference

C++ header file with declarations for the µTest++ test suite. More...

Included Headers

#include <functional>

Namespaces Index

namespacemicro_os_plus

The primary namespace for the µOS++ framework. More...

namespacemicro_os_plus::micro_test_plus

Primary namespace for the µTest++ testing framework. More...

Classes Index

classtest_suite

Represents a named group of test cases that self-register to the runner. More...

classtest_suite_base

Base class for all test suites. More...

Description

C++ header file with declarations for the µTest++ test suite.

This header provides the declarations for the test suite facilities used within the µTest++ framework. It defines the interfaces for constructing, registering, and managing test suites and their associated test cases. The core classes, test_suite_base and test_suite, offer mechanisms for tracking test case execution, managing counters for successful and failed checks, and supporting automated registration and discovery of test suites.

The design ensures that test suites are non-copyable and non-movable, maintaining unique ownership and consistent state. Flexible support for callable objects enables a wide range of test suite definitions, facilitating expressive and maintainable test organisation across embedded and general C++ projects.

All definitions reside within the micro_os_plus::micro_test_plus namespace, ensuring clear separation from user code and minimising the risk of naming conflicts.

The header files are organised within the include/micro-os-plus/micro-test-plus folder to maintain a structured and modular codebase.

This file is intended solely for internal use within the framework and should not be included directly by user code.

File Listing

The file content with the documentation metadata removed is:

1/*
2 * This file is part of the µOS++ project (https://micro-os-plus.github.io/).
3 * Copyright (c) 2021 Liviu Ionescu. All rights reserved.
4 *
5 * Permission to use, copy, modify, and/or distribute this software
6 * for any purpose is hereby granted, under the terms of the MIT license.
7 *
8 * If a copy of the license was not distributed with this file, it can
10 *
11 * Major parts of the code are inspired from v1.1.8 of the Boost UT project,
12 * released under the terms of the Boost Version 1 Software License,
13 * which can be obtained from https://www.boost.org/LICENSE&#95;1&#95;0.txt.
14 */
15
16// ----------------------------------------------------------------------------
17
47
48#ifndef MICRO_TEST_PLUS_TEST_SUITE_H_
49#define MICRO_TEST_PLUS_TEST_SUITE_H_
50
51// ----------------------------------------------------------------------------
52
53#ifdef __cplusplus
54
55// ----------------------------------------------------------------------------
56
57#include <functional>
58
59// ----------------------------------------------------------------------------
60
61#if defined(__GNUC__)
62#pragma GCC diagnostic push
63#pragma GCC diagnostic ignored "-Wpadded"
64#if !defined(__clang__) // GCC only
65#pragma GCC diagnostic ignored "-Wsuggest-final-types"
66#pragma GCC diagnostic ignored "-Wsuggest-final-methods"
67#endif
68#if defined(__clang__)
69#pragma clang diagnostic ignored "-Wc++98-compat"
70#endif
71#endif
72
74{
75 // --------------------------------------------------------------------------
76
98 {
99 public:
108 test_suite_base (const char* name);
109
114
119
125 = delete;
126
132 = delete;
133
137 virtual ~test_suite_base ();
138
147 virtual void
148 run (void);
149
157 void
158 begin_test_case (const char* name);
159
167 void
168 end_test_case (void);
169
177 [[nodiscard]] constexpr const char*
178 name (void)
179 {
180 return name_;
181 }
182
191 void
193
202 void
203 increment_failed (void);
204
212 [[nodiscard]] constexpr int
214 {
215 return successful_checks_;
216 }
217
225 [[nodiscard]] constexpr int
227 {
228 return failed_checks_;
229 }
230
238 [[nodiscard]] constexpr int
240 {
241 return test_cases_;
242 }
243
252 void
253 begin_test_suite (void);
254
263 void
264 end_test_suite (void);
265
273 [[nodiscard]] constexpr bool
275 {
276 // Also fail if none passed.
277 return (failed_checks_ == 0 && successful_checks_ != 0);
278 }
279
287 [[nodiscard]] constexpr bool
288 unused (void)
289 {
290 return (failed_checks_ == 0 && successful_checks_ == 0
291 && test_cases_ == 0);
292 }
293
294 protected:
298 const char* name_;
299
303 const char* test_case_name_;
304
309
314
318 int test_cases_ = 0;
319
320 public:
325
333 struct
334 {
339
345 };
346
372 {
373 public:
389 template <typename Callable_T, typename... Args_T>
390 test_suite (const char* name, Callable_T&& callable,
391 Args_T&&... arguments);
392
396 test_suite (const test_suite&) = delete;
397
401 test_suite (test_suite&&) = delete;
402
408 = delete;
409
415 = delete;
416
420 virtual ~test_suite () override;
421
431 virtual void
432 run (void) override;
433
434 protected:
438 std::function<void (void)> callable_;
439 };
440
441 // --------------------------------------------------------------------------
442} // namespace micro_os_plus::micro_test_plus
443
444#if defined(__GNUC__)
445#pragma GCC diagnostic pop
446#endif
447
448// ----------------------------------------------------------------------------
449
450#endif // __cplusplus
451
452// ----------------------------------------------------------------------------
453
454#endif // MICRO_TEST_PLUS_TEST_SUITE_H_
455
456// ----------------------------------------------------------------------------

Generated via docusaurus-plugin-doxygen by Doxygen 1.14.0.