Skip to main content

test_suite_base Class

Base class for all test suites. More...

Declaration

class micro_os_plus::micro_test_plus::test_suite_base { ... }

Included Headers

Derived Classes

classtest_suite

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

Public Constructors Index

test_suite_base (const char *name)

Constructs a test suite. More...

test_suite_base (const test_suite_base &)=delete

Deleted copy constructor to prevent copying. More...

test_suite_base (test_suite_base &&)=delete

Deleted move constructor to prevent moving. More...

Public Destructor Index

~test_suite_base ()

Virtual destructor for the test_suite_base class. More...

Public Operators Index

test_suite_base &operator= (const test_suite_base &)=delete

Deleted copy assignment operator to prevent copying. More...

test_suite_base &operator= (test_suite_base &&)=delete

Deleted move assignment operator to prevent moving. More...

Public Member Functions Index

voidbegin_test_case (const char *name)

Marks the beginning of a named test case. More...

voidbegin_test_suite (void)

Begins the execution of the test suite. More...

voidend_test_case (void)

Marks the end of a test case. More...

voidend_test_suite (void)

Marks the end of the test suite. More...

constexpr size_tfailed_checks (void)

Gets the number of test conditions that failed. More...

voidincrement_failed (void)

Increments the count of failed test conditions. More...

voidincrement_successful (void)

Increments the count of passed test conditions. More...

constexpr const char *name (void)

Gets the suite name. More...

voidrun (void)

Runs the sequence of test cases in the suite. More...

constexpr size_tsuccessful_checks (void)

Gets the number of conditions that passed. More...

constexpr size_ttest_cases_count (void)

Gets the number of test cases. More...

constexpr boolunused (void)

Checks if the test suite was not used. More...

constexpr boolwas_successful (void)

Gets the test suite result. More...

Public Member Attributes Index

struct { ... }current_test_case

Structure holding the current test case's check counters. More...

size_tfailed_checks = 0

Number of failed checks in the current test case. More...

size_tindex = 1

The test suite index, counting from 1. More...

boolprocess_deferred_begin = true

Indicates whether to process deferred begin for test cases. More...

size_tsuccessful_checks = 0

Number of successful checks in the current test case. More...

Protected Member Attributes Index

size_tfailed_checks_ = 0

Count of test conditions that failed. More...

const char *name_

The test suite name. More...

size_tsuccessful_checks_ = 0

Count of test conditions that passed. More...

const char *test_case_name_

The current test case name. More...

size_ttest_cases_count_ = 0

Count of test cases in the test suite. More...

Description

Base class for all test suites.

The test_suite_base class provides the foundational interface for managing test suites within the µTest++ framework. It maintains counters for successful and failed checks, tracks test cases, and offers methods for marking the commencement and completion of test cases and suites.

This class ensures consistent state management and reporting for all derived test suites. It also provides utility methods for querying the suite's name, the number of successful and failed checks, the number of test cases, and the overall result of the suite.

All members and methods are defined within the micro_os_plus::micro_test_plus namespace, ensuring clear separation from user code and minimising the risk of naming conflicts.

Definition at line 99 of file test-suite.h.

Public Constructors

test_suite_base()

micro_os_plus::micro_test_plus::test_suite_base::test_suite_base (const char * name)

Constructs a test suite.

Parameters
[in] name

The test suite name.

The rule of five is enforced to prevent accidental copying or moving.

The constructor initialises a new instance of the test_suite_base class with the specified name. It sets up the internal state required for managing test cases within the suite. If tracing is enabled, the function signature is output for diagnostic purposes. The default test suite does not require explicit registration, ensuring seamless integration within the µTest++ framework and supporting organised test management across all files and folders.

Declaration at line 110 of file test-suite.h, definition at line 75 of file test-suite.cpp.

76 {
77#if defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS)
78 printf ("%s\n", __PRETTY_FUNCTION__);
79#endif // MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS
80
81 name_ = name;
82 // The default test suite needs no registration.
83 }

References name and name_.

Referenced by micro_os_plus::micro_test_plus::test_suite::test_suite, test_suite_base, test_suite_base, operator= and operator=.

test_suite_base()

micro_os_plus::micro_test_plus::test_suite_base::test_suite_base (const test_suite_base &)
delete

Deleted copy constructor to prevent copying.

Definition at line 115 of file test-suite.h.

Reference test_suite_base.

test_suite_base()

micro_os_plus::micro_test_plus::test_suite_base::test_suite_base (test_suite_base &&)
delete

Deleted move constructor to prevent moving.

Definition at line 120 of file test-suite.h.

Reference test_suite_base.

Public Destructor

~test_suite_base()

micro_os_plus::micro_test_plus::test_suite_base::~test_suite_base ()
virtual

Virtual destructor for the test_suite_base class.

The destructor releases any resources associated with the test_suite_base instance. It ensures that the test suite is properly cleaned up after execution, supporting robust and reliable test management across all files and folders within the µTest++ framework.

Declaration at line 139 of file test-suite.h, definition at line 92 of file test-suite.cpp.

Public Operators

operator=()

test_suite_base & micro_os_plus::micro_test_plus::test_suite_base::operator= (const test_suite_base &)
delete

Deleted copy assignment operator to prevent copying.

Definition at line 126 of file test-suite.h.

Reference test_suite_base.

operator=()

test_suite_base & micro_os_plus::micro_test_plus::test_suite_base::operator= (test_suite_base &&)
delete

Deleted move assignment operator to prevent moving.

Definition at line 133 of file test-suite.h.

References test_suite_base and name.

Public Member Functions

begin_test_case()

void micro_os_plus::micro_test_plus::test_suite_base::begin_test_case (const char * name)

Marks the beginning of a named test case.

Parameters
[in] name

The test case name.

Returns

Nothing.

This method marks the beginning of a test case within the suite. If the start of the suite was deferred, it ensures the suite is properly begun before proceeding. The method sets the current test case name, increments the total number of test cases, resets the current test case statistics, and notifies the test reporter to begin the test case. This approach guarantees that each test case is clearly identified, accurately tracked, and properly reported across all test cases and folders.

Declaration at line 160 of file test-suite.h, definition at line 177 of file test-suite.cpp.

178 {
180 {
181 reporter->begin_test (runner.test_suites_count ());
182
184 }
185
188
190
191 reporter->begin_test_case (test_case_name_);
192 }

References begin_test_suite, current_test_case, name, process_deferred_begin, micro_os_plus::micro_test_plus::reporter, micro_os_plus::micro_test_plus::runner, test_case_name_ and test_cases_count_.

begin_test_suite()

void micro_os_plus::micro_test_plus::test_suite_base::begin_test_suite (void)

Begins the execution of the test suite.

Parameters

None.

Returns

Nothing.

This method marks the beginning of a test suite's execution. It resets the deferred begin flag and notifies the test reporter to start the suite, passing the suite's name. This ensures that test suite output is clearly delineated and properly initialised, supporting organised and readable reporting across all test cases and folders.

Declaration at line 255 of file test-suite.h, definition at line 122 of file test-suite.cpp.

123 {
124#if defined(_WIN32) || defined(CLOCK_MONOTONIC)
125#if defined(_WIN32)
126 timespec_get (&begin_time, TIME_UTC);
127#else
128 clock_gettime (CLOCK_MONOTONIC, &begin_time);
129#endif
130#endif
131
133
134 reporter->begin_test_suite (name_);
135 }

References name_, process_deferred_begin and micro_os_plus::micro_test_plus::reporter.

Referenced by begin_test_case, end_test_suite and micro_os_plus::micro_test_plus::test_runner::exit_code.

end_test_case()

void micro_os_plus::micro_test_plus::test_suite_base::end_test_case (void)

Marks the end of a test case.

Parameters

None.

Returns

Nothing.

This method marks the end of a test case within the suite. It notifies the test reporter to conclude the test case, passing the current test case name. This ensures that the results of the test case are accurately finalised and clearly reported, supporting organised and reliable test management across all test cases and folders.

Declaration at line 170 of file test-suite.h, definition at line 203 of file test-suite.cpp.

204 {
205 reporter->end_test_case (test_case_name_);
206 }

References micro_os_plus::micro_test_plus::reporter and test_case_name_.

end_test_suite()

void micro_os_plus::micro_test_plus::test_suite_base::end_test_suite (void)

Marks the end of the test suite.

Parameters

None.

Returns

Nothing.

This method marks the end of a test suite's execution. If the suite's start was deferred, it ensures the suite is properly begun before finalising. The method then notifies the test reporter to conclude the suite, passing a reference to the suite instance. This guarantees that all results are accurately summarised and reported, supporting clear and organised test management across all test cases and folders.

Declaration at line 266 of file test-suite.h, definition at line 147 of file test-suite.cpp.

148 {
150 {
151 reporter->begin_test (runner.test_suites_count ());
152
154 }
155
156#if defined(_WIN32) || defined(CLOCK_MONOTONIC)
157#if defined(_WIN32)
158 timespec_get (&end_time, TIME_UTC);
159#else
160 clock_gettime (CLOCK_MONOTONIC, &end_time);
161#endif
162#endif
163 reporter->end_test_suite (*this);
164 }

References begin_test_suite, process_deferred_begin, micro_os_plus::micro_test_plus::reporter and micro_os_plus::micro_test_plus::runner.

Referenced by micro_os_plus::micro_test_plus::test_runner::exit_code.

failed_checks()

size_t micro_os_plus::micro_test_plus::test_suite_base::failed_checks (void)
inline nodiscard constexpr

Gets the number of test conditions that failed.

Parameters

None.

Returns

An integer with the number of checks that failed.

Definition at line 228 of file test-suite.h.

229 {
230 return failed_checks_;
231 }

Reference failed_checks_.

increment_failed()

void micro_os_plus::micro_test_plus::test_suite_base::increment_failed (void)

Increments the count of failed test conditions.

Parameters

None.

Returns

Nothing.

This method increments the count of failed checks for the test suite and the current test case. It ensures that each failing assertion is accurately recorded, supporting precise tracking and reporting of test outcomes across all test cases and folders.

Declaration at line 205 of file test-suite.h, definition at line 230 of file test-suite.cpp.

231 {
233 ++current_test_case.failed_checks;
234 }

References current_test_case and failed_checks_.

increment_successful()

void micro_os_plus::micro_test_plus::test_suite_base::increment_successful (void)

Increments the count of passed test conditions.

Parameters

None.

Returns

Nothing.

This method increments the count of successful checks for the test suite and the current test case. It ensures that each passing assertion is accurately recorded, supporting precise tracking and reporting of test outcomes across all test cases and folders.

Declaration at line 194 of file test-suite.h, definition at line 216 of file test-suite.cpp.

217 {
219 ++current_test_case.successful_checks;
220 }

References current_test_case and successful_checks_.

name()

const char * micro_os_plus::micro_test_plus::test_suite_base::name (void)
inline nodiscard constexpr

Gets the suite name.

Parameters

None.

Returns

A pointer to the null-terminated test suite name.

Definition at line 180 of file test-suite.h.

180 name (void)
181 {
182 return name_;
183 }

Reference name_.

Referenced by micro_os_plus::micro_test_plus::test_suite::test_suite, test_suite_base, begin_test_case, micro_os_plus::micro_test_plus::test_reporter_basic::end_test_suite, micro_os_plus::micro_test_plus::test_reporter_tap::end_test_suite and operator=.

run()

void micro_os_plus::micro_test_plus::test_suite_base::run (void)
virtual

Runs the sequence of test cases in the suite.

Parameters

None.

Returns

Nothing.

This method executes the test suite by invoking its associated callable object. If tracing is enabled, the function signature is output for diagnostic purposes. The method ensures that all test cases grouped within the suite are executed in an organised manner, supporting comprehensive and structured testing across all files and folders within the µTest++ framework.

Declaration at line 150 of file test-suite.h, definition at line 106 of file test-suite.cpp.

107 {
108#if defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS)
109 printf ("%s\n", __PRETTY_FUNCTION__);
110#endif // MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS
111 }

successful_checks()

size_t micro_os_plus::micro_test_plus::test_suite_base::successful_checks (void)
inline nodiscard constexpr

Gets the number of conditions that passed.

Parameters

None.

Returns

An integer with the number of checks that passed.

Definition at line 215 of file test-suite.h.

216 {
217 return successful_checks_;
218 }

Reference successful_checks_.

test_cases_count()

size_t micro_os_plus::micro_test_plus::test_suite_base::test_cases_count (void)
inline nodiscard constexpr

Gets the number of test cases.

Parameters

None.

Returns

An integer with the number of test cases.

Definition at line 241 of file test-suite.h.

242 {
243 return test_cases_count_;
244 }

Reference test_cases_count_.

Referenced by micro_os_plus::micro_test_plus::test_reporter_basic::end_test_suite, micro_os_plus::micro_test_plus::test_reporter_tap::end_test_suite and micro_os_plus::micro_test_plus::test_runner::exit_code.

unused()

bool micro_os_plus::micro_test_plus::test_suite_base::unused (void)
inline nodiscard constexpr

Checks if the test suite was not used.

Parameters

None.

Returns

True if the test suite is not used.

Definition at line 305 of file test-suite.h.

305 unused (void)
306 {
307 return (failed_checks_ == 0 && successful_checks_ == 0
308 && test_cases_count_ == 0);
309 }

References failed_checks_, successful_checks_ and test_cases_count_.

was_successful()

bool micro_os_plus::micro_test_plus::test_suite_base::was_successful (void)
inline nodiscard constexpr

Gets the test suite result.

Parameters

None.

Returns

True if the test suite was successful.

Definition at line 291 of file test-suite.h.

292 {
293 // Also fail if none passed.
294 return (failed_checks_ == 0 && successful_checks_ != 0);
295 }

References failed_checks_ and successful_checks_.

Referenced by micro_os_plus::micro_test_plus::test_runner::exit_code.

Public Member Attributes

current_test_case

struct micro_os_plus::micro_test_plus::test_suite_base micro_os_plus::micro_test_plus::test_suite_base::current_test_case

Structure holding the current test case's check counters.

Tracks the number of successful and failed checks for the currently running test case.

Definition at line 380 of file test-suite.h.

Referenced by begin_test_case, increment_failed and increment_successful.

failed_checks

size_t micro_os_plus::micro_test_plus::test_suite_base::failed_checks = 0

index

size_t micro_os_plus::micro_test_plus::test_suite_base::index = 1

The test suite index, counting from 1.

Definition at line 341 of file test-suite.h.

341 size_t index = 1;

Referenced by micro_os_plus::micro_test_plus::test_reporter_tap::end_test_suite and micro_os_plus::micro_test_plus::test_runner::register_test_suite.

process_deferred_begin

bool micro_os_plus::micro_test_plus::test_suite_base::process_deferred_begin = true

Indicates whether to process deferred begin for test cases.

Definition at line 358 of file test-suite.h.

Referenced by begin_test_case, begin_test_suite and end_test_suite.

successful_checks

size_t micro_os_plus::micro_test_plus::test_suite_base::successful_checks = 0

Protected Member Attributes

failed_checks_

size_t micro_os_plus::micro_test_plus::test_suite_base::failed_checks_ = 0
protected

Count of test conditions that failed.

Definition at line 330 of file test-suite.h.

330 size_t failed_checks_ = 0;

Referenced by failed_checks, increment_failed, unused and was_successful.

name_

const char* micro_os_plus::micro_test_plus::test_suite_base::name_
protected

The test suite name.

Definition at line 315 of file test-suite.h.

315 const char* name_;

Referenced by test_suite_base, begin_test_suite and name.

successful_checks_

size_t micro_os_plus::micro_test_plus::test_suite_base::successful_checks_ = 0
protected

Count of test conditions that passed.

Definition at line 325 of file test-suite.h.

Referenced by increment_successful, successful_checks, unused and was_successful.

test_case_name_

const char* micro_os_plus::micro_test_plus::test_suite_base::test_case_name_
protected

The current test case name.

Definition at line 320 of file test-suite.h.

320 const char* test_case_name_;

Referenced by begin_test_case and end_test_case.

test_cases_count_

size_t micro_os_plus::micro_test_plus::test_suite_base::test_cases_count_ = 0
protected

Count of test cases in the test suite.

Definition at line 335 of file test-suite.h.

Referenced by begin_test_case, test_cases_count and unused.


The documentation for this class was generated from the following files:


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.14.0.