Skip to content

Commit 7b9e3a1

Browse files
committed
r22 | charles.nicholson | 2010-03-18 18:39:32 -0500 (Thu, 18 Mar 2010) | 1 line
negate config flags and comment them out by default; this allows command-line preprocessor symbol injection to control flags. Useful for having a master copy of utpp that build with different flags for different compilers/platforms
1 parent 909f4b2 commit 7b9e3a1

24 files changed

+65
-51
lines changed

config.h

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,29 @@
2727
#define UNITTEST_MINGW
2828
#endif
2929

30-
// by default, MemoryOutStream is implemented in terms of std::ostringstream, which can be expensive.
31-
// uncomment this line to use the custom MemoryOutStream (no deps on std::ostringstream).
3230

33-
#define UNITTEST_USE_CUSTOM_STREAMS
34-
#define UNITTEST_USE_DEFERRED_REPORTER
35-
#define UNITTEST_USE_EXCEPTIONS
31+
// MemoryOutStream is a custom reimplementation of parts of std::ostringstream.
32+
// Uncomment this line to have MemoryOutStream implemented in terms of std::ostringstream.
33+
// This is useful if you are using the CHECK macros on objects that have something like this defined:
34+
// std::ostringstream& operator<<(std::ostringstream& s, const YourObject& value)
35+
36+
//#define UNITTEST_MEMORYOUTSTREAM_IS_STD_OSTRINGSTREAM
37+
38+
39+
// DeferredTestReporter uses the STL to collect test results for subsequent export by reporters like
40+
// XmlTestReporter. If you don't want to use this functionality, uncomment this line and no STL
41+
// headers or code will be compiled into UnitTest++
42+
43+
//#define UNITTEST_NO_DEFERRED_REPORTER
44+
45+
46+
// By default, asserts that you report via UnitTest::ReportAssert() abort the current test and
47+
// continue to the next one by throwing an exception, which unwinds the stack naturally, destroying
48+
// all auto variables on its way back down. If you don't want to (or can't) use exceptions for your
49+
// platform/compiler, uncomment this line. All exception code will be removed from UnitTest++,
50+
// assert recovery will be done via setjmp/longjmp, and NO correct stack unwinding will happen!
51+
52+
//#define UNITTEST_NO_EXCEPTIONS
53+
3654

3755
#endif

src/AssertException.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "AssertException.h"
22

3-
#ifdef UNITTEST_USE_EXCEPTIONS
3+
#ifndef UNITTEST_NO_EXCEPTIONS
44

55
namespace UnitTest {
66

src/AssertException.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define UNITTEST_ASSERTEXCEPTION_H
33

44
#include "../config.h"
5-
#ifdef UNITTEST_USE_EXCEPTIONS
5+
#ifndef UNITTEST_NO_EXCEPTIONS
66

77
#include "HelperMacros.h"
88
#include <exception>

src/CheckMacros.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@
114114
UNITTEST_MULTILINE_MACRO_END
115115

116116

117-
// CHECK_THROW and CHECK_ASSERT only exist when UNITTEST_USE_EXCEPTIONS is defined (see Config.h)
118-
#ifdef UNITTEST_USE_EXCEPTIONS
117+
// CHECK_THROW and CHECK_ASSERT only exist when UNITTEST_NO_EXCEPTIONS isn't defined (see config.h)
118+
#ifndef UNITTEST_NO_EXCEPTIONS
119119
#define CHECK_THROW(expression, ExpectedExceptionType) \
120120
UNITTEST_MULTILINE_MACRO_BEGIN \
121121
bool caught_ = false; \
@@ -134,4 +134,4 @@
134134
UnitTest::Detail::ExpectAssert(false); \
135135
UNITTEST_MULTILINE_MACRO_END
136136
#endif
137-
#endif
137+
#endif

src/DeferredTestReporter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "../config.h"
2-
#ifdef UNITTEST_USE_DEFERRED_REPORTER
2+
#ifndef UNITTEST_NO_DEFERRED_REPORTER
33

44
#include "DeferredTestReporter.h"
55
#include "TestDetails.h"

src/DeferredTestReporter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#include "../config.h"
55

6-
#ifdef UNITTEST_USE_DEFERRED_REPORTER
6+
#ifndef UNITTEST_NO_DEFERRED_REPORTER
77

88
#include "TestReporter.h"
99
#include "DeferredTestResult.h"

src/DeferredTestResult.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "../config.h"
2-
#ifdef UNITTEST_USE_DEFERRED_REPORTER
2+
#ifndef UNITTEST_NO_DEFERRED_REPORTER
33

44
#include "DeferredTestResult.h"
55
#include <cstring>

src/DeferredTestResult.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define UNITTEST_DEFERREDTESTRESULT_H
33

44
#include "../config.h"
5-
#ifdef UNITTEST_USE_DEFERRED_REPORTER
5+
#ifndef UNITTEST_NO_DEFERRED_REPORTER
66

77
#include "HelperMacros.h"
88
#include <string>

src/ExceptionMacros.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#include "../config.h"
55

6-
#ifdef UNITTEST_USE_EXCEPTIONS
6+
#ifndef UNITTEST_NO_EXCEPTIONS
77
#define UT_TRY(x) try x
88
#define UT_THROW(x) throw x
99
#define UT_CATCH(ExceptionType, ExceptionName, CatchBody) catch(ExceptionType& ExceptionName) CatchBody

src/ExecuteTest.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include "AssertException.h"
1010
#include "CurrentTest.h"
1111

12-
#ifndef UNITTEST_USE_EXCEPTIONS
12+
#ifdef UNITTEST_NO_EXCEPTIONS
1313
#include "ReportAssertImpl.h"
1414
#endif
1515

@@ -25,7 +25,7 @@ void ExecuteTest(T& testObject, TestDetails const& details, bool isMockTest)
2525
if (isMockTest == false)
2626
CurrentTest::Details() = &details;
2727

28-
#ifndef UNITTEST_USE_EXCEPTIONS
28+
#ifdef UNITTEST_NO_EXCEPTIONS
2929
if (UNITTEST_SET_ASSERT_JUMP_TARGET() == 0)
3030
{
3131
#endif
@@ -49,7 +49,7 @@ void ExecuteTest(T& testObject, TestDetails const& details, bool isMockTest)
4949
({
5050
CurrentTest::Results()->OnTestFailure(details, "Unhandled exception: test crashed");
5151
})
52-
#ifndef UNITTEST_USE_EXCEPTIONS
52+
#ifdef UNITTEST_NO_EXCEPTIONS
5353
}
5454
#endif
5555
}

src/MemoryOutStream.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,19 @@
11
#include "MemoryOutStream.h"
22

3-
#ifndef UNITTEST_USE_CUSTOM_STREAMS
4-
3+
#ifdef UNITTEST_MEMORYOUTSTREAM_IS_STD_OSTRINGSTREAM
54

65
namespace UnitTest {
76

87
char const* MemoryOutStream::GetText() const
98
{
10-
m_text = this->str();
11-
return m_text.c_str();
9+
m_text = this->str();
10+
return m_text.c_str();
1211
}
1312

14-
1513
}
1614

17-
1815
#else
1916

20-
2117
#include <cstring>
2218
#include <cstdio>
2319

src/MemoryOutStream.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include "../config.h"
55
#include "HelperMacros.h"
66

7-
#ifndef UNITTEST_USE_CUSTOM_STREAMS
7+
#ifdef UNITTEST_MEMORYOUTSTREAM_IS_STD_OSTRINGSTREAM
88

99
#include <sstream>
1010

src/ReportAssert.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include "TestResults.h"
66
#include "TestDetails.h"
77

8-
#ifndef UNITTEST_USE_EXCEPTIONS
8+
#ifdef UNITTEST_NO_EXCEPTIONS
99
#include "ReportAssertImpl.h"
1010
#endif
1111

@@ -28,7 +28,7 @@ UNITTEST_LINKAGE void ReportAssert(char const* description, char const* filename
2828

2929
namespace Detail {
3030

31-
#ifndef UNITTEST_USE_EXCEPTIONS
31+
#ifdef UNITTEST_NO_EXCEPTIONS
3232
jmp_buf* GetAssertJmpBuf()
3333
{
3434
static jmp_buf s_jmpBuf;
@@ -50,7 +50,7 @@ UNITTEST_LINKAGE void ReportAssertEx(TestResults* testResults,
5050

5151
ExpectAssert(false);
5252

53-
#ifdef UNITTEST_USE_EXCEPTIONS
53+
#ifndef UNITTEST_NO_EXCEPTIONS
5454
throw AssertException();
5555
#else
5656
UNITTEST_JUMP_TO_ASSERT_JUMP_TARGET();

src/ReportAssertImpl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#include "../config.h"
55

6-
#ifndef UNITTEST_USE_EXCEPTIONS
6+
#ifdef UNITTEST_NO_EXCEPTIONS
77
#include <csetjmp>
88
#endif
99

@@ -24,7 +24,7 @@ UNITTEST_LINKAGE void ReportAssertEx(TestResults* testResults,
2424

2525
UNITTEST_LINKAGE bool AssertExpected();
2626

27-
#ifndef UNITTEST_USE_EXCEPTIONS
27+
#ifdef UNITTEST_NO_EXCEPTIONS
2828
UNITTEST_LINKAGE jmp_buf* GetAssertJmpBuf();
2929

3030
#ifdef UNITTEST_WIN32

src/XmlTestReporter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "../config.h"
2-
#ifdef UNITTEST_USE_DEFERRED_REPORTER
2+
#ifndef UNITTEST_NO_DEFERRED_REPORTER
33

44
#include "XmlTestReporter.h"
55

src/XmlTestReporter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define UNITTEST_XMLTESTREPORTER_H
33

44
#include "../config.h"
5-
#ifdef UNITTEST_USE_DEFERRED_REPORTER
5+
#ifndef UNITTEST_NO_DEFERRED_REPORTER
66

77
#include "DeferredTestReporter.h"
88

src/tests/TestAssertHandler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ TEST(CanSetAssertExpected)
2121
CHECK(!Detail::AssertExpected());
2222
}
2323

24-
#ifdef UNITTEST_USE_EXCEPTIONS
24+
#ifndef UNITTEST_NO_EXCEPTIONS
2525

2626
TEST(ReportAssertThrowsAssertException)
2727
{

src/tests/TestDeferredTestReporter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "../../config.h"
22

3-
#ifdef UNITTEST_USE_DEFERRED_REPORTER
3+
#ifndef UNITTEST_NO_DEFERRED_REPORTER
44

55
#include "../../unittestpp.h"
66
#include "../DeferredTestReporter.h"
@@ -12,7 +12,7 @@ namespace UnitTest
1212
namespace
1313
{
1414

15-
#ifdef UNITTEST_USE_CUSTOM_STREAMS
15+
#ifndef UNITTEST_MEMORYOUTSTREAM_IS_STD_OSTRINGSTREAM
1616
MemoryOutStream& operator <<(MemoryOutStream& lhs, const std::string& rhs)
1717
{
1818
lhs << rhs.c_str();

src/tests/TestExceptions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "../../config.h"
2-
#ifdef UNITTEST_USE_EXCEPTIONS
2+
#ifndef UNITTEST_NO_EXCEPTIONS
33

44
#include "../../unittestpp.h"
55
#include "../CurrentTest.h"

src/tests/TestMemoryOutStream.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ TEST(StreamingSizeTWritesCorrectCharacters)
8787
CHECK_EQUAL("53124", stream.GetText());
8888
}
8989

90-
#ifdef UNITTEST_USE_CUSTOM_STREAMS
90+
#ifndef UNITTEST_MEMORYOUTSTREAM_IS_STD_OSTRINGSTREAM
9191

9292
TEST(StreamInitialCapacityIsCorrect)
9393
{

src/tests/TestTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ TEST(FailingTestHasFailures)
5050
CHECK_EQUAL(1, results.GetFailureCount());
5151
}
5252

53-
#ifdef UNITTEST_USE_EXCEPTIONS
53+
#ifndef UNITTEST_NO_EXCEPTIONS
5454
TEST(ThrowingTestsAreReportedAsFailures)
5555
{
5656
class CrashingTest : public Test

src/tests/TestTestMacros.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ TEST (TestsAreAddedToTheListThroughMacro)
2222
CHECK(list1.GetHead()->m_nextTest == 0);
2323
}
2424

25-
#ifdef UNITTEST_USE_EXCEPTIONS
25+
#ifndef UNITTEST_NO_EXCEPTIONS
2626

2727
struct ThrowingThingie
2828
{
@@ -108,7 +108,7 @@ TEST(TestAddedWithTEST_FIXTURE_EXMacroGetsDefaultSuite)
108108
CHECK_EQUAL ("DefaultSuite", macroTestList2.GetHead()->m_details.suiteName);
109109
}
110110

111-
#ifdef UNITTEST_USE_EXCEPTIONS
111+
#ifndef UNITTEST_NO_EXCEPTIONS
112112

113113
struct FixtureCtorThrows
114114
{

src/tests/TestUnitTestPP.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ TEST(ArrayCloseSucceeds)
4444
CHECK_ARRAY_CLOSE(a1, a2, 3, 0.1f);
4545
}
4646

47-
#ifdef UNITTEST_USE_EXCEPTIONS
47+
#ifndef UNITTEST_NO_EXCEPTIONS
4848

4949
TEST(CheckThrowMacroSucceedsOnCorrectException)
5050
{

src/tests/TestXmlTestReporter.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "../../config.h"
2-
#ifdef UNITTEST_USE_DEFERRED_REPORTER
2+
#ifndef UNITTEST_NO_DEFERRED_REPORTER
33

44
#include "../../unittestpp.h"
55
#include "../XmlTestReporter.h"
@@ -12,7 +12,7 @@ using std::ostringstream;
1212
namespace
1313
{
1414

15-
#ifdef UNITTEST_USE_CUSTOM_STREAMS
15+
#ifndef UNITTEST_MEMORYOUTSTREAM_IS_STD_OSTRINGSTREAM
1616

1717
// Overload to let MemoryOutStream accept std::string
1818
MemoryOutStream& operator<<(MemoryOutStream& s, const std::string& value)
@@ -73,9 +73,9 @@ TEST_FIXTURE(XmlTestReporterFixture, EmptyReportSummaryFormat)
7373
reporter.ReportSummary(0, 0, 0, 0.1f);
7474

7575
const char *expected =
76-
"<?xml version=\"1.0\"?>"
77-
"<unittest-results tests=\"0\" failedtests=\"0\" failures=\"0\" time=\"0.1\">"
78-
"</unittest-results>";
76+
"<?xml version=\"1.0\"?>"
77+
"<unittest-results tests=\"0\" failedtests=\"0\" failures=\"0\" time=\"0.1\">"
78+
"</unittest-results>";
7979

8080
CHECK_EQUAL(expected, output.str());
8181
}
@@ -88,10 +88,10 @@ TEST_FIXTURE(XmlTestReporterFixture, SingleSuccessfulTestReportSummaryFormat)
8888
reporter.ReportSummary(1, 0, 0, 0.1f);
8989

9090
const char *expected =
91-
"<?xml version=\"1.0\"?>"
92-
"<unittest-results tests=\"1\" failedtests=\"0\" failures=\"0\" time=\"0.1\">"
93-
"<test suite=\"DefaultSuite\" name=\"TestName\" time=\"0\"/>"
94-
"</unittest-results>";
91+
"<?xml version=\"1.0\"?>"
92+
"<unittest-results tests=\"1\" failedtests=\"0\" failures=\"0\" time=\"0.1\">"
93+
"<test suite=\"DefaultSuite\" name=\"TestName\" time=\"0\"/>"
94+
"</unittest-results>";
9595

9696
CHECK_EQUAL(expected, output.str());
9797
}

0 commit comments

Comments
 (0)