UTPP
Loading...
Searching...
No Matches
utpp.h
Go to the documentation of this file.
1#pragma once
2/*
3 UTPP - A New Generation of UnitTest++
4 (c) Mircea Neacsu 2017-2024
5
6 See LICENSE file for full copyright information.
7*/
8
16
17#ifdef _WIN32
18#if !defined(_CRT_SECURE_NO_WARNINGS)
19#define _CRT_SECURE_NO_WARNINGS 1
20#endif
21//Acrobatics to leave out winsock.h (for the benefit of winsock2.h)
22#ifndef _WINSOCKAPI_
23#define _WINSOCKAPI_
24#define MUST_UNDEF_WINSOCK
25#endif
26
27#include <windows.h>
28
29#ifdef MUST_UNDEF_WINSOCK
30#undef _WINSOCKAPI_
31#undef MUST_UNDEF_WINSOCK
32#endif
33
34#endif
35
36#include <string>
37#include <deque>
38#include <stdexcept>
39#include <sstream>
40#include <cassert>
41#ifndef _WIN32
42#include <sys/time.h>
43#include <sys/stat.h>
44#include <unistd.h>
45#endif
46
47namespace UnitTest {
48
50const size_t MAX_MESSAGE_SIZE = 1024;
51
52}
54#define DEFAULT_SUITE "DefaultSuite"
55
56//------------------------------ Test macros ----------------------------------
57#ifdef TEST
58#error Macro TEST is already defined
59#endif
60
61#ifdef TEST_FIXTURE
62#error Macro TEST_FIXTURE is already defined
63#endif
64
65#ifdef SUITE
66#error Macro SUITE is already defined
67#endif
68
69/* VC doesn't define the proper value for __cplusplus but _MSVC_LANG is correct.
70 Fake it here for non-MS compilers
71*/
72#ifndef _MSVC_LANG
73#define _MSVC_LANG __cplusplus
74#endif
75
91
92#if _MSVC_LANG < 201703L
93#define TEST_MAIN(ARGC, ARGV) \
94UnitTest::Test *UnitTest::CurrentTest; \
95UnitTest::Reporter *UnitTest::CurrentReporter; \
96double UnitTest::default_tolerance; \
97std::string UnitTest::CurrentSuite; \
98int main (ARGC,ARGV)
99#else
100#define TEST_MAIN(ARGC, ARGV) int main (ARGC, ARGV)
101#endif
102
103
108
119#define SUITE(Name) \
120 namespace Suite##Name \
121 { \
122 inline char const* GetSuiteName () { return #Name ; } \
123 } \
124 namespace Suite##Name
125
132#define TEST(Name) \
133 class Test##Name : public UnitTest::Test \
134 { \
135 public: \
136 Test##Name() : Test(#Name) {} \
137 private: \
138 void RunImpl() override; \
139 }; \
140 UnitTest::Test* Name##_maker() {return new Test##Name; } \
141 UnitTest::TestSuite::Inserter Name##_inserter (GetSuiteName(), #Name, __FILE__, __LINE__,\
142 Name##_maker); \
143 void Test##Name::RunImpl()
144
145
157#define TEST_FIXTURE(Fixture, Name) \
158 class Fixture##Name##Helper : public Fixture, public UnitTest::Test \
159 { \
160 public: \
161 Fixture##Name##Helper() : Fixture (), Test(#Name) {} \
162 private: \
163 void RunImpl() override; \
164 }; \
165 UnitTest::Test* Name##_maker() {return new Fixture##Name##Helper;} \
166 UnitTest::TestSuite::Inserter Name##_inserter (GetSuiteName(), #Name, \
167 __FILE__, __LINE__, Name##_maker); \
168 void Fixture##Name##Helper::RunImpl()
169
170#ifdef ABORT
171#error Macro ABORT is already defined
172#endif
173
180#define ABORT(value) \
181 do \
182 { \
183 if (UnitTest::Check(value)) \
184 throw UnitTest::test_abort (__FILE__, __LINE__, #value); \
185 } while (0)
186
187#ifdef ABORT_EX
188#error Macro ABORT_EX is already defined
189#endif
190
197#define ABORT_EX(value, ...) \
198 do \
199 { \
200 if (UnitTest::Check(value)) { \
201 char message[UnitTest::MAX_MESSAGE_SIZE]; \
202 snprintf (message, UnitTest::MAX_MESSAGE_SIZE, __VA_ARGS__); \
203 throw UnitTest::test_abort (__FILE__, __LINE__, message); \
204 } \
205 } while (0)
206
208
211
218#define UTPP_TIME_CONSTRAINT(ms) \
219 UnitTest::TimeConstraint unitTest__timeConstraint__(ms, __FILE__, __LINE__)
220
226#define UTPP_TIME_CONSTRAINT_EXEMPT() no_time_constraint ()
227
229
230namespace UnitTest {
231
232// forward declarations
233struct Failure;
234class TestSuite;
235
236void ReportFailure(const std::string& filename, int line, const std::string& message);
237
239class Test
240{
241public:
242 Test (const std::string& testName);
243 virtual ~Test() {};
244 void no_time_constraint ();
245 bool is_time_constraint () const;
246
247 int failure_count () const;
248 int test_time_ms () const;
249 const std::string& test_name () const;
250
251 void failure ();
252 void run ();
253
255 virtual void RunImpl () {};
256
257protected:
258 std::string name;
260 int time;
262
263private:
264 Test (Test const&) = delete;
265 Test& operator =(Test const&) = delete;
266 friend class TestSuite;
267};
268
271{
272 std::string filename;
273 std::string message;
275};
276
277
279class Reporter
280{
281public:
282 Reporter ();
283 virtual ~Reporter () {};
284
286 void SetTrace (bool on_off) { trace = on_off; }
287
289 virtual void SuiteStart (const TestSuite& suite);
290
292 virtual void TestStart (const Test& test);
293
295 virtual void ReportFailure (const Failure& failure);
296
298 virtual void TestFinish (const Test& test);
299
301 virtual int SuiteFinish (const TestSuite& suite);
302
304 virtual int Summary () { return total_failed_count; }
305
307 virtual void Clear ();
308
309protected:
314
319
321 bool trace;
322
323};
324
326class ReporterDeferred : public Reporter
327{
328public:
329 ReporterDeferred () {};
330 void SuiteStart (const TestSuite& suite) override;
331 void TestStart (const Test& test) override;
332 void ReportFailure (const Failure& failure) override;
333 void TestFinish (const Test& test) override;
334 void Clear () override;
335
336protected:
339 {
340 TestResult ();
341 TestResult (const std::string& suite, const std::string& test);
342
343 std::string suite_name;
344 std::string test_name;
346 std::deque<Failure> failures;
347 };
348
349 std::deque<TestResult> results;
350};
351
353typedef UnitTest::Test* (*Testmaker)();
354
361class TestSuite
362{
363public:
366 {
367 public:
368 Inserter (const std::string& suite,
369 const std::string& test,
370 const std::string& file,
371 int line,
372 Testmaker func);
373
374 private:
375 const std::string test_name,
376 file_name;
377 const int line;
378 const Testmaker maker;
379
380 friend class TestSuite;
381 };
382
383 explicit TestSuite (const std::string& name);
384 void Add (const Inserter* inf);
385 bool IsEnabled () const;
386 void Enable (bool on_off);
387 int RunTests (Reporter& reporter, int max_runtime_ms);
388
389 std::string name;
390
391private:
392 std::deque <const Inserter*> test_list;
393 int max_runtime;
394 bool enabled;
395
396 bool SetupCurrentTest (const Inserter* inf);
397 void RunCurrentTest (const Inserter* inf);
398 void TearDownCurrentTest (const Inserter* inf);
399};
400
402class Timer
403{
404public:
405 Timer ();
406 void Start ();
407 int GetTimeInMs () const;
408 long long GetTimeInUs () const;
409
410private:
411 long long GetTime () const;
412 long long startTime;
413 static double frequency();
414};
415
418{
419public:
420 TimeConstraint (int ms, const char* file, int line);
422
423private:
424 void operator=(TimeConstraint const&) = delete;
425 TimeConstraint (TimeConstraint const&) = delete;
426
427 Timer timer;
428 std::string filename;
429 int line_number;
430 int const max_ms;
431};
432
435public:
436 void Add (const std::string& suite, const TestSuite::Inserter* inf);
437 int Run (const std::string& suite, Reporter& reporter, int max_time_ms);
438 int RunAll (Reporter& reporter, int max_time_ms);
439 static SuitesList& GetSuitesList ();
440 void Enable (const std::string& suite, bool enable = true);
441
442private:
443
444 std::deque <TestSuite> suites;
445};
446
448struct test_abort : public std::runtime_error
449{
450 test_abort (const char* file_, int line_, const char* msg)
451 : std::runtime_error (msg)
452 , file (file_)
453 , line (line_)
454 {};
455 const char* file;
456 int line;
457};
458
459struct tolerance_not_set : public std::runtime_error
460{
461 tolerance_not_set ()
462 : std::runtime_error ("UnitTest::default_tolerance not set")
463 {};
464};
465
467extern Test* CurrentTest;
468
470extern std::string CurrentSuite;
471
474
477
479int RunAllTests (Reporter& rpt = GetDefaultReporter (), int max_time_ms = 0);
480
482void DisableSuite (const std::string& suite_name);
483
485void EnableSuite (const std::string& suite_name);
486
488int RunSuite (const char *suite_name, Reporter& rpt = GetDefaultReporter (), int max_time_ms = 0);
489
491void ReportFailure (const std::string& filename, int line, const std::string& message);
492
493//-------------------------- Test member functions ----------------------------
495inline
496Test::Test(const std::string& test_name)
497 : name(test_name)
498 , failures(0)
499 , time(0)
500 , time_exempt(false)
501{
502}
503
509inline
511{
512 Timer test_timer;
513 test_timer.Start();
514
515 RunImpl();
516 time = test_timer.GetTimeInMs();
517}
518
522inline
524{
525 failures++;
526}
527
529inline
531{
532 return failures;
533}
534
536inline
538{
539 return time;
540}
541
543inline
544const std::string& Test::test_name () const
545{
546 return name;
547}
548
550inline
552{
553 time_exempt = true;
554}
555
557inline
559{
560 return !time_exempt;
561}
562
563//--------------------- Reporter member functions -----------------------------
564inline
565Reporter::Reporter ()
566 : suite_test_count (0)
567 , suite_failed_count (0)
568 , suite_failures_count (0)
569 , suite_time_msec (0)
570 , total_test_count (0)
571 , total_failed_count (0)
572 , total_failures_count (0)
573 , total_time_msec (0)
574 , suites_count (0)
575 , trace (false)
576{
577}
578
580inline
586
587inline
589{
592}
593
594inline
596{
597}
598
599inline
601{
602 int f = t.failure_count ();
603 if (f)
604 {
609 }
610 int ms = t.test_time_ms ();
611 suite_time_msec += ms;
612 total_time_msec += ms;
613}
614
616inline
618{
620}
621
622
623inline
638
639//------------------- ReporterDeferred member functions -----------------------
641inline
646
648inline
649ReporterDeferred::TestResult::TestResult (const std::string& suite, const std::string& test)
650 : suite_name (suite)
651 , test_name (test)
652 , test_time_ms (0)
653{
654}
655
663inline
665{
666 results.push_back (TestResult (suite.name, std::string()));
667}
668
675inline
677{
678 Reporter::TestStart (test);
679 results.push_back (TestResult (CurrentSuite, test.test_name ()));
680}
681
686inline
688{
689 assert (!results.empty ());
690
691 Reporter::ReportFailure (failure);
692 results.back ().failures.push_back (failure);
693}
694
699inline
701{
703 results.back ().test_time_ms = test.test_time_ms ();
704}
705
707{
709 results.clear ();
710}
711
712
713//------------------- TestSuite member functions ------------------------------
714
715inline
716TestSuite::TestSuite (const std::string& name_)
717 : name (name_)
718 , max_runtime (0)
719 , enabled (true)
720{
721}
722
731inline
732void TestSuite::Add (const Inserter* inf)
733{
734 test_list.push_back (inf);
735}
736
746inline
747int TestSuite::RunTests (Reporter& rep, int maxtime)
748{
751 CurrentReporter = &rep;
752
754 CurrentReporter->SuiteStart (*this);
755 std::deque <const Inserter*>::iterator listp = test_list.begin ();
756 max_runtime = maxtime;
757 while (listp != test_list.end ())
758 {
760 if (SetupCurrentTest (*listp))
761 {
762 RunCurrentTest (*listp);
763 TearDownCurrentTest (*listp);
764 }
766 ++listp;
767 }
769 return CurrentReporter->SuiteFinish (*this);
770}
771
781inline
782bool TestSuite::SetupCurrentTest (const Inserter* inf)
783{
784 bool ok = false;
785 try {
786 CurrentTest = (inf->maker)();
787 ok = true;
788 }
789 catch (UnitTest::test_abort& x)
790 {
791 std::stringstream stream;
792 stream << " Aborted setup of " << inf->test_name << " - " << x.what ();
793 CurrentTest = new Test (inf->test_name); //mock-up to keep ReportFailure happy
794 ReportFailure (x.file, x.line, stream.str ());
795 delete CurrentTest;
796 CurrentTest = 0;
797 }
798 catch (const std::exception& e)
799 {
800 std::stringstream stream;
801 stream << "Unhandled exception: " << e.what ()
802 << " while setting up test " << inf->test_name;
803 CurrentTest = new Test (inf->test_name); //mock-up to keep ReportFailure happy
804 ReportFailure (inf->file_name, inf->line, stream.str ());
805 delete CurrentTest;
806 CurrentTest = 0;
807 }
808 catch (...)
809 {
810 std::stringstream stream;
811 stream << "Setup unhandled exception while setting up test " << inf->test_name;
812 CurrentTest = new Test (inf->test_name); //mock-up to keep ReportFailure happy
813 ReportFailure (inf->file_name, inf->line, stream.str ());
814 delete CurrentTest;
815 CurrentTest = 0;
816 }
817 return ok;
818}
819
821inline
822void TestSuite::RunCurrentTest (const Inserter* inf)
823{
824 assert (CurrentTest);
825 CurrentReporter->TestStart (*CurrentTest);
826
827
828 try {
829 CurrentTest->run ();
830 }
831 catch (UnitTest::test_abort& x)
832 {
833 ReportFailure (x.file, x.line, std::string ("Test aborted: ") + x.what ());
834 }
835 catch (const std::exception& e)
836 {
837 std::stringstream stream;
838 stream << "Unhandled exception: " << e.what ()
839 << " while running test " << inf->test_name;
840 ReportFailure (inf->file_name, inf->line, stream.str ());
841 }
842 catch (...)
843 {
844 std::stringstream stream;
845 stream << "Unhandled exception while running test " << inf->test_name;
846 ReportFailure (inf->file_name, inf->line, stream.str ());
847 }
848
849 int actual_time = CurrentTest->test_time_ms ();
850 if (CurrentTest->is_time_constraint () && max_runtime && actual_time > max_runtime)
851 {
852 std::stringstream stream;
853 stream << "Global time constraint failed while running test " << inf->test_name
854 << " Expected under " << max_runtime
855 << "ms but took " << actual_time << "ms.";
856
857 ReportFailure (inf->file_name, inf->line, stream.str ());
858 }
859 CurrentReporter->TestFinish (*CurrentTest);
860}
861
863inline
864void TestSuite::TearDownCurrentTest (const Inserter* inf)
865{
866 try {
867 delete CurrentTest;
868 CurrentTest = 0;
869 }
870 catch (const std::exception& e)
871 {
872 std::stringstream stream;
873 stream << "Unhandled exception: " << e.what ()
874 << " while tearing down test " << inf->test_name;
875 ReportFailure (inf->file_name, inf->line, stream.str ());
876 }
877 catch (...)
878 {
879 std::stringstream stream;
880 stream << "Unhandled exception tearing down test " << inf->test_name;
881 ReportFailure (inf->file_name, inf->line, stream.str ());
882 }
883}
884
886inline
888{
889 return enabled;
890}
891
893inline
894void TestSuite::Enable (bool on_off)
895{
896 enabled = on_off;
897}
898
899//------------------ TestSuite::Inserter --------------------------------------
910inline
911TestSuite::Inserter::Inserter (const std::string& suite, const std::string& test,
912 const std::string& file, int ln, Testmaker func)
913 : test_name (test)
914 , file_name (file)
915 , line (ln)
916 , maker (func)
917{
918 SuitesList::GetSuitesList ().Add (suite, this);
919}
920
921//-----------------Timer member functions -------------------------------------
922inline
923Timer::Timer ()
924 : startTime (0)
925{
926}
927
929inline
931{
932 startTime = GetTime ();
933}
934
936inline
938{
939 long long elapsedTime = GetTime () - startTime;
940 double seconds = (double)elapsedTime / frequency ();
941 return int (seconds * 1000.0);
942}
943
945inline
946long long Timer::GetTimeInUs () const
947{
948 long long int elapsedTime = GetTime () - startTime;
949 double seconds = (double)elapsedTime / frequency ();
950 return (long long int) (seconds * 1000000.0);
951}
952
953inline
954long long Timer::GetTime () const
955{
956#ifdef _WIN32
957 LARGE_INTEGER curTime;
958 ::QueryPerformanceCounter (&curTime);
959 return curTime.QuadPart;
960#else
961 struct timeval currentTime;
962 gettimeofday (&currentTime, 0);
963 return currentTime.tv_sec * (long long)frequency () + currentTime.tv_usec;
964#endif
965}
966
967inline
968double Timer::frequency ()
969{
970 static long long f;
971#ifdef _WIN32
972 if (!f)
973 ::QueryPerformanceFrequency (reinterpret_cast<LARGE_INTEGER*>(&f));
974#else
975 f = 1000000;
976#endif
977 return (double)f;
978}
979
981inline
982void SleepMs (int const ms)
983{
984#ifdef _WIN32
985 ::Sleep (ms);
986#else
987 usleep (static_cast<useconds_t>(ms * 1000));
988#endif
989}
990
991//------------------TimeConstraint member functions ---------------------------
992
1002inline
1003TimeConstraint::TimeConstraint (int ms, const char* file, int line)
1004 : filename (file)
1005 , line_number (line)
1006 , max_ms (ms)
1007{
1008 timer.Start ();
1009}
1010
1015inline
1017{
1018 int t = timer.GetTimeInMs ();
1019 if (t > max_ms)
1020 {
1021 std::stringstream stream;
1022 stream << "Time constraint failed. Expected to run test under " << max_ms <<
1023 "ms but took " << t << "ms.";
1024
1025 ReportFailure (filename, line_number, stream.str ());
1026 }
1027}
1028
1029
1030//-------------------SuitesList member functions ------------------------------
1031
1040inline
1041void SuitesList::Add (const std::string& suite_name, const TestSuite::Inserter* inf)
1042{
1043 auto p = suites.begin ();
1044 while (p != suites.end () && p->name != suite_name)
1045 p++;
1046
1047 if (p == suites.end ())
1048 {
1049 suites.emplace_back (suite_name);
1050 suites.back ().Add (inf);
1051 }
1052 else
1053 p->Add (inf);
1054}
1055
1065inline
1066int SuitesList::Run (const std::string& suite_name, Reporter& reporter, int max_time_ms)
1067{
1068 for (auto& s : suites)
1069 {
1070 if (s.name == suite_name)
1071 {
1072 s.RunTests (reporter, max_time_ms);
1073 return reporter.Summary ();
1074 }
1075 }
1076 return -1;
1077}
1078
1086inline
1087int SuitesList::RunAll (Reporter& reporter, int max_time_ms)
1088{
1089 for (auto& s : suites)
1090 {
1091 if (s.IsEnabled ())
1092 s.RunTests (reporter, max_time_ms);
1093 }
1094
1095 return reporter.Summary ();
1096}
1097
1102inline
1104{
1105 static SuitesList all_suites;
1106 return all_suites;
1107}
1108
1116inline
1117void SuitesList::Enable (const std::string& suite, bool enable)
1118{
1119 for (auto& s : suites)
1120 {
1121 if (s.name == suite)
1122 {
1123 s.Enable (enable);
1124 break;
1125 }
1126 }
1127}
1128
1130
1144inline
1145int RunAllTests (Reporter& rpt, int max_time_ms)
1146{
1147 rpt.Clear ();
1148 return SuitesList::GetSuitesList ().RunAll (rpt, max_time_ms);
1149}
1150
1162inline
1163int RunSuite (const char* suite_name, Reporter& rpt, int max_time_ms)
1164{
1165 return SuitesList::GetSuitesList ().Run (suite_name, rpt, max_time_ms);
1166}
1167
1176inline
1177void DisableSuite (const std::string& suite_name)
1178{
1179 SuitesList::GetSuitesList ().Enable (suite_name, false);
1180}
1181
1189inline
1190void EnableSuite (const std::string& suite_name)
1191{
1192 SuitesList::GetSuitesList ().Enable (suite_name, true);
1193}
1194
1204inline
1205void ReportFailure(const std::string& filename, int line, const std::string& message)
1206{
1207 if (CurrentTest)
1208 CurrentTest->failure();
1209 Failure f = { filename, message, line };
1210 CurrentReporter->ReportFailure(f);
1211}
1212
1213} // end of UnitTest namespace
1214
1215
1220inline
1221const char* GetSuiteName ()
1222{
1223 return DEFAULT_SUITE;
1224}
1225
1226#include "reporter_stream.h"
1227#include "reporter_xml.h"
1228#ifdef _WIN32
1229#include "reporter_dbgout.h"
1230#endif
1231#include "checks.h"
1232
1234inline
1236{
1237 static UnitTest::ReporterStream the_default_reporter;
1238 return the_default_reporter;
1239}
1240
1241#if (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) \
1242 || (!defined(_MSVC_LANG) && (__cplusplus >= 201703L))
1243// In C++ 17 and later we have inline data. TEST_MAIN is not really needed.
1246inline std::string UnitTest::CurrentSuite;
1247#endif
Definition of Check... template functions and CHECK_... macro-definitions.
void Clear() override
Reset all statistics.
Definition utpp.h:706
void TestStart(const Test &test) override
Definition utpp.h:676
std::deque< TestResult > results
Results of all tests.
Definition utpp.h:349
void ReportFailure(const Failure &failure) override
Definition utpp.h:687
void SuiteStart(const TestSuite &suite) override
Definition utpp.h:664
void TestFinish(const Test &test) override
Definition utpp.h:700
Abstract base for all reporters.
Definition utpp.h:280
virtual void Clear()
Reset all statistics.
Definition utpp.h:624
int suites_count
number of suites ran
Definition utpp.h:320
int suite_failures_count
number of failures in suite
Definition utpp.h:312
int total_failures_count
total number of failures
Definition utpp.h:317
int suite_test_count
number of tests in suite
Definition utpp.h:310
virtual void SuiteStart(const TestSuite &suite)
Invoked at the beginning of a test suite.
Definition utpp.h:581
virtual void TestStart(const Test &test)
Invoked at the beginning of a test.
Definition utpp.h:588
bool trace
true if tracing is enabled
Definition utpp.h:321
int suite_failed_count
number of failed tests in suite
Definition utpp.h:311
virtual void TestFinish(const Test &test)
Invoked at the end of a test.
Definition utpp.h:600
int suite_time_msec
total suite running time in milliseconds
Definition utpp.h:313
int total_test_count
total number of tests
Definition utpp.h:315
virtual void ReportFailure(const Failure &failure)
Called when a test has failed.
Definition utpp.h:595
virtual int Summary()
Generate results report.
Definition utpp.h:304
int total_failed_count
total number of failed tests
Definition utpp.h:316
virtual int SuiteFinish(const TestSuite &suite)
Invoked at the end of a test suite.
Definition utpp.h:617
int total_time_msec
total running time in milliseconds
Definition utpp.h:318
void SetTrace(bool on_off)
Controls test tracing feature.
Definition utpp.h:286
A Reporter that sends results directly to an output stream.
Definition reporter_stream.h:21
A singleton object containing all test suites.
Definition utpp.h:434
void Add(const std::string &suite, const TestSuite::Inserter *inf)
Definition utpp.h:1041
void Enable(const std::string &suite, bool enable=true)
Definition utpp.h:1117
int RunAll(Reporter &reporter, int max_time_ms)
Definition utpp.h:1087
static SuitesList & GetSuitesList()
Definition utpp.h:1103
int Run(const std::string &suite, Reporter &reporter, int max_time_ms)
Definition utpp.h:1066
Representation of a test case.
Definition utpp.h:240
int failures
Number of failures in this test.
Definition utpp.h:259
void run()
Definition utpp.h:510
void failure()
Definition utpp.h:523
const std::string & test_name() const
Return test name.
Definition utpp.h:544
int failure_count() const
Return the number of failures in this test.
Definition utpp.h:530
int test_time_ms() const
Return test running time in milliseconds.
Definition utpp.h:537
virtual void RunImpl()
Actual body of test.
Definition utpp.h:255
Test(const std::string &testName)
Constructor.
Definition utpp.h:496
int time
Run time.
Definition utpp.h:260
bool is_time_constraint() const
Return true if test must be run under global time constraints.
Definition utpp.h:558
std::string name
Name of this test.
Definition utpp.h:258
bool time_exempt
true if exempt from time constraints
Definition utpp.h:261
void no_time_constraint()
Flags the test as exempt from global time constraint.
Definition utpp.h:551
Constructor of this objects inserts the test in suite.
Definition utpp.h:366
Inserter(const std::string &suite, const std::string &test, const std::string &file, int line, Testmaker func)
Definition utpp.h:911
Definition utpp.h:362
std::string name
Suite name.
Definition utpp.h:389
bool IsEnabled() const
Returns true if suite is enabled.
Definition utpp.h:887
void Add(const Inserter *inf)
Definition utpp.h:732
int RunTests(Reporter &reporter, int max_runtime_ms)
Definition utpp.h:747
void Enable(bool on_off)
Enables or disables this suite.
Definition utpp.h:894
~TimeConstraint()
Definition utpp.h:1016
TimeConstraint(int ms, const char *file, int line)
Definition utpp.h:1003
An object that can be interrogated to get elapsed time.
Definition utpp.h:403
void Start()
Record starting time.
Definition utpp.h:930
int GetTimeInMs() const
Return elapsed time in milliseconds since the starting time.
Definition utpp.h:937
long long GetTimeInUs() const
Return elapsed time in microseconds since the starting time.
Definition utpp.h:946
int RunAllTests(Reporter &rpt=GetDefaultReporter(), int max_time_ms=0)
Run all tests from all test suites.
Definition utpp.h:1145
void EnableSuite(const std::string &suite_name)
Enable a test suite.
Definition utpp.h:1190
int RunSuite(const char *suite_name, Reporter &rpt=GetDefaultReporter(), int max_time_ms=0)
Run all tests from one suite.
Definition utpp.h:1163
void DisableSuite(const std::string &suite_name)
Disable a test suite.
Definition utpp.h:1177
Definition of UnitTest::ReporterDbgout class.
Definition of UnitTest::ReporterStream class.
Definition of UnitTest::ReporterXml class.
The failure object records the file name, the line number and a message.
Definition utpp.h:271
int line_number
Line number where the failure has occurred.
Definition utpp.h:274
std::string message
Description of failure.
Definition utpp.h:273
std::string filename
Name of file where a failure has occurred.
Definition utpp.h:272
Test results including all failure messages
Definition utpp.h:339
std::deque< Failure > failures
All failures of a test.
Definition utpp.h:346
std::string suite_name
suite name
Definition utpp.h:343
std::string test_name
test name
Definition utpp.h:344
TestResult()
Default constructor needed container inclusion.
Definition utpp.h:642
int test_time_ms
test running time in milliseconds
Definition utpp.h:345
Exception thrown by ABORT macro.
Definition utpp.h:449
UnitTest::Test *(* Testmaker)()
Function pointer to a function that creates a test object.
Definition utpp.h:353
#define DEFAULT_SUITE
Name of default suite.
Definition utpp.h:54
void ReportFailure(const std::string &filename, int line, const std::string &message)
Main error reporting function.
Definition utpp.h:1205
Reporter * CurrentReporter
Pointer to current reporter object.
Test * CurrentTest
Currently executing test.
std::string CurrentSuite
Name of currently running suite.
void SleepMs(int const ms)
Pause current thread for the specified time.
Definition utpp.h:982
Reporter & GetDefaultReporter()
Return the default reporter object.
Definition utpp.h:1235
const size_t MAX_MESSAGE_SIZE
Maximum size of message buffer for ..._EX macro definitions.
Definition utpp.h:50
const char * GetSuiteName()
Definition utpp.h:1221