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-2025
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#include <chrono>
42#ifndef _WIN32
43#include <sys/stat.h>
44#include <unistd.h>
45#endif
46
47// --------------- Global configuration options -------------------------------
48#define UTPP_VERSION "2.2.0"
49
50// --------------- end of configuration options -------------------------------
51
52namespace UnitTest {
53
55const size_t MAX_MESSAGE_SIZE = 1024;
56
57}
59#define DEFAULT_SUITE "DefaultSuite"
60
61//------------------------------ Test macros ----------------------------------
62#ifdef TEST
63#error Macro TEST is already defined
64#endif
65
66#ifdef TEST_FIXTURE
67#error Macro TEST_FIXTURE is already defined
68#endif
69
70#ifdef SUITE
71#error Macro SUITE is already defined
72#endif
73
74/* VC doesn't define the proper value for __cplusplus but _MSVC_LANG is correct.
75 Fake it here for non-MS compilers
76*/
77#ifndef _MSVC_LANG
78#define _MSVC_LANG __cplusplus
79#endif
80
96
97#if _MSVC_LANG < 201703L
98#define TEST_MAIN(ARGC, ARGV) \
99UnitTest::Test *UnitTest::CurrentTest; \
100UnitTest::Reporter *UnitTest::CurrentReporter; \
101double UnitTest::default_tolerance; \
102std::string UnitTest::CurrentSuite; \
103int main (ARGC,ARGV)
104#else
105#define TEST_MAIN(ARGC, ARGV) int main (ARGC, ARGV)
106#endif
107
108
113
124#define SUITE(Name) \
125 namespace Suite##Name \
126 { \
127 inline char const* GetSuiteName () { return #Name ; } \
128 } \
129 namespace Suite##Name
130
137#define TEST(Name) \
138 class Test##Name : public UnitTest::Test \
139 { \
140 public: \
141 Test##Name() : Test(#Name) {} \
142 private: \
143 void RunImpl() override; \
144 }; \
145 UnitTest::Test* Name##_maker() {return new Test##Name; } \
146 UnitTest::TestSuite::Inserter Name##_inserter (GetSuiteName(), #Name, __FILE__, __LINE__,\
147 Name##_maker); \
148 void Test##Name::RunImpl()
149
150
162#define TEST_FIXTURE(Fixture, Name) \
163 class Fixture##Name##Helper : public Fixture, public UnitTest::Test \
164 { \
165 public: \
166 Fixture##Name##Helper() : Fixture (), Test(#Name) {} \
167 private: \
168 void RunImpl() override; \
169 }; \
170 UnitTest::Test* Name##_maker() {return new Fixture##Name##Helper;} \
171 UnitTest::TestSuite::Inserter Name##_inserter (GetSuiteName(), #Name, \
172 __FILE__, __LINE__, Name##_maker); \
173 void Fixture##Name##Helper::RunImpl()
174
175#ifdef ABORT
176#error Macro ABORT is already defined
177#endif
178
185#define ABORT(value) \
186 do \
187 { \
188 if (UnitTest::Check(value)) \
189 throw UnitTest::test_abort (__FILE__, __LINE__, #value); \
190 } while (0)
191
192#ifdef ABORT_EX
193#error Macro ABORT_EX is already defined
194#endif
195
202#define ABORT_EX(value, ...) \
203 do \
204 { \
205 if (UnitTest::Check(value)) { \
206 char message[UnitTest::MAX_MESSAGE_SIZE]; \
207 snprintf (message, UnitTest::MAX_MESSAGE_SIZE, __VA_ARGS__); \
208 throw UnitTest::test_abort (__FILE__, __LINE__, message); \
209 } \
210 } while (0)
211
213
216
223#define UTPP_TIME_CONSTRAINT(ms) \
224 UnitTest::TimeConstraint unitTest__timeConstraint__(ms, __FILE__, __LINE__)
225
231#define UTPP_TIME_CONSTRAINT_EXEMPT() no_time_constraint ()
232
234
235namespace UnitTest {
236
237// forward declarations
238struct Failure;
239class TestSuite;
240
241void ReportFailure(const std::string& filename, int line, const std::string& message);
242
244class Test
245{
246public:
247 Test (const std::string& testName);
248 virtual ~Test() {};
249 void no_time_constraint ();
250 bool is_time_constraint () const;
251
252 int failure_count () const;
253 int test_time_ms () const;
254 const std::string& test_name () const;
255
256 void failure ();
257 void run ();
258
260 virtual void RunImpl () {};
261
262protected:
263 std::string name;
265 int time;
267
268private:
269 Test (Test const&) = delete;
270 Test& operator =(Test const&) = delete;
271 friend class TestSuite;
272};
273
276{
277 std::string filename;
278 std::string message;
280};
281
282
284class Reporter
285{
286public:
287 Reporter ();
288 virtual ~Reporter () {};
289
291 void SetTrace (bool on_off) { trace = on_off; }
292
294 virtual void SuiteStart (const TestSuite& suite);
295
297 virtual void TestStart (const Test& test);
298
300 virtual void ReportFailure (const Failure& failure);
301
303 virtual void TestFinish (const Test& test);
304
306 virtual int SuiteFinish (const TestSuite& suite);
307
309 virtual int Summary () { return total_failed_count; }
310
312 virtual void Clear ();
313
314protected:
319
324
326 bool trace;
327
328};
329
331class ReporterDeferred : public Reporter
332{
333public:
334 ReporterDeferred () {};
335 void SuiteStart (const TestSuite& suite) override;
336 void TestStart (const Test& test) override;
337 void ReportFailure (const Failure& failure) override;
338 void TestFinish (const Test& test) override;
339 void Clear () override;
340
341protected:
344 {
345 TestResult ();
346 TestResult (const std::string& suite, const std::string& test);
347
348 std::string suite_name;
349 std::string test_name;
351 std::deque<Failure> failures;
352 };
353
354 std::deque<TestResult> results;
355};
356
358typedef UnitTest::Test* (*Testmaker)();
359
366class TestSuite
367{
368public:
371 {
372 public:
373 Inserter (const std::string& suite,
374 const std::string& test,
375 const std::string& file,
376 int line,
377 Testmaker func);
378
379 private:
380 const std::string test_name,
381 file_name;
382 const int line;
383 const Testmaker maker;
384
385 friend class TestSuite;
386 };
387
388 explicit TestSuite (const std::string& name);
389 void Add (const Inserter* inf);
390 bool IsEnabled () const;
391 void Enable (bool on_off);
392 int RunTests (Reporter& reporter, int max_runtime_ms);
393
394 std::string name;
395
396private:
397 std::deque <const Inserter*> test_list;
398 int max_runtime;
399 bool enabled;
400
401 bool SetupCurrentTest (const Inserter* inf);
402 void RunCurrentTest (const Inserter* inf);
403 void TearDownCurrentTest (const Inserter* inf);
404};
405
407class Timer
408{
409public:
410 Timer ();
411 void Start ();
412 int GetTimeInMs () const;
413 long long GetTimeInUs () const;
414
415private:
416 std::chrono::steady_clock::time_point startTime;
417};
418
421{
422public:
423 TimeConstraint (int ms, const char* file, int line);
425
426private:
427 void operator=(TimeConstraint const&) = delete;
428 TimeConstraint (TimeConstraint const&) = delete;
429
430 Timer timer;
431 std::string filename;
432 int line_number;
433 int const max_ms;
434};
435
438public:
439 void Add (const std::string& suite, const TestSuite::Inserter* inf);
440 int Run (const std::string& suite, Reporter& reporter, int max_time_ms);
441 int RunAll (Reporter& reporter, int max_time_ms);
442 static SuitesList& GetSuitesList ();
443 void Enable (const std::string& suite, bool enable = true);
444
445private:
446
447 std::deque <TestSuite> suites;
448};
449
451struct test_abort : public std::runtime_error
452{
453 test_abort (const char* file_, int line_, const char* msg)
454 : std::runtime_error (msg)
455 , file (file_)
456 , line (line_)
457 {};
458 const char* file;
459 int line;
460};
461
462struct tolerance_not_set : public std::runtime_error
463{
464 tolerance_not_set ()
465 : std::runtime_error ("UnitTest::default_tolerance not set")
466 {};
467};
468
470extern Test* CurrentTest;
471
473extern std::string CurrentSuite;
474
477
480
482int RunAllTests (Reporter& rpt = GetDefaultReporter (), int max_time_ms = 0);
483
485void DisableSuite (const std::string& suite_name);
486
488void EnableSuite (const std::string& suite_name);
489
491int RunSuite (const char *suite_name, Reporter& rpt = GetDefaultReporter (), int max_time_ms = 0);
492
494void ReportFailure (const std::string& filename, int line, const std::string& message);
495
496//-------------------------- Test member functions ----------------------------
498inline
499Test::Test(const std::string& test_name)
500 : name(test_name)
501 , failures(0)
502 , time(0)
503 , time_exempt(false)
504{
505}
506
512inline
514{
515 Timer test_timer;
516 test_timer.Start();
517
518 RunImpl();
519 time = test_timer.GetTimeInMs();
520}
521
525inline
527{
528 failures++;
529}
530
532inline
534{
535 return failures;
536}
537
539inline
541{
542 return time;
543}
544
546inline
547const std::string& Test::test_name () const
548{
549 return name;
550}
551
553inline
555{
556 time_exempt = true;
557}
558
560inline
562{
563 return !time_exempt;
564}
565
566//--------------------- Reporter member functions -----------------------------
567inline
568Reporter::Reporter ()
569 : suite_test_count (0)
570 , suite_failed_count (0)
571 , suite_failures_count (0)
572 , suite_time_msec (0)
573 , total_test_count (0)
574 , total_failed_count (0)
575 , total_failures_count (0)
576 , total_time_msec (0)
577 , suites_count (0)
578 , trace (false)
579{
580}
581
583inline
589
590inline
592{
595}
596
597inline
599{
600}
601
602inline
604{
605 int f = t.failure_count ();
606 if (f)
607 {
612 }
613 int ms = t.test_time_ms ();
614 suite_time_msec += ms;
615 total_time_msec += ms;
616}
617
619inline
621{
623}
624
625
626inline
641
642//------------------- ReporterDeferred member functions -----------------------
644inline
649
651inline
652ReporterDeferred::TestResult::TestResult (const std::string& suite, const std::string& test)
653 : suite_name (suite)
654 , test_name (test)
655 , test_time_ms (0)
656{
657}
658
666inline
668{
669 results.push_back (TestResult (suite.name, std::string()));
670}
671
678inline
680{
681 Reporter::TestStart (test);
682 results.push_back (TestResult (CurrentSuite, test.test_name ()));
683}
684
689inline
691{
692 assert (!results.empty ());
693
694 Reporter::ReportFailure (failure);
695 results.back ().failures.push_back (failure);
696}
697
702inline
704{
706 results.back ().test_time_ms = test.test_time_ms ();
707}
708
710{
712 results.clear ();
713}
714
715
716//------------------- TestSuite member functions ------------------------------
717
718inline
719TestSuite::TestSuite (const std::string& name_)
720 : name (name_)
721 , max_runtime (0)
722 , enabled (true)
723{
724}
725
734inline
735void TestSuite::Add (const Inserter* inf)
736{
737 test_list.push_back (inf);
738}
739
749inline
750int TestSuite::RunTests (Reporter& rep, int maxtime)
751{
754 CurrentReporter = &rep;
755
757 CurrentReporter->SuiteStart (*this);
758 std::deque <const Inserter*>::iterator listp = test_list.begin ();
759 max_runtime = maxtime;
760 while (listp != test_list.end ())
761 {
763 if (SetupCurrentTest (*listp))
764 {
765 RunCurrentTest (*listp);
766 TearDownCurrentTest (*listp);
767 }
769 ++listp;
770 }
772 return CurrentReporter->SuiteFinish (*this);
773}
774
784inline
785bool TestSuite::SetupCurrentTest (const Inserter* inf)
786{
787 bool ok = false;
788 try {
789 CurrentTest = (inf->maker)();
790 ok = true;
791 }
792 catch (UnitTest::test_abort& x)
793 {
794 std::stringstream stream;
795 stream << " Aborted setup of " << inf->test_name << " - " << x.what ();
796 CurrentTest = new Test (inf->test_name); //mock-up to keep ReportFailure happy
797 ReportFailure (x.file, x.line, stream.str ());
798 delete CurrentTest;
799 CurrentTest = 0;
800 }
801 catch (const std::exception& e)
802 {
803 std::stringstream stream;
804 stream << "Unhandled exception: " << e.what ()
805 << " while setting up test " << inf->test_name;
806 CurrentTest = new Test (inf->test_name); //mock-up to keep ReportFailure happy
807 ReportFailure (inf->file_name, inf->line, stream.str ());
808 delete CurrentTest;
809 CurrentTest = 0;
810 }
811 catch (...)
812 {
813 std::stringstream stream;
814 stream << "Setup unhandled exception while setting up test " << inf->test_name;
815 CurrentTest = new Test (inf->test_name); //mock-up to keep ReportFailure happy
816 ReportFailure (inf->file_name, inf->line, stream.str ());
817 delete CurrentTest;
818 CurrentTest = 0;
819 }
820 return ok;
821}
822
824inline
825void TestSuite::RunCurrentTest (const Inserter* inf)
826{
827 assert (CurrentTest);
828 CurrentReporter->TestStart (*CurrentTest);
829
830
831 try {
832 CurrentTest->run ();
833 }
834 catch (UnitTest::test_abort& x)
835 {
836 ReportFailure (x.file, x.line, std::string ("Test aborted: ") + x.what ());
837 }
838 catch (const std::exception& e)
839 {
840 std::stringstream stream;
841 stream << "Unhandled exception: " << e.what ()
842 << " while running test " << inf->test_name;
843 ReportFailure (inf->file_name, inf->line, stream.str ());
844 }
845 catch (...)
846 {
847 std::stringstream stream;
848 stream << "Unhandled exception while running test " << inf->test_name;
849 ReportFailure (inf->file_name, inf->line, stream.str ());
850 }
851
852 int actual_time = CurrentTest->test_time_ms ();
853 if (CurrentTest->is_time_constraint () && max_runtime && actual_time > max_runtime)
854 {
855 std::stringstream stream;
856 stream << "Global time constraint failed while running test " << inf->test_name
857 << " Expected under " << max_runtime
858 << "ms but took " << actual_time << "ms.";
859
860 ReportFailure (inf->file_name, inf->line, stream.str ());
861 }
862 CurrentReporter->TestFinish (*CurrentTest);
863}
864
866inline
867void TestSuite::TearDownCurrentTest (const Inserter* inf)
868{
869 try {
870 delete CurrentTest;
871 CurrentTest = 0;
872 }
873 catch (const std::exception& e)
874 {
875 std::stringstream stream;
876 stream << "Unhandled exception: " << e.what ()
877 << " while tearing down test " << inf->test_name;
878 ReportFailure (inf->file_name, inf->line, stream.str ());
879 }
880 catch (...)
881 {
882 std::stringstream stream;
883 stream << "Unhandled exception tearing down test " << inf->test_name;
884 ReportFailure (inf->file_name, inf->line, stream.str ());
885 }
886}
887
889inline
891{
892 return enabled;
893}
894
896inline
897void TestSuite::Enable (bool on_off)
898{
899 enabled = on_off;
900}
901
902//------------------ TestSuite::Inserter --------------------------------------
913inline
914TestSuite::Inserter::Inserter (const std::string& suite, const std::string& test,
915 const std::string& file, int ln, Testmaker func)
916 : test_name (test)
917 , file_name (file)
918 , line (ln)
919 , maker (func)
920{
921 SuitesList::GetSuitesList ().Add (suite, this);
922}
923
924//-----------------Timer member functions -------------------------------------
925inline
926Timer::Timer ()
927 : startTime (std::chrono::steady_clock::now())
928{
929}
930
932inline
934{
935 startTime = std::chrono::steady_clock::now ();
936}
937
939inline
941{
942 auto elapsedTime = std::chrono::steady_clock::now () - startTime;
943 return (int)std::chrono::duration_cast<std::chrono::milliseconds>
944 (elapsedTime).count ();
945}
946
948inline
949long long Timer::GetTimeInUs () const
950{
951 auto elapsedTime = std::chrono::steady_clock::now () - startTime;
952 return std::chrono::duration_cast<std::chrono::microseconds>(elapsedTime).count ();
953}
954
956inline
957void SleepMs (int const ms)
958{
959#ifdef _WIN32
960 ::Sleep (ms);
961#else
962 usleep (static_cast<useconds_t>(ms * 1000));
963#endif
964}
965
966//------------------TimeConstraint member functions ---------------------------
967
977inline
978TimeConstraint::TimeConstraint (int ms, const char* file, int line)
979 : filename (file)
980 , line_number (line)
981 , max_ms (ms)
982{
983 timer.Start ();
984}
985
990inline
992{
993 int t = timer.GetTimeInMs ();
994 if (t > max_ms)
995 {
996 std::stringstream stream;
997 stream << "Time constraint failed. Expected to run test under " << max_ms <<
998 "ms but took " << t << "ms.";
999
1000 ReportFailure (filename, line_number, stream.str ());
1001 }
1002}
1003
1004
1005//-------------------SuitesList member functions ------------------------------
1006
1015inline
1016void SuitesList::Add (const std::string& suite_name, const TestSuite::Inserter* inf)
1017{
1018 auto p = suites.begin ();
1019 while (p != suites.end () && p->name != suite_name)
1020 p++;
1021
1022 if (p == suites.end ())
1023 {
1024 suites.emplace_back (suite_name);
1025 suites.back ().Add (inf);
1026 }
1027 else
1028 p->Add (inf);
1029}
1030
1040inline
1041int SuitesList::Run (const std::string& suite_name, Reporter& reporter, int max_time_ms)
1042{
1043 for (auto& s : suites)
1044 {
1045 if (s.name == suite_name)
1046 {
1047 s.RunTests (reporter, max_time_ms);
1048 return reporter.Summary ();
1049 }
1050 }
1051 return -1;
1052}
1053
1061inline
1062int SuitesList::RunAll (Reporter& reporter, int max_time_ms)
1063{
1064 for (auto& s : suites)
1065 {
1066 if (s.IsEnabled ())
1067 s.RunTests (reporter, max_time_ms);
1068 }
1069
1070 return reporter.Summary ();
1071}
1072
1077inline
1079{
1080 static SuitesList all_suites;
1081 return all_suites;
1082}
1083
1091inline
1092void SuitesList::Enable (const std::string& suite, bool enable)
1093{
1094 for (auto& s : suites)
1095 {
1096 if (s.name == suite)
1097 {
1098 s.Enable (enable);
1099 break;
1100 }
1101 }
1102}
1103
1105
1119inline
1120int RunAllTests (Reporter& rpt, int max_time_ms)
1121{
1122 rpt.Clear ();
1123 return SuitesList::GetSuitesList ().RunAll (rpt, max_time_ms);
1124}
1125
1137inline
1138int RunSuite (const char* suite_name, Reporter& rpt, int max_time_ms)
1139{
1140 return SuitesList::GetSuitesList ().Run (suite_name, rpt, max_time_ms);
1141}
1142
1151inline
1152void DisableSuite (const std::string& suite_name)
1153{
1154 SuitesList::GetSuitesList ().Enable (suite_name, false);
1155}
1156
1164inline
1165void EnableSuite (const std::string& suite_name)
1166{
1167 SuitesList::GetSuitesList ().Enable (suite_name, true);
1168}
1169
1179inline
1180void ReportFailure(const std::string& filename, int line, const std::string& message)
1181{
1182 if (CurrentTest)
1183 CurrentTest->failure();
1184 Failure f = { filename, message, line };
1185 CurrentReporter->ReportFailure(f);
1186}
1187
1188} // end of UnitTest namespace
1189
1190
1195inline
1196const char* GetSuiteName ()
1197{
1198 return DEFAULT_SUITE;
1199}
1200
1201#include "reporter_stream.h"
1202#include "reporter_xml.h"
1203#ifdef _WIN32
1204#include "reporter_dbgout.h"
1205#endif
1206#include "checks.h"
1207
1209inline
1211{
1212 static UnitTest::ReporterStream the_default_reporter;
1213 return the_default_reporter;
1214}
1215
1216#if (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) \
1217 || (!defined(_MSVC_LANG) && (__cplusplus >= 201703L))
1218// In C++ 17 and later we have inline data. TEST_MAIN is not really needed.
1221inline std::string UnitTest::CurrentSuite;
1222#endif
Definition of Check... template functions and CHECK_... macro-definitions.
void Clear() override
Reset all statistics.
Definition utpp.h:709
void TestStart(const Test &test) override
Definition utpp.h:679
std::deque< TestResult > results
Results of all tests.
Definition utpp.h:354
void ReportFailure(const Failure &failure) override
Definition utpp.h:690
void SuiteStart(const TestSuite &suite) override
Definition utpp.h:667
void TestFinish(const Test &test) override
Definition utpp.h:703
Abstract base for all reporters.
Definition utpp.h:285
virtual void Clear()
Reset all statistics.
Definition utpp.h:627
int suites_count
number of suites ran
Definition utpp.h:325
int suite_failures_count
number of failures in suite
Definition utpp.h:317
int total_failures_count
total number of failures
Definition utpp.h:322
int suite_test_count
number of tests in suite
Definition utpp.h:315
virtual void SuiteStart(const TestSuite &suite)
Invoked at the beginning of a test suite.
Definition utpp.h:584
virtual void TestStart(const Test &test)
Invoked at the beginning of a test.
Definition utpp.h:591
bool trace
true if tracing is enabled
Definition utpp.h:326
int suite_failed_count
number of failed tests in suite
Definition utpp.h:316
virtual void TestFinish(const Test &test)
Invoked at the end of a test.
Definition utpp.h:603
int suite_time_msec
total suite running time in milliseconds
Definition utpp.h:318
int total_test_count
total number of tests
Definition utpp.h:320
virtual void ReportFailure(const Failure &failure)
Called when a test has failed.
Definition utpp.h:598
virtual int Summary()
Generate results report.
Definition utpp.h:309
int total_failed_count
total number of failed tests
Definition utpp.h:321
virtual int SuiteFinish(const TestSuite &suite)
Invoked at the end of a test suite.
Definition utpp.h:620
int total_time_msec
total running time in milliseconds
Definition utpp.h:323
void SetTrace(bool on_off)
Controls test tracing feature.
Definition utpp.h:291
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:437
void Add(const std::string &suite, const TestSuite::Inserter *inf)
Definition utpp.h:1016
void Enable(const std::string &suite, bool enable=true)
Definition utpp.h:1092
int RunAll(Reporter &reporter, int max_time_ms)
Definition utpp.h:1062
static SuitesList & GetSuitesList()
Definition utpp.h:1078
int Run(const std::string &suite, Reporter &reporter, int max_time_ms)
Definition utpp.h:1041
Representation of a test case.
Definition utpp.h:245
int failures
Number of failures in this test.
Definition utpp.h:264
void run()
Definition utpp.h:513
void failure()
Definition utpp.h:526
const std::string & test_name() const
Return test name.
Definition utpp.h:547
int failure_count() const
Return the number of failures in this test.
Definition utpp.h:533
int test_time_ms() const
Return test running time in milliseconds.
Definition utpp.h:540
virtual void RunImpl()
Actual body of test.
Definition utpp.h:260
Test(const std::string &testName)
Constructor.
Definition utpp.h:499
int time
Run time.
Definition utpp.h:265
bool is_time_constraint() const
Return true if test must be run under global time constraints.
Definition utpp.h:561
std::string name
Name of this test.
Definition utpp.h:263
bool time_exempt
true if exempt from time constraints
Definition utpp.h:266
void no_time_constraint()
Flags the test as exempt from global time constraint.
Definition utpp.h:554
Constructor of this objects inserts the test in suite.
Definition utpp.h:371
Inserter(const std::string &suite, const std::string &test, const std::string &file, int line, Testmaker func)
Definition utpp.h:914
Definition utpp.h:367
std::string name
Suite name.
Definition utpp.h:394
bool IsEnabled() const
Returns true if suite is enabled.
Definition utpp.h:890
void Add(const Inserter *inf)
Definition utpp.h:735
int RunTests(Reporter &reporter, int max_runtime_ms)
Definition utpp.h:750
void Enable(bool on_off)
Enables or disables this suite.
Definition utpp.h:897
~TimeConstraint()
Definition utpp.h:991
TimeConstraint(int ms, const char *file, int line)
Definition utpp.h:978
An object that can be interrogated to get elapsed time.
Definition utpp.h:408
void Start()
Record starting time.
Definition utpp.h:933
int GetTimeInMs() const
Return elapsed time in milliseconds since the starting time.
Definition utpp.h:940
long long GetTimeInUs() const
Return elapsed time in microseconds since the starting time.
Definition utpp.h:949
int RunAllTests(Reporter &rpt=GetDefaultReporter(), int max_time_ms=0)
Run all tests from all test suites.
Definition utpp.h:1120
void EnableSuite(const std::string &suite_name)
Enable a test suite.
Definition utpp.h:1165
int RunSuite(const char *suite_name, Reporter &rpt=GetDefaultReporter(), int max_time_ms=0)
Run all tests from one suite.
Definition utpp.h:1138
void DisableSuite(const std::string &suite_name)
Disable a test suite.
Definition utpp.h:1152
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:276
int line_number
Line number where the failure has occurred.
Definition utpp.h:279
std::string message
Description of failure.
Definition utpp.h:278
std::string filename
Name of file where a failure has occurred.
Definition utpp.h:277
Test results including all failure messages
Definition utpp.h:344
std::deque< Failure > failures
All failures of a test.
Definition utpp.h:351
std::string suite_name
suite name
Definition utpp.h:348
std::string test_name
test name
Definition utpp.h:349
TestResult()
Default constructor needed container inclusion.
Definition utpp.h:645
int test_time_ms
test running time in milliseconds
Definition utpp.h:350
Exception thrown by ABORT macro.
Definition utpp.h:452
UnitTest::Test *(* Testmaker)()
Function pointer to a function that creates a test object.
Definition utpp.h:358
#define DEFAULT_SUITE
Name of default suite.
Definition utpp.h:59
void ReportFailure(const std::string &filename, int line, const std::string &message)
Main error reporting function.
Definition utpp.h:1180
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:957
Reporter & GetDefaultReporter()
Return the default reporter object.
Definition utpp.h:1210
const size_t MAX_MESSAGE_SIZE
Maximum size of message buffer for ..._EX macro definitions.
Definition utpp.h:55
const char * GetSuiteName()
Definition utpp.h:1196