@@ -70,70 +70,18 @@ class Test : public api::ExecutionContext, public TestFlags {
7070 API_AF (Initialize, printer::Printer *, printer, nullptr );
7171 };
7272
73- /* ! \details Initializes the test report.
74- *
75- * This must be called before any tests are even
76- * constructed.
77- *
78- */
7973 static void initialize (const Initialize &options);
80-
81- /* ! \details Finalizes the test report.
82- *
83- * This should be called after the last test
84- * has been deconstructed.
85- *
86- */
8774 static void finalize ();
8875
89- /* ! \details Parse command line options for running test types.
90- *
91- * This method searches for the following options and returns
92- * a value that has which tests to execute.
93- *
94- * - -execute_all
95- * - -api
96- * - -performance
97- * - -stress
98- * - -additional
99- *
100- * \code
101- * #include <test.hpp>
102- * #include <sys.hpp>
103- *
104- * int main(int argc, char * argv[]){
105- * Cli cli(argc, argv);
106- * u32 o_execute_flags = Test::parse_options(cli);
107- *
108- * Test::initialize(cli.name(), cli.version());
109- *
110- * if( o_execute_flags ){
111- * Test test("do nothing");
112- * test.execute(o_execute_flags);
113- * }
114- *
115- * Test::finalize();
116- *
117- * return 0;
118- * }
119- *
120- * \endcode
121- *
122- */
12376 static ExecuteFlags parse_execution_flags (const sys::Cli &cli);
124- static u32
125- parse_test ( const sys::Cli &cli, var::StringView name, u32 test_flag);
77+ static u32 parse_test ( const sys::Cli &cli, var::StringView name,
78+ u32 test_flag);
12679
12780 Test (var::StringView name);
12881 ~Test ();
12982
13083 void execute (const sys::Cli &cli);
13184
132- /* ! \details Executes the tests specified by \a o_flags.
133- *
134- * @param o_flags Bitmask of the tests to execute (e.g., Test::EXECUTE_API)
135- *
136- */
13785 void execute (ExecuteFlags execute_flags = ExecuteFlags::all) {
13886 if (execute_flags & ExecuteFlags::api) {
13987 execute_api_case ();
@@ -146,59 +94,17 @@ class Test : public api::ExecutionContext, public TestFlags {
14694 }
14795 }
14896
149- /* ! \details Executes the API test case. */
15097 void execute_api_case ();
151- /* ! \details Executes the performance test case. */
15298 void execute_performance_case ();
153- /* ! \details Executes the stress test case. */
15499 void execute_stress_case ();
155100
156- /* ! \details Executes the class api test.
157- *
158- * This method should be overridden by the inheriting
159- * class.
160- *
161- */
162101 virtual bool execute_class_api_case ();
163-
164- /* ! \details Executes the class performance test.
165- *
166- * This method should be overridden by the inheriting
167- * class.
168- *
169- */
170102 virtual bool execute_class_performance_case ();
171-
172- /* ! \details Executes the class stress test.
173- *
174- * This method should be overridden by the inheriting
175- * class.
176- *
177- */
178103 virtual bool execute_class_stress_case ();
179104
180- /* ! \details Returns the results of the test.
181- *
182- * If any single test case has a false result,
183- * the result of the test is false. Otherwise,
184- * the result is true.
185- *
186- */
187105 bool result () const { return m_test_result; }
188-
189- /* ! \details Returns the current value of the case result.
190- *
191- * When a case is opened, the case result is set to true (passing).
192- *
193- * Calling set_case_failed() or print_case_failed() will set
194- * the case result value to false.
195- *
196- * case_result() is the default return value of close_case().
197- *
198- */
199106 bool case_result () const { return m_case_result; }
200107
201- /* ! \details Sets the current case result to failed. */
202108 void set_case_failed () {
203109 m_case_result = false ;
204110 m_test_result = false ;
@@ -210,9 +116,8 @@ class Test : public api::ExecutionContext, public TestFlags {
210116 return true ;
211117 }
212118
213- printer ().key (
214- var::String ().format (" expect%d" , line),
215- var::String ().format (" %s failed" , function));
119+ printer ().key (var::String ().format (" expect%d" , line),
120+ var::String ().format (" %s failed" , function));
216121
217122 if (is_error ()) {
218123 printer ().object (" errorContext" , api::ExecutionContext::error ());
@@ -225,6 +130,42 @@ class Test : public api::ExecutionContext, public TestFlags {
225130
226131 static bool final_result () { return m_final_result; }
227132
133+ class TimedScope {
134+ public:
135+ TimedScope (Test &test, const var::StringView name,
136+ const chrono::MicroTime &minimum,
137+ const chrono::MicroTime &maximum)
138+ : m_test(test), m_name(name), m_start(test.case_timer().milliseconds()),
139+ m_minimum (minimum.milliseconds()), m_maximum(maximum.milliseconds()) {
140+ m_test.printer ().open_object (name);
141+ API_ASSERT (m_minimum < m_maximum);
142+ }
143+
144+ ~TimedScope () {
145+ const auto stop = m_test.case_timer ().milliseconds ();
146+ const auto duration = stop - m_start;
147+ m_test.printer ()
148+ .key (" minimum (ms)" , var::NumberString (m_minimum))
149+ .key (" maximum (ms)" , var::NumberString (m_maximum))
150+ .key (" duration (ms)" , var::NumberString (duration));
151+ if (duration < m_minimum) {
152+ m_test.printer ().error (" duration below minimum" );
153+ m_test.set_case_failed ();
154+ } else if ( duration > m_maximum ){
155+ m_test.printer ().error (" duration above maximum" );
156+ m_test.set_case_failed ();
157+ }
158+ m_test.printer ().close_object ();
159+ }
160+
161+ private:
162+ Test &m_test;
163+ var::StringView m_name;
164+ u32 m_start;
165+ u32 m_minimum;
166+ u32 m_maximum;
167+ };
168+
228169protected:
229170 const chrono::ClockTimer &case_timer () const { return m_case_timer; }
230171 chrono::ClockTimer &case_timer () { return m_case_timer; }
0 commit comments