micro-test-plus 3.2.2
µTest++ Testing Framework
Loading...
Searching...
No Matches
test-suite.h
Go to the documentation of this file.
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
9 * be 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.0 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#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// ----------------------------------------------------------------------------
int failed_checks_
Count of test conditions that failed.
Definition test-suite.h:313
virtual void run(void)
Runs the sequence of test cases in the suite.
test_suite_base(const char *name)
Constructs a test suite.
int test_cases_
Count of test cases in the test suite.
Definition test-suite.h:318
void increment_failed(void)
Increments the count of failed test conditions.
constexpr bool unused(void)
Checks if the test suite was not used.
Definition test-suite.h:288
struct micro_os_plus::micro_test_plus::test_suite_base::@307331361010072137141032203112105164200271360345 current_test_case
Structure holding the current test case's check counters.
constexpr const char * name(void)
Gets the suite name.
Definition test-suite.h:178
int failed_checks
Number of failed checks in the current test case.
Definition test-suite.h:343
int successful_checks
Number of successful checks in the current test case.
Definition test-suite.h:338
constexpr int failed_checks(void)
Gets the number of test conditions that failed.
Definition test-suite.h:226
void begin_test_case(const char *name)
Marks the beginning of a named test case.
const char * name_
The test suite name.
Definition test-suite.h:298
void increment_successful(void)
Increments the count of passed test conditions.
virtual ~test_suite_base()
Virtual destructor for the test_suite_base class.
void end_test_suite(void)
Marks the end of the test suite.
void end_test_case(void)
Marks the end of a test case.
test_suite_base & operator=(const test_suite_base &)=delete
Deleted copy assignment operator to prevent copying.
test_suite_base(const test_suite_base &)=delete
Deleted copy constructor to prevent copying.
bool process_deferred_begin
Indicates whether to process deferred begin for test cases.
Definition test-suite.h:324
test_suite_base(test_suite_base &&)=delete
Deleted move constructor to prevent moving.
constexpr int successful_checks(void)
Gets the number of conditions that passed.
Definition test-suite.h:213
int successful_checks_
Count of test conditions that passed.
Definition test-suite.h:308
void begin_test_suite(void)
Begins the execution of the test suite.
const char * test_case_name_
The current test case name.
Definition test-suite.h:303
constexpr bool was_successful(void)
Gets the test suite result.
Definition test-suite.h:274
constexpr int test_cases(void)
Gets the number of test cases.
Definition test-suite.h:239
std::function< void(void)> callable_
Callable object representing the test suite's execution logic.
Definition test-suite.h:438
test_suite(const test_suite &)=delete
Deleted copy constructor to prevent copying.
test_suite(const char *name, Callable_T &&callable, Args_T &&... arguments)
Class template constructor for test_suite.
test_suite & operator=(const test_suite &)=delete
Deleted copy assignment operator to prevent copying.
virtual void run(void) override
Runs the sequence of test cases in the suite by invoking the stored callable.
test_suite(test_suite &&)=delete
Deleted move constructor to prevent moving.
virtual ~test_suite() override
Virtual destructor for the test_suite class.
Primary namespace for the µTest++ testing framework.