Skip to content

Commit cc3fbd8

Browse files
committed
Merge pull request #43 from martinmoene/master
Add changes required to compile with MS VC6
2 parents 49fb0ce + 65d2e03 commit cc3fbd8

File tree

7 files changed

+82
-11
lines changed

7 files changed

+82
-11
lines changed

UnitTest++/Config.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
#pragma warning(disable:4702) // unreachable code
88
#pragma warning(disable:4722) // destructor never returns, potential memory leak
99

10-
#if (_MSC_VER == 1200) // VC6
10+
#if (_MSC_VER == 1200) // VC6
11+
#define UNITTEST_COMPILER_IS_MSVC6
1112
#pragma warning(disable:4786)
1213
#pragma warning(disable:4290)
1314
#endif
@@ -60,4 +61,13 @@
6061

6162
//#define UNITTEST_NO_EXCEPTIONS
6263

64+
65+
// std namespace qualification: used for functions like strcpy that
66+
// may live in std:: namespace (cstring header).
67+
#if defined( UNITTEST_COMPILER_IS_MSVC6 )
68+
#define UNIITEST_NS_QUAL_STD(x) x
69+
#else
70+
#define UNIITEST_NS_QUAL_STD(x) ::std::x
71+
#endif
72+
6373
#endif

UnitTest++/DeferredTestResult.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ DeferredTestFailure::DeferredTestFailure()
1616
DeferredTestFailure::DeferredTestFailure(int lineNumber_, const char* failureStr_)
1717
: lineNumber(lineNumber_)
1818
{
19-
std::strcpy(failureStr, failureStr_);
19+
UNIITEST_NS_QUAL_STD(strcpy)(failureStr, failureStr_);
2020
}
2121

2222
DeferredTestResult::DeferredTestResult()

UnitTest++/HelperMacros.h

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

66
#define UNITTEST_MULTILINE_MACRO_BEGIN do {
77

8-
#ifdef UNITTEST_WIN32
8+
#if defined(UNITTEST_WIN32) && !defined(UNITTEST_COMPILER_IS_MSVC6)
99
#define UNITTEST_MULTILINE_MACRO_END \
1010
} __pragma(warning(push)) __pragma(warning(disable:4127)) while (0) __pragma(warning(pop))
1111
#else

UnitTest++/MemoryOutStream.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,33 @@ void MemoryOutStream::Clear()
1616
m_text = this->str();
1717
}
1818

19+
#ifdef UNITTEST_COMPILER_IS_MSVC6
20+
21+
#define snprintf _snprintf
22+
23+
template<typename ValueType>
24+
std::ostream& FormatToStream(std::ostream& stream, char const* format, ValueType const& value)
25+
{
26+
using namespace std;
27+
28+
const size_t BUFFER_SIZE=32;
29+
char txt[BUFFER_SIZE];
30+
snprintf(txt, BUFFER_SIZE, format, value);
31+
return stream << txt;
32+
}
33+
34+
std::ostream& operator<<(std::ostream& stream, __int64 const n)
35+
{
36+
return FormatToStream(stream, "%I64d", n);
37+
}
38+
39+
std::ostream& operator<<(std::ostream& stream, unsigned __int64 const n)
40+
{
41+
return FormatToStream(stream, "%I64u", n);
42+
}
43+
44+
#endif
45+
1946
}
2047

2148
#else
@@ -108,7 +135,11 @@ MemoryOutStream& MemoryOutStream::operator <<(unsigned long const n)
108135
return *this;
109136
}
110137

138+
#ifdef UNITTEST_COMPILER_IS_MSVC6
139+
MemoryOutStream& MemoryOutStream::operator <<(__int64 const n)
140+
#else
111141
MemoryOutStream& MemoryOutStream::operator <<(long long const n)
142+
#endif
112143
{
113144
#ifdef UNITTEST_WIN32
114145
FormatToStream(*this, "%I64d", n);
@@ -119,7 +150,11 @@ MemoryOutStream& MemoryOutStream::operator <<(long long const n)
119150
return *this;
120151
}
121152

153+
#ifdef UNITTEST_COMPILER_IS_MSVC6
154+
MemoryOutStream& MemoryOutStream::operator <<(unsigned __int64 const n)
155+
#else
122156
MemoryOutStream& MemoryOutStream::operator <<(unsigned long long const n)
157+
#endif
123158
{
124159
#ifdef UNITTEST_WIN32
125160
FormatToStream(*this, "%I64u", n);

UnitTest++/MemoryOutStream.h

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,21 @@ class UNITTEST_LINKAGE MemoryOutStream : public std::ostringstream
2626
mutable std::string m_text;
2727
};
2828

29+
#ifdef UNITTEST_COMPILER_IS_MSVC6
30+
std::ostream& operator<<(std::ostream& stream, __int64 const n);
31+
std::ostream& operator<<(std::ostream& stream, unsigned __int64 const n);
32+
#endif
33+
2934
}
3035

3136
#else
3237

3338
#include <cstddef>
3439

40+
#ifdef UNITTEST_COMPILER_IS_MSVC6
41+
namespace std {}
42+
#endif
43+
3544
namespace UnitTest
3645
{
3746

@@ -47,10 +56,15 @@ class UNITTEST_LINKAGE MemoryOutStream
4756
MemoryOutStream& operator <<(char const* txt);
4857
MemoryOutStream& operator <<(int n);
4958
MemoryOutStream& operator <<(long n);
50-
MemoryOutStream& operator <<(long long n);
5159
MemoryOutStream& operator <<(unsigned long n);
52-
MemoryOutStream& operator <<(unsigned long long n);
53-
MemoryOutStream& operator <<(float f);
60+
#ifdef UNITTEST_COMPILER_IS_MSVC6
61+
MemoryOutStream& operator <<(__int64 n);
62+
MemoryOutStream& operator <<(unsigned __int64 n);
63+
#else
64+
MemoryOutStream& operator <<(long long n);
65+
MemoryOutStream& operator <<(unsigned long long n);
66+
#endif
67+
MemoryOutStream& operator <<(float f);
5468
MemoryOutStream& operator <<(double d);
5569
MemoryOutStream& operator <<(void const* p);
5670
MemoryOutStream& operator <<(unsigned int s);

tests/TestChecks.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ TEST(CheckCloseWithNaNFails)
150150
{
151151
const unsigned int bitpattern = 0xFFFFFFFF;
152152
float nan;
153-
std::memcpy(&nan, &bitpattern, sizeof(bitpattern));
153+
UNIITEST_NS_QUAL_STD(memcpy)(&nan, &bitpattern, sizeof(bitpattern));
154154

155155
TestResults results;
156156
CheckClose(results, 3.0f, nan, 0.1f, TestDetails("", "", "", 0));
@@ -161,7 +161,7 @@ TEST(CheckCloseWithNaNAgainstItselfFails)
161161
{
162162
const unsigned int bitpattern = 0xFFFFFFFF;
163163
float nan;
164-
std::memcpy(&nan, &bitpattern, sizeof(bitpattern));
164+
UNIITEST_NS_QUAL_STD(memcpy)(&nan, &bitpattern, sizeof(bitpattern));
165165

166166
TestResults results;
167167
CheckClose(results, nan, nan, 0.1f, TestDetails("", "", "", 0));

tests/TestMemoryOutStream.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,12 @@ TEST(StreamingMinUnsignedLongWritesCorrectCharacters)
170170
TEST(StreamingLongLongWritesCorrectCharacters)
171171
{
172172
MemoryOutStream stream;
173+
#ifdef UNITTEST_COMPILER_IS_MSVC6
174+
stream << (__int64)-12345i64;
175+
#else
173176
stream << (long long)-12345ll;
174-
CHECK_EQUAL("-12345", stream.GetText());
177+
#endif
178+
CHECK_EQUAL("-12345", stream.GetText());
175179
}
176180

177181
#ifdef LLONG_MAX
@@ -195,8 +199,12 @@ TEST(StreamingMinLongLongWritesCorrectCharacters)
195199
TEST(StreamingUnsignedLongLongWritesCorrectCharacters)
196200
{
197201
MemoryOutStream stream;
198-
stream << (unsigned long long)85899ull;
199-
CHECK_EQUAL("85899", stream.GetText());
202+
#ifdef UNITTEST_COMPILER_IS_MSVC6
203+
stream << (unsigned __int64)85899ui64;
204+
#else
205+
stream << (unsigned long long)85899ull;
206+
#endif
207+
CHECK_EQUAL("85899", stream.GetText());
200208
}
201209

202210
#ifdef ULLONG_MAX
@@ -211,7 +219,11 @@ TEST(StreamingMaxUnsignedLongLongWritesCorrectCharacters)
211219
TEST(StreamingMinUnsignedLongLongWritesCorrectCharacters)
212220
{
213221
MemoryOutStream stream;
222+
#ifdef UNITTEST_COMPILER_IS_MSVC6
223+
stream << (unsigned __int64)0ui64;
224+
#else
214225
stream << (unsigned long long)0ull;
226+
#endif
215227
CHECK_EQUAL("0", stream.GetText());
216228
}
217229

0 commit comments

Comments
 (0)