Skip to main content

test-suite.h File

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

Included Headers

#include <time.h> #include <functional>

Namespaces Index

namespacemicro_os_plus

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

namespacemicro_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-2026 Liviu Ionescu. All rights reserved.
4 *
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * 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 be
9 * obtained from https://opensource.org/licenses/mit.
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_1_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#include <time.h>
54
55#ifdef __cplusplus
56
57// ----------------------------------------------------------------------------
58
59#include <functional>
60
61// ----------------------------------------------------------------------------
62
63#if defined(__GNUC__)
64#pragma GCC diagnostic push
65#pragma GCC diagnostic ignored "-Wpadded"
66#if !defined(__clang__) // GCC only
67#pragma GCC diagnostic ignored "-Wsuggest-final-types"
68#pragma GCC diagnostic ignored "-Wsuggest-final-methods"
69#endif
70#if defined(__clang__)
71#pragma clang diagnostic ignored "-Wc++98-compat"
72#endif
73#endif
74
76{
77 // --------------------------------------------------------------------------
78
100 {
101 public:
110 test_suite_base (const char* name);
111
116
121
127 = delete;
128
134 = delete;
135
139 virtual ~test_suite_base ();
140
149 virtual void
150 run (void);
151
159 void
160 begin_test_case (const char* name);
161
169 void
170 end_test_case (void);
171
179 [[nodiscard]] constexpr const char*
180 name (void)
181 {
182 return name_;
183 }
184
193 void
195
204 void
205 increment_failed (void);
206
214 [[nodiscard]] constexpr size_t
216 {
217 return successful_checks_;
218 }
219
227 [[nodiscard]] constexpr size_t
229 {
230 return failed_checks_;
231 }
232
240 [[nodiscard]] constexpr size_t
242 {
243 return test_cases_count_;
244 }
245
254 void
255 begin_test_suite (void);
256
265 void
266 end_test_suite (void);
267
268#if defined(_WIN32) || defined(CLOCK_MONOTONIC)
278 void
279 compute_elapsed_time (timespec& begin_time, timespec& end_time,
280 long& milliseconds, long& microseconds);
281#endif
282
290 [[nodiscard]] constexpr bool
292 {
293 // Also fail if none passed.
294 return (failed_checks_ == 0 && successful_checks_ != 0);
295 }
296
304 [[nodiscard]] constexpr bool
305 unused (void)
306 {
307 return (failed_checks_ == 0 && successful_checks_ == 0
308 && test_cases_count_ == 0);
309 }
310
311 protected:
315 const char* name_;
316
320 const char* test_case_name_;
321
326
330 size_t failed_checks_ = 0;
331
336
337 public:
341 size_t index = 1;
342
343#if defined(_WIN32) || defined(CLOCK_MONOTONIC)
347 timespec begin_time{};
348
352 timespec end_time{};
353#endif
354
359
367 struct
368 {
373
377 size_t failed_checks = 0;
378
379 size_t index = 0;
381 };
382
408 {
409 public:
425 template <typename Callable_T, typename... Args_T>
426 test_suite (const char* name, Callable_T&& callable,
427 Args_T&&... arguments);
428
432 test_suite (const test_suite&) = delete;
433
437 test_suite (test_suite&&) = delete;
438
444 = delete;
445
451 = delete;
452
456 virtual ~test_suite () override;
457
467 virtual void
468 run (void) override;
469
470 protected:
474 std::function<void (void)> callable_;
475 };
476
477 // --------------------------------------------------------------------------
478} // namespace micro_os_plus::micro_test_plus
479
480#if defined(__GNUC__)
481#pragma GCC diagnostic pop
482#endif
483
484// ----------------------------------------------------------------------------
485
486#endif // __cplusplus
487
488// ----------------------------------------------------------------------------
489
490#endif // MICRO_TEST_PLUS_TEST_SUITE_H_
491
492// ----------------------------------------------------------------------------

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.14.0.