libGimbal 0.1.0
C17-Based Extended Standard Library and Cross-Language Runtime Framework
Loading...
Searching...
No Matches
gimbal_test_scenario.h
Go to the documentation of this file.
1/*! \file
2 * \brief GblTestScenario and related functions.
3 * \ingroup testing
4 *
5 * This file contains the type declaration for GblTestScenario
6 * and its related public API.
7 *
8 * \author 2023, 2024, 2025 Falco Girgis
9 * \copyright MIT License
10 *
11 * \todo
12 * - removing GblTestSuites
13 * - Complex/Extended constructor like GblBox
14 * - Uniform argument parsing/handling?
15 * - abort the scenario
16 * - option for dumping failed cases at the end
17 * - suite count public API
18 * - expecting error
19 * - emit property changed signals
20 */
21#ifndef GIMBAL_TEST_SCENARIO_H
22#define GIMBAL_TEST_SCENARIO_H
23
24#include "../meta/instances/gimbal_context.h"
25#include "../meta/signals/gimbal_signal.h"
26
27/*! \name Type System
28 * \brief Type UUID and cast operators.
29 * @{
30 */
31#define GBL_TEST_SCENARIO_TYPE GBL_TYPEID(GblTestScenario) //!< GblType UUID for GblTestScenario
32#define GBL_TEST_SCENARIO(self) GBL_CAST(GblTestScenario, self) //!< Casts a GblInstance to a GblTestScenario
33#define GBL_TEST_SCENARIO_CLASS(klass) GBL_CLASS_CAST(GblTestScenario, klass) //!< Casts a GblClass to a GblTestScenarioClass
34#define GBL_TEST_SCENARIO_CLASSOF(self) GBL_CLASSOF(GblTestScenario, self) //!< Retrieves a GblTestScenarioClass from a GblInstance
35//! @}
36
37#define GBL_SELF_TYPE GblTestScenario
38
40
41GBL_FORWARD_DECLARE_STRUCT(GblTestScenario);
42GBL_FORWARD_DECLARE_STRUCT(GblTestSuite);
43
44/*! \struct GblTestScenarioClass
45 * \extends GblContextClass
46 * \brief GblClass VTable structure for a GblTestScenario.
47 *
48 * Provides a series of overridable virtual methods for looking
49 * up into individual GblTestSuites and executing them. This allows
50 * for mapping to a custom back-end that doesn't use GblTestSuite
51 * objects. The default implementations of these methods implement
52 * the built-in behavior of iterating through each child suite and
53 * executing its tests.
54 *
55 * \sa GblTestScenario
56 */
57GBL_CLASS_DERIVE(GblTestScenario, GblContext)
58 //! Virtual function which gets called just before a GblTestScenario begins execution.
59 GBL_RESULT (*pFnBegin) (GBL_SELF);
60 //! Virtual function which gets called just after a GblTestScenario ends execution.
61 GBL_RESULT (*pFnEnd) (GBL_SELF);
62 //! Virtual function which implements the actual GblTestScenario execution behavior.
63 GBL_RESULT (*pFnRun) (GBL_SELF, int argc, const char* argv[]);
64 //! Virtual function which gets called just before a GblTestSuite begins execution.
65 GBL_RESULT (*pFnSuiteBegin)(GBL_SELF, const GblTestSuite* pSuite);
66 //! Virtual function which gets called just after a GblTestSuite ends execution.
67 GBL_RESULT (*pFnSuiteEnd) (GBL_SELF, const GblTestSuite* pSuite);
69
70/*! \struct GblTestScenario
71 * \extends GblContext
72 * \ingroup testing
73 * \brief Represents a single top-level test object.
74 *
75 * GblTestScenario is the highest-level test object in the
76 * testing framework, and is logically divided into a series
77 * of related, yet independently executing GblTestSuite
78 * objects.
79 *
80 * \sa GblTestScenarioClass, GblTestSuite
81 */
83 GBL_RESULT result; //!< Current overall result code from test scenario run.
84 size_t suitesRun; //!< Total number of test suites which have run.
85 size_t suitesPassed; //!< Total number of test suites which have passed during run.
86 size_t suitesFailed; //!< Total number of test suites which have failed during run.
87 size_t suitesSkipped; //!< Total number of test suites which have been skipped during run.
88 size_t caseCount; //!< Total number of test cases contained within all test suites contained within the test scenario.
89 size_t casesRun; //!< Total numer of test cases which have run.
90 size_t casesPassed; //!< Total number of test cases which have passed.
91 size_t casesFailed; //!< Total number of test cases which have failed.
92 size_t casesSkipped; //!< Total number of test cases which have been skipped.
93 double totalTime; //!< Total time spent executing tests, in milliseconds.
95
96// \cond
97GBL_PROPERTIES(GblTestScenario,
98 (testResult, GBL_GENERIC, (READ, SAVE), GBL_UINT32_TYPE),
99 (suiteCount, GBL_GENERIC, (READ, SAVE), GBL_UINT32_TYPE),
100 (suitesRun, GBL_GENERIC, (READ, SAVE), GBL_UINT32_TYPE),
101 (suitesPassed, GBL_GENERIC, (READ, SAVE), GBL_UINT32_TYPE),
102 (suitesFailed, GBL_GENERIC, (READ, SAVE), GBL_UINT32_TYPE),
103 (suitesSkipped, GBL_GENERIC, (READ, SAVE), GBL_UINT32_TYPE),
104 (caseCount, GBL_GENERIC, (READ, SAVE), GBL_UINT32_TYPE),
105 (casesRun, GBL_GENERIC, (READ, SAVE), GBL_UINT32_TYPE),
106 (casesPassed, GBL_GENERIC, (READ, SAVE), GBL_UINT32_TYPE),
107 (casesFailed, GBL_GENERIC, (READ, SAVE), GBL_UINT32_TYPE),
108 (casesSkipped, GBL_GENERIC, (READ, SAVE), GBL_UINT32_TYPE)
109)
110
111GBL_SIGNALS(GblTestScenario,
112 (began),
113 (ended),
114 (suiteBegan, (GBL_INSTANCE_TYPE, pSuite)),
115 (suiteEnded, (GBL_INSTANCE_TYPE, pSuite)),
116 (caseBegan, (GBL_INSTANCE_TYPE, pSuite), (GBL_SIZE_TYPE, caseIndex)),
117 (caseEnded, (GBL_INSTANCE_TYPE, pSuite), (GBL_SIZE_TYPE, caseIndex))
118)
119// \endcond
120
121//! Returns the GblType UUID associated with GblTestScenario.
123
124/*! \name Lifetime Management
125 * \brief Creation and reference ownership methods.
126 * @{
127 */
128//! Creates a GblTestScenario with the given name, optionally as an extended subtype with the given instance structure size and floating class.
129GBL_EXPORT GblTestScenario* GblTestScenario_create (const char* pName
130#if 0
131,
132 GblType type/*=GBL_TEST_SCENARIO_TYPE*/,
133 size_t size/*=sizeof(GblTestScenario)*/,
134 GBL_KLASS* pClass=/*NULL*/
135#endif
136 ) GBL_NOEXCEPT;
137//! Returns a new reference to an existing GblTestScenario instance, incrementing its reference counter.
139//! Releases a reference to the given GblTestScenario, destroying it when the reference counter hits zero.
141//! @}
142
143/*! \name Suite Management
144 * \brief Routines for managing child test suites.
145 * @{
146 */
147//! Enqueues the given GblTestSuite instance to be run as part of the given GblTestScenario's test plan.
149 const GblTestSuite* pSuite) GBL_NOEXCEPT;
150//! Finds a GblTestSuite by name which has been enqueued onto the given GblTestScenario.
152 const char* pName) GBL_NOEXCEPT;
153//! @}
154
155/*! \name Current Tests
156 * \brief Routines for querying the active tests.
157 * @{
158 */
159//! Returns a pointer to the currently executing GblTestSuite within the given GblTestScenario, if there is an active one.
161//! Returns the index of the currently executing test case within the currently executing GblTestSuite within the given GblTestScenario, if there is an active one, or GBL_NPOS otherwise.
163//! @}
164
165/*! \name Execution
166 * \brief Routines for starting text execution.
167 * @{
168 */
169//! Begins execution of the given GblTestScenario instance, running through all of its enqueued GblTestSuites, possibly processing the given command-line arguments.
170GBL_EXPORT GBL_RESULT GblTestScenario_run (GBL_SELF, int argc, const char* argv[]) GBL_NOEXCEPT;
171//! Variant of GblTestScenario_run() which releases the GblTestScenario after execution and returns a status code which can be directly returned from main().
172GBL_EXPORT int GblTestScenario_exec (GBL_SELF, int argc, const char* argv[]) GBL_NOEXCEPT;
173//! @}
174
175/*! \name Results
176 * \brief Routines for querying the overall results.
177 * @{
178 */
179//! Returns whether or not the given GblTestScenario has run.
181//! Returns whether or not the given GblTestScenario had any failing tests.
183//! @}
184
185//! Signals to an executing GblTestScenario that the next error raised by the active test case is expected and should not be considered a test failure.
187
189
190#undef GBL_SELF_TYPE
191
192#endif // GIMBAL_TEST_SCENARIO_H
#define GBL_NOEXCEPT
#define GBL_DECLS_BEGIN
#define GBL_FORWARD_DECLARE_STRUCT(S)
#define GBL_TYPEID(instanceStruct)
#define GBL_INSTANCE_DERIVE(derivedInstance, baseInstance)
#define GBL_CLASS_DERIVE(...)
#define GBL_INSTANCE_END
#define GBL_EXPORT
#define GBL_CLASS_END
#define GBL_UINT32_TYPE
Builtin ID for uint32_t GblVariant type.
#define GBL_PROPERTIES(object,...)
Declares a list of properties for the given object/instance structure.
#define GBL_SIGNALS(instanceStruct,...)
Declares a list of signals to be associated with the given instanceStruct.
void GblTestScenario_expectError(const GblTestScenario *pSelf)
Signals to an executing GblTestScenario that the next error raised by the active test case is expecte...
GBL_RESULT GblTestScenario_run(GblTestScenario *pSelf, int argc, const char *argv[])
Begins execution of the given GblTestScenario instance, running through all of its enqueued GblTestSu...
int GblTestScenario_exec(GblTestScenario *pSelf, int argc, const char *argv[])
Variant of GblTestScenario_run() which releases the GblTestScenario after execution and returns a sta...
GblTestSuite * GblTestScenario_currentSuite(const GblTestScenario *pSelf)
Returns a pointer to the currently executing GblTestSuite within the given GblTestScenario,...
GblTestSuite * GblTestScenario_findSuite(const GblTestScenario *pSelf, const char *pName)
Finds a GblTestSuite by name which has been enqueued onto the given GblTestScenario.
GblTestScenario * GblTestScenario_create(const char *pName)
Creates a GblTestScenario with the given name, optionally as an extended subtype with the given insta...
GblTestScenario * GblTestScenario_ref(GblTestScenario *pSelf)
Returns a new reference to an existing GblTestScenario instance, incrementing its reference counter.
GblBool GblTestScenario_passed(const GblTestScenario *pSelf)
Returns whether or not the given GblTestScenario had any failing tests.
GblType GblTestScenario_type(void)
Returns the GblType UUID associated with GblTestScenario.
size_t GblTestScenario_currentCase(const GblTestScenario *pSelf)
Returns the index of the currently executing test case within the currently executing GblTestSuite wi...
GblBool GblTestScenario_ran(const GblTestScenario *pSelf)
Returns whether or not the given GblTestScenario has run.
GblRefCount GblTestScenario_unref(GblTestScenario *pSelf)
Releases a reference to the given GblTestScenario, destroying it when the reference counter hits zero...
GBL_RESULT GblTestScenario_enqueueSuite(GblTestScenario *pSelf, const GblTestSuite *pSuite)
Enqueues the given GblTestSuite instance to be run as part of the given GblTestScenario's test plan.
uint8_t GblBool
Basic boolean type, standardized to sizeof(char)
uint16_t GblRefCount
Type able to hold a reference counter across the codebase.
uintptr_t GblType
Meta Type UUID.
Definition gimbal_type.h:52
Represents a single top-level test object.
size_t caseCount
Total number of test cases contained within all test suites contained within the test scenario.
size_t casesPassed
Total number of test cases which have passed.
size_t casesRun
Total numer of test cases which have run.
double totalTime
Total time spent executing tests, in milliseconds.
GBL_RESULT result
Current overall result code from test scenario run.
size_t casesSkipped
Total number of test cases which have been skipped.
size_t suitesFailed
Total number of test suites which have failed during run.
size_t suitesSkipped
Total number of test suites which have been skipped during run.
size_t suitesRun
Total number of test suites which have run.
size_t casesFailed
Total number of test cases which have failed.
size_t suitesPassed
Total number of test suites which have passed during run.